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_HYBRID_API.hxx"
22 #include <SMESH_Comment.hxx>
23 #include <SMESH_File.hxx>
24 #include <SMESH_MGLicenseKeyGen.hxx>
25 #include <Utils_SALOME_Exception.hxx>
35 #include <meshgems/meshgems.h>
36 #include <meshgems/hybrid.h>
39 #define MESHGEMS_VERSION_HEX (MESHGEMS_VERSION_MAJOR << 16 | MESHGEMS_VERSION_MINOR << 8 | MESHGEMS_VERSION_PATCH)
40 #define MESHGEMS_215 (2 << 16 | 15 << 8 | 0)
42 struct MG_HYBRID_API::LibData
46 hybrid_session_t *_session;
49 mesh_t * _hybrid_mesh;
52 std::vector<double> _xyz;
53 std::vector<double> _nodeSize; // required nodes
54 std::vector<int> _edgeNodesTags;
56 std::vector<int> _triaNodesTags;
58 std::vector<int> _quadNodes;
59 std::vector<int> _corners;
62 volatile bool& _cancelled_flag;
63 std::string _errorStr;
68 LibData( volatile bool & cancelled_flag, double& progress )
69 : _context(0), _session(0), _surf_mesh(0), _sizemap(0), _hybrid_mesh(0),
70 _nbRequiredEdges(0), _nbRequiredTria(0),
71 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
74 // methods setting callbacks implemented after callback definitions
81 hybrid_regain_mesh( _session, _hybrid_mesh );
83 hybrid_session_delete( _session );
85 mesh_delete( _surf_mesh );
87 sizemap_delete( _sizemap );
89 context_delete( _context );
98 void AddError( const char *txt )
106 const std::string& GetErrors()
111 void MG_Error(const char* txt="")
113 SMESH_Comment msg("\nMeshGems error. ");
115 AddError( msg.c_str() );
118 bool SetParam( const std::string& param, const std::string& value )
120 status_t ret = hybrid_set_param( _session, param.c_str(), value.c_str() );
122 //std::cout << param << " = " << value << std::endl;
124 return ( ret == STATUS_OK );
129 return _cancelled_flag;
132 int ReadNbSubDomains()
135 status_t ret = mesh_get_subdomain_count( _hybrid_mesh, & nb );
137 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
146 status_t ret = mesh_get_vertex_count( _hybrid_mesh, & nb );
148 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
155 status_t ret = mesh_get_edge_count( _hybrid_mesh, & nb );
157 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
164 status_t ret = mesh_get_triangle_count( _hybrid_mesh, & nb );
166 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
173 status_t ret = mesh_get_quadrangle_count( _hybrid_mesh, & nb );
175 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
182 status_t ret = mesh_get_tetrahedron_count( _hybrid_mesh, & nb );
184 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
191 status_t ret = mesh_get_hexahedron_count( _hybrid_mesh, & nb );
193 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
200 status_t ret = mesh_get_prism_count( _hybrid_mesh, & nb );
202 if ( ret != STATUS_OK ) MG_Error("mesh_get_prism_count problem");
208 return _corners.size();
216 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
218 integer tag, seed_type, seed_idx, seed_orientation;
219 status_t ret = mesh_get_subdomain_description( _hybrid_mesh, _count,
220 &tag, &seed_type, &seed_idx, &seed_orientation);
222 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
227 *ori = seed_orientation;
231 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
234 status_t ret = mesh_get_vertex_coordinates( _hybrid_mesh, _count, coo );
235 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
241 integer isCorner = 0;
242 ret = mesh_get_vertex_corner_property( _hybrid_mesh, _count, &isCorner);
243 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
245 _corners.push_back( _count );
250 void ReadEdgeNodes( int* node1, int* node2, int* domain )
253 status_t ret = mesh_get_edge_vertices( _hybrid_mesh, _count, vtx);
254 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
259 ret = mesh_get_edge_tag( _hybrid_mesh, _count, &tag );
260 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
267 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
270 status_t ret = mesh_get_triangle_vertices( _hybrid_mesh, _count, vtx);
271 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
277 ret = mesh_get_triangle_tag( _hybrid_mesh, _count, &tag );
278 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
285 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
288 status_t ret = mesh_get_quadrangle_vertices( _hybrid_mesh, _count, vtx);
289 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
296 ret = mesh_get_quadrangle_tag( _hybrid_mesh, _count, &tag );
297 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
304 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
307 status_t ret = mesh_get_tetrahedron_vertices( _hybrid_mesh, _count, vtx);
308 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
315 ret = mesh_get_tetrahedron_tag( _hybrid_mesh, _count, &tag );
316 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
323 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
324 int* node5, int* node6, int* node7, int* node8, int* domain )
327 status_t ret = mesh_get_hexahedron_vertices( _hybrid_mesh, _count, vtx);
328 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
339 ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
340 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
347 void ReadPrismNodes( int* node1, int* node2, int* node3, int* node4,
348 int* node5, int* node6, int* /*domain*/ )
351 status_t ret = mesh_get_prism_vertices( _hybrid_mesh, _count, vtx);
352 if (ret != STATUS_OK) MG_Error( "unable to get resulting prism" );
362 // ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
363 // if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
370 void ReadPyramidNodes( int* node1, int* node2, int* node3, int* node4, int* node5, int* domain )
373 status_t ret = mesh_get_pyramid_vertices( _hybrid_mesh, _count, vtx);
374 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid" );
383 ret = mesh_get_pyramid_tag( _hybrid_mesh, _count, &tag );
384 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid tag" );
391 void ReadCorner( int* node )
393 if ( _count <= ReadNbCorners() )
394 *node = _corners[ _count - 1 ];
401 void SetNbVertices( int nb )
403 _xyz.reserve( _xyz.capacity() + nb );
406 void SetNbEdges( int nb )
408 _edgeNodesTags.reserve( nb * 3 );
411 void SetNbTria( int nb )
413 _triaNodesTags.reserve( nb * 4 );
416 void SetNbQuads( int nb )
418 _quadNodes.reserve( nb * 4 );
421 void SetNbReqVertices( int nb )
423 _nodeSize.reserve( nb );
426 void SetNbReqEdges( int nb )
428 _nbRequiredEdges = nb;
431 void SetNbReqTria( int nb )
433 _nbRequiredTria = nb;
436 void AddNode( double x, double y, double z, int /*domain*/ )
443 void AddSizeAtNode( double size )
445 _nodeSize.push_back( size );
448 void AddEdgeNodes( int node1, int node2, int domain )
450 _edgeNodesTags.push_back( node1 );
451 _edgeNodesTags.push_back( node2 );
452 _edgeNodesTags.push_back( domain );
455 void AddTriaNodes( int node1, int node2, int node3, int domain )
457 _triaNodesTags.push_back( node1 );
458 _triaNodesTags.push_back( node2 );
459 _triaNodesTags.push_back( node3 );
460 _triaNodesTags.push_back( domain );
463 void AddQuadNodes( int node1, int node2, int node3, int node4 )
465 _quadNodes.push_back( node1 );
466 _quadNodes.push_back( node2 );
467 _quadNodes.push_back( node3 );
468 _quadNodes.push_back( node4 );
473 return _xyz.size() / 3;
476 double* NodeCoord( int iNode )
478 return & _xyz[ iNode * 3 ];
483 return _edgeNodesTags.size() / 3;
486 int* GetEdgeNodes( int iEdge )
488 return & _edgeNodesTags[ iEdge * 3 ];
491 int GetEdgeTag( int iEdge )
493 return _edgeNodesTags[ iEdge * 3 + 2 ];
498 return _triaNodesTags.size() / 4;
501 int * GetTriaNodes( int iTria )
503 return & _triaNodesTags[ iTria * 4 ];
506 int GetTriaTag( int iTria )
508 return _triaNodesTags[ iTria * 4 + 3 ];
513 return _quadNodes.size() / 4;
516 int * GetQuadNodes( int iQ )
518 return & _quadNodes[ iQ * 4 ];
521 int IsVertexRequired( int iNode )
523 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
526 double GetSizeAtVertex( int iNode )
528 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
532 namespace // functions called by MG library to exchange with the application
534 status_t get_vertex_count(integer * nbvtx, void *user_data)
536 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
537 *nbvtx = data->NbNodes();
542 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
544 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
545 double* coord = data->NodeCoord( ivtx-1 );
546 for (int j = 0; j < 3; j++)
551 status_t get_edge_count(integer * nbedge, void *user_data)
553 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
554 *nbedge = data->NbEdges();
559 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
561 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
562 int* nodes = data->GetEdgeNodes( iedge-1 );
569 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
571 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
572 * tag = data->GetEdgeTag( iedge-1 );
577 status_t get_triangle_count(integer * nbtri, void *user_data)
579 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
580 *nbtri = data->NbTriangles();
585 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
587 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
588 int* nodes = data->GetTriaNodes( itri-1 );
596 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
598 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
599 * tag = data->GetTriaTag( itri-1 );
604 status_t get_quadrangle_count(integer * nbq, void *user_data)
606 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
607 *nbq = data->NbQuads();
612 status_t get_quadrangle_vertices(integer iq, integer * vq, void *user_data)
614 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
615 int* nodes = data->GetQuadNodes( iq-1 );
624 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
626 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
627 *rvtx = data->IsVertexRequired( ivtx - 1 );
632 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
634 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
635 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
640 status_t my_message_cb(message_t * msg, void *user_data)
643 message_get_description(msg, &desc);
645 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
646 data->AddError( desc );
651 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
653 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
654 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
662 void MG_HYBRID_API::LibData::Init()
666 // Create the meshgems working context
667 _context = context_new();
668 if ( !_context ) MG_Error( "unable to create a new context" );
670 // Set the message callback for the _context.
671 ret = context_set_message_callback( _context, my_message_cb, this );
672 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
674 // Create the structure holding the callbacks giving access to triangle mesh
675 _surf_mesh = mesh_new( _context );
676 if ( !_surf_mesh ) MG_Error("unable to create a new mesh");
678 // Set callbacks to provide triangle mesh data
679 mesh_set_get_vertex_count( _surf_mesh, get_vertex_count, this );
680 mesh_set_get_vertex_coordinates( _surf_mesh, get_vertex_coordinates, this );
681 mesh_set_get_vertex_required_property( _surf_mesh, get_vertex_required_property, this );
682 mesh_set_get_edge_count( _surf_mesh, get_edge_count, this);
683 mesh_set_get_edge_vertices( _surf_mesh, get_edge_vertices, this );
684 mesh_set_get_edge_tag( _surf_mesh, get_edge_tag, this );
685 mesh_set_get_triangle_count( _surf_mesh, get_triangle_count, this );
686 mesh_set_get_triangle_vertices( _surf_mesh, get_triangle_vertices, this );
687 mesh_set_get_triangle_tag( _surf_mesh, get_triangle_tag, this );
688 mesh_set_get_quadrangle_count( _surf_mesh, get_quadrangle_count, this );
689 mesh_set_get_quadrangle_vertices( _surf_mesh, get_quadrangle_vertices, this );
691 // Create a hybrid session
692 _session = hybrid_session_new( _context );
693 if ( !_session ) MG_Error( "unable to create a new hybrid session");
695 ret = hybrid_set_interrupt_callback( _session, my_interrupt_callback, this );
696 if ( ret != STATUS_OK ) MG_Error("in hybrid_set_interrupt_callback");
700 bool MG_HYBRID_API::LibData::Compute()
703 std::string errorTxt;
705 #if MESHGEMS_VERSION_HEX > MESHGEMS_215
706 // unlock Hybrid license
707 std::string SPATIAL_LICENSE = SMESHUtils_MGLicenseKeyGen::GetKey(errorTxt);
708 ret = meshgems_hybrid_unlock_product(SPATIAL_LICENSE.c_str());
709 if STATUS_IS_ERROR( ret )
711 AddError( SMESH_Comment( "Problem with SPATIAL_LICENSE to unlock Hybrid: ") << errorTxt );
715 MESSAGE("SPATIAL_LICENSE unlock Hybrid: " << ret);
717 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _surf_mesh, errorTxt ))
719 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
725 ret = hybrid_set_surface_mesh( _session, _surf_mesh );
726 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
730 if ( !_nodeSize.empty() )
732 _sizemap = meshgems_sizemap_new( _surf_mesh, meshgems_sizemap_type_iso_mesh_vertex,
733 (void*) &get_vertex_weight, this );
734 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
736 ret = hybrid_set_sizemap( _session, _sizemap );
737 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
741 //////////////////////////////////////////////////////////////////////////////////////////
742 // const char* file = "/tmp/ghs3d_IN.mesh";
743 // mesh_write_mesh( _surf_mesh,file);
744 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
746 ret = hybrid_compute_mesh( _session );
747 if ( ret != STATUS_OK ) return false;
749 ret = hybrid_get_mesh( _session, &_hybrid_mesh);
750 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
752 //////////////////////////////////////////////////////////////////////////////////////////
753 // file = "/tmp/ghs3d_OUT.mesh";
754 // mesh_write_mesh( _hybrid_mesh,file);
755 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
760 #else // ifdef USE_MG_LIBS
762 struct MG_HYBRID_API::LibData // to avoid compiler warnings
764 volatile bool& _cancelled_flag;
766 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
769 #endif // ifdef USE_MG_LIBS
772 //================================================================================
776 //================================================================================
778 MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress)
779 :_nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
782 _libData = new LibData( cancelled_flag, progress );
786 if ( getenv("MG_HYBRID_USE_EXE"))
791 //================================================================================
795 //================================================================================
797 MG_HYBRID_API::~MG_HYBRID_API()
803 std::set<int>::iterator id = _openFiles.begin();
804 for ( ; id != _openFiles.end(); ++id )
805 ::GmfCloseMesh( *id );
809 //================================================================================
811 * \brief Return the way of MG usage
813 //================================================================================
815 bool MG_HYBRID_API::IsLibrary()
820 //================================================================================
822 * \brief Switch to usage of MG-HYBRID executable
824 //================================================================================
826 void MG_HYBRID_API::SetUseExecutable()
831 //================================================================================
833 * \brief Compute the hybrid mesh
834 * \param [in] cmdLine - a command to run mg_hybrid.exe
835 * \return bool - Ok or not
837 //================================================================================
839 bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
845 std::istringstream strm( cmdLine );
846 std::istream_iterator<std::string> sIt( strm ), sEnd;
847 std::vector< std::string > args( sIt, sEnd );
850 std::string param, value;
851 for ( size_t i = 1; i < args.size(); ++i )
853 // look for a param name; it starts from "-"
855 if ( param.size() < 2 || param[0] != '-')
857 while ( param[0] == '-')
858 param = param.substr( 1 );
861 while ( i+1 < args.size() && args[i+1][0] != '-' )
863 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
865 if ( !value.empty() ) value += " ";
868 if ( !_libData->SetParam( param, value ))
869 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
873 bool ok = _libData->Compute();
875 GetLog(); // write a log file
876 _logFile = ""; // not to write it again
882 // add MG license key
884 std::string errorTxt, meshIn;
885 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
886 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
890 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
894 const_cast< std::string& >( cmdLine ) += " --key " + key;
897 int err = system( cmdLine.c_str() ); // run
900 errStr = SMESH_Comment("system(mg-hybrid.exe ...) command failed with error: ")
901 << strerror( errno );
907 //================================================================================
909 * \brief Prepare for reading a mesh data
911 //================================================================================
913 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
920 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
921 _openFiles.insert( id );
925 //================================================================================
927 * \brief Return nb of entities
929 //================================================================================
931 int MG_HYBRID_API::GmfStatKwd( int iMesh, GmfKwdCod what )
937 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
938 case GmfVertices: return _libData->ReadNbNodes();
939 case GmfEdges: return _libData->ReadNbEdges();
940 case GmfTriangles: return _libData->ReadNbTria();
941 case GmfQuadrilaterals: return _libData->ReadNbQuads();
942 case GmfTetrahedra: return _libData->ReadNbTetra();
943 case GmfPrisms: return _libData->ReadNbPrisms();
944 case GmfHexahedra: return _libData->ReadNbHexa();
945 case GmfCorners: return _libData->ReadNbCorners();
951 return ::GmfStatKwd( iMesh, what );
954 //================================================================================
956 * \brief Prepare for reading some data
958 //================================================================================
960 void MG_HYBRID_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
964 _libData->ResetCounter();
968 ::GmfGotoKwd( iMesh, what );
971 //================================================================================
973 * \brief Return index of a domain identified by a triangle normal
974 * \param [in] iMesh - mesh file index
975 * \param [in] what - must be GmfSubDomainFromGeom
976 * \param [out] nbNodes - nb nodes in a face
977 * \param [out] faceInd - face index
978 * \param [out] ori - face orientation
979 * \param [out] domain - domain index
980 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
983 //================================================================================
985 void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
989 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
993 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
996 //================================================================================
998 * \brief Return coordinates of a next node
1000 //================================================================================
1002 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1003 double* x, double* y, double *z, int* domain )
1007 _libData->ReadNodeXYZ( x, y, z, domain );
1011 ::GmfGetLin(iMesh, what, x, y, z, domain );
1014 //================================================================================
1016 * \brief Return coordinates of a next node
1018 //================================================================================
1020 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1021 float* x, float* y, float *z, int* domain )
1026 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
1033 ::GmfGetLin(iMesh, what, x, y, z, domain );
1036 //================================================================================
1038 * \brief Return node index of a next corner
1040 //================================================================================
1042 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
1046 _libData->ReadCorner( node );
1050 ::GmfGetLin(iMesh, what, node );
1053 //================================================================================
1055 * \brief Return node indices of a next edge
1057 //================================================================================
1059 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1063 _libData->ReadEdgeNodes( node1, node2, domain );
1067 ::GmfGetLin( iMesh, what, node1, node2, domain );
1070 //================================================================================
1072 * \brief Return node indices of a next triangle
1074 //================================================================================
1076 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1077 int* node1, int* node2, int* node3, int* domain )
1081 _libData->ReadTriaNodes( node1, node2, node3, domain );
1085 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1088 //================================================================================
1090 * \brief Return node indices of a next tetrahedron or quadrangle
1092 //================================================================================
1094 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1095 int* node1, int* node2, int* node3, int* node4, int* domain )
1099 if ( what == GmfQuadrilaterals )
1100 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1102 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1106 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1109 //================================================================================
1111 * \brief Return node indices of a next hexahedron
1113 //================================================================================
1115 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1116 int* node1, int* node2, int* node3, int* node4,
1117 int* node5, int* node6, int* node7, int* node8,
1122 _libData->ReadHexaNodes( node1, node2, node3, node4, node5, node6, node7, node8, domain );
1126 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1129 //================================================================================
1131 * \brief Return node indices of a next pyramid
1133 //================================================================================
1135 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1136 int* node1, int* node2, int* node3, int* node4,
1137 int* node5, int* domain )
1141 _libData->ReadPyramidNodes( node1, node2, node3, node4, node5, domain );
1145 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, domain );
1148 //================================================================================
1150 * \brief Return node indices of a next prism
1152 //================================================================================
1154 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1155 int* node1, int* node2, int* node3, int* node4,
1156 int* node5, int* node6, int* domain )
1160 _libData->ReadPrismNodes( node1, node2, node3, node4, node5, node6, domain );
1164 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, domain );
1167 //================================================================================
1169 * \brief Prepare for passing data to MeshGems
1171 //================================================================================
1173 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1180 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1181 _openFiles.insert( id );
1185 //================================================================================
1187 * \brief Set number of entities
1189 //================================================================================
1191 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1196 case GmfVertices: _nbNodes = nb; break;
1197 case GmfEdges: _nbEdges = nb; break;
1198 case GmfTriangles: _nbFaces += nb; break;
1199 case GmfQuadrilaterals: _nbFaces += nb; break;
1206 case GmfVertices: _libData->SetNbVertices( nb ); break;
1207 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1208 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1209 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1210 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1216 ::GmfSetKwd(iMesh, what, nb );
1219 //================================================================================
1221 * \brief Add coordinates of a node
1223 //================================================================================
1225 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1229 _libData->AddNode( x, y, z, domain );
1233 ::GmfSetLin(iMesh, what, x, y, z, domain);
1236 //================================================================================
1238 * \brief Set number of field entities
1239 * \param [in] iMesh - solution file index
1240 * \param [in] what - solution type
1241 * \param [in] nbNodes - nb of entities
1242 * \param [in] nbTypes - nb of data entries in each entity
1243 * \param [in] type - types of the data entries
1245 * Used to prepare to storing size at nodes
1247 //================================================================================
1249 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1253 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1257 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1260 //================================================================================
1262 * \brief Add solution data
1264 //================================================================================
1266 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1270 _libData->AddSizeAtNode( vals[0] );
1274 ::GmfSetLin(iMesh, what, vals);
1277 //================================================================================
1279 * \brief Add edge nodes
1281 //================================================================================
1283 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1287 _libData->AddEdgeNodes( node1, node2, domain );
1291 ::GmfSetLin(iMesh, what, node1, node2, domain );
1294 //================================================================================
1296 * \brief Add a 'required' flag
1298 //================================================================================
1300 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1307 ::GmfSetLin(iMesh, what, id );
1310 //================================================================================
1312 * \brief Add triangle nodes
1314 //================================================================================
1316 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1320 _libData->AddTriaNodes( node1, node2, node3, domain );
1324 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1327 //================================================================================
1329 * \brief Add quadrangle nodes
1331 //================================================================================
1333 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int node4, int domain )
1337 _libData->AddQuadNodes( node1, node2, node3, node4 );
1341 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1344 //================================================================================
1346 * \brief Close a file
1348 //================================================================================
1350 void MG_HYBRID_API::GmfCloseMesh( int iMesh )
1357 ::GmfCloseMesh( iMesh );
1358 _openFiles.erase( iMesh );
1361 //================================================================================
1363 * \brief Return true if the log is not empty
1365 //================================================================================
1367 bool MG_HYBRID_API::HasLog()
1371 return !_libData->GetErrors().empty();
1374 SMESH_File file( _logFile );
1375 return file.size() > 0;
1378 //================================================================================
1380 * \brief Return log contents
1382 //================================================================================
1384 std::string MG_HYBRID_API::GetLog()
1388 const std::string& err = _libData->GetErrors();
1389 if ( !_logFile.empty() && !err.empty() )
1391 SMESH_File file( _logFile, /*openForReading=*/false );
1392 file.openForWriting();
1393 file.write( err.c_str(), err.size() );
1398 SMESH_File file( _logFile );
1399 return file.getPos();