1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2019 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.
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
20 #include "GMSHPlugin_Mesher.hxx"
21 #include "GMSHPlugin_Hypothesis_2D.hxx"
23 #include <SMDS_FaceOfNodes.hxx>
24 #include <SMDS_MeshElement.hxx>
25 #include <SMDS_MeshNode.hxx>
26 #include <SMESHDS_Mesh.hxx>
27 #include <SMESH_Block.hxx>
28 #include <SMESH_Comment.hxx>
29 #include <SMESH_ComputeError.hxx>
30 #include <SMESH_File.hxx>
31 #include <SMESH_Gen_i.hxx>
32 #include <SMESH_Mesh.hxx>
33 #include <SMESH_MesherHelper.hxx>
34 #include <SMESH_subMesh.hxx>
35 #include <utilities.h>
40 #include <BRep_Tool.hxx>
41 #include <Bnd_B3d.hxx>
42 #include <GCPnts_AbscissaPoint.hxx>
43 #include <GeomAdaptor_Curve.hxx>
44 #include <NCollection_Map.hxx>
45 #include <OSD_File.hxx>
46 #include <OSD_Path.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_ProgramError.hxx>
49 #include <TCollection_AsciiString.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
53 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
54 #include <TopTools_DataMapOfShapeInteger.hxx>
55 #include <TopTools_DataMapOfShapeShape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
60 #if GMSH_MAJOR_VERSION >=4
61 #include <GmshGlobal.h>
71 SBoundingBox3d _bounds;
75 //================================================================================
77 * \brief Retrieve ShapeBounds from a compound GEdge
79 //================================================================================
81 bool getBoundsOfShapes( GEdge* gEdge,
82 std::vector< ShapeBounds > & topoEdges )
85 #if GMSH_MAJOR_VERSION >=4
86 for ( size_t i = 0; i < gEdge->_compound.size(); ++i )
88 GEdge* gE = static_cast< GEdge* >( gEdge->_compound[ i ]);
89 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
92 if ( gEdge->geomType() == GEntity::CompoundCurve )
94 std::vector<GEdge*> gEdges = ((GEdgeCompound*)gEdge)->getCompounds();
95 for ( size_t i = 0; i < gEdges.size(); ++i )
97 GEdge* gE = gEdges[ i ];
98 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
102 return topoEdges.size();
105 //================================================================================
107 * \brief Retrieve ShapeBounds from a compound GFace
109 //================================================================================
111 bool getBoundsOfShapes( GFace* gFace,
112 std::vector< ShapeBounds > & topoFaces )
115 #if GMSH_MAJOR_VERSION >=4
116 for ( size_t i = 0; i < gFace->_compound.size(); ++i )
118 GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]);
119 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
122 if ( gFace->geomType() == GEntity::CompoundSurface )
124 std::list<GFace*> gFaces = ((GFaceCompound*)gFace)->getCompounds();
125 for ( std::list<GFace*>::const_iterator itl = gFaces.begin();itl != gFaces.end(); ++itl )
128 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
132 return topoFaces.size();
134 //================================================================================
136 * \brief Find a shape whose bounding box includes a given point
138 //================================================================================
140 TopoDS_Shape getShapeAtPoint( const SPoint3& point, const std::vector< ShapeBounds > & shapes )
143 float distmin = std::numeric_limits<float>::max();
144 for ( size_t i = 0; i < shapes.size(); ++i )
146 float dist = GMSHPlugin_Mesher::DistBoundingBox( shapes[i]._bounds, point );
149 shape = shapes[i]._shape;
159 //=============================================================================
163 //=============================================================================
165 GMSHPlugin_Mesher::GMSHPlugin_Mesher (SMESH_Mesh* mesh,
166 const TopoDS_Shape& aShape)
170 // il faudra peut être mettre un truc par defaut si l'utilisateur ne rentre rien en para
171 //defaultParameters();
174 //void GMSHPlugin_Mesher::defaultParameters(){}
176 void GMSHPlugin_Mesher::SetParameters(const GMSHPlugin_Hypothesis* hyp)
180 _algo2d = hyp->Get2DAlgo();
181 _algo3d = hyp->Get3DAlgo();
182 _recomb2DAlgo = hyp->GetRecomb2DAlgo();
183 _recombineAll = hyp->GetRecombineAll();
184 _subdivAlgo = hyp->GetSubdivAlgo();
185 _remeshAlgo = hyp->GetRemeshAlgo();
186 _remeshPara = hyp->GetRemeshPara();
187 _smouthSteps = hyp->GetSmouthSteps();
188 _sizeFactor = hyp->GetSizeFactor();
189 _minSize = hyp->GetMinSize();
190 _maxSize = hyp->GetMaxSize();
191 _secondOrder = hyp->GetSecondOrder();
192 _useIncomplElem = hyp->GetUseIncomplElem();
193 _is2d = hyp->GetIs2d();
194 _compounds = hyp->GetCompoundOnEntries();
201 _recombineAll = false;
209 _secondOrder = false;
210 _useIncomplElem = true;
216 //================================================================================
218 * \brief Set Gmsh Options
220 //================================================================================
222 void GMSHPlugin_Mesher::SetGmshOptions()
224 MESSAGE("GMSHPlugin_Mesher::SetGmshOptions");
226 printf("We chose _algo2d %d \n", _algo2d );
227 printf("We chose _algo3d %d \n", _algo3d );
228 printf("We chose _recomb2DAlgo %d \n", _recomb2DAlgo );
229 printf("We chose _recombineAll %d \n", (_recombineAll)?1:0);
230 printf("We chose _subdivAlgo %d \n", _subdivAlgo );
231 printf("We chose _remeshAlgo %d \n", _remeshAlgo );
232 printf("We chose _remeshPara %d \n", _remeshPara );
233 printf("We chose _smouthSteps %e \n", _smouthSteps );
234 printf("We chose _sizeFactor %e \n", _sizeFactor );
235 printf("We chose _minSize %e \n", _minSize );
236 printf("We chose _maxSize %e \n", _maxSize );
237 printf("We chose _secondOrder %d \n", (_secondOrder)?1:0);
238 printf("We chose _useIncomplElem %d \n", (_useIncomplElem)?1:0);
239 printf("We are in dimension %d \n", (_is2d)?2:3);
242 std::map <int,double> mapAlgo2d;
243 mapAlgo2d[0]=2; mapAlgo2d[1]=1; mapAlgo2d[2]=5; mapAlgo2d[3]=6; mapAlgo2d[4]=8; mapAlgo2d[5]=9;
244 std::map <int,double> mapAlgo3d;
245 mapAlgo3d[0]=1; mapAlgo3d[1]=4; mapAlgo3d[2]=5; mapAlgo3d[3]=6; mapAlgo3d[4]=7; mapAlgo3d[5]=9;
248 ok = GmshSetOption("Mesh", "Algorithm" , mapAlgo2d[_algo2d]) ;
252 ok = GmshSetOption("Mesh", "Algorithm3D" , mapAlgo2d[_algo3d]) ;
255 ok = GmshSetOption("Mesh", "RecombinationAlgorithm" , (double)_recomb2DAlgo) ;
257 ok = GmshSetOption("Mesh", "RecombineAll" , (_recombineAll)?1.:0.) ;
259 ok = GmshSetOption("Mesh", "SubdivisionAlgorithm" , (double)_subdivAlgo) ;
261 ok = GmshSetOption("Mesh", "RemeshAlgorithm" , (double)_remeshAlgo) ;
263 ok = GmshSetOption("Mesh", "RemeshParametrization" , (double)_remeshPara) ;
265 ok = GmshSetOption("Mesh", "Smoothing" , (double)_smouthSteps) ;
267 ok = GmshSetOption("Mesh", "CharacteristicLengthFactor", _sizeFactor) ;
269 ok = GmshSetOption("Mesh", "CharacteristicLengthMin" , _minSize) ;
271 ok = GmshSetOption("Mesh", "CharacteristicLengthMax" , _maxSize) ;
273 ok = GmshSetOption("Mesh", "ElementOrder" , (_secondOrder)?2.:1.) ;
277 ok = GmshSetOption("Mesh", "SecondOrderIncomplete" ,(_useIncomplElem)?1.:0.);
282 //================================================================================
284 * \brief Create and add Compounds into GModel _gModel.
286 //================================================================================
288 void GMSHPlugin_Mesher::CreateGmshCompounds()
290 MESSAGE("GMSHPlugin_Mesher::CreateGmshCompounds");
292 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
294 OCC_Internals* occgeo = _gModel->getOCCInternals();
295 bool toSynchronize = false;
297 for(std::set<std::string>::const_iterator its = _compounds.begin();its != _compounds.end(); ++its )
299 GEOM::GEOM_Object_var aGeomObj;
300 TopoDS_Shape geomShape = TopoDS_Shape();
301 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( (*its).c_str() );
302 SALOMEDS::GenericAttribute_var anAttr;
303 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR"))
305 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
306 CORBA::String_var aVal = anIOR->Value();
307 CORBA::Object_var obj = SMESH_Gen_i::getStudyServant()->ConvertIORToObject(aVal);
308 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
310 geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
311 if ( geomShape.IsNull() )
314 TopAbs_ShapeEnum geomType = geomShape.ShapeType();
315 if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire
317 MESSAGE("shapeType == TopAbs_COMPOUND");
318 TopoDS_Iterator it(geomShape);
321 TopAbs_ShapeEnum shapeType = it.Value().ShapeType();
322 #if GMSH_MAJOR_VERSION >=4
323 std::vector< std::pair< int, int > > dimTags;
324 for ( ; it.More(); it.Next())
326 const TopoDS_Shape& topoShape = it.Value();
327 ASSERT(topoShape.ShapeType() == shapeType);
328 if ( _mesh->GetMeshDS()->ShapeToIndex( topoShape ) > 0 )
329 occgeo->importShapes( &topoShape, false, dimTags );
332 TopoDS_Shape face = TopExp_Explorer( _shape, shapeType ).Current();
333 SMESH_subMesh* sm = _mesh->GetSubMesh( face );
334 sm->GetComputeError() =
335 SMESH_ComputeError::New
336 ( COMPERR_WARNING, "Compound shape does not belong to the main geometry. Ingnored");
339 std::vector<int> tags;
340 int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2;
341 for ( size_t i = 0; i < dimTags.size(); ++i )
343 if ( dimTags[i].first == dim )
344 tags.push_back( dimTags[i].second );
348 _gModel->getGEOInternals()->setCompoundMesh( dim, tags );
349 toSynchronize = true;
353 if (shapeType == TopAbs_EDGE)
355 MESSAGE(" shapeType == TopAbs_EDGE :");
356 int num = _gModel->getNumEdges()+1;
357 Curve *curve = CreateCurve(num, MSH_SEGM_COMPOUND, 1, NULL, NULL, -1, -1, 0., 1.);
358 for ( ; it.More(); it.Next())
360 TopoDS_Shape topoShape = it.Value();
361 ASSERT(topoShape.ShapeType() == shapeType);
362 curve->compound.push_back(occgeo->addEdgeToModel(_gModel, (TopoDS_Edge&)topoShape)->tag());
364 toSynchronize = true;
365 Tree_Add(_gModel->getGEOInternals()->Curves, &curve);
366 //_gModel->importGEOInternals();
369 else if (shapeType == TopAbs_FACE)
371 MESSAGE(" shapeType == TopAbs_FACE :");
372 int num = _gModel->getNumFaces()+1;
373 Surface *surface = CreateSurface(num, MSH_SURF_COMPOUND);
374 for ( ; it.More(); it.Next())
376 TopoDS_Shape topoShape = it.Value();
377 ASSERT(topoShape.ShapeType() == shapeType);
378 surface->compound.push_back(occgeo->addFaceToModel(_gModel, (TopoDS_Face&)topoShape)->tag());
380 toSynchronize = true;
381 Tree_Add(_gModel->getGEOInternals()->Surfaces, &surface);
385 _gModel->getGEOInternals()->synchronize(_gModel);
390 //================================================================================
392 * \brief Write mesh from GModel instance to SMESH instance
394 //================================================================================
396 void GMSHPlugin_Mesher::FillSMesh()
398 SMESHDS_Mesh* meshDS = _mesh->GetMeshDS();
401 for ( GModel::viter it = _gModel->firstVertex(); it != _gModel->lastVertex(); ++it)
403 GVertex *gVertex = *it;
405 // GET topoVertex CORRESPONDING TO gVertex
406 TopoDS_Vertex topoVertex = *((TopoDS_Vertex*)gVertex->getNativePtr());
408 if (gVertex->getVisibility() == 0) // belongs to a compound
410 SMESH_subMesh* sm = _mesh->GetSubMesh(topoVertex);
411 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
415 // FILL SMESH FOR topoVertex
417 for(unsigned int i = 0; i < gVertex->mesh_vertices.size(); i++)
419 MVertex *v = gVertex->mesh_vertices[i];
420 if(v->getIndex() >= 0)
422 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
423 meshDS->SetNodeOnVertex( node, topoVertex );
426 // WE DON'T ADD 0D ELEMENTS because it does not follow the salome meshers philosophy
428 // for(unsigned int i = 0; i < gVertex->getNumMeshElements(); i++)
430 // MElement *e = gVertex->getMeshElement(i);
431 // std::vector<MVertex*> verts;
432 // e->getVertices(verts);
433 // ASSERT(verts.size()==1);
434 // SMDS_Mesh0DElement* zeroDElement = 0;
435 // zeroDElement = meshDS->Add0DElementWithID(verts[0]->getNum(),e->getNum());
436 // meshDS->SetMeshElementOnShape(zeroDElement, topoVertex);
441 for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it)
445 // GET topoEdge CORRESPONDING TO gEdge
446 TopoDS_Edge topoEdge;
447 std::vector< ShapeBounds > topoEdges;
449 if ( gEdge->geomType() != GEntity::CompoundCurve )
451 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
452 if (gEdge->getVisibility() == 0) // belongs to a compound
454 SMESH_subMesh* sm = _mesh->GetSubMesh(topoEdge);
455 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
459 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
461 // FILL SMESH FOR topoEdge
463 for ( size_t i = 0; i < gEdge->mesh_vertices.size(); i++ )
465 MVertex *v = gEdge->mesh_vertices[i];
466 if ( v->getIndex() >= 0 )
468 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
471 topoEdge = TopoDS::Edge( getShapeAtPoint( v->point(), topoEdges ));
473 meshDS->SetNodeOnEdge( node, topoEdge );
478 for ( GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it )
481 if ( gEdge->getVisibility() == 0) // belongs to a compound
484 TopoDS_Edge topoEdge;
485 std::vector< ShapeBounds > topoEdges;
486 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
488 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
491 std::vector<MVertex*> verts(3);
492 for ( size_t i = 0; i < gEdge->getNumMeshElements(); i++ )
494 MElement *e = gEdge->getMeshElement(i);
496 e->getVertices(verts);
498 // if a node wasn't set, it is assigned here
499 for ( size_t j = 0; j < verts.size(); j++ )
501 if ( verts[j]->onWhat()->getVisibility() == 0 )
503 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[i]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
504 meshDS->SetNodeOnEdge( node, topoEdge );
505 verts[j]->setEntity(gEdge);
509 SMDS_MeshEdge* edge = 0;
510 switch (verts.size())
513 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
514 verts[1]->getNum(),e->getNum());
517 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
519 verts[2]->getNum(),e->getNum());
526 topoEdge = TopoDS::Edge( getShapeAtPoint( e->barycenter(), topoEdges ));
528 meshDS->SetMeshElementOnShape( edge, topoEdge );
533 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
537 // GET topoFace CORRESPONDING TO gFace
538 TopoDS_Face topoFace;
539 std::vector< ShapeBounds > topoFaces;
541 if ( gFace->geomType() != GEntity::CompoundSurface )
543 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
544 if (gFace->getVisibility() == 0) // belongs to a compound
546 SMESH_subMesh* sm = _mesh->GetSubMesh(topoFace);
547 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
551 bool isCompound = getBoundsOfShapes( gFace, topoFaces );
553 // FILL SMESH FOR topoFace
555 for ( size_t i = 0; i < gFace->mesh_vertices.size(); i++ )
557 MVertex *v = gFace->mesh_vertices[i];
558 if ( v->getIndex() >= 0 )
560 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
563 topoFace = TopoDS::Face( getShapeAtPoint( v->point(), topoFaces ));
565 meshDS->SetNodeOnFace( node, topoFace );
570 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
574 bool isCompound = ( gFace->geomType() == GEntity::CompoundSurface );
575 if ( !isCompound && gFace->getVisibility() == 0 )
576 continue; // belongs to a compound
578 TopoDS_Face topoFace;
579 std::vector< ShapeBounds > topoFaces;
581 getBoundsOfShapes( gFace, topoFaces );
583 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
586 std::vector<MVertex*> verts;
587 for ( size_t i = 0; i < gFace->getNumMeshElements(); i++ )
589 MElement *e = gFace->getMeshElement(i);
591 e->getVertices(verts);
592 SMDS_MeshFace* face = 0;
594 // if a node wasn't set, it is assigned here
595 for ( size_t j = 0; j < verts.size(); j++)
597 if(verts[j]->onWhat()->getVisibility() == 0)
599 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[j]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
600 meshDS->SetNodeOnFace( node, topoFace );
601 verts[i]->setEntity(gFace);
604 switch (verts.size())
607 face = meshDS->AddFaceWithID(verts[0]->getNum(),
609 verts[2]->getNum(),e->getNum());
612 face = meshDS->AddFaceWithID(verts[0]->getNum(),
615 verts[3]->getNum(),e->getNum());
618 face = meshDS->AddFaceWithID(verts[0]->getNum(),
623 verts[5]->getNum(),e->getNum());
626 face = meshDS->AddFaceWithID(verts[0]->getNum(),
633 verts[7]->getNum(),e->getNum());
636 face = meshDS->AddFaceWithID(verts[0]->getNum(),
644 verts[8]->getNum(),e->getNum());
652 topoFace = TopoDS::Face( getShapeAtPoint( e->barycenter(), topoFaces ));
654 meshDS->SetMeshElementOnShape(face, topoFace);
659 for ( GModel::riter it = _gModel->firstRegion(); it != _gModel->lastRegion(); ++it)
661 GRegion *gRegion = *it;
662 if (gRegion->getVisibility() == 0)
665 // GET topoSolid CORRESPONDING TO gRegion
666 TopoDS_Solid topoSolid = *((TopoDS_Solid*)gRegion->getNativePtr());
668 // FILL SMESH FOR topoSolid
671 for(unsigned int i = 0; i < gRegion->mesh_vertices.size(); i++)
673 MVertex *v = gRegion->mesh_vertices[i];
674 if(v->getIndex() >= 0)
676 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
677 meshDS->SetNodeInVolume( node, topoSolid );
682 std::vector<MVertex*> verts;
683 for(unsigned int i = 0; i < gRegion->getNumMeshElements(); i++)
685 MElement *e = gRegion->getMeshElement(i);
687 e->getVertices(verts);
688 SMDS_MeshVolume* volume = 0;
689 switch (verts.size()){
691 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
694 verts[3]->getNum(),e->getNum());
697 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
701 verts[4]->getNum(),e->getNum());
704 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
709 verts[4]->getNum(),e->getNum());
712 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
719 verts[5]->getNum(),e->getNum());
722 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
731 verts[9]->getNum(),e->getNum());
734 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
746 verts[9]->getNum(),e->getNum());
748 case 14: // same as case 13, because no pyra14 in smesh
749 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
761 verts[9]->getNum(),e->getNum());
764 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
778 verts[10]->getNum(),e->getNum());
780 case 18: // same as case 15, because no penta18 in smesh
781 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
795 verts[10]->getNum(),e->getNum());
798 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
817 verts[12]->getNum(),e->getNum());
820 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
853 meshDS->SetMeshElementOnShape(volume, topoSolid);
860 //================================================================================
862 * \brief Find if SPoint point is in SBoundingBox3d bounds
864 //================================================================================
866 float GMSHPlugin_Mesher::DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point)
868 SPoint3 min = bounds.min();
869 SPoint3 max = bounds.max();
873 if (point.x() < min.x())
874 x = min.x()-point.x();
875 else if (point.x() > max.x())
876 x = point.x()-max.x();
880 if (point.y() < min.y())
881 y = min.y()-point.y();
882 else if (point.y() > max.y())
883 y = point.y()-max.y();
887 if (point.z() < min.z())
888 z = min.z()-point.z();
889 else if (point.z() > max.z())
890 z = point.z()-max.z();
896 //================================================================================
898 * \brief Reimplemented GmshMessage call. Actions done if errors occurs
899 * during gmsh meshing. We define here what to display and what to do.
901 //================================================================================
902 void GMSHPlugin_Mesher::mymsg::operator()(std::string level, std::string msg)
904 //MESSAGE("level="<< level.c_str() << ", msg=" << msg.c_str()<< "\n");
905 printf("level=%s msg=%s\n", level.c_str(), msg.c_str());
907 if(level == "Fatal" || level == "Error")
909 std::ostringstream oss;
910 if (level == "Fatal")
911 oss << "Fatal error during Generation of Gmsh Mesh\n";
913 oss << "Error during Generation of Gmsh Mesh\n";
914 oss << " " << msg.c_str() << "\n";
915 GEntity *e = _gModel->getCurrentMeshEntity();
918 oss << " error occurred while meshing entity:\n" <<
919 " tag=" << e->tag() << "\n" <<
920 " dimension=" << e->dim() << "\n" <<
921 " native pointer=" << e->getNativePtr();
922 //if(e->geomType() != GEntity::CompoundCurve and e->geomType() != GEntity::CompoundSurface)
924 //SMESH_subMesh *sm = _mesh->GetSubMesh(*((TopoDS_Shape*)e->getNativePtr()));
925 //SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
926 //SMESH_Comment comment;
927 //comment << SMESH_Comment(oss.str);
928 //std::string str = oss.str();
929 //smError.reset( new SMESH_ComputeError( str ));
931 // plutot que de faire de la merde ici, on pourait simplement
932 // remplir une liste pour dire sur quelles entités gmsh se plante
933 // (puis faire le fillsmesh)
934 // puis faire une nouvelle routine qui réécrit les messages d'erreur
935 // probleme : gmsh peut planté en Fatal, dans ce cas pas de fillsmesh
938 if (level == "Fatal")
940 CTX::instance()->lock = 0;
944 printf(oss.str().c_str());
948 //=============================================================================
950 * Here we are going to use the GMSH mesher
952 //=============================================================================
954 bool GMSHPlugin_Mesher::Compute()
956 MESSAGE("GMSHPlugin_Mesher::Compute");
962 _gModel = new GModel();
964 GmshSetMessageHandler(&msg);
965 _gModel->importOCCShape((void*)&_shape);
966 if (_compounds.size() > 0) CreateGmshCompounds();
967 MESSAGE("GModel::Mesh");
970 _gModel->mesh((_is2d)?2:3);
971 #ifdef WITH_SMESH_CANCEL_COMPUTE
975 catch (std::string& str)
983 MESSAGE("Unrecoverable error during Generation of Gmsh Mesh");
988 #if GMSH_MAJOR_VERSION < 4
989 if (_compounds.size() > 0) _gModel->setCompoundVisibility();
995 MESSAGE("GMSHPlugin_Mesher::Compute:End");