1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2021 EDF R&D
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.alneos.com/ or email : contact@alneos.fr
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "GMSHPlugin_Mesher.hxx"
22 #include "GMSHPlugin_Hypothesis_2D.hxx"
24 #include <SMDS_FaceOfNodes.hxx>
25 #include <SMDS_MeshElement.hxx>
26 #include <SMDS_MeshNode.hxx>
27 #include <SMESHDS_Mesh.hxx>
28 #include <SMESH_Block.hxx>
29 #include <SMESH_Comment.hxx>
30 #include <SMESH_ComputeError.hxx>
31 #include <SMESH_File.hxx>
32 #include <SMESH_Gen_i.hxx>
33 #include <SMESH_Mesh.hxx>
34 #include <SMESH_MesherHelper.hxx>
35 #include <SMESH_subMesh.hxx>
36 #include <utilities.h>
41 #include <BRep_Tool.hxx>
42 #include <Bnd_B3d.hxx>
43 #include <GCPnts_AbscissaPoint.hxx>
44 #include <GeomAdaptor_Curve.hxx>
45 #include <NCollection_Map.hxx>
46 #include <OSD_File.hxx>
47 #include <OSD_Path.hxx>
48 #include <Standard_ErrorHandler.hxx>
49 #include <Standard_ProgramError.hxx>
50 #include <TCollection_AsciiString.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
54 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
55 #include <TopTools_DataMapOfShapeInteger.hxx>
56 #include <TopTools_DataMapOfShapeShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
61 #if GMSH_MAJOR_VERSION >=4
62 #include <GmshGlobal.h>
72 SBoundingBox3d _bounds;
76 //================================================================================
78 * \brief Retrieve ShapeBounds from a compound GEdge
80 //================================================================================
82 bool getBoundsOfShapes( GEdge* gEdge,
83 std::vector< ShapeBounds > & topoEdges )
86 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
87 for ( size_t i = 0; i < gEdge->compound.size(); ++i )
89 GEdge* gE = static_cast< GEdge* >( gEdge->compound[ i ]);
90 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
93 for ( size_t i = 0; i < gEdge->_compound.size(); ++i )
95 GEdge* gE = static_cast< GEdge* >( gEdge->_compound[ i ]);
96 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
99 return topoEdges.size();
102 //================================================================================
104 * \brief Retrieve ShapeBounds from a compound GFace
106 //================================================================================
108 bool getBoundsOfShapes( GFace* gFace,
109 std::vector< ShapeBounds > & topoFaces )
112 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
113 for ( size_t i = 0; i < gFace->compound.size(); ++i )
115 GFace* gF = static_cast< GFace* >( gFace->compound[ i ]);
116 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
119 for ( size_t i = 0; i < gFace->_compound.size(); ++i )
121 GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]);
122 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
125 return topoFaces.size();
127 //================================================================================
129 * \brief Find a shape whose bounding box includes a given point
131 //================================================================================
133 TopoDS_Shape getShapeAtPoint( const SPoint3& point, const std::vector< ShapeBounds > & shapes )
136 float distmin = std::numeric_limits<float>::max();
137 for ( size_t i = 0; i < shapes.size(); ++i )
139 float dist = GMSHPlugin_Mesher::DistBoundingBox( shapes[i]._bounds, point );
142 shape = shapes[i]._shape;
152 //=============================================================================
156 //=============================================================================
158 GMSHPlugin_Mesher::GMSHPlugin_Mesher (SMESH_Mesh* mesh,
159 const TopoDS_Shape& aShape)
163 // il faudra peut être mettre un truc par defaut si l'utilisateur ne rentre rien en para
164 //defaultParameters();
167 //void GMSHPlugin_Mesher::defaultParameters(){}
169 void GMSHPlugin_Mesher::SetParameters(const GMSHPlugin_Hypothesis* hyp)
173 _algo2d = hyp->Get2DAlgo();
174 _algo3d = hyp->Get3DAlgo();
175 _recomb2DAlgo = hyp->GetRecomb2DAlgo();
176 _recombineAll = hyp->GetRecombineAll();
177 _subdivAlgo = hyp->GetSubdivAlgo();
178 _remeshAlgo = hyp->GetRemeshAlgo();
179 _remeshPara = hyp->GetRemeshPara();
180 _smouthSteps = hyp->GetSmouthSteps();
181 _sizeFactor = hyp->GetSizeFactor();
182 _minSize = hyp->GetMinSize();
183 _maxSize = hyp->GetMaxSize();
184 _secondOrder = hyp->GetSecondOrder();
185 _useIncomplElem = hyp->GetUseIncomplElem();
186 _is2d = hyp->GetIs2d();
187 _compounds = hyp->GetCompoundOnEntries();
194 _recombineAll = false;
202 _secondOrder = false;
203 _useIncomplElem = true;
209 //================================================================================
211 * \brief Set Gmsh Options
213 //================================================================================
215 void GMSHPlugin_Mesher::SetGmshOptions()
217 MESSAGE("GMSHPlugin_Mesher::SetGmshOptions");
219 printf("We chose _algo2d %d \n", _algo2d );
220 printf("We chose _algo3d %d \n", _algo3d );
221 printf("We chose _recomb2DAlgo %d \n", _recomb2DAlgo );
222 printf("We chose _recombineAll %d \n", (_recombineAll)?1:0);
223 printf("We chose _subdivAlgo %d \n", _subdivAlgo );
224 printf("We chose _remeshAlgo %d \n", _remeshAlgo );
225 printf("We chose _remeshPara %d \n", _remeshPara );
226 printf("We chose _smouthSteps %e \n", _smouthSteps );
227 printf("We chose _sizeFactor %e \n", _sizeFactor );
228 printf("We chose _minSize %e \n", _minSize );
229 printf("We chose _maxSize %e \n", _maxSize );
230 printf("We chose _secondOrder %d \n", (_secondOrder)?1:0);
231 printf("We chose _useIncomplElem %d \n", (_useIncomplElem)?1:0);
232 printf("We are in dimension %d \n", (_is2d)?2:3);
235 std::map <int,double> mapAlgo2d;
236 mapAlgo2d[0]=2; // Automatic
237 mapAlgo2d[1]=1; // MeshAdapt
238 mapAlgo2d[2]=5; // Delaunay
239 mapAlgo2d[3]=6; // Frontal-Delaunay
240 mapAlgo2d[4]=8; // DelQuad (Frontal-Delaunay for Quads)
241 mapAlgo2d[5]=9; // Packing of parallelograms
243 std::map <int,double> mapAlgo3d;
244 mapAlgo3d[0]=1; // Delaunay
245 mapAlgo3d[1]=4; // Frontal
246 mapAlgo3d[2]=7; // MMG3D
247 mapAlgo3d[3]=9; // R-tree
250 ok = GmshSetOption("Mesh", "Algorithm" , mapAlgo2d[_algo2d]) ;
254 ok = GmshSetOption("Mesh", "Algorithm3D" , mapAlgo3d[_algo3d]) ;
257 ok = GmshSetOption("Mesh", "RecombinationAlgorithm" , (double)_recomb2DAlgo) ;
259 ok = GmshSetOption("Mesh", "RecombineAll" , (_recombineAll)?1.:0.) ;
261 ok = GmshSetOption("Mesh", "SubdivisionAlgorithm" , (double)_subdivAlgo) ;
263 ok = GmshSetOption("Mesh", "RemeshAlgorithm" , (double)_remeshAlgo) ;
265 ok = GmshSetOption("Mesh", "RemeshParametrization" , (double)_remeshPara) ;
267 ok = GmshSetOption("Mesh", "Smoothing" , (double)_smouthSteps) ;
269 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
270 ok = GmshSetOption("Mesh", "MeshSizeFactor" , _sizeFactor) ;
272 ok = GmshSetOption("Mesh", "MeshSizeMin" , _minSize) ;
274 ok = GmshSetOption("Mesh", "MeshSizeMax" , _maxSize) ;
277 ok = GmshSetOption("Mesh", "CharacteristicLengthFactor" , _sizeFactor) ;
279 ok = GmshSetOption("Mesh", "CharacteristicLengthMin" , _minSize) ;
281 ok = GmshSetOption("Mesh", "CharacteristicLengthMax" , _maxSize) ;
284 ok = GmshSetOption("Mesh", "ElementOrder" , (_secondOrder)?2.:1.) ;
288 ok = GmshSetOption("Mesh", "SecondOrderIncomplete" ,(_useIncomplElem)?1.:0.);
293 //================================================================================
295 * \brief Create and add Compounds into GModel _gModel.
297 //================================================================================
299 void GMSHPlugin_Mesher::CreateGmshCompounds()
301 MESSAGE("GMSHPlugin_Mesher::CreateGmshCompounds");
303 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
305 OCC_Internals* occgeo = _gModel->getOCCInternals();
306 bool toSynchronize = false;
308 for(std::set<std::string>::const_iterator its = _compounds.begin();its != _compounds.end(); ++its )
310 GEOM::GEOM_Object_var aGeomObj;
311 TopoDS_Shape geomShape = TopoDS_Shape();
312 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( (*its).c_str() );
313 SALOMEDS::GenericAttribute_var anAttr;
314 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR"))
316 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
317 CORBA::String_var aVal = anIOR->Value();
318 CORBA::Object_var obj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->ConvertIORToObject(aVal);
319 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
321 geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
322 if ( geomShape.IsNull() )
325 TopAbs_ShapeEnum geomType = geomShape.ShapeType();
326 if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire
328 MESSAGE("shapeType == TopAbs_COMPOUND");
329 TopoDS_Iterator it(geomShape);
332 TopAbs_ShapeEnum shapeType = it.Value().ShapeType();
333 std::vector< std::pair< int, int > > dimTags;
334 for ( ; it.More(); it.Next())
336 const TopoDS_Shape& topoShape = it.Value();
337 ASSERT(topoShape.ShapeType() == shapeType);
338 if ( _mesh->GetMeshDS()->ShapeToIndex( topoShape ) > 0 )
339 occgeo->importShapes( &topoShape, false, dimTags );
342 TopoDS_Shape face = TopExp_Explorer( _shape, shapeType ).Current();
343 SMESH_subMesh* sm = _mesh->GetSubMesh( face );
344 sm->GetComputeError() =
345 SMESH_ComputeError::New
346 ( COMPERR_WARNING, "Compound shape does not belong to the main geometry. Ignored");
349 std::vector<int> tags;
350 int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2;
351 for ( size_t i = 0; i < dimTags.size(); ++i )
353 if ( dimTags[i].first == dim )
354 tags.push_back( dimTags[i].second );
358 _gModel->getGEOInternals()->setCompoundMesh( dim, tags );
359 toSynchronize = true;
362 _gModel->getGEOInternals()->synchronize(_gModel);
367 //================================================================================
369 * \brief For a compound mesh set the mesh components to be transmitted to SMESH
371 //================================================================================
373 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
374 void GMSHPlugin_Mesher::SetCompoundMeshVisibility()
377 // Loop over all faces, if the face belongs to a compound entry then
378 // for all (boundary) edges whithin the face visibility is set to 0,
379 // if the face doesn't belong to a compound entry then visibility is
380 // set to 1 for all its (boundary) edges. Later, in FillSMesh() func
381 // getVisibility() (returns either 1 or 0) is used to decide weather
382 // the mesh of edge should be transmitted to SMESH or not.
384 for ( GModel::fiter itF = _gModel->firstFace(); itF != _gModel->lastFace(); ++itF )
386 std::vector< GEdge *> faceEdges = (*itF)->edges();
388 for ( auto itE = faceEdges.begin(); itE != faceEdges.end(); ++itE )
390 if ( ((*itF)->compound.size()) )
391 (*itE)->setVisibility(0);
393 (*itE)->setVisibility(1);
398 // Loop over all edges, if the edge belongs to a compound entry then
399 // for all (boundary) vertices whithin the edge visibility is set to
400 // 0, if the edge doesn't belong to a compound entry then visibility
401 // is set to 1 for all its (boundary) vertices. Later, in FillSMesh()
402 // func getVisibility() (returns either 1 or 0) is used to decide we-
403 // ather the mesh of vertices should be transmitted to SMESH or not.
405 for ( GModel::eiter itE = _gModel->firstEdge(); itE != _gModel->lastEdge(); ++itE )
407 std::vector<GVertex *> bndVerticies = (*itE)->vertices();
409 for( auto itV = bndVerticies.begin(); itV != bndVerticies.end(); ++itV )
411 if(((*itE)->compound.size()))
412 (*itV)->setVisibility(0);
414 (*itV)->setVisibility(1);
421 //================================================================================
423 * \brief Write mesh from GModel instance to SMESH instance
425 //================================================================================
427 void GMSHPlugin_Mesher::FillSMesh()
429 SMESHDS_Mesh* meshDS = _mesh->GetMeshDS();
432 for ( GModel::viter it = _gModel->firstVertex(); it != _gModel->lastVertex(); ++it)
434 GVertex *gVertex = *it;
436 // GET topoVertex CORRESPONDING TO gVertex
437 TopoDS_Vertex topoVertex = *((TopoDS_Vertex*)gVertex->getNativePtr());
439 if (gVertex->getVisibility() == 0) // belongs to a compound
441 SMESH_subMesh* sm = _mesh->GetSubMesh(topoVertex);
442 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
446 // FILL SMESH FOR topoVertex
448 for(unsigned int i = 0; i < gVertex->mesh_vertices.size(); i++)
450 MVertex *v = gVertex->mesh_vertices[i];
451 if(v->getIndex() >= 0)
453 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
454 meshDS->SetNodeOnVertex( node, topoVertex );
457 // WE DON'T ADD 0D ELEMENTS because it does not follow the salome meshers philosophy
459 // for(unsigned int i = 0; i < gVertex->getNumMeshElements(); i++)
461 // MElement *e = gVertex->getMeshElement(i);
462 // std::vector<MVertex*> verts;
463 // e->getVertices(verts);
464 // ASSERT(verts.size()==1);
465 // SMDS_Mesh0DElement* zeroDElement = 0;
466 // zeroDElement = meshDS->Add0DElementWithID(verts[0]->getNum(),e->getNum());
467 // meshDS->SetMeshElementOnShape(zeroDElement, topoVertex);
472 for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it)
476 // GET topoEdge CORRESPONDING TO gEdge
477 TopoDS_Edge topoEdge;
478 std::vector< ShapeBounds > topoEdges;
479 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
480 if(gEdge->haveParametrization())
482 if ( gEdge->geomType() != GEntity::CompoundCurve )
485 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
486 if (gEdge->getVisibility() == 0) // belongs to a compound
488 SMESH_subMesh* sm = _mesh->GetSubMesh(topoEdge);
489 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
493 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
495 // FILL SMESH FOR topoEdge
497 for ( size_t i = 0; i < gEdge->mesh_vertices.size(); i++ )
499 MVertex *v = gEdge->mesh_vertices[i];
500 if ( v->getIndex() >= 0 )
502 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
505 topoEdge = TopoDS::Edge( getShapeAtPoint( v->point(), topoEdges ));
507 meshDS->SetNodeOnEdge( node, topoEdge );
512 for ( GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it )
515 if ( gEdge->getVisibility() == 0) // belongs to a compound
518 TopoDS_Edge topoEdge;
519 std::vector< ShapeBounds > topoEdges;
520 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
522 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
525 std::vector<MVertex*> verts(3);
526 for ( size_t i = 0; i < gEdge->getNumMeshElements(); i++ )
528 MElement *e = gEdge->getMeshElement(i);
530 e->getVertices(verts);
532 // if a node wasn't set, it is assigned here
533 for ( size_t j = 0; j < verts.size(); j++ )
535 if ( verts[j]->onWhat()->getVisibility() == 0 )
537 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[i]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
538 meshDS->SetNodeOnEdge( node, topoEdge );
539 verts[j]->setEntity(gEdge);
543 SMDS_MeshEdge* edge = 0;
544 switch (verts.size())
547 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
548 verts[1]->getNum(),e->getNum());
551 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
553 verts[2]->getNum(),e->getNum());
560 topoEdge = TopoDS::Edge( getShapeAtPoint( e->barycenter(), topoEdges ));
562 meshDS->SetMeshElementOnShape( edge, topoEdge );
567 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
571 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
572 // Gmsh since version 4.3 is now producing extra surface and mesh when
573 // compounds are involved. Since in Gmsh meshing procedure needs acess
574 // to each of the original topology and the meshed topology. Hence we
575 // bypass the additional mesh in case of compounds. Note, similar cri-
576 // teria also occus in the following 'for' loop.
577 if ( _compounds.size() && gFace->geomType() == GEntity::DiscreteSurface )
581 // GET topoFace CORRESPONDING TO gFace
582 TopoDS_Face topoFace;
583 std::vector< ShapeBounds > topoFaces;
585 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
586 if(gFace->haveParametrization())
588 if ( gFace->geomType() != GEntity::CompoundSurface )
591 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
592 if (gFace->getVisibility() == 0) // belongs to a compound
594 SMESH_subMesh* sm = _mesh->GetSubMesh(topoFace);
595 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
599 bool isCompound = getBoundsOfShapes( gFace, topoFaces );
601 // FILL SMESH FOR topoFace
603 for ( size_t i = 0; i < gFace->mesh_vertices.size(); i++ )
605 MVertex *v = gFace->mesh_vertices[i];
606 if ( v->getIndex() >= 0 )
608 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
611 topoFace = TopoDS::Face( getShapeAtPoint( v->point(), topoFaces ));
613 meshDS->SetNodeOnFace( node, topoFace );
618 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
622 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
623 if ( _compounds.size() && gFace->geomType() == GEntity::DiscreteSurface )
626 bool isCompound = (!gFace->haveParametrization());
628 bool isCompound = ( gFace->geomType() == GEntity::CompoundSurface );
631 if ( !isCompound && gFace->getVisibility() == 0 )
632 continue; // belongs to a compound
634 TopoDS_Face topoFace;
635 std::vector< ShapeBounds > topoFaces;
637 getBoundsOfShapes( gFace, topoFaces );
639 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
642 std::vector<MVertex*> verts;
643 for ( size_t i = 0; i < gFace->getNumMeshElements(); i++ )
645 MElement *e = gFace->getMeshElement(i);
647 e->getVertices(verts);
648 SMDS_MeshFace* face = 0;
650 // if a node wasn't set, it is assigned here
651 for ( size_t j = 0; j < verts.size(); j++)
653 if(verts[j]->onWhat()->getVisibility() == 0)
655 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[j]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
656 meshDS->SetNodeOnFace( node, topoFace );
657 verts[i]->setEntity(gFace);
660 switch (verts.size())
663 face = meshDS->AddFaceWithID(verts[0]->getNum(),
665 verts[2]->getNum(),e->getNum());
668 face = meshDS->AddFaceWithID(verts[0]->getNum(),
671 verts[3]->getNum(),e->getNum());
674 face = meshDS->AddFaceWithID(verts[0]->getNum(),
679 verts[5]->getNum(),e->getNum());
682 face = meshDS->AddFaceWithID(verts[0]->getNum(),
689 verts[7]->getNum(),e->getNum());
692 face = meshDS->AddFaceWithID(verts[0]->getNum(),
700 verts[8]->getNum(),e->getNum());
708 topoFace = TopoDS::Face( getShapeAtPoint( e->barycenter(), topoFaces ));
710 meshDS->SetMeshElementOnShape(face, topoFace);
715 for ( GModel::riter it = _gModel->firstRegion(); it != _gModel->lastRegion(); ++it)
717 GRegion *gRegion = *it;
718 if (gRegion->getVisibility() == 0)
721 // GET topoSolid CORRESPONDING TO gRegion
722 TopoDS_Solid topoSolid = *((TopoDS_Solid*)gRegion->getNativePtr());
724 // FILL SMESH FOR topoSolid
727 for(unsigned int i = 0; i < gRegion->mesh_vertices.size(); i++)
729 MVertex *v = gRegion->mesh_vertices[i];
730 if(v->getIndex() >= 0)
732 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
733 meshDS->SetNodeInVolume( node, topoSolid );
738 std::vector<MVertex*> verts;
739 for(unsigned int i = 0; i < gRegion->getNumMeshElements(); i++)
741 MElement *e = gRegion->getMeshElement(i);
743 e->getVertices(verts);
744 SMDS_MeshVolume* volume = 0;
745 switch (verts.size()){
747 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
750 verts[3]->getNum(),e->getNum());
753 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
757 verts[4]->getNum(),e->getNum());
760 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
765 verts[4]->getNum(),e->getNum());
768 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
775 verts[5]->getNum(),e->getNum());
778 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
787 verts[9]->getNum(),e->getNum());
790 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
802 verts[9]->getNum(),e->getNum());
804 case 14: // same as case 13, because no pyra14 in smesh
805 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
817 verts[9]->getNum(),e->getNum());
820 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
834 verts[10]->getNum(),e->getNum());
836 case 18: // same as case 15, because no penta18 in smesh
837 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
851 verts[10]->getNum(),e->getNum());
854 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
873 verts[12]->getNum(),e->getNum());
876 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
909 meshDS->SetMeshElementOnShape(volume, topoSolid);
916 //================================================================================
918 * \brief Find if SPoint point is in SBoundingBox3d bounds
920 //================================================================================
922 float GMSHPlugin_Mesher::DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point)
924 SPoint3 min = bounds.min();
925 SPoint3 max = bounds.max();
929 if (point.x() < min.x())
930 x = min.x()-point.x();
931 else if (point.x() > max.x())
932 x = point.x()-max.x();
936 if (point.y() < min.y())
937 y = min.y()-point.y();
938 else if (point.y() > max.y())
939 y = point.y()-max.y();
943 if (point.z() < min.z())
944 z = min.z()-point.z();
945 else if (point.z() > max.z())
946 z = point.z()-max.z();
952 //================================================================================
954 * \brief Reimplemented GmshMessage call. Actions done if errors occurs
955 * during gmsh meshing. We define here what to display and what to do.
957 //================================================================================
958 void GMSHPlugin_Mesher::mymsg::operator()(std::string level, std::string msg)
960 //MESSAGE("level="<< level.c_str() << ", msg=" << msg.c_str()<< "\n");
961 printf("level=%s msg=%s\n", level.c_str(), msg.c_str());
963 if(level == "Fatal" || level == "Error")
965 std::ostringstream oss;
966 if (level == "Fatal")
967 oss << "Fatal error during Generation of Gmsh Mesh\n";
969 oss << "Error during Generation of Gmsh Mesh\n";
970 oss << " " << msg.c_str() << "\n";
971 GEntity *e = _gModel->getCurrentMeshEntity();
974 oss << " error occurred while meshing entity:\n" <<
975 " tag=" << e->tag() << "\n" <<
976 " dimension=" << e->dim() << "\n" <<
977 " native pointer=" << e->getNativePtr();
978 //if(e->geomType() != GEntity::CompoundCurve and e->geomType() != GEntity::CompoundSurface)
980 //SMESH_subMesh *sm = _mesh->GetSubMesh(*((TopoDS_Shape*)e->getNativePtr()));
981 //SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
982 //SMESH_Comment comment;
983 //comment << SMESH_Comment(oss.str);
984 //std::string str = oss.str();
985 //smError.reset( new SMESH_ComputeError( str ));
987 // plutot que de faire de la merde ici, on pourait simplement
988 // remplir une liste pour dire sur quelles entités gmsh se plante
989 // (puis faire le fillsmesh)
990 // puis faire une nouvelle routine qui réécrit les messages d'erreur
991 // probleme : gmsh peut planté en Fatal, dans ce cas pas de fillsmesh
994 if (level == "Fatal")
996 CTX::instance()->lock = 0;
1000 printf("%s\n", oss.str().c_str());
1004 //=============================================================================
1006 * Here we are going to use the GMSH mesher
1008 //=============================================================================
1010 bool GMSHPlugin_Mesher::Compute()
1012 MESSAGE("GMSHPlugin_Mesher::Compute");
1018 _gModel = new GModel();
1020 GmshSetMessageHandler(&msg);
1021 _gModel->importOCCShape((void*)&_shape);
1022 if (_compounds.size() > 0) CreateGmshCompounds();
1023 MESSAGE("GModel::Mesh");
1026 _gModel->mesh((_is2d)?2:3);
1027 #ifdef WITH_SMESH_CANCEL_COMPUTE
1031 catch (std::string& str)
1039 MESSAGE("Unrecoverable error during Generation of Gmsh Mesh");
1044 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
1045 if (_compounds.size() > 0)
1046 SetCompoundMeshVisibility();
1052 MESSAGE("GMSHPlugin_Mesher::Compute:End");