1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2020 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 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 if ( gEdge->geomType() == GEntity::CompoundCurve )
95 std::vector<GEdge*> gEdges = ((GEdgeCompound*)gEdge)->getCompounds();
96 for ( size_t i = 0; i < gEdges.size(); ++i )
98 GEdge* gE = gEdges[ i ];
99 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
103 return topoEdges.size();
106 //================================================================================
108 * \brief Retrieve ShapeBounds from a compound GFace
110 //================================================================================
112 bool getBoundsOfShapes( GFace* gFace,
113 std::vector< ShapeBounds > & topoFaces )
116 #if GMSH_MAJOR_VERSION >=4
117 for ( size_t i = 0; i < gFace->_compound.size(); ++i )
119 GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]);
120 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
123 if ( gFace->geomType() == GEntity::CompoundSurface )
125 std::list<GFace*> gFaces = ((GFaceCompound*)gFace)->getCompounds();
126 for ( std::list<GFace*>::const_iterator itl = gFaces.begin();itl != gFaces.end(); ++itl )
129 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
133 return topoFaces.size();
135 //================================================================================
137 * \brief Find a shape whose bounding box includes a given point
139 //================================================================================
141 TopoDS_Shape getShapeAtPoint( const SPoint3& point, const std::vector< ShapeBounds > & shapes )
144 float distmin = std::numeric_limits<float>::max();
145 for ( size_t i = 0; i < shapes.size(); ++i )
147 float dist = GMSHPlugin_Mesher::DistBoundingBox( shapes[i]._bounds, point );
150 shape = shapes[i]._shape;
160 //=============================================================================
164 //=============================================================================
166 GMSHPlugin_Mesher::GMSHPlugin_Mesher (SMESH_Mesh* mesh,
167 const TopoDS_Shape& aShape)
171 // il faudra peut être mettre un truc par defaut si l'utilisateur ne rentre rien en para
172 //defaultParameters();
175 //void GMSHPlugin_Mesher::defaultParameters(){}
177 void GMSHPlugin_Mesher::SetParameters(const GMSHPlugin_Hypothesis* hyp)
181 _algo2d = hyp->Get2DAlgo();
182 _algo3d = hyp->Get3DAlgo();
183 _recomb2DAlgo = hyp->GetRecomb2DAlgo();
184 _recombineAll = hyp->GetRecombineAll();
185 _subdivAlgo = hyp->GetSubdivAlgo();
186 _remeshAlgo = hyp->GetRemeshAlgo();
187 _remeshPara = hyp->GetRemeshPara();
188 _smouthSteps = hyp->GetSmouthSteps();
189 _sizeFactor = hyp->GetSizeFactor();
190 _minSize = hyp->GetMinSize();
191 _maxSize = hyp->GetMaxSize();
192 _secondOrder = hyp->GetSecondOrder();
193 _useIncomplElem = hyp->GetUseIncomplElem();
194 _is2d = hyp->GetIs2d();
195 _compounds = hyp->GetCompoundOnEntries();
202 _recombineAll = false;
210 _secondOrder = false;
211 _useIncomplElem = true;
217 //================================================================================
219 * \brief Set Gmsh Options
221 //================================================================================
223 void GMSHPlugin_Mesher::SetGmshOptions()
225 MESSAGE("GMSHPlugin_Mesher::SetGmshOptions");
227 printf("We chose _algo2d %d \n", _algo2d );
228 printf("We chose _algo3d %d \n", _algo3d );
229 printf("We chose _recomb2DAlgo %d \n", _recomb2DAlgo );
230 printf("We chose _recombineAll %d \n", (_recombineAll)?1:0);
231 printf("We chose _subdivAlgo %d \n", _subdivAlgo );
232 printf("We chose _remeshAlgo %d \n", _remeshAlgo );
233 printf("We chose _remeshPara %d \n", _remeshPara );
234 printf("We chose _smouthSteps %e \n", _smouthSteps );
235 printf("We chose _sizeFactor %e \n", _sizeFactor );
236 printf("We chose _minSize %e \n", _minSize );
237 printf("We chose _maxSize %e \n", _maxSize );
238 printf("We chose _secondOrder %d \n", (_secondOrder)?1:0);
239 printf("We chose _useIncomplElem %d \n", (_useIncomplElem)?1:0);
240 printf("We are in dimension %d \n", (_is2d)?2:3);
243 std::map <int,double> mapAlgo2d;
244 mapAlgo2d[0]=2; mapAlgo2d[1]=1; mapAlgo2d[2]=5; mapAlgo2d[3]=6; mapAlgo2d[4]=8; mapAlgo2d[5]=9;
245 std::map <int,double> mapAlgo3d;
246 mapAlgo3d[0]=1; mapAlgo3d[1]=4; mapAlgo3d[2]=5; mapAlgo3d[3]=6; mapAlgo3d[4]=7; mapAlgo3d[5]=9;
249 ok = GmshSetOption("Mesh", "Algorithm" , mapAlgo2d[_algo2d]) ;
253 ok = GmshSetOption("Mesh", "Algorithm3D" , mapAlgo2d[_algo3d]) ;
256 ok = GmshSetOption("Mesh", "RecombinationAlgorithm" , (double)_recomb2DAlgo) ;
258 ok = GmshSetOption("Mesh", "RecombineAll" , (_recombineAll)?1.:0.) ;
260 ok = GmshSetOption("Mesh", "SubdivisionAlgorithm" , (double)_subdivAlgo) ;
262 ok = GmshSetOption("Mesh", "RemeshAlgorithm" , (double)_remeshAlgo) ;
264 ok = GmshSetOption("Mesh", "RemeshParametrization" , (double)_remeshPara) ;
266 ok = GmshSetOption("Mesh", "Smoothing" , (double)_smouthSteps) ;
268 ok = GmshSetOption("Mesh", "CharacteristicLengthFactor", _sizeFactor) ;
270 ok = GmshSetOption("Mesh", "CharacteristicLengthMin" , _minSize) ;
272 ok = GmshSetOption("Mesh", "CharacteristicLengthMax" , _maxSize) ;
274 ok = GmshSetOption("Mesh", "ElementOrder" , (_secondOrder)?2.:1.) ;
278 ok = GmshSetOption("Mesh", "SecondOrderIncomplete" ,(_useIncomplElem)?1.:0.);
283 //================================================================================
285 * \brief Create and add Compounds into GModel _gModel.
287 //================================================================================
289 void GMSHPlugin_Mesher::CreateGmshCompounds()
291 MESSAGE("GMSHPlugin_Mesher::CreateGmshCompounds");
293 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
295 OCC_Internals* occgeo = _gModel->getOCCInternals();
296 bool toSynchronize = false;
298 for(std::set<std::string>::const_iterator its = _compounds.begin();its != _compounds.end(); ++its )
300 GEOM::GEOM_Object_var aGeomObj;
301 TopoDS_Shape geomShape = TopoDS_Shape();
302 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( (*its).c_str() );
303 SALOMEDS::GenericAttribute_var anAttr;
304 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR"))
306 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
307 CORBA::String_var aVal = anIOR->Value();
308 CORBA::Object_var obj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->ConvertIORToObject(aVal);
309 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
311 geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
312 if ( geomShape.IsNull() )
315 TopAbs_ShapeEnum geomType = geomShape.ShapeType();
316 if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire
318 MESSAGE("shapeType == TopAbs_COMPOUND");
319 TopoDS_Iterator it(geomShape);
322 TopAbs_ShapeEnum shapeType = it.Value().ShapeType();
323 #if GMSH_MAJOR_VERSION >=4
324 std::vector< std::pair< int, int > > dimTags;
325 for ( ; it.More(); it.Next())
327 const TopoDS_Shape& topoShape = it.Value();
328 ASSERT(topoShape.ShapeType() == shapeType);
329 if ( _mesh->GetMeshDS()->ShapeToIndex( topoShape ) > 0 )
330 occgeo->importShapes( &topoShape, false, dimTags );
333 TopoDS_Shape face = TopExp_Explorer( _shape, shapeType ).Current();
334 SMESH_subMesh* sm = _mesh->GetSubMesh( face );
335 sm->GetComputeError() =
336 SMESH_ComputeError::New
337 ( COMPERR_WARNING, "Compound shape does not belong to the main geometry. Ignored");
340 std::vector<int> tags;
341 int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2;
342 for ( size_t i = 0; i < dimTags.size(); ++i )
344 if ( dimTags[i].first == dim )
345 tags.push_back( dimTags[i].second );
349 _gModel->getGEOInternals()->setCompoundMesh( dim, tags );
350 toSynchronize = true;
354 if (shapeType == TopAbs_EDGE)
356 MESSAGE(" shapeType == TopAbs_EDGE :");
357 int num = _gModel->getNumEdges()+1;
358 Curve *curve = CreateCurve(num, MSH_SEGM_COMPOUND, 1, NULL, NULL, -1, -1, 0., 1.);
359 for ( ; it.More(); it.Next())
361 TopoDS_Shape topoShape = it.Value();
362 ASSERT(topoShape.ShapeType() == shapeType);
363 curve->compound.push_back(occgeo->addEdgeToModel(_gModel, (TopoDS_Edge&)topoShape)->tag());
365 toSynchronize = true;
366 Tree_Add(_gModel->getGEOInternals()->Curves, &curve);
367 //_gModel->importGEOInternals();
370 else if (shapeType == TopAbs_FACE)
372 MESSAGE(" shapeType == TopAbs_FACE :");
373 int num = _gModel->getNumFaces()+1;
374 Surface *surface = CreateSurface(num, MSH_SURF_COMPOUND);
375 for ( ; it.More(); it.Next())
377 TopoDS_Shape topoShape = it.Value();
378 ASSERT(topoShape.ShapeType() == shapeType);
379 surface->compound.push_back(occgeo->addFaceToModel(_gModel, (TopoDS_Face&)topoShape)->tag());
381 toSynchronize = true;
382 Tree_Add(_gModel->getGEOInternals()->Surfaces, &surface);
386 _gModel->getGEOInternals()->synchronize(_gModel);
391 //================================================================================
393 * \brief Write mesh from GModel instance to SMESH instance
395 //================================================================================
397 void GMSHPlugin_Mesher::FillSMesh()
399 SMESHDS_Mesh* meshDS = _mesh->GetMeshDS();
402 for ( GModel::viter it = _gModel->firstVertex(); it != _gModel->lastVertex(); ++it)
404 GVertex *gVertex = *it;
406 // GET topoVertex CORRESPONDING TO gVertex
407 TopoDS_Vertex topoVertex = *((TopoDS_Vertex*)gVertex->getNativePtr());
409 if (gVertex->getVisibility() == 0) // belongs to a compound
411 SMESH_subMesh* sm = _mesh->GetSubMesh(topoVertex);
412 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
416 // FILL SMESH FOR topoVertex
418 for(unsigned int i = 0; i < gVertex->mesh_vertices.size(); i++)
420 MVertex *v = gVertex->mesh_vertices[i];
421 if(v->getIndex() >= 0)
423 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
424 meshDS->SetNodeOnVertex( node, topoVertex );
427 // WE DON'T ADD 0D ELEMENTS because it does not follow the salome meshers philosophy
429 // for(unsigned int i = 0; i < gVertex->getNumMeshElements(); i++)
431 // MElement *e = gVertex->getMeshElement(i);
432 // std::vector<MVertex*> verts;
433 // e->getVertices(verts);
434 // ASSERT(verts.size()==1);
435 // SMDS_Mesh0DElement* zeroDElement = 0;
436 // zeroDElement = meshDS->Add0DElementWithID(verts[0]->getNum(),e->getNum());
437 // meshDS->SetMeshElementOnShape(zeroDElement, topoVertex);
442 for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it)
446 // GET topoEdge CORRESPONDING TO gEdge
447 TopoDS_Edge topoEdge;
448 std::vector< ShapeBounds > topoEdges;
450 if ( gEdge->geomType() != GEntity::CompoundCurve )
452 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
453 if (gEdge->getVisibility() == 0) // belongs to a compound
455 SMESH_subMesh* sm = _mesh->GetSubMesh(topoEdge);
456 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
460 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
462 // FILL SMESH FOR topoEdge
464 for ( size_t i = 0; i < gEdge->mesh_vertices.size(); i++ )
466 MVertex *v = gEdge->mesh_vertices[i];
467 if ( v->getIndex() >= 0 )
469 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
472 topoEdge = TopoDS::Edge( getShapeAtPoint( v->point(), topoEdges ));
474 meshDS->SetNodeOnEdge( node, topoEdge );
479 for ( GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it )
482 if ( gEdge->getVisibility() == 0) // belongs to a compound
485 TopoDS_Edge topoEdge;
486 std::vector< ShapeBounds > topoEdges;
487 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
489 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
492 std::vector<MVertex*> verts(3);
493 for ( size_t i = 0; i < gEdge->getNumMeshElements(); i++ )
495 MElement *e = gEdge->getMeshElement(i);
497 e->getVertices(verts);
499 // if a node wasn't set, it is assigned here
500 for ( size_t j = 0; j < verts.size(); j++ )
502 if ( verts[j]->onWhat()->getVisibility() == 0 )
504 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[i]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
505 meshDS->SetNodeOnEdge( node, topoEdge );
506 verts[j]->setEntity(gEdge);
510 SMDS_MeshEdge* edge = 0;
511 switch (verts.size())
514 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
515 verts[1]->getNum(),e->getNum());
518 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
520 verts[2]->getNum(),e->getNum());
527 topoEdge = TopoDS::Edge( getShapeAtPoint( e->barycenter(), topoEdges ));
529 meshDS->SetMeshElementOnShape( edge, topoEdge );
534 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
538 // GET topoFace CORRESPONDING TO gFace
539 TopoDS_Face topoFace;
540 std::vector< ShapeBounds > topoFaces;
542 if ( gFace->geomType() != GEntity::CompoundSurface )
544 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
545 if (gFace->getVisibility() == 0) // belongs to a compound
547 SMESH_subMesh* sm = _mesh->GetSubMesh(topoFace);
548 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
552 bool isCompound = getBoundsOfShapes( gFace, topoFaces );
554 // FILL SMESH FOR topoFace
556 for ( size_t i = 0; i < gFace->mesh_vertices.size(); i++ )
558 MVertex *v = gFace->mesh_vertices[i];
559 if ( v->getIndex() >= 0 )
561 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
564 topoFace = TopoDS::Face( getShapeAtPoint( v->point(), topoFaces ));
566 meshDS->SetNodeOnFace( node, topoFace );
571 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
575 bool isCompound = ( gFace->geomType() == GEntity::CompoundSurface );
576 if ( !isCompound && gFace->getVisibility() == 0 )
577 continue; // belongs to a compound
579 TopoDS_Face topoFace;
580 std::vector< ShapeBounds > topoFaces;
582 getBoundsOfShapes( gFace, topoFaces );
584 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
587 std::vector<MVertex*> verts;
588 for ( size_t i = 0; i < gFace->getNumMeshElements(); i++ )
590 MElement *e = gFace->getMeshElement(i);
592 e->getVertices(verts);
593 SMDS_MeshFace* face = 0;
595 // if a node wasn't set, it is assigned here
596 for ( size_t j = 0; j < verts.size(); j++)
598 if(verts[j]->onWhat()->getVisibility() == 0)
600 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[j]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
601 meshDS->SetNodeOnFace( node, topoFace );
602 verts[i]->setEntity(gFace);
605 switch (verts.size())
608 face = meshDS->AddFaceWithID(verts[0]->getNum(),
610 verts[2]->getNum(),e->getNum());
613 face = meshDS->AddFaceWithID(verts[0]->getNum(),
616 verts[3]->getNum(),e->getNum());
619 face = meshDS->AddFaceWithID(verts[0]->getNum(),
624 verts[5]->getNum(),e->getNum());
627 face = meshDS->AddFaceWithID(verts[0]->getNum(),
634 verts[7]->getNum(),e->getNum());
637 face = meshDS->AddFaceWithID(verts[0]->getNum(),
645 verts[8]->getNum(),e->getNum());
653 topoFace = TopoDS::Face( getShapeAtPoint( e->barycenter(), topoFaces ));
655 meshDS->SetMeshElementOnShape(face, topoFace);
660 for ( GModel::riter it = _gModel->firstRegion(); it != _gModel->lastRegion(); ++it)
662 GRegion *gRegion = *it;
663 if (gRegion->getVisibility() == 0)
666 // GET topoSolid CORRESPONDING TO gRegion
667 TopoDS_Solid topoSolid = *((TopoDS_Solid*)gRegion->getNativePtr());
669 // FILL SMESH FOR topoSolid
672 for(unsigned int i = 0; i < gRegion->mesh_vertices.size(); i++)
674 MVertex *v = gRegion->mesh_vertices[i];
675 if(v->getIndex() >= 0)
677 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
678 meshDS->SetNodeInVolume( node, topoSolid );
683 std::vector<MVertex*> verts;
684 for(unsigned int i = 0; i < gRegion->getNumMeshElements(); i++)
686 MElement *e = gRegion->getMeshElement(i);
688 e->getVertices(verts);
689 SMDS_MeshVolume* volume = 0;
690 switch (verts.size()){
692 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
695 verts[3]->getNum(),e->getNum());
698 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
702 verts[4]->getNum(),e->getNum());
705 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
710 verts[4]->getNum(),e->getNum());
713 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
720 verts[5]->getNum(),e->getNum());
723 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
732 verts[9]->getNum(),e->getNum());
735 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
747 verts[9]->getNum(),e->getNum());
749 case 14: // same as case 13, because no pyra14 in smesh
750 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
762 verts[9]->getNum(),e->getNum());
765 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
779 verts[10]->getNum(),e->getNum());
781 case 18: // same as case 15, because no penta18 in smesh
782 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
796 verts[10]->getNum(),e->getNum());
799 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
818 verts[12]->getNum(),e->getNum());
821 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
854 meshDS->SetMeshElementOnShape(volume, topoSolid);
861 //================================================================================
863 * \brief Find if SPoint point is in SBoundingBox3d bounds
865 //================================================================================
867 float GMSHPlugin_Mesher::DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point)
869 SPoint3 min = bounds.min();
870 SPoint3 max = bounds.max();
874 if (point.x() < min.x())
875 x = min.x()-point.x();
876 else if (point.x() > max.x())
877 x = point.x()-max.x();
881 if (point.y() < min.y())
882 y = min.y()-point.y();
883 else if (point.y() > max.y())
884 y = point.y()-max.y();
888 if (point.z() < min.z())
889 z = min.z()-point.z();
890 else if (point.z() > max.z())
891 z = point.z()-max.z();
897 //================================================================================
899 * \brief Reimplemented GmshMessage call. Actions done if errors occurs
900 * during gmsh meshing. We define here what to display and what to do.
902 //================================================================================
903 void GMSHPlugin_Mesher::mymsg::operator()(std::string level, std::string msg)
905 //MESSAGE("level="<< level.c_str() << ", msg=" << msg.c_str()<< "\n");
906 printf("level=%s msg=%s\n", level.c_str(), msg.c_str());
908 if(level == "Fatal" || level == "Error")
910 std::ostringstream oss;
911 if (level == "Fatal")
912 oss << "Fatal error during Generation of Gmsh Mesh\n";
914 oss << "Error during Generation of Gmsh Mesh\n";
915 oss << " " << msg.c_str() << "\n";
916 GEntity *e = _gModel->getCurrentMeshEntity();
919 oss << " error occurred while meshing entity:\n" <<
920 " tag=" << e->tag() << "\n" <<
921 " dimension=" << e->dim() << "\n" <<
922 " native pointer=" << e->getNativePtr();
923 //if(e->geomType() != GEntity::CompoundCurve and e->geomType() != GEntity::CompoundSurface)
925 //SMESH_subMesh *sm = _mesh->GetSubMesh(*((TopoDS_Shape*)e->getNativePtr()));
926 //SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
927 //SMESH_Comment comment;
928 //comment << SMESH_Comment(oss.str);
929 //std::string str = oss.str();
930 //smError.reset( new SMESH_ComputeError( str ));
932 // plutot que de faire de la merde ici, on pourait simplement
933 // remplir une liste pour dire sur quelles entités gmsh se plante
934 // (puis faire le fillsmesh)
935 // puis faire une nouvelle routine qui réécrit les messages d'erreur
936 // probleme : gmsh peut planté en Fatal, dans ce cas pas de fillsmesh
939 if (level == "Fatal")
941 CTX::instance()->lock = 0;
945 printf(oss.str().c_str());
949 //=============================================================================
951 * Here we are going to use the GMSH mesher
953 //=============================================================================
955 bool GMSHPlugin_Mesher::Compute()
957 MESSAGE("GMSHPlugin_Mesher::Compute");
963 _gModel = new GModel();
965 GmshSetMessageHandler(&msg);
966 _gModel->importOCCShape((void*)&_shape);
967 if (_compounds.size() > 0) CreateGmshCompounds();
968 MESSAGE("GModel::Mesh");
971 _gModel->mesh((_is2d)?2:3);
972 #ifdef WITH_SMESH_CANCEL_COMPUTE
976 catch (std::string& str)
984 MESSAGE("Unrecoverable error during Generation of Gmsh Mesh");
989 #if GMSH_MAJOR_VERSION < 4
990 if (_compounds.size() > 0) _gModel->setCompoundVisibility();
996 MESSAGE("GMSHPlugin_Mesher::Compute:End");