1 // Copyright (C) 2004-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MG_Hexotic_API.hxx"
26 #include <DriverGMF_Read.hxx>
27 #include <SMESH_Comment.hxx>
28 #include <SMESH_File.hxx>
29 #include <SMESH_MGLicenseKeyGen.hxx>
30 #include <Utils_SALOME_Exception.hxx>
40 #include <meshgems/meshgems.h>
41 #include <meshgems/hexa.h>
44 #define MESHGEMS_VERSION_HEX (MESHGEMS_VERSION_MAJOR << 16 | MESHGEMS_VERSION_MINOR << 8 | MESHGEMS_VERSION_PATCH)
45 #define MESHGEMS_215 (2 << 16 | 15 << 8 | 0)
47 struct MG_Hexotic_API::LibData
51 hexa_session_t * _session;
57 std::vector<double> _xyz;
58 std::vector<double> _nodeSize; // required nodes
59 std::vector<int> _edgeNodesTags;
61 std::vector<int> _triaNodesTags;
64 std::vector<int> _corners;
67 volatile bool& _cancelled_flag;
68 std::string _errorStr;
72 LibData( volatile bool & cancelled_flag, double& progress )
73 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _hexa_mesh(0),
74 _nbRequiredEdges(0), _nbRequiredTria(0),
75 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
78 // methods setting callbacks implemented after callback definitions
85 hexa_regain_mesh( _session, _hexa_mesh );
87 mesh_delete( _tria_mesh );
89 sizemap_delete( _sizemap );
91 hexa_session_delete( _session );
93 context_delete( _context );
102 void AddError( const char *txt )
110 const std::string& GetErrors()
115 void MG_Error(const char* txt="")
117 SMESH_Comment msg("\nMeshGems error. ");
119 AddError( msg.c_str() );
122 bool SetParam( const std::string& param, const std::string& value )
124 status_t ret = hexa_set_param( _session, param.c_str(), value.c_str() );
126 //std::cout << param << " = " << value << std::endl;
128 return ( ret == STATUS_OK );
133 return _cancelled_flag;
136 int ReadNbSubDomains()
139 status_t ret = mesh_get_subdomain_count( _hexa_mesh, & nb );
141 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
150 status_t ret = mesh_get_vertex_count( _hexa_mesh, & nb );
152 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
159 status_t ret = mesh_get_edge_count( _hexa_mesh, & nb );
161 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
168 status_t ret = mesh_get_triangle_count( _hexa_mesh, & nb );
170 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
177 status_t ret = mesh_get_quadrangle_count( _hexa_mesh, & nb );
179 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
186 status_t ret = mesh_get_tetrahedron_count( _hexa_mesh, & nb );
188 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
195 status_t ret = mesh_get_hexahedron_count( _hexa_mesh, & nb );
197 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
203 return _corners.size();
211 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
213 integer tag, seed_type, seed_idx, seed_orientation;
214 status_t ret = mesh_get_subdomain_description( _hexa_mesh, _count,
215 &tag, &seed_type, &seed_idx, &seed_orientation);
217 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
222 *ori = seed_orientation;
226 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
229 status_t ret = mesh_get_vertex_coordinates( _hexa_mesh, _count, coo );
230 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
236 integer isCorner = 0;
237 ret = mesh_get_vertex_corner_property( _hexa_mesh, _count, &isCorner);
238 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
240 _corners.push_back( _count );
245 void ReadEdgeNodes( int* node1, int* node2, int* domain )
248 status_t ret = mesh_get_edge_vertices( _hexa_mesh, _count, vtx);
249 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
254 ret = mesh_get_edge_tag( _hexa_mesh, _count, &tag );
255 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
262 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
265 status_t ret = mesh_get_triangle_vertices( _hexa_mesh, _count, vtx);
266 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
272 ret = mesh_get_triangle_tag( _hexa_mesh, _count, &tag );
273 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
280 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
283 status_t ret = mesh_get_quadrangle_vertices( _hexa_mesh, _count, vtx);
284 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
291 ret = mesh_get_quadrangle_tag( _hexa_mesh, _count, &tag );
292 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
299 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
302 status_t ret = mesh_get_tetrahedron_vertices( _hexa_mesh, _count, vtx);
303 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
310 ret = mesh_get_tetrahedron_tag( _hexa_mesh, _count, &tag );
311 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
318 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
319 int* node5, int* node6, int* node7, int* node8, int* domain )
322 status_t ret = mesh_get_hexahedron_vertices( _hexa_mesh, _count, vtx);
323 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
334 ret = mesh_get_hexahedron_tag( _hexa_mesh, _count, &tag );
335 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
342 void ReadCorner( int* node )
344 if ( _count <= ReadNbCorners() )
345 *node = _corners[ _count - 1 ];
352 void SetNbVertices( int nb )
354 _xyz.reserve( _xyz.capacity() + nb );
357 void SetNbEdges( int nb )
359 _edgeNodesTags.reserve( nb * 3 );
362 void SetNbTria( int nb )
364 _triaNodesTags.reserve( nb * 4 );
367 void SetNbReqVertices( int nb )
369 _nodeSize.reserve( nb );
372 void SetNbReqEdges( int nb )
374 _nbRequiredEdges = nb;
377 void SetNbReqTria( int nb )
379 _nbRequiredTria = nb;
382 void AddNode( double x, double y, double z, int /*domain*/ )
389 void AddSizeAtNode( double size )
391 _nodeSize.push_back( size );
394 void AddEdgeNodes( int node1, int node2, int domain )
396 _edgeNodesTags.push_back( node1 );
397 _edgeNodesTags.push_back( node2 );
398 _edgeNodesTags.push_back( domain );
401 void AddTriaNodes( int node1, int node2, int node3, int domain )
403 _triaNodesTags.push_back( node1 );
404 _triaNodesTags.push_back( node2 );
405 _triaNodesTags.push_back( node3 );
406 _triaNodesTags.push_back( domain );
411 return _xyz.size() / 3;
414 double* NodeCoord( int iNode )
416 return & _xyz[ iNode * 3 ];
421 return _edgeNodesTags.size() / 3;
424 int* GetEdgeNodes( int iEdge )
426 return & _edgeNodesTags[ iEdge * 3 ];
429 int GetEdgeTag( int iEdge )
431 return _edgeNodesTags[ iEdge * 3 + 2 ];
436 return _triaNodesTags.size() / 4;
439 int * GetTriaNodes( int iTria )
441 return & _triaNodesTags[ iTria * 4 ];
444 int GetTriaTag( int iTria )
446 return _triaNodesTags[ iTria * 4 + 3 ];
449 int IsVertexRequired( int iNode )
451 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
454 double GetSizeAtVertex( int iNode )
456 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
460 namespace // functions called by MG library to exchange with the application
462 status_t get_vertex_count(integer * nbvtx, void *user_data)
464 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
465 *nbvtx = data->NbNodes();
470 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
472 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
473 double* coord = data->NodeCoord( ivtx-1 );
474 for (int j = 0; j < 3; j++)
479 status_t get_edge_count(integer * nbedge, void *user_data)
481 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
482 *nbedge = data->NbEdges();
487 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
489 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
490 int* nodes = data->GetEdgeNodes( iedge-1 );
497 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
499 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
500 * tag = data->GetEdgeTag( iedge-1 );
505 status_t get_triangle_count(integer * nbtri, void *user_data)
507 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
508 *nbtri = data->NbTriangles();
513 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
515 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
516 int* nodes = data->GetTriaNodes( itri-1 );
524 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
526 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
527 * tag = data->GetTriaTag( itri-1 );
532 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
533 // integer * evtri, void *user_data)
536 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
539 // /* We want to describe a linear "3 nodes" triangle */
540 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
542 // /* We want to describe a quadratic "6 nodes" triangle */
543 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
544 // for (j = 0; j < 3; j++)
545 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
551 // status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
553 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
555 // *nbtetra = 0; /* the number of tetra in your input mesh (0 if you describe a surface mesh) */
560 // status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
564 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
566 // for (j = 0; j < 4; j++)
567 // vtetra[j] = 0; /* the j'th vertex index of the itetra'th tetrahedron */
572 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
574 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
575 *rvtx = data->IsVertexRequired( ivtx - 1 );
580 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
582 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
583 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
588 status_t my_message_cb(message_t * msg, void *user_data)
591 message_get_description(msg, &desc);
593 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
594 data->AddError( desc );
597 //std::cout << desc << std::endl;
601 // corresponding messages are:
602 // " | Analyzing the surface mesh |" => 1 %
603 // " | Building and conforming the octree |" => 8 %
604 // " | Subdomains and boundary recovery |" => 15%
605 // " | Mesh bending and smoothing |" => 45%
606 // " | Final mesh statistics |" => 99%
608 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
609 if ( strlen( desc ) > 25 )
611 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
612 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
613 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
614 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
615 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
616 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
617 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
618 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
619 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
622 data->_progress = std::max( data->_progress, newProgress );
627 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
629 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
630 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
638 void MG_Hexotic_API::LibData::Init()
642 // Create the meshgems working context
643 _context = context_new();
644 if ( !_context ) MG_Error( "unable to create a new context" );
646 // Set the message callback for the _context.
647 ret = context_set_message_callback( _context, my_message_cb, this );
648 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
650 // Create the structure holding the callbacks giving access to triangle mesh
651 _tria_mesh = mesh_new( _context );
652 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
654 // Set callbacks to provide triangle mesh data
655 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
656 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
657 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
658 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
659 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
660 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
661 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
662 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
663 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
665 // Create a hexa session
666 _session = hexa_session_new( _context );
667 if ( !_session ) MG_Error( "unable to create a new hexa session");
669 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
670 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
674 bool MG_Hexotic_API::LibData::Compute()
677 std::string errorTxt;
680 #if MESHGEMS_VERSION_HEX > MESHGEMS_215
681 // unlock Hexa license only once
682 std::string SPATIAL_LICENSE = SMESHUtils_MGLicenseKeyGen::GetKey(errorTxt);
683 ret = meshgems_hexa_unlock_product(SPATIAL_LICENSE.c_str());
684 if STATUS_IS_ERROR( ret )
686 AddError( SMESH_Comment( "Problem with SPATIAL_LICENSE to unlock Hexa: ") << errorTxt );
690 MESSAGE("SPATIAL_LICENSE unlock Hexa: " << ret);
692 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
694 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
700 ret = hexa_set_surface_mesh( _session, _tria_mesh );
701 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
704 if ( !_nodeSize.empty() )
706 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
707 (void*) &get_vertex_weight, this );
708 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
710 ret = hexa_set_sizemap( _session, _sizemap );
711 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
714 //////////////////////////////////////////////////////////////////////////////////////////
715 // const char* file = "/tmp/ghs3d_IN.mesh";
716 // mesh_write_mesh( _tria_mesh,file);
717 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
719 ret = hexa_compute_mesh( _session );
720 if ( ret != STATUS_OK ) return false;
722 ret = hexa_get_mesh( _session, &_hexa_mesh);
723 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
725 //////////////////////////////////////////////////////////////////////////////////////////
726 // file = "/tmp/ghs3d_OUT.mesh";
727 // mesh_write_mesh( _hexa_mesh,file);
728 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
733 #else // ifdef USE_MG_LIBS
735 struct MG_Hexotic_API::LibData // to avoid compiler warnings
737 volatile bool& _cancelled_flag;
739 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
742 #endif // ifdef USE_MG_LIBS
745 //================================================================================
749 //================================================================================
751 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress):
752 _isMesh(true), _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
755 _libData = new LibData( cancelled_flag, progress );
759 if ( getenv("MG_HEXA_USE_EXE"))
764 //================================================================================
768 //================================================================================
770 MG_Hexotic_API::~MG_Hexotic_API()
776 std::set<int>::iterator id = _openFiles.begin();
777 for ( ; id != _openFiles.end(); ++id )
778 ::GmfCloseMesh( *id );
782 //================================================================================
784 * \brief Return the way of MG usage
786 //================================================================================
788 bool MG_Hexotic_API::IsLibrary()
793 //================================================================================
795 * \brief Switch to usage of MG-Hexa executable
797 //================================================================================
799 void MG_Hexotic_API::SetUseExecutable()
804 //================================================================================
806 * \brief Compute the hexa mesh
807 * \param [in] cmdLine - a command to run mg_hexa.exe
808 * \return bool - Ok or not
810 //================================================================================
812 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
818 std::istringstream strm( cmdLine );
819 std::istream_iterator<std::string> sIt( strm ), sEnd;
820 std::vector< std::string > args( sIt, sEnd );
823 std::string param, value;
824 for ( size_t i = 1; i < args.size(); ++i )
826 // look for a param name; it starts from "-"
828 if ( param.size() < 2 || param[0] != '-')
830 while ( param[0] == '-')
831 param = param.substr( 1 );
834 while ( i+1 < args.size() && args[i+1][0] != '-' )
836 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
838 if ( !value.empty() ) value += " ";
841 if ( !_libData->SetParam( param, value ))
842 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
846 bool ok = _libData->Compute();
848 GetLog(); // write a log file
849 _logFile = ""; // not to write it again
854 // add MG license key
856 std::string errorTxt, meshIn;
857 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
858 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
862 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
867 const_cast< std::string& >( cmdLine ) += " --key " + key;
870 int err = system( cmdLine.c_str() ); // run
873 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
874 << strerror( errno );
880 //================================================================================
882 * \brief Prepare for reading a mesh data
884 //================================================================================
886 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
893 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
894 _openFiles.insert( id );
898 //================================================================================
900 * \brief Return nb of entities
902 //================================================================================
904 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
910 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
911 case GmfVertices: return _libData->ReadNbNodes();
912 case GmfEdges: return _libData->ReadNbEdges();
913 case GmfTriangles: return _libData->ReadNbTria();
914 case GmfQuadrilaterals: return _libData->ReadNbQuads();
915 case GmfTetrahedra: return _libData->ReadNbTetra();
916 case GmfHexahedra: return _libData->ReadNbHexa();
917 case GmfCorners: return _libData->ReadNbCorners();
923 return ::GmfStatKwd( iMesh, what );
926 //================================================================================
928 * \brief Prepare for reading some data
930 //================================================================================
932 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
936 _libData->ResetCounter();
940 ::GmfGotoKwd( iMesh, what );
943 //================================================================================
945 * \brief Return index of a domain identified by a triangle normal
946 * \param [in] iMesh - mesh file index
947 * \param [in] what - must be GmfSubDomainFromGeom
948 * \param [out] nbNodes - nb nodes in a face
949 * \param [out] faceInd - face index
950 * \param [out] ori - face orientation
951 * \param [out] domain - domain index
952 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
955 //================================================================================
957 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
961 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
965 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
968 //================================================================================
970 * \brief Return coordinates of a next node
972 //================================================================================
974 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
975 double* x, double* y, double *z, int* domain )
979 _libData->ReadNodeXYZ( x, y, z, domain );
983 ::GmfGetLin(iMesh, what, x, y, z, domain );
986 //================================================================================
988 * \brief Return coordinates of a next node
990 //================================================================================
992 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
993 float* x, float* y, float *z, int* domain )
998 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
1005 ::GmfGetLin(iMesh, what, x, y, z, domain );
1008 //================================================================================
1010 * \brief Return node index of a next corner
1012 //================================================================================
1014 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
1018 _libData->ReadCorner( node );
1022 ::GmfGetLin(iMesh, what, node );
1025 //================================================================================
1027 * \brief Return node indices of a next edge
1029 //================================================================================
1031 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1035 _libData->ReadEdgeNodes( node1, node2, domain );
1039 ::GmfGetLin( iMesh, what, node1, node2, domain );
1042 //================================================================================
1044 * \brief Return node indices of a next triangle
1046 //================================================================================
1048 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1049 int* node1, int* node2, int* node3, int* domain )
1053 _libData->ReadTriaNodes( node1, node2, node3, domain );
1057 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1060 //================================================================================
1062 * \brief Return node indices of a next tetrahedron or quadrangle
1064 //================================================================================
1066 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1067 int* node1, int* node2, int* node3, int* node4, int* domain )
1071 if ( what == GmfQuadrilaterals )
1072 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1074 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1078 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1081 //================================================================================
1083 * \brief Return node indices of a next hexahedron
1085 //================================================================================
1087 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1088 int* node1, int* node2, int* node3, int* node4,
1089 int* node5, int* node6, int* node7, int* node8,
1094 _libData->ReadHexaNodes( node1, node2, node3, node4,
1095 node5, node6, node7, node8, domain );
1099 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1102 //================================================================================
1104 * \brief Prepare for passing data to MeshGems
1106 //================================================================================
1108 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1115 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1116 _openFiles.insert( id );
1120 //================================================================================
1122 * \brief Set number of entities
1124 //================================================================================
1126 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1128 if ( iMesh == 1 && _isMesh )
1131 case GmfVertices: _nbNodes += nb; break;
1132 case GmfEdges: _nbEdges += nb; break;
1133 case GmfTriangles: _nbFaces += nb; break;
1141 case GmfVertices: _libData->SetNbVertices( nb ); break;
1142 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1143 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1144 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1145 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1151 ::GmfSetKwd(iMesh, what, nb );
1154 //================================================================================
1156 * \brief Set GMF file made by MG-CADSurf to get nb of mesh entities from it
1158 //================================================================================
1160 void MG_Hexotic_API::SetInputFile( const std::string mesh2DFile )
1162 DriverGMF_Read fileReader;
1163 fileReader.SetFile( mesh2DFile );
1165 smIdType nbVertex, nbEdge, nbFace, nbVol;
1166 if ( fileReader.GetMeshInfo(nbVertex, nbEdge, nbFace, nbVol))
1168 _nbNodes += nbVertex;
1174 //================================================================================
1176 * \brief Add coordinates of a node
1178 //================================================================================
1180 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1184 _libData->AddNode( x, y, z, domain );
1188 ::GmfSetLin(iMesh, what, x, y, z, domain);
1191 //================================================================================
1193 * \brief Set number of field entities
1194 * \param [in] iMesh - solution file index
1195 * \param [in] what - solution type
1196 * \param [in] nbNodes - nb of entities
1197 * \param [in] nbTypes - nb of data entries in each entity
1198 * \param [in] type - types of the data entries
1200 * Used to prepare to storing size at nodes
1202 //================================================================================
1204 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1208 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1212 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1215 //================================================================================
1217 * \brief Add solution data
1219 //================================================================================
1221 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1225 _libData->AddSizeAtNode( vals[0] );
1229 ::GmfSetLin(iMesh, what, vals);
1232 //================================================================================
1234 * \brief Add edge nodes
1236 //================================================================================
1238 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1242 _libData->AddEdgeNodes( node1, node2, domain );
1246 ::GmfSetLin(iMesh, what, node1, node2, domain );
1249 //================================================================================
1251 * \brief Add a 'required' flag
1253 //================================================================================
1255 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1262 ::GmfSetLin(iMesh, what, id );
1265 //================================================================================
1267 * \brief Add triangle nodes
1269 //================================================================================
1271 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1275 _libData->AddTriaNodes( node1, node2, node3, domain );
1279 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1282 //================================================================================
1284 * \brief Close a file
1286 //================================================================================
1288 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1295 ::GmfCloseMesh( iMesh );
1296 _openFiles.erase( iMesh );
1299 //================================================================================
1301 * \brief Return true if the log is not empty
1303 //================================================================================
1305 bool MG_Hexotic_API::HasLog()
1309 return !_libData->GetErrors().empty();
1312 SMESH_File file( _logFile );
1313 return file.size() > 0;
1316 //================================================================================
1318 * \brief Return log contents
1320 //================================================================================
1322 std::string MG_Hexotic_API::GetLog()
1326 const std::string& err = _libData->GetErrors();
1327 if ( !_logFile.empty() && !err.empty() )
1329 SMESH_File file( _logFile, /*openForReading=*/false );
1330 file.openForWriting();
1331 file.write( err.c_str(), err.size() );
1336 SMESH_File file( _logFile );
1337 return file.exists() ? file.getPos() : "";