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
87 #if GMSH_MINOR_VERSION >=3
88 for ( size_t i = 0; i < gEdge->compound.size(); ++i )
90 GEdge* gE = static_cast< GEdge* >( gEdge->compound[ i ]);
91 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
94 #if GMSH_MINOR_VERSION <3
95 for ( size_t i = 0; i < gEdge->_compound.size(); ++i )
97 GEdge* gE = static_cast< GEdge* >( gEdge->_compound[ i ]);
98 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
102 if ( gEdge->geomType() == GEntity::CompoundCurve )
104 std::vector<GEdge*> gEdges = ((GEdgeCompound*)gEdge)->getCompounds();
105 for ( size_t i = 0; i < gEdges.size(); ++i )
107 GEdge* gE = gEdges[ i ];
108 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
112 return topoEdges.size();
115 //================================================================================
117 * \brief Retrieve ShapeBounds from a compound GFace
119 //================================================================================
121 bool getBoundsOfShapes( GFace* gFace,
122 std::vector< ShapeBounds > & topoFaces )
125 #if GMSH_MAJOR_VERSION >=4
126 #if GMSH_MINOR_VERSION >=3
127 for ( size_t i = 0; i < gFace->compound.size(); ++i )
129 GFace* gF = static_cast< GFace* >( gFace->compound[ i ]);
130 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
133 #if GMSH_MINOR_VERSION <3
134 for ( size_t i = 0; i < gFace->_compound.size(); ++i )
136 GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]);
137 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
141 if ( gFace->geomType() == GEntity::CompoundSurface )
143 std::list<GFace*> gFaces = ((GFaceCompound*)gFace)->getCompounds();
144 for ( std::list<GFace*>::const_iterator itl = gFaces.begin();itl != gFaces.end(); ++itl )
147 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
151 return topoFaces.size();
153 //================================================================================
155 * \brief Find a shape whose bounding box includes a given point
157 //================================================================================
159 TopoDS_Shape getShapeAtPoint( const SPoint3& point, const std::vector< ShapeBounds > & shapes )
162 float distmin = std::numeric_limits<float>::max();
163 for ( size_t i = 0; i < shapes.size(); ++i )
165 float dist = GMSHPlugin_Mesher::DistBoundingBox( shapes[i]._bounds, point );
168 shape = shapes[i]._shape;
178 //=============================================================================
182 //=============================================================================
184 GMSHPlugin_Mesher::GMSHPlugin_Mesher (SMESH_Mesh* mesh,
185 const TopoDS_Shape& aShape)
189 // il faudra peut être mettre un truc par defaut si l'utilisateur ne rentre rien en para
190 //defaultParameters();
193 //void GMSHPlugin_Mesher::defaultParameters(){}
195 void GMSHPlugin_Mesher::SetParameters(const GMSHPlugin_Hypothesis* hyp)
199 _algo2d = hyp->Get2DAlgo();
200 _algo3d = hyp->Get3DAlgo();
201 _recomb2DAlgo = hyp->GetRecomb2DAlgo();
202 _recombineAll = hyp->GetRecombineAll();
203 _subdivAlgo = hyp->GetSubdivAlgo();
204 _remeshAlgo = hyp->GetRemeshAlgo();
205 _remeshPara = hyp->GetRemeshPara();
206 _smouthSteps = hyp->GetSmouthSteps();
207 _sizeFactor = hyp->GetSizeFactor();
208 _minSize = hyp->GetMinSize();
209 _maxSize = hyp->GetMaxSize();
210 _secondOrder = hyp->GetSecondOrder();
211 _useIncomplElem = hyp->GetUseIncomplElem();
212 _is2d = hyp->GetIs2d();
213 _compounds = hyp->GetCompoundOnEntries();
220 _recombineAll = false;
228 _secondOrder = false;
229 _useIncomplElem = true;
235 //================================================================================
237 * \brief Set Gmsh Options
239 //================================================================================
241 void GMSHPlugin_Mesher::SetGmshOptions()
243 MESSAGE("GMSHPlugin_Mesher::SetGmshOptions");
245 printf("We chose _algo2d %d \n", _algo2d );
246 printf("We chose _algo3d %d \n", _algo3d );
247 printf("We chose _recomb2DAlgo %d \n", _recomb2DAlgo );
248 printf("We chose _recombineAll %d \n", (_recombineAll)?1:0);
249 printf("We chose _subdivAlgo %d \n", _subdivAlgo );
250 printf("We chose _remeshAlgo %d \n", _remeshAlgo );
251 printf("We chose _remeshPara %d \n", _remeshPara );
252 printf("We chose _smouthSteps %e \n", _smouthSteps );
253 printf("We chose _sizeFactor %e \n", _sizeFactor );
254 printf("We chose _minSize %e \n", _minSize );
255 printf("We chose _maxSize %e \n", _maxSize );
256 printf("We chose _secondOrder %d \n", (_secondOrder)?1:0);
257 printf("We chose _useIncomplElem %d \n", (_useIncomplElem)?1:0);
258 printf("We are in dimension %d \n", (_is2d)?2:3);
261 std::map <int,double> mapAlgo2d;
262 mapAlgo2d[0]=2; mapAlgo2d[1]=1; mapAlgo2d[2]=5; mapAlgo2d[3]=6; mapAlgo2d[4]=8; mapAlgo2d[5]=9;
263 std::map <int,double> mapAlgo3d;
264 mapAlgo3d[0]=1; mapAlgo3d[1]=4; mapAlgo3d[2]=5; mapAlgo3d[3]=6; mapAlgo3d[4]=7; mapAlgo3d[5]=9;
267 ok = GmshSetOption("Mesh", "Algorithm" , mapAlgo2d[_algo2d]) ;
271 ok = GmshSetOption("Mesh", "Algorithm3D" , mapAlgo2d[_algo3d]) ;
274 ok = GmshSetOption("Mesh", "RecombinationAlgorithm" , (double)_recomb2DAlgo) ;
276 ok = GmshSetOption("Mesh", "RecombineAll" , (_recombineAll)?1.:0.) ;
278 ok = GmshSetOption("Mesh", "SubdivisionAlgorithm" , (double)_subdivAlgo) ;
280 ok = GmshSetOption("Mesh", "RemeshAlgorithm" , (double)_remeshAlgo) ;
282 ok = GmshSetOption("Mesh", "RemeshParametrization" , (double)_remeshPara) ;
284 ok = GmshSetOption("Mesh", "Smoothing" , (double)_smouthSteps) ;
286 ok = GmshSetOption("Mesh", "CharacteristicLengthFactor", _sizeFactor) ;
288 ok = GmshSetOption("Mesh", "CharacteristicLengthMin" , _minSize) ;
290 ok = GmshSetOption("Mesh", "CharacteristicLengthMax" , _maxSize) ;
292 ok = GmshSetOption("Mesh", "ElementOrder" , (_secondOrder)?2.:1.) ;
296 ok = GmshSetOption("Mesh", "SecondOrderIncomplete" ,(_useIncomplElem)?1.:0.);
301 //================================================================================
303 * \brief Create and add Compounds into GModel _gModel.
305 //================================================================================
307 void GMSHPlugin_Mesher::CreateGmshCompounds()
309 MESSAGE("GMSHPlugin_Mesher::CreateGmshCompounds");
311 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
313 OCC_Internals* occgeo = _gModel->getOCCInternals();
314 bool toSynchronize = false;
316 for(std::set<std::string>::const_iterator its = _compounds.begin();its != _compounds.end(); ++its )
318 GEOM::GEOM_Object_var aGeomObj;
319 TopoDS_Shape geomShape = TopoDS_Shape();
320 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( (*its).c_str() );
321 SALOMEDS::GenericAttribute_var anAttr;
322 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR"))
324 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
325 CORBA::String_var aVal = anIOR->Value();
326 CORBA::Object_var obj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->ConvertIORToObject(aVal);
327 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
329 geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
330 if ( geomShape.IsNull() )
333 TopAbs_ShapeEnum geomType = geomShape.ShapeType();
334 if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire
336 MESSAGE("shapeType == TopAbs_COMPOUND");
337 TopoDS_Iterator it(geomShape);
340 TopAbs_ShapeEnum shapeType = it.Value().ShapeType();
341 #if GMSH_MAJOR_VERSION >=4
342 std::vector< std::pair< int, int > > dimTags;
343 for ( ; it.More(); it.Next())
345 const TopoDS_Shape& topoShape = it.Value();
346 ASSERT(topoShape.ShapeType() == shapeType);
347 if ( _mesh->GetMeshDS()->ShapeToIndex( topoShape ) > 0 )
348 occgeo->importShapes( &topoShape, false, dimTags );
351 TopoDS_Shape face = TopExp_Explorer( _shape, shapeType ).Current();
352 SMESH_subMesh* sm = _mesh->GetSubMesh( face );
353 sm->GetComputeError() =
354 SMESH_ComputeError::New
355 ( COMPERR_WARNING, "Compound shape does not belong to the main geometry. Ignored");
358 std::vector<int> tags;
359 int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2;
360 for ( size_t i = 0; i < dimTags.size(); ++i )
362 if ( dimTags[i].first == dim )
363 tags.push_back( dimTags[i].second );
367 _gModel->getGEOInternals()->setCompoundMesh( dim, tags );
368 toSynchronize = true;
372 if (shapeType == TopAbs_EDGE)
374 MESSAGE(" shapeType == TopAbs_EDGE :");
375 int num = _gModel->getNumEdges()+1;
376 Curve *curve = CreateCurve(num, MSH_SEGM_COMPOUND, 1, NULL, NULL, -1, -1, 0., 1.);
377 for ( ; it.More(); it.Next())
379 TopoDS_Shape topoShape = it.Value();
380 ASSERT(topoShape.ShapeType() == shapeType);
381 curve->compound.push_back(occgeo->addEdgeToModel(_gModel, (TopoDS_Edge&)topoShape)->tag());
383 toSynchronize = true;
384 Tree_Add(_gModel->getGEOInternals()->Curves, &curve);
385 //_gModel->importGEOInternals();
388 else if (shapeType == TopAbs_FACE)
390 MESSAGE(" shapeType == TopAbs_FACE :");
391 int num = _gModel->getNumFaces()+1;
392 Surface *surface = CreateSurface(num, MSH_SURF_COMPOUND);
393 for ( ; it.More(); it.Next())
395 TopoDS_Shape topoShape = it.Value();
396 ASSERT(topoShape.ShapeType() == shapeType);
397 surface->compound.push_back(occgeo->addFaceToModel(_gModel, (TopoDS_Face&)topoShape)->tag());
399 toSynchronize = true;
400 Tree_Add(_gModel->getGEOInternals()->Surfaces, &surface);
404 _gModel->getGEOInternals()->synchronize(_gModel);
409 //================================================================================
411 * \brief Write mesh from GModel instance to SMESH instance
413 //================================================================================
415 void GMSHPlugin_Mesher::FillSMesh()
417 SMESHDS_Mesh* meshDS = _mesh->GetMeshDS();
420 for ( GModel::viter it = _gModel->firstVertex(); it != _gModel->lastVertex(); ++it)
422 GVertex *gVertex = *it;
424 // GET topoVertex CORRESPONDING TO gVertex
425 TopoDS_Vertex topoVertex = *((TopoDS_Vertex*)gVertex->getNativePtr());
427 if (gVertex->getVisibility() == 0) // belongs to a compound
429 SMESH_subMesh* sm = _mesh->GetSubMesh(topoVertex);
430 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
434 // FILL SMESH FOR topoVertex
436 for(unsigned int i = 0; i < gVertex->mesh_vertices.size(); i++)
438 MVertex *v = gVertex->mesh_vertices[i];
439 if(v->getIndex() >= 0)
441 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
442 meshDS->SetNodeOnVertex( node, topoVertex );
445 // WE DON'T ADD 0D ELEMENTS because it does not follow the salome meshers philosophy
447 // for(unsigned int i = 0; i < gVertex->getNumMeshElements(); i++)
449 // MElement *e = gVertex->getMeshElement(i);
450 // std::vector<MVertex*> verts;
451 // e->getVertices(verts);
452 // ASSERT(verts.size()==1);
453 // SMDS_Mesh0DElement* zeroDElement = 0;
454 // zeroDElement = meshDS->Add0DElementWithID(verts[0]->getNum(),e->getNum());
455 // meshDS->SetMeshElementOnShape(zeroDElement, topoVertex);
460 for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it)
464 // GET topoEdge CORRESPONDING TO gEdge
465 TopoDS_Edge topoEdge;
466 std::vector< ShapeBounds > topoEdges;
467 #if GMSH_MAJOR_VERSION >=4
468 #if GMSH_MINOR_VERSION >=3
469 if(gEdge->haveParametrization())
472 if ( gEdge->geomType() != GEntity::CompoundCurve )
475 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
476 if (gEdge->getVisibility() == 0) // belongs to a compound
478 SMESH_subMesh* sm = _mesh->GetSubMesh(topoEdge);
479 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
483 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
485 // FILL SMESH FOR topoEdge
487 for ( size_t i = 0; i < gEdge->mesh_vertices.size(); i++ )
489 MVertex *v = gEdge->mesh_vertices[i];
490 if ( v->getIndex() >= 0 )
492 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
495 topoEdge = TopoDS::Edge( getShapeAtPoint( v->point(), topoEdges ));
497 meshDS->SetNodeOnEdge( node, topoEdge );
502 for ( GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it )
505 if ( gEdge->getVisibility() == 0) // belongs to a compound
508 TopoDS_Edge topoEdge;
509 std::vector< ShapeBounds > topoEdges;
510 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
512 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
515 std::vector<MVertex*> verts(3);
516 for ( size_t i = 0; i < gEdge->getNumMeshElements(); i++ )
518 MElement *e = gEdge->getMeshElement(i);
520 e->getVertices(verts);
522 // if a node wasn't set, it is assigned here
523 for ( size_t j = 0; j < verts.size(); j++ )
525 if ( verts[j]->onWhat()->getVisibility() == 0 )
527 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[i]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
528 meshDS->SetNodeOnEdge( node, topoEdge );
529 verts[j]->setEntity(gEdge);
533 SMDS_MeshEdge* edge = 0;
534 switch (verts.size())
537 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
538 verts[1]->getNum(),e->getNum());
541 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
543 verts[2]->getNum(),e->getNum());
550 topoEdge = TopoDS::Edge( getShapeAtPoint( e->barycenter(), topoEdges ));
552 meshDS->SetMeshElementOnShape( edge, topoEdge );
557 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
561 // GET topoFace CORRESPONDING TO gFace
562 TopoDS_Face topoFace;
563 std::vector< ShapeBounds > topoFaces;
565 #if GMSH_MAJOR_VERSION >=4
566 #if GMSH_MINOR_VERSION >=3
567 if(gFace->haveParametrization())
570 if ( gFace->geomType() != GEntity::CompoundSurface )
573 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
574 if (gFace->getVisibility() == 0) // belongs to a compound
576 SMESH_subMesh* sm = _mesh->GetSubMesh(topoFace);
577 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
581 bool isCompound = getBoundsOfShapes( gFace, topoFaces );
583 // FILL SMESH FOR topoFace
585 for ( size_t i = 0; i < gFace->mesh_vertices.size(); i++ )
587 MVertex *v = gFace->mesh_vertices[i];
588 if ( v->getIndex() >= 0 )
590 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
593 topoFace = TopoDS::Face( getShapeAtPoint( v->point(), topoFaces ));
595 meshDS->SetNodeOnFace( node, topoFace );
600 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
604 #if GMSH_MAJOR_VERSION >=4
605 #if GMSH_MINOR_VERSION >=3
606 bool isCompound = (!gFace->haveParametrization());
609 bool isCompound = ( gFace->geomType() == GEntity::CompoundSurface );
611 if ( !isCompound && gFace->getVisibility() == 0 )
612 continue; // belongs to a compound
614 TopoDS_Face topoFace;
615 std::vector< ShapeBounds > topoFaces;
617 getBoundsOfShapes( gFace, topoFaces );
619 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
622 std::vector<MVertex*> verts;
623 for ( size_t i = 0; i < gFace->getNumMeshElements(); i++ )
625 MElement *e = gFace->getMeshElement(i);
627 e->getVertices(verts);
628 SMDS_MeshFace* face = 0;
630 // if a node wasn't set, it is assigned here
631 for ( size_t j = 0; j < verts.size(); j++)
633 if(verts[j]->onWhat()->getVisibility() == 0)
635 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[j]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
636 meshDS->SetNodeOnFace( node, topoFace );
637 verts[i]->setEntity(gFace);
640 switch (verts.size())
643 face = meshDS->AddFaceWithID(verts[0]->getNum(),
645 verts[2]->getNum(),e->getNum());
648 face = meshDS->AddFaceWithID(verts[0]->getNum(),
651 verts[3]->getNum(),e->getNum());
654 face = meshDS->AddFaceWithID(verts[0]->getNum(),
659 verts[5]->getNum(),e->getNum());
662 face = meshDS->AddFaceWithID(verts[0]->getNum(),
669 verts[7]->getNum(),e->getNum());
672 face = meshDS->AddFaceWithID(verts[0]->getNum(),
680 verts[8]->getNum(),e->getNum());
688 topoFace = TopoDS::Face( getShapeAtPoint( e->barycenter(), topoFaces ));
690 meshDS->SetMeshElementOnShape(face, topoFace);
695 for ( GModel::riter it = _gModel->firstRegion(); it != _gModel->lastRegion(); ++it)
697 GRegion *gRegion = *it;
698 if (gRegion->getVisibility() == 0)
701 // GET topoSolid CORRESPONDING TO gRegion
702 TopoDS_Solid topoSolid = *((TopoDS_Solid*)gRegion->getNativePtr());
704 // FILL SMESH FOR topoSolid
707 for(unsigned int i = 0; i < gRegion->mesh_vertices.size(); i++)
709 MVertex *v = gRegion->mesh_vertices[i];
710 if(v->getIndex() >= 0)
712 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
713 meshDS->SetNodeInVolume( node, topoSolid );
718 std::vector<MVertex*> verts;
719 for(unsigned int i = 0; i < gRegion->getNumMeshElements(); i++)
721 MElement *e = gRegion->getMeshElement(i);
723 e->getVertices(verts);
724 SMDS_MeshVolume* volume = 0;
725 switch (verts.size()){
727 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
730 verts[3]->getNum(),e->getNum());
733 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
737 verts[4]->getNum(),e->getNum());
740 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
745 verts[4]->getNum(),e->getNum());
748 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
755 verts[5]->getNum(),e->getNum());
758 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
767 verts[9]->getNum(),e->getNum());
770 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
782 verts[9]->getNum(),e->getNum());
784 case 14: // same as case 13, because no pyra14 in smesh
785 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
797 verts[9]->getNum(),e->getNum());
800 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
814 verts[10]->getNum(),e->getNum());
816 case 18: // same as case 15, because no penta18 in smesh
817 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
831 verts[10]->getNum(),e->getNum());
834 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
853 verts[12]->getNum(),e->getNum());
856 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
889 meshDS->SetMeshElementOnShape(volume, topoSolid);
896 //================================================================================
898 * \brief Find if SPoint point is in SBoundingBox3d bounds
900 //================================================================================
902 float GMSHPlugin_Mesher::DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point)
904 SPoint3 min = bounds.min();
905 SPoint3 max = bounds.max();
909 if (point.x() < min.x())
910 x = min.x()-point.x();
911 else if (point.x() > max.x())
912 x = point.x()-max.x();
916 if (point.y() < min.y())
917 y = min.y()-point.y();
918 else if (point.y() > max.y())
919 y = point.y()-max.y();
923 if (point.z() < min.z())
924 z = min.z()-point.z();
925 else if (point.z() > max.z())
926 z = point.z()-max.z();
932 //================================================================================
934 * \brief Reimplemented GmshMessage call. Actions done if errors occurs
935 * during gmsh meshing. We define here what to display and what to do.
937 //================================================================================
938 void GMSHPlugin_Mesher::mymsg::operator()(std::string level, std::string msg)
940 //MESSAGE("level="<< level.c_str() << ", msg=" << msg.c_str()<< "\n");
941 printf("level=%s msg=%s\n", level.c_str(), msg.c_str());
943 if(level == "Fatal" || level == "Error")
945 std::ostringstream oss;
946 if (level == "Fatal")
947 oss << "Fatal error during Generation of Gmsh Mesh\n";
949 oss << "Error during Generation of Gmsh Mesh\n";
950 oss << " " << msg.c_str() << "\n";
951 GEntity *e = _gModel->getCurrentMeshEntity();
954 oss << " error occurred while meshing entity:\n" <<
955 " tag=" << e->tag() << "\n" <<
956 " dimension=" << e->dim() << "\n" <<
957 " native pointer=" << e->getNativePtr();
958 //if(e->geomType() != GEntity::CompoundCurve and e->geomType() != GEntity::CompoundSurface)
960 //SMESH_subMesh *sm = _mesh->GetSubMesh(*((TopoDS_Shape*)e->getNativePtr()));
961 //SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
962 //SMESH_Comment comment;
963 //comment << SMESH_Comment(oss.str);
964 //std::string str = oss.str();
965 //smError.reset( new SMESH_ComputeError( str ));
967 // plutot que de faire de la merde ici, on pourait simplement
968 // remplir une liste pour dire sur quelles entités gmsh se plante
969 // (puis faire le fillsmesh)
970 // puis faire une nouvelle routine qui réécrit les messages d'erreur
971 // probleme : gmsh peut planté en Fatal, dans ce cas pas de fillsmesh
974 if (level == "Fatal")
976 CTX::instance()->lock = 0;
980 printf(oss.str().c_str());
984 //=============================================================================
986 * Here we are going to use the GMSH mesher
988 //=============================================================================
990 bool GMSHPlugin_Mesher::Compute()
992 MESSAGE("GMSHPlugin_Mesher::Compute");
998 _gModel = new GModel();
1000 GmshSetMessageHandler(&msg);
1001 _gModel->importOCCShape((void*)&_shape);
1002 if (_compounds.size() > 0) CreateGmshCompounds();
1003 MESSAGE("GModel::Mesh");
1006 _gModel->mesh((_is2d)?2:3);
1007 #ifdef WITH_SMESH_CANCEL_COMPUTE
1011 catch (std::string& str)
1019 MESSAGE("Unrecoverable error during Generation of Gmsh Mesh");
1024 #if GMSH_MAJOR_VERSION < 4
1025 if (_compounds.size() > 0) _gModel->setCompoundVisibility();
1031 MESSAGE("GMSHPlugin_Mesher::Compute:End");