1 // Copyright (C) 2004-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : GHS3DPlugin_GHS3D.cxx
23 // Author : Edward AGAPOV, modified by Lioka RAZAFINDRAZAKA (CEA) 09/02/2007
25 //=============================================================================
27 #include "GHS3DPlugin_GHS3D.hxx"
28 #include "GHS3DPlugin_Hypothesis.hxx"
30 #include <Basics_Utils.hxx>
32 //#include "SMESH_Gen.hxx"
33 #include <SMESH_Client.hxx>
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_Comment.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "SMESH_MeshEditor.hxx"
38 #include "SMESH_OctreeNode.hxx"
39 #include "SMESH_Group.hxx"
41 #include "SMDS_MeshElement.hxx"
42 #include "SMDS_MeshNode.hxx"
43 #include "SMDS_FaceOfNodes.hxx"
44 #include "SMDS_VolumeOfNodes.hxx"
46 #include "SMESHDS_Group.hxx"
48 #include <StdMeshers_QuadToTriaAdaptor.hxx>
49 #include <StdMeshers_ViscousLayers.hxx>
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRepBndLib.hxx>
53 #include <BRepBuilderAPI_MakeVertex.hxx>
54 #include <BRepClass3d_SolidClassifier.hxx>
55 #include <BRepExtrema_DistShapeShape.hxx>
56 #include <BRepGProp.hxx>
57 #include <BRepTools.hxx>
58 #include <BRep_Tool.hxx>
59 #include <Bnd_Box.hxx>
60 #include <GProp_GProps.hxx>
61 #include <GeomAPI_ProjectPointOnSurf.hxx>
62 #include <OSD_File.hxx>
63 #include <Precision.hxx>
64 #include <Quantity_Parameter.hxx>
65 #include <Standard_ErrorHandler.hxx>
66 #include <Standard_Failure.hxx>
67 #include <Standard_ProgramError.hxx>
69 #include <TopExp_Explorer.hxx>
70 #include <TopTools_IndexedMapOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <TopTools_MapOfShape.hxx>
74 #include <TopoDS_Shape.hxx>
75 #include <TopoDS_Solid.hxx>
77 #include "utilities.h"
82 #include <sys/sysinfo.h>
86 //#include <Standard_Stream.hxx>
89 #define castToNode(n) static_cast<const SMDS_MeshNode *>( n );
102 #include <sys/mman.h>
104 #include <sys/stat.h>
110 #ifndef GHS3D_VERSION
111 #define GHS3D_VERSION 41
114 typedef const list<const SMDS_MeshFace*> TTriaList;
116 static void removeFile( const TCollection_AsciiString& fileName )
119 OSD_File( fileName ).Remove();
121 catch ( Standard_ProgramError ) {
122 MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied");
126 //=============================================================================
130 //=============================================================================
132 GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen)
133 : SMESH_3D_Algo(hypId, studyId, gen)
135 MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D");
137 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
138 _onlyUnaryInput = false; // Compute() will be called on a compound of solids
141 _compatibleHypothesis.push_back( GHS3DPlugin_Hypothesis::GetHypType());
142 _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() );
143 _requireShape = false; // can work without shape_studyId
145 smeshGen_i = SMESH_Gen_i::GetSMESHGen();
146 CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
147 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
149 MESSAGE("studyid = " << _studyId);
152 myStudy = aStudyMgr->GetStudyByID(_studyId);
154 MESSAGE("myStudy->StudyId() = " << myStudy->StudyId());
156 #ifdef WITH_SMESH_CANCEL_COMPUTE
157 _compute_canceled = false;
161 //=============================================================================
165 //=============================================================================
167 GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D()
169 MESSAGE("GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D");
172 //=============================================================================
176 //=============================================================================
178 bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh,
179 const TopoDS_Shape& aShape,
180 Hypothesis_Status& aStatus )
182 aStatus = SMESH_Hypothesis::HYP_OK;
185 _viscousLayersHyp = 0;
188 const list <const SMESHDS_Hypothesis * >& hyps =
189 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
190 list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
191 for ( ; h != hyps.end(); ++h )
194 _hyp = dynamic_cast< const GHS3DPlugin_Hypothesis*> ( *h );
195 if ( !_viscousLayersHyp )
196 _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h );
199 _keepFiles = _hyp->GetKeepFiles();
205 //=======================================================================
206 //function : entryToShape
208 //=======================================================================
210 TopoDS_Shape GHS3DPlugin_GHS3D::entryToShape(std::string entry)
212 MESSAGE("GHS3DPlugin_GHS3D::entryToShape "<<entry );
213 GEOM::GEOM_Object_var aGeomObj;
214 TopoDS_Shape S = TopoDS_Shape();
215 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
216 SALOMEDS::GenericAttribute_var anAttr;
218 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
219 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
220 CORBA::String_var aVal = anIOR->Value();
221 CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal);
222 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
224 if ( !aGeomObj->_is_nil() )
225 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
229 //=======================================================================
230 //function : findShape
232 //=======================================================================
234 static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[],
236 const TopoDS_Shape shape[],
239 TopAbs_State * state = 0)
242 int j, iShape, nbNode = 4;
244 for ( j=0; j<nbNode; j++ ) {
245 gp_XYZ p ( aNode[j]->X(), aNode[j]->Y(), aNode[j]->Z() );
246 if ( aNode[j]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) {
253 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
254 if (state) *state = SC.State();
255 if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) {
256 for (iShape = 0; iShape < nShape; iShape++) {
257 aShape = shape[iShape];
258 if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() ||
259 aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() ||
260 aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) {
261 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
262 if (state) *state = SC.State();
263 if (SC.State() == TopAbs_IN)
271 //=======================================================================
272 //function : readMapIntLine
274 //=======================================================================
276 static char* readMapIntLine(char* ptr, int tab[]) {
278 std::cout << std::endl;
280 for ( int i=0; i<17; i++ ) {
281 intVal = strtol(ptr, &ptr, 10);
288 //================================================================================
290 * \brief returns true if a triangle defined by the nodes is a temporary face on a
291 * side facet of pyramid and defines sub-domian inside the pyramid
293 //================================================================================
295 static bool isTmpFace(const SMDS_MeshNode* node1,
296 const SMDS_MeshNode* node2,
297 const SMDS_MeshNode* node3)
299 // find a pyramid sharing the 3 nodes
300 //const SMDS_MeshElement* pyram = 0;
301 SMDS_ElemIteratorPtr vIt1 = node1->GetInverseElementIterator(SMDSAbs_Volume);
302 while ( vIt1->more() )
304 const SMDS_MeshElement* pyram = vIt1->next();
305 if ( pyram->NbCornerNodes() != 5 ) continue;
307 if ( (i2 = pyram->GetNodeIndex( node2 )) >= 0 &&
308 (i3 = pyram->GetNodeIndex( node3 )) >= 0 )
310 // Triangle defines sub-domian inside the pyramid if it's
311 // normal points out of the pyram
313 // make i2 and i3 hold indices of base nodes of the pyram while
314 // keeping the nodes order in the triangle
317 i2 = i3, i3 = pyram->GetNodeIndex( node1 );
318 else if ( i3 == iApex )
319 i3 = i2, i2 = pyram->GetNodeIndex( node1 );
321 int i3base = (i2+1) % 4; // next index after i2 within the pyramid base
322 return ( i3base != i3 );
328 //=======================================================================
329 //function : findShapeID
330 //purpose : find the solid corresponding to GHS3D sub-domain following
331 // the technique proposed in GHS3D manual (available within
332 // ghs3d installation) in chapter "B.4 Subdomain (sub-region) assignment".
333 // In brief: normal of the triangle defined by the given nodes
334 // points out of the domain it is associated to
335 //=======================================================================
337 static int findShapeID(SMESH_Mesh& mesh,
338 const SMDS_MeshNode* node1,
339 const SMDS_MeshNode* node2,
340 const SMDS_MeshNode* node3,
341 const bool toMeshHoles)
343 const int invalidID = 0;
344 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
346 // face the nodes belong to
347 const SMDS_MeshElement * face = meshDS->FindFace(node1,node2,node3);
349 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
351 std::cout << "bnd face " << face->GetID() << " - ";
353 // geom face the face assigned to
354 SMESH_MeshEditor editor(&mesh);
355 int geomFaceID = editor.FindShape( face );
357 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
358 TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID );
359 if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE )
361 TopoDS_Face geomFace = TopoDS::Face( shape );
363 // solids bounded by geom face
364 TopTools_IndexedMapOfShape solids, shells;
365 TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace);
366 for ( ; ansIt.More(); ansIt.Next() ) {
367 switch ( ansIt.Value().ShapeType() ) {
369 solids.Add( ansIt.Value() ); break;
371 shells.Add( ansIt.Value() ); break;
375 // analyse found solids
376 if ( solids.Extent() == 0 || shells.Extent() == 0)
379 const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) );
380 if ( solids.Extent() == 1 )
383 return meshDS->ShapeToIndex( solid1 );
385 //////////// UNCOMMENT AS SOON AS
386 //////////// http://tracker.dev.opencascade.org/view.php?id=23129
387 //////////// IS SOLVED
388 // - Are we at a hole boundary face?
389 // if ( shells(1).IsSame( BRepTools::OuterShell( solid1 )) )
390 // { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell?
391 // bool touch = false;
392 // TopExp_Explorer eExp( shells(1), TopAbs_EDGE );
393 // // check if any edge of shells(1) belongs to another shell
394 // for ( ; eExp.More() && !touch; eExp.Next() ) {
395 // ansIt = mesh.GetAncestors( eExp.Current() );
396 // for ( ; ansIt.More() && !touch; ansIt.Next() ) {
397 // if ( ansIt.Value().ShapeType() == TopAbs_SHELL )
398 // touch = ( !ansIt.Value().IsSame( shells(1) ));
402 // return meshDS->ShapeToIndex( solid1 );
405 // find orientation of geom face within the first solid
406 TopExp_Explorer fExp( solid1, TopAbs_FACE );
407 for ( ; fExp.More(); fExp.Next() )
408 if ( geomFace.IsSame( fExp.Current() )) {
409 geomFace = TopoDS::Face( fExp.Current() );
413 return invalidID; // face not found
415 // normale to triangle
416 gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() );
417 gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() );
418 gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() );
419 gp_Vec vec12( node1Pnt, node2Pnt );
420 gp_Vec vec13( node1Pnt, node3Pnt );
421 gp_Vec meshNormal = vec12 ^ vec13;
422 if ( meshNormal.SquareMagnitude() < DBL_MIN )
425 // get normale to geomFace at any node
426 bool geomNormalOK = false;
428 const SMDS_MeshNode* nodes[3] = { node1, node2, node3 };
429 SMESH_MesherHelper helper( mesh ); helper.SetSubShape( geomFace );
430 for ( int i = 0; !geomNormalOK && i < 3; ++i )
432 // find UV of i-th node on geomFace
433 const SMDS_MeshNode* nNotOnSeamEdge = 0;
434 if ( helper.IsSeamShape( nodes[i]->getshapeId() )) {
435 if ( helper.IsSeamShape( nodes[(i+1)%3]->getshapeId() ))
436 nNotOnSeamEdge = nodes[(i+2)%3];
438 nNotOnSeamEdge = nodes[(i+1)%3];
441 gp_XY uv = helper.GetNodeUV( geomFace, nodes[i], nNotOnSeamEdge, &uvOK );
442 // check that uv is correct
445 TopoDS_Shape nodeShape = helper.GetSubShapeByNode( nodes[i], meshDS );
446 if ( !nodeShape.IsNull() )
447 switch ( nodeShape.ShapeType() )
449 case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break;
450 case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break;
451 case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break;
454 gp_Pnt nodePnt ( nodes[i]->X(), nodes[i]->Y(), nodes[i]->Z() );
455 BRepAdaptor_Surface surface( geomFace );
456 uvOK = ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) < 2 * tol );
458 // normale to geomFace at UV
460 surface.D1( uv.X(), uv.Y(), nodePnt, du, dv );
461 geomNormal = du ^ dv;
462 if ( geomFace.Orientation() == TopAbs_REVERSED )
463 geomNormal.Reverse();
464 geomNormalOK = ( geomNormal.SquareMagnitude() > DBL_MIN * 1e3 );
472 bool isReverse = ( meshNormal * geomNormal ) < 0;
474 return meshDS->ShapeToIndex( solid1 );
476 if ( solids.Extent() == 1 )
477 return HOLE_ID; // we are inside a hole
479 return meshDS->ShapeToIndex( solids(2) );
482 //=======================================================================
483 //function : countShape
485 //=======================================================================
487 // template < class Mesh, class Shape >
488 // static int countShape( Mesh* mesh, Shape shape ) {
489 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
490 // TopTools_MapOfShape mapShape;
492 // for ( ; expShape.More(); expShape.Next() ) {
493 // if (mapShape.Add(expShape.Current())) {
500 //=======================================================================
501 //function : getShape
503 //=======================================================================
505 // template < class Mesh, class Shape, class Tab >
506 // void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
507 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
508 // TopTools_MapOfShape mapShape;
509 // for ( int i=0; expShape.More(); expShape.Next() ) {
510 // if (mapShape.Add(expShape.Current())) {
511 // t_Shape[i] = expShape.Current();
518 // //=======================================================================
519 // //function : findEdgeID
521 // //=======================================================================
523 // static int findEdgeID(const SMDS_MeshNode* aNode,
524 // const SMESHDS_Mesh* theMesh,
526 // const TopoDS_Shape* t_Edge) {
528 // TopoDS_Shape aPntShape, foundEdge;
529 // TopoDS_Vertex aVertex;
530 // gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() );
532 // int foundInd, ind;
533 // double nearest = RealLast(), *t_Dist;
534 // double epsilon = Precision::Confusion();
536 // t_Dist = new double[ nEdge ];
537 // aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
538 // aVertex = TopoDS::Vertex( aPntShape );
540 // for ( ind=0; ind < nEdge; ind++ ) {
541 // BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] );
542 // t_Dist[ind] = aDistance.Value();
543 // if ( t_Dist[ind] < nearest ) {
544 // nearest = t_Dist[ind];
545 // foundEdge = t_Edge[ind];
547 // if ( nearest < epsilon )
553 // return theMesh->ShapeToIndex( foundEdge );
557 //=======================================================================
558 //function : readGMFFile
559 //purpose : read GMF file with geometry associated to mesh
561 //=======================================================================
563 // static bool readGMFFile(
564 // const int fileOpen,
565 // const char* theFileName,
566 // SMESH_Mesh& theMesh,
567 // const int nbShape,
568 // const TopoDS_Shape* tabShape,
570 // map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
572 // int nbEnforcedVertices,
573 // int nbEnforcedNodes)
575 // TopoDS_Shape aShape;
576 // TopoDS_Vertex aVertex;
577 // SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS();
578 // int nbElem = 0, nbRef = 0, IdShapeRef = 1;
580 // int aGMFNodeID = 0;
582 // nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
583 // int tetraShapeID = compoundID;
584 // double epsilon = Precision::Confusion();
585 // int *nodeAssigne, *GMFNodeAssigne;
586 // SMDS_MeshNode** GMFNode;
587 // TopoDS_Shape *tabCorner, *tabEdge;
588 // std::map <GmfKwdCod,int> tabRef;
592 // MESSAGE("Read " << theFileName << " file");
593 // int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim);
597 // // ===========================
598 // // Fill the tabID array: BEGIN
599 // // ===========================
602 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
604 // Kernel_Utils::Localizer loc;
605 // struct stat status;
608 // char *ptr, *mapPtr;
610 // int *tab = new int[3];
612 // // Read the file state
613 // fstat(fileOpen, &status);
614 // length = status.st_size;
616 // // Mapping the result file into memory
618 // HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ,
619 // NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
620 // HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
621 // 0, (DWORD)length, NULL);
622 // ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
624 // ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
628 // ptr = readMapIntLine(ptr, tab);
632 // int nbNodes = tab[1];
634 // for (int i=0; i < 4*nbElem; i++)
635 // strtol(ptr, &ptr, 10);
637 // for (int iNode=1; iNode <= nbNodes; iNode++)
638 // for (int iCoor=0; iCoor < 3; iCoor++)
639 // strtod(ptr, &ptr);
642 // // Reading the number of triangles which corresponds to the number of sub-domains
643 // int nbTriangle = strtol(ptr, &ptr, 10);
646 // // The keyword does not exist yet => to update when it is created
647 // // int nbTriangle = GmfStatKwd(InpMsh, GmfSubdomain);
651 // tabID = new int[nbTriangle];
652 // for (int i=0; i < nbTriangle; i++) {
654 // int nodeId1, nodeId2, nodeId3;
655 // // find the solid corresponding to GHS3D sub-domain following
656 // // the technique proposed in GHS3D manual in chapter
657 // // "B.4 Subdomain (sub-region) assignment"
659 // nodeId1 = strtol(ptr, &ptr, 10);
660 // nodeId2 = strtol(ptr, &ptr, 10);
661 // nodeId3 = strtol(ptr, &ptr, 10);
663 // // // The keyword does not exist yet => to update when it is created
664 // // GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]);
665 // // nodeId1 = id_tri[0];
666 // // nodeId2 = id_tri[1];
667 // // nodeId3 = id_tri[2];
669 // if ( nbTriangle > 1 ) {
670 // // get the nodes indices
671 // const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
672 // const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
673 // const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
675 // OCC_CATCH_SIGNALS;
676 // tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
677 // // -- 0020330: Pb with ghs3d as a submesh
678 // // check that found shape is to be meshed
679 // if ( tabID[i] > 0 ) {
680 // const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
681 // bool isToBeMeshed = false;
682 // for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
683 // isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
684 // if ( !isToBeMeshed )
685 // tabID[i] = HOLE_ID;
687 // // END -- 0020330: Pb with ghs3d as a submesh
689 // std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
692 // catch ( Standard_Failure & ex)
695 // std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
700 // std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
706 // // ===========================
707 // // Fill the tabID array: END
708 // // ===========================
711 // tabRef[GmfVertices] = 3;
712 // tabRef[GmfCorners] = 1;
713 // tabRef[GmfEdges] = 2;
714 // tabRef[GmfRidges] = 1;
715 // tabRef[GmfTriangles] = 3;
716 // // tabRef[GmfQuadrilaterals] = 4;
717 // tabRef[GmfTetrahedra] = 4;
718 // // tabRef[GmfHexahedra] = 8;
720 // SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator();
721 // while ( itOnGMFInputNode->more() )
722 // theMeshDS->RemoveNode( itOnGMFInputNode->next() );
725 // int nbVertices = GmfStatKwd(InpMsh, GmfVertices);
726 // int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners));
727 // int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE );
729 // tabCorner = new TopoDS_Shape[ nbCorners ];
730 // tabEdge = new TopoDS_Shape[ nbShapeEdge ];
731 // nodeAssigne = new int[ nbVertices + 1 ];
732 // GMFNodeAssigne = new int[ nbVertices + 1 ];
733 // GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ];
735 // getShape(theMeshDS, TopAbs_VERTEX, tabCorner);
736 // getShape(theMeshDS, TopAbs_EDGE, tabEdge);
738 // std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
739 // for ( ; it != tabRef.end() ; ++it)
742 // GmfKwdCod token = it->first;
743 // nbRef = it->second;
745 // nbElem = GmfStatKwd(InpMsh, token);
747 // GmfGotoKwd(InpMsh, token);
748 // std::cout << "Read " << nbElem;
753 // int id[nbElem*tabRef[token]];
754 // int ghs3dShapeID[nbElem];
756 // if (token == GmfVertices) {
757 // std::cout << " vertices" << std::endl;
760 // float VerTab_f[nbElem][3];
761 // double VerTab_d[nbElem][3];
762 // SMDS_MeshNode * aGMFNode;
764 // for ( int iElem = 0; iElem < nbElem; iElem++ ) {
765 // aGMFID = iElem + 1;
766 // if (ver == GmfFloat) {
767 // GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]);
768 // aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]);
771 // GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]);
772 // aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]);
774 // GMFNode[ aGMFID ] = aGMFNode;
775 // nodeAssigne[ aGMFID ] = 0;
776 // GMFNodeAssigne[ aGMFID ] = 0;
779 // else if (token == GmfCorners && nbElem > 0) {
780 // std::cout << " corners" << std::endl;
781 // for ( int iElem = 0; iElem < nbElem; iElem++ )
782 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
784 // else if (token == GmfRidges && nbElem > 0) {
785 // std::cout << " ridges" << std::endl;
786 // for ( int iElem = 0; iElem < nbElem; iElem++ )
787 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
789 // else if (token == GmfEdges && nbElem > 0) {
790 // std::cout << " edges" << std::endl;
791 // for ( int iElem = 0; iElem < nbElem; iElem++ )
792 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &ghs3dShapeID[iElem]);
794 // else if (token == GmfTriangles && nbElem > 0) {
795 // std::cout << " triangles" << std::endl;
796 // for ( int iElem = 0; iElem < nbElem; iElem++ )
797 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &ghs3dShapeID[iElem]);
799 // // else if (token == GmfQuadrilaterals && nbElem > 0) {
800 // // std::cout << " Quadrilaterals" << std::endl;
801 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
802 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &ghs3dShapeID[iElem]);
804 // else if (token == GmfTetrahedra && nbElem > 0) {
805 // std::cout << " Tetrahedra" << std::endl;
806 // for ( int iElem = 0; iElem < nbElem; iElem++ )
807 // GmfGetLin(InpMsh, token,
808 // &id[iElem*tabRef[token]],
809 // &id[iElem*tabRef[token]+1],
810 // &id[iElem*tabRef[token]+2],
811 // &id[iElem*tabRef[token]+3],
812 // &ghs3dShapeID[iElem]);
814 // // else if (token == GmfHexahedra && nbElem > 0) {
815 // // std::cout << " Hexahedra" << std::endl;
816 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
817 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
818 // // &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &ghs3dShapeID[iElem]);
825 // case GmfTriangles:
826 // // case GmfQuadrilaterals:
827 // case GmfTetrahedra:
828 // // case GmfHexahedra:
830 // int nodeDim, shapeID, *nodeID;
831 // SMDS_MeshNode** node;
832 // // std::vector< SMDS_MeshNode* > enfNode( nbRef );
833 // SMDS_MeshElement * aGMFElement;
835 // node = new SMDS_MeshNode*[nbRef];
836 // nodeID = new int[ nbRef ];
838 // for ( int iElem = 0; iElem < nbElem; iElem++ )
840 // for ( int iRef = 0; iRef < nbRef; iRef++ )
842 // aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
843 // node [ iRef ] = GMFNode[ aGMFNodeID ];
844 // nodeID[ iRef ] = aGMFNodeID;
849 // case GmfCorners: {
851 // gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
852 // for ( int i=0; i<nbElem; i++ ) {
853 // aVertex = TopoDS::Vertex( tabCorner[i] );
854 // gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
855 // if ( aPnt.Distance( GMFPnt ) < epsilon )
862 // aGMFElement = theMeshDS->AddEdge( node[0], node[1] );
864 // if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 )
866 // shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge );
871 // case GmfTriangles: {
873 // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]);
877 // // case GmfQuadrilaterals: {
879 // // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] );
883 // case GmfTetrahedra: {
886 // TopoDS_Shape aSolid;
887 // // We always run GHS3D with "to mesh holes"==TRUE but we must not create
888 // // tetras within holes depending on hypo option,
889 // // so we first check if aTet is inside a hole and then create it
890 // if ( nbTriangle > 1 ) {
891 // tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles
892 // int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef;
893 // if ( tabID[ aGhs3dShapeID ] == 0 ) {
894 // TopAbs_State state;
895 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
896 // if ( toMeshHoles || state == TopAbs_IN )
897 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
898 // tabID[ aGhs3dShapeID ] = tetraShapeID;
901 // tetraShapeID = tabID[ aGhs3dShapeID ];
903 // else if ( nbShape > 1 ) {
904 // // Case where nbTriangle == 1 while nbShape == 2 encountered
905 // // with compound of 2 boxes and "To mesh holes"==False,
906 // // so there are no subdomains specified for each tetrahedron.
907 // // Try to guess a solid by a node already bound to shape
909 // for ( int i=0; i<4 && tetraShapeID==0; i++ ) {
910 // if ( nodeAssigne[ nodeID[i] ] == 1 &&
911 // node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
912 // node[i]->getshapeId() > 1 )
914 // tetraShapeID = node[i]->getshapeId();
917 // if ( tetraShapeID==0 ) {
918 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
919 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
922 // // set new nodes and tetrahedron onto the shape
923 // for ( int i=0; i<4; i++ ) {
924 // if ( nodeAssigne[ nodeID[i] ] == 0 ) {
925 // if ( tetraShapeID != HOLE_ID )
926 // theMeshDS->SetNodeInVolume( node[i], tetraShapeID );
927 // nodeAssigne[ nodeID[i] ] = tetraShapeID;
930 // if ( toMeshHoles || tetraShapeID != HOLE_ID ) {
931 // aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
932 // theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID );
940 // // case GmfHexahedra: {
942 // // aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1],
943 // // node[4], node[7], node[6], node[5] );
946 // default: continue;
948 // if (token != GmfRidges)
950 // for ( int i=0; i<nbRef; i++ ) {
951 // if ( GMFNodeAssigne[ nodeID[i] ] == 0 ) {
952 // if ( token == GmfCorners ) theMeshDS->SetNodeOnVertex( node[0], aVertex );
953 // else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID );
954 // else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID );
955 // GMFNodeAssigne[ nodeID[i] ] = nodeDim;
958 // if ( token != "Corners" )
959 // theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID );
963 // if ( !toMeshHoles ) {
964 // map <int,const SMDS_MeshNode*>::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) );
965 // for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
966 // if ( nodeAssigne[ itOnNode->first ] == HOLE_ID )
967 // theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
974 // } // case GmfTetrahedra
975 // } // switch(token)
977 // cout << std::endl;
980 // UnmapViewOfFile(mapPtr);
981 // CloseHandle(hMapObject);
984 // munmap(mapPtr, length);
989 // delete [] tabCorner;
990 // delete [] tabEdge;
991 // delete [] nodeAssigne;
992 // delete [] GMFNodeAssigne;
993 // delete [] GMFNode;
999 //=======================================================================
1000 //function : addElemInMeshGroup
1001 //purpose : Update or create groups in mesh
1002 //=======================================================================
1004 static void addElemInMeshGroup(SMESH_Mesh* theMesh,
1005 const SMDS_MeshElement* anElem,
1006 std::string groupName,
1007 std::set<std::string> groupsToRemove)
1009 bool groupDone = false;
1010 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1011 while (grIt->more()) {
1012 SMESH_Group * group = grIt->next();
1013 if ( !group ) continue;
1014 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1015 if ( !groupDS ) continue;
1016 if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) {
1017 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( groupDS );
1018 aGroupDS->SMDSGroup().Add(anElem);
1020 // MESSAGE("Successfully added enforced element to existing group " << groupName);
1028 SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId);
1029 aGroup->SetName( groupName.c_str() );
1030 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1031 aGroupDS->SMDSGroup().Add(anElem);
1032 // MESSAGE("Successfully created enforced vertex group " << groupName);
1036 throw SALOME_Exception(LOCALIZED("A enforced vertex node was not added to a group"));
1040 //=======================================================================
1041 //function : updateMeshGroups
1042 //purpose : Update or create groups in mesh
1043 //=======================================================================
1045 static void updateMeshGroups(SMESH_Mesh* theMesh, std::set<std::string> groupsToRemove)
1047 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1048 while (grIt->more()) {
1049 SMESH_Group * group = grIt->next();
1050 if ( !group ) continue;
1051 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1052 if ( !groupDS ) continue;
1053 std::string currentGroupName = (string)group->GetName();
1054 if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) {
1055 // Previous group created by enforced elements
1056 MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName())
1057 theMesh->RemoveGroup(groupDS->GetID());
1062 //=======================================================================
1063 //function : readGMFFile
1064 //purpose : read GMF file w/o geometry associated to mesh
1065 //=======================================================================
1067 static bool readGMFFile(const char* theFile,
1068 #ifdef WITH_SMESH_CANCEL_COMPUTE
1069 GHS3DPlugin_GHS3D* theAlgo,
1071 SMESH_MesherHelper* theHelper,
1072 TopoDS_Shape theSolid,
1073 vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1074 map<const SMDS_MeshNode*,int> & theNodeToGhs3dIdMap,
1075 std::vector<std::string> & aNodeGroupByGhs3dId,
1076 std::vector<std::string> & anEdgeGroupByGhs3dId,
1077 std::vector<std::string> & aFaceGroupByGhs3dId,
1078 std::set<std::string> & groupsToRemove
1082 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
1084 int nbInitialNodes = theNodeByGhs3dId.size();
1085 int nbMeshNodes = theMeshDS->NbNodes();
1087 const bool isQuadMesh =
1088 theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
1089 theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
1090 theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC );
1093 std::cout << "theNodeByGhs3dId.size(): " << nbInitialNodes << std::endl;
1094 std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl;
1095 std::cout << "isQuadMesh: " << isQuadMesh << std::endl;
1098 if (theHelper->GetSubShapeID() != 0)
1099 theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() );
1101 // ---------------------------------
1102 // Read generated elements and nodes
1103 // ---------------------------------
1105 int nbElem = 0, nbRef = 0;
1106 int aGMFNodeID = 0/*, shapeID*/;
1108 const SMDS_MeshNode** GMFNode;
1110 std::map<int, std::set<int> > subdomainId2tetraId;
1112 std::map <GmfKwdCod,int> tabRef;
1114 tabRef[GmfVertices] = 3; // for new nodes and enforced nodes
1115 tabRef[GmfCorners] = 1;
1116 tabRef[GmfEdges] = 2; // for enforced edges
1117 tabRef[GmfRidges] = 1;
1118 tabRef[GmfTriangles] = 3; // for enforced faces
1119 tabRef[GmfQuadrilaterals] = 4;
1120 tabRef[GmfTetrahedra] = 4; // for new tetras
1121 tabRef[GmfHexahedra] = 8;
1124 MESSAGE("Read " << theFile << " file");
1125 int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim);
1130 // Issue 0020682. Avoid creating nodes and tetras at place where
1131 // volumic elements already exist
1132 SMESH_ElementSearcher* elemSearcher = 0;
1133 vector< const SMDS_MeshElement* > foundVolumes;
1134 if ( theHelper->GetMesh()->NbVolumes() > 0 )
1135 elemSearcher = SMESH_MeshEditor( theHelper->GetMesh() ).GetElementSearcher();
1137 int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes;
1138 GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ];
1139 //nodeAssigne = new int[ nbVertices + 1 ];
1141 std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
1142 for ( ; it != tabRef.end() ; ++it)
1144 #ifdef WITH_SMESH_CANCEL_COMPUTE
1145 if(theAlgo->computeCanceled()) {
1146 GmfCloseMesh(InpMsh);
1148 //delete [] nodeAssigne;
1153 GmfKwdCod token = it->first;
1156 nbElem = GmfStatKwd(InpMsh, token);
1158 GmfGotoKwd(InpMsh, token);
1159 std::cout << "Read " << nbElem;
1164 std::vector<int> id (nbElem*tabRef[token]); // node ids
1166 if (token == GmfVertices) {
1167 (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices";
1168 // std::cout << nbInitialNodes << " from input mesh " << std::endl;
1170 // Remove orphan nodes from previous enforced mesh which was cleared
1171 // if ( nbElem < nbMeshNodes ) {
1172 // const SMDS_MeshNode* node;
1173 // SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
1174 // while ( nodeIt->more() )
1176 // node = nodeIt->next();
1177 // if (theNodeToGhs3dIdMap.find(node) != theNodeToGhs3dIdMap.end())
1178 // theMeshDS->RemoveNode(node);
1187 const SMDS_MeshNode * aGMFNode;
1189 //shapeID = theMeshDS->ShapeToIndex( theSolid );
1190 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1191 #ifdef WITH_SMESH_CANCEL_COMPUTE
1192 if(theAlgo->computeCanceled()) {
1193 GmfCloseMesh(InpMsh);
1195 //delete [] nodeAssigne;
1199 if (ver == GmfFloat) {
1200 GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy);
1206 GmfGetLin(InpMsh, token, &x, &y, &z, &dummy);
1208 if (iElem >= nbInitialNodes) {
1209 if ( elemSearcher &&
1210 elemSearcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_Volume, foundVolumes))
1213 aGMFNode = theHelper->AddNode(x, y, z);
1215 aGMFID = iElem -nbInitialNodes +1;
1216 GMFNode[ aGMFID ] = aGMFNode;
1217 //nodeAssigne[ aGMFID ] = 0;
1218 if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty())
1219 addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove);
1223 else if (token == GmfCorners && nbElem > 0) {
1224 (nbElem <= 1) ? tmpStr = " corner" : tmpStr = " corners";
1225 for ( int iElem = 0; iElem < nbElem; iElem++ )
1226 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1228 else if (token == GmfRidges && nbElem > 0) {
1229 (nbElem <= 1) ? tmpStr = " ridge" : tmpStr = " ridges";
1230 for ( int iElem = 0; iElem < nbElem; iElem++ )
1231 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1233 else if (token == GmfEdges && nbElem > 0) {
1234 (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges";
1235 for ( int iElem = 0; iElem < nbElem; iElem++ )
1236 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &dummy);
1238 else if (token == GmfTriangles && nbElem > 0) {
1239 (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles";
1240 for ( int iElem = 0; iElem < nbElem; iElem++ )
1241 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &dummy);
1243 else if (token == GmfQuadrilaterals && nbElem > 0) {
1244 (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals";
1245 for ( int iElem = 0; iElem < nbElem; iElem++ )
1246 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy);
1248 else if (token == GmfTetrahedra && nbElem > 0) {
1249 (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra";
1250 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1251 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy);
1253 subdomainId2tetraId[dummy].insert(iElem+1);
1254 // MESSAGE("subdomainId2tetraId["<<dummy<<"].insert("<<iElem+1<<")");
1258 else if (token == GmfHexahedra && nbElem > 0) {
1259 (nbElem <= 1) ? tmpStr = " Hexahedron" : tmpStr = " Hexahedra";
1260 for ( int iElem = 0; iElem < nbElem; iElem++ )
1261 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
1262 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &dummy);
1264 std::cout << tmpStr << std::endl;
1265 std::cout << std::endl;
1272 case GmfQuadrilaterals:
1276 std::vector< const SMDS_MeshNode* > node( nbRef );
1277 std::vector< int > nodeID( nbRef );
1278 std::vector< SMDS_MeshNode* > enfNode( nbRef );
1279 const SMDS_MeshElement* aCreatedElem;
1281 for ( int iElem = 0; iElem < nbElem; iElem++ )
1283 #ifdef WITH_SMESH_CANCEL_COMPUTE
1284 if(theAlgo->computeCanceled()) {
1285 GmfCloseMesh(InpMsh);
1287 //delete [] nodeAssigne;
1291 // Check if elem is already in input mesh. If yes => skip
1292 bool fullyCreatedElement = false; // if at least one of the nodes was created
1293 for ( int iRef = 0; iRef < nbRef; iRef++ )
1295 aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
1296 if (aGMFNodeID <= nbInitialNodes) // input nodes
1299 node[ iRef ] = theNodeByGhs3dId[aGMFNodeID];
1303 fullyCreatedElement = true;
1304 aGMFNodeID -= nbInitialNodes;
1305 nodeID[ iRef ] = aGMFNodeID ;
1306 node [ iRef ] = GMFNode[ aGMFNodeID ];
1313 if (fullyCreatedElement) {
1314 aCreatedElem = theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false );
1315 if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty())
1316 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove);
1320 if (fullyCreatedElement) {
1321 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], /*id =*/0, /*force3d =*/false );
1322 // for ( int iRef = 0; iRef < nbRef; iRef++ )
1323 // nodeAssigne[ nodeID[ iRef ]] = 1;
1324 if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty())
1325 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove);
1328 case GmfQuadrilaterals:
1329 if (fullyCreatedElement) {
1330 theHelper->AddFace( node[0], node[1], node[2], node[3], /*id =*/0, /*force3d =*/false );
1331 // for ( int iRef = 0; iRef < nbRef; iRef++ )
1332 // nodeAssigne[ nodeID[ iRef ]] = 1;
1335 if ( elemSearcher ) {
1336 // Issue 0020682. Avoid creating nodes and tetras at place where
1337 // volumic elements already exist
1338 if ( !node[1] || !node[0] || !node[2] || !node[3] )
1340 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1341 SMESH_TNodeXYZ(node[1]) +
1342 SMESH_TNodeXYZ(node[2]) +
1343 SMESH_TNodeXYZ(node[3]) ) / 4.,
1344 SMDSAbs_Volume, foundVolumes ))
1347 theHelper->AddVolume( node[1], node[0], node[2], node[3], /*id =*/0, /*force3d =*/false );
1348 // theMeshDS->SetMeshElementOnShape( aTet, shapeID );
1351 if ( elemSearcher ) {
1352 // Issue 0020682. Avoid creating nodes and tetras at place where
1353 // volumic elements already exist
1354 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] || !node[6] || !node[7])
1356 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1357 SMESH_TNodeXYZ(node[1]) +
1358 SMESH_TNodeXYZ(node[2]) +
1359 SMESH_TNodeXYZ(node[3]) +
1360 SMESH_TNodeXYZ(node[4]) +
1361 SMESH_TNodeXYZ(node[5]) +
1362 SMESH_TNodeXYZ(node[6]) +
1363 SMESH_TNodeXYZ(node[7])) / 8.,
1364 SMDSAbs_Volume, foundVolumes ))
1367 theHelper->AddVolume( node[0], node[3], node[2], node[1],
1368 node[4], node[7], node[6], node[5], /*id =*/0, /*force3d =*/false );
1369 // theMeshDS->SetMeshElementOnShape( aTet, shapeID );
1379 // for ( int i = 0; i < nbVertices; ++i ) {
1380 // if ( !nodeAssigne[ i+1 ])
1381 // theMeshDS->SetNodeInVolume( GMFNode[ i+1 ], shapeID );
1384 GmfCloseMesh(InpMsh);
1386 //delete [] nodeAssigne;
1388 MESSAGE("Nb subdomains " << subdomainId2tetraId.size());
1389 std::map<int, std::set<int> >::const_iterator subdomainIt = subdomainId2tetraId.begin();
1390 TCollection_AsciiString aSubdomainFileName = theFile;
1391 aSubdomainFileName = aSubdomainFileName + ".subdomain";
1392 ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out);
1394 aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl;
1395 for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) {
1396 int subdomainId = subdomainIt->first;
1397 std::set<int> tetraIds = subdomainIt->second;
1398 MESSAGE("Subdomain #"<<subdomainId<<": "<<tetraIds.size()<<" tetrahedrons");
1399 std::set<int>::const_iterator tetraIdsIt = tetraIds.begin();
1400 aSubdomainFile << subdomainId << std::endl;
1401 for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) {
1402 aSubdomainFile << (*tetraIdsIt) << " ";
1404 aSubdomainFile << std::endl;
1406 aSubdomainFile.close();
1412 static bool writeGMFFile(const char* theMeshFileName,
1413 const char* theRequiredFileName,
1414 const char* theSolFileName,
1415 const SMESH_ProxyMesh& theProxyMesh,
1416 SMESH_Mesh * theMesh,
1417 std::vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1418 std::map<const SMDS_MeshNode*,int> & aNodeToGhs3dIdMap,
1419 std::vector<std::string> & aNodeGroupByGhs3dId,
1420 std::vector<std::string> & anEdgeGroupByGhs3dId,
1421 std::vector<std::string> & aFaceGroupByGhs3dId,
1422 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
1423 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
1424 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
1425 std::map<std::vector<double>, std::string> & enfVerticesWithGroup,
1426 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
1428 MESSAGE("writeGMFFile w/o geometry");
1430 int idx, idxRequired = 0, idxSol = 0;
1431 const int dummyint = 0;
1432 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
1433 std::vector<double> enfVertexSizes;
1434 const SMDS_MeshElement* elem;
1435 TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles;
1436 SMDS_ElemIteratorPtr nodeIt;
1437 std::vector <const SMDS_MeshNode*> theEnforcedNodeByGhs3dId;
1438 map<const SMDS_MeshNode*,int> anEnforcedNodeToGhs3dIdMap, anExistingEnforcedNodeToGhs3dIdMap;
1439 std::vector< const SMDS_MeshElement* > foundElems;
1440 map<const SMDS_MeshNode*,TopAbs_State> aNodeToTopAbs_StateMap;
1442 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt;
1443 TIDSortedElemSet::iterator elemSetIt;
1445 auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher());
1447 int nbEnforcedVertices = theEnforcedVertices.size();
1450 int nbFaces = theProxyMesh.NbFaces();
1453 // groups management
1454 int usedEnforcedNodes = 0;
1455 std::string gn = "";
1460 idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1464 /* ========================== FACES ========================== */
1465 /* TRIANGLES ========================== */
1466 SMDS_ElemIteratorPtr eIt = theProxyMesh.GetFaces();
1467 while ( eIt->more() )
1470 anElemSet.insert(elem);
1471 nodeIt = elem->nodesIterator();
1472 nbNodes = elem->NbCornerNodes();
1473 while ( nodeIt->more() && nbNodes--)
1476 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1477 int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1478 aNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1482 /* EDGES ========================== */
1484 // Iterate over the enforced edges
1485 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
1486 elem = elemIt->first;
1488 nodeIt = elem->nodesIterator();
1490 while ( nodeIt->more() && nbNodes-- ) {
1492 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1493 // Test if point is inside shape to mesh
1494 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1495 TopAbs_State result = pntCls->GetPointState( myPoint );
1496 if ( result == TopAbs_OUT ) {
1500 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1503 nodeIt = elem->nodesIterator();
1506 while ( nodeIt->more() && nbNodes-- ) {
1508 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1509 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1510 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1512 std::cout << "Node at "<<node->X()<<", "<<node->Y()<<", "<<node->Z()<<std::endl;
1513 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1515 if (nbFoundElems ==0) {
1516 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1517 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1518 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1521 else if (nbFoundElems ==1) {
1522 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1523 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1524 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1529 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1533 theKeptEnforcedEdges.insert(elem);
1537 /* ENFORCED TRIANGLES ========================== */
1539 // Iterate over the enforced triangles
1540 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
1541 elem = elemIt->first;
1543 nodeIt = elem->nodesIterator();
1545 while ( nodeIt->more() && nbNodes--) {
1547 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1548 // Test if point is inside shape to mesh
1549 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1550 TopAbs_State result = pntCls->GetPointState( myPoint );
1551 if ( result == TopAbs_OUT ) {
1555 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1558 nodeIt = elem->nodesIterator();
1561 while ( nodeIt->more() && nbNodes--) {
1563 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1564 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1565 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1567 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1569 if (nbFoundElems ==0) {
1570 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1571 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1572 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1575 else if (nbFoundElems ==1) {
1576 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1577 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1578 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1583 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1587 theKeptEnforcedTriangles.insert(elem);
1591 // put nodes to theNodeByGhs3dId vector
1593 std::cout << "aNodeToGhs3dIdMap.size(): "<<aNodeToGhs3dIdMap.size()<<std::endl;
1595 theNodeByGhs3dId.resize( aNodeToGhs3dIdMap.size() );
1596 map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToGhs3dIdMap.begin();
1597 for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id)
1599 // std::cout << "n2id->first: "<<n2id->first<<std::endl;
1600 theNodeByGhs3dId[ n2id->second - 1 ] = n2id->first; // ghs3d ids count from 1
1603 // put nodes to anEnforcedNodeToGhs3dIdMap vector
1605 std::cout << "anEnforcedNodeToGhs3dIdMap.size(): "<<anEnforcedNodeToGhs3dIdMap.size()<<std::endl;
1607 theEnforcedNodeByGhs3dId.resize( anEnforcedNodeToGhs3dIdMap.size());
1608 n2id = anEnforcedNodeToGhs3dIdMap.begin();
1609 for ( ; n2id != anEnforcedNodeToGhs3dIdMap.end(); ++ n2id)
1611 if (n2id->second > aNodeToGhs3dIdMap.size()) {
1612 theEnforcedNodeByGhs3dId[ n2id->second - aNodeToGhs3dIdMap.size() - 1 ] = n2id->first; // ghs3d ids count from 1
1617 /* ========================== NODES ========================== */
1618 vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
1619 std::set< std::vector<double> > nodesCoords;
1620 vector<const SMDS_MeshNode*>::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin();
1621 vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
1623 (theNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1624 std::cout << theNodeByGhs3dId.size() << tmpStr << " from mesh ..." << std::endl;
1625 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1627 const SMDS_MeshNode* node = *ghs3dNodeIt;
1628 std::vector<double> coords;
1629 coords.push_back(node->X());
1630 coords.push_back(node->Y());
1631 coords.push_back(node->Z());
1632 nodesCoords.insert(coords);
1633 theOrderedNodes.push_back(node);
1636 // Iterate over the enforced nodes given by enforced elements
1637 ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin();
1638 after = theEnforcedNodeByGhs3dId.end();
1639 (theEnforcedNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1640 std::cout << theEnforcedNodeByGhs3dId.size() << tmpStr << " from enforced elements ..." << std::endl;
1641 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1643 const SMDS_MeshNode* node = *ghs3dNodeIt;
1644 std::vector<double> coords;
1645 coords.push_back(node->X());
1646 coords.push_back(node->Y());
1647 coords.push_back(node->Z());
1649 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1652 if (nodesCoords.find(coords) != nodesCoords.end()) {
1653 // node already exists in original mesh
1655 std::cout << " found" << std::endl;
1660 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1661 // node already exists in enforced vertices
1663 std::cout << " found" << std::endl;
1668 // gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1669 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1670 // if (nbFoundElems ==0) {
1671 // std::cout << " not found" << std::endl;
1672 // if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1673 // nodesCoords.insert(coords);
1674 // theOrderedNodes.push_back(node);
1678 // std::cout << " found in initial mesh" << std::endl;
1679 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1680 // nodesCoords.insert(coords);
1681 // theOrderedNodes.push_back(existingNode);
1685 std::cout << " not found" << std::endl;
1688 nodesCoords.insert(coords);
1689 theOrderedNodes.push_back(node);
1690 // theRequiredNodes.push_back(node);
1694 // Iterate over the enforced nodes
1695 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt;
1696 (theEnforcedNodes.size() <= 1) ? tmpStr = " node" : " nodes";
1697 std::cout << theEnforcedNodes.size() << tmpStr << " from enforced nodes ..." << std::endl;
1698 for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt)
1700 const SMDS_MeshNode* node = enfNodeIt->first;
1701 std::vector<double> coords;
1702 coords.push_back(node->X());
1703 coords.push_back(node->Y());
1704 coords.push_back(node->Z());
1706 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1709 // Test if point is inside shape to mesh
1710 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1711 TopAbs_State result = pntCls->GetPointState( myPoint );
1712 if ( result == TopAbs_OUT ) {
1714 std::cout << " out of volume" << std::endl;
1719 if (nodesCoords.find(coords) != nodesCoords.end()) {
1721 std::cout << " found in nodesCoords" << std::endl;
1723 // theRequiredNodes.push_back(node);
1727 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1729 std::cout << " found in theEnforcedVertices" << std::endl;
1734 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1735 // if (nbFoundElems ==0) {
1736 // std::cout << " not found" << std::endl;
1737 // if (result == TopAbs_IN) {
1738 // nodesCoords.insert(coords);
1739 // theRequiredNodes.push_back(node);
1743 // std::cout << " found in initial mesh" << std::endl;
1744 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1745 // // nodesCoords.insert(coords);
1746 // theRequiredNodes.push_back(existingNode);
1751 // if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1754 // if ( result != TopAbs_IN )
1758 std::cout << " not found" << std::endl;
1760 nodesCoords.insert(coords);
1761 // theOrderedNodes.push_back(node);
1762 theRequiredNodes.push_back(node);
1764 int requiredNodes = theRequiredNodes.size();
1767 std::vector<std::vector<double> > ReqVerTab;
1768 if (nbEnforcedVertices) {
1769 // ReqVerTab.clear();
1770 (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes";
1771 std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl;
1772 // Iterate over the enforced vertices
1773 for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
1774 double x = vertexIt->first[0];
1775 double y = vertexIt->first[1];
1776 double z = vertexIt->first[2];
1777 // Test if point is inside shape to mesh
1778 gp_Pnt myPoint(x,y,z);
1779 TopAbs_State result = pntCls->GetPointState( myPoint );
1780 if ( result == TopAbs_OUT )
1782 if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1785 // if ( result != TopAbs_IN )
1787 std::vector<double> coords;
1788 coords.push_back(x);
1789 coords.push_back(y);
1790 coords.push_back(z);
1791 ReqVerTab.push_back(coords);
1792 enfVertexSizes.push_back(vertexIt->second);
1799 std::cout << "Begin writting required nodes in GmfVertices" << std::endl;
1800 std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl;
1801 GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()/*+solSize*/);
1802 for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) {
1803 GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1806 std::cout << "End writting required nodes in GmfVertices" << std::endl;
1808 if (requiredNodes + solSize) {
1809 std::cout << "Begin writting in req and sol file" << std::endl;
1810 aNodeGroupByGhs3dId.resize( requiredNodes + solSize );
1811 idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1816 idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1820 GmfCloseMesh(idxRequired);
1823 int TypTab[] = {GmfSca};
1824 GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
1825 GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
1826 // int usedEnforcedNodes = 0;
1827 // std::string gn = "";
1828 for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) {
1829 GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1830 GmfSetLin(idxSol, GmfSolAtVertices, 0.0);
1831 if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end())
1832 gn = theEnforcedNodes.find((*ghs3dNodeIt))->second;
1833 aNodeGroupByGhs3dId[usedEnforcedNodes] = gn;
1834 usedEnforcedNodes++;
1837 for (int i=0;i<solSize;i++) {
1838 std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
1840 std::cout << "enfVertexSizes.at("<<i<<"): " << enfVertexSizes.at(i) << std::endl;
1842 double solTab[] = {enfVertexSizes.at(i)};
1843 GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
1844 GmfSetLin(idxSol, GmfSolAtVertices, solTab);
1845 aNodeGroupByGhs3dId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second;
1847 std::cout << "aNodeGroupByGhs3dId["<<usedEnforcedNodes<<"] = \""<<aNodeGroupByGhs3dId[usedEnforcedNodes]<<"\""<<std::endl;
1849 usedEnforcedNodes++;
1851 std::cout << "End writting in req and sol file" << std::endl;
1854 int nedge[2], ntri[3];
1857 int usedEnforcedEdges = 0;
1858 if (theKeptEnforcedEdges.size()) {
1859 anEdgeGroupByGhs3dId.resize( theKeptEnforcedEdges.size() );
1860 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1861 // if (!idxRequired)
1863 GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size());
1864 // GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size());
1865 for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) {
1866 elem = (*elemSetIt);
1867 nodeIt = elem->nodesIterator();
1869 while ( nodeIt->more() ) {
1871 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1872 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
1873 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
1874 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
1875 if (it == anEnforcedNodeToGhs3dIdMap.end())
1876 throw "Node not found";
1878 nedge[index] = it->second;
1881 GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint);
1882 anEdgeGroupByGhs3dId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second;
1883 // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint);
1884 usedEnforcedEdges++;
1886 // GmfCloseMesh(idxRequired);
1890 if (usedEnforcedEdges) {
1891 GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges);
1892 for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) {
1893 GmfSetLin(idx, GmfRequiredEdges, enfID);
1898 int usedEnforcedTriangles = 0;
1899 if (anElemSet.size()+theKeptEnforcedTriangles.size()) {
1900 aFaceGroupByGhs3dId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() );
1901 GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size());
1903 for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) {
1904 elem = (*elemSetIt);
1905 nodeIt = elem->nodesIterator();
1907 for ( int j = 0; j < 3; ++j ) {
1909 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1910 map< const SMDS_MeshNode*,int >::iterator it = aNodeToGhs3dIdMap.find(node);
1911 if (it == aNodeToGhs3dIdMap.end())
1912 throw "Node not found";
1913 ntri[index] = it->second;
1916 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
1917 aFaceGroupByGhs3dId[k] = "";
1919 if (theKeptEnforcedTriangles.size()) {
1920 for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) {
1921 elem = (*elemSetIt);
1922 nodeIt = elem->nodesIterator();
1924 for ( int j = 0; j < 3; ++j ) {
1926 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1927 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
1928 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
1929 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
1930 if (it == anEnforcedNodeToGhs3dIdMap.end())
1931 throw "Node not found";
1933 ntri[index] = it->second;
1936 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
1937 aFaceGroupByGhs3dId[k] = theEnforcedTriangles.find(elem)->second;
1938 usedEnforcedTriangles++;
1944 if (usedEnforcedTriangles) {
1945 GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles);
1946 for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++)
1947 GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID);
1952 GmfCloseMesh(idxRequired);
1954 GmfCloseMesh(idxSol);
1960 // static bool writeGMFFile(const char* theMeshFileName,
1961 // const char* theRequiredFileName,
1962 // const char* theSolFileName,
1963 // SMESH_MesherHelper& theHelper,
1964 // const SMESH_ProxyMesh& theProxyMesh,
1965 // std::map <int,int> & theNodeId2NodeIndexMap,
1966 // std::map <int,int> & theSmdsToGhs3dIdMap,
1967 // std::map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
1968 // TIDSortedNodeSet & theEnforcedNodes,
1969 // TIDSortedElemSet & theEnforcedEdges,
1970 // TIDSortedElemSet & theEnforcedTriangles,
1971 // // TIDSortedElemSet & theEnforcedQuadrangles,
1972 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
1974 // MESSAGE("writeGMFFile with geometry");
1975 // int idx, idxRequired, idxSol;
1976 // int nbv, nbev, nben, aGhs3dID = 0;
1977 // const int dummyint = 0;
1978 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
1979 // std::vector<double> enfVertexSizes;
1980 // TIDSortedNodeSet::const_iterator enfNodeIt;
1981 // const SMDS_MeshNode* node;
1982 // SMDS_NodeIteratorPtr nodeIt;
1984 // idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1988 // SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
1990 // /* ========================== NODES ========================== */
1992 // nbv = theMeshDS->NbNodes();
1995 // nbev = theEnforcedVertices.size();
1996 // nben = theEnforcedNodes.size();
1998 // // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
1999 // // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2000 // // and replace not-free nodes on edges by the node on vertex
2001 // TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2002 // TNodeNodeMap::iterator n2nDegenIt;
2003 // if ( theHelper.HasDegeneratedEdges() )
2005 // set<int> checkedSM;
2006 // for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2008 // SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2009 // if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2011 // if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2013 // TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2014 // const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2016 // SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2017 // while ( nIt->more() )
2018 // n2nDegen.insert( make_pair( nIt->next(), vNode ));
2025 // const bool isQuadMesh =
2026 // theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2027 // theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2028 // theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2030 // std::vector<std::vector<double> > VerTab;
2031 // std::set<std::vector<double> > VerMap;
2033 // std::vector<double> aVerTab;
2034 // // Loop from 1 to NB_NODES
2036 // nodeIt = theMeshDS->nodesIterator();
2038 // while ( nodeIt->more() )
2040 // node = nodeIt->next();
2041 // if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2043 // if ( n2nDegen.count( node ) ) // Issue 0020674
2046 // std::vector<double> coords;
2047 // coords.push_back(node->X());
2048 // coords.push_back(node->Y());
2049 // coords.push_back(node->Z());
2050 // if (VerMap.find(coords) != VerMap.end()) {
2051 // aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()];
2052 // theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node;
2055 // VerTab.push_back(coords);
2056 // VerMap.insert(coords);
2058 // theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2059 // theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2063 // /* ENFORCED NODES ========================== */
2065 // std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl;
2066 // for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) {
2067 // double x = (*enfNodeIt)->X();
2068 // double y = (*enfNodeIt)->Y();
2069 // double z = (*enfNodeIt)->Z();
2070 // // Test if point is inside shape to mesh
2071 // gp_Pnt myPoint(x,y,z);
2072 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2073 // scl.Perform(myPoint, 1e-7);
2074 // TopAbs_State result = scl.State();
2075 // if ( result != TopAbs_IN )
2077 // std::vector<double> coords;
2078 // coords.push_back(x);
2079 // coords.push_back(y);
2080 // coords.push_back(z);
2081 // if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2083 // if (VerMap.find(coords) != VerMap.end())
2085 // VerTab.push_back(coords);
2086 // VerMap.insert(coords);
2088 // theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID ));
2093 // /* ENFORCED VERTICES ========================== */
2095 // std::vector<std::vector<double> > ReqVerTab;
2096 // ReqVerTab.clear();
2098 // std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl;
2099 // for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2100 // double x = vertexIt->first[0];
2101 // double y = vertexIt->first[1];
2102 // double z = vertexIt->first[2];
2103 // // Test if point is inside shape to mesh
2104 // gp_Pnt myPoint(x,y,z);
2105 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2106 // scl.Perform(myPoint, 1e-7);
2107 // TopAbs_State result = scl.State();
2108 // if ( result != TopAbs_IN )
2110 // enfVertexSizes.push_back(vertexIt->second);
2111 // std::vector<double> coords;
2112 // coords.push_back(x);
2113 // coords.push_back(y);
2114 // coords.push_back(z);
2115 // if (VerMap.find(coords) != VerMap.end())
2117 // ReqVerTab.push_back(coords);
2118 // VerMap.insert(coords);
2124 // /* ========================== FACES ========================== */
2126 // int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID;
2127 // TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/;
2128 // TIDSortedElemSet::const_iterator elemIt;
2129 // const SMESHDS_SubMesh* theSubMesh;
2130 // TopoDS_Shape aShape;
2131 // SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2132 // const SMDS_MeshElement* aFace;
2133 // map<int,int>::const_iterator itOnMap;
2134 // std::vector<std::vector<int> > tt, qt,et;
2138 // std::vector<int> att, aqt, aet;
2140 // TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap );
2142 // for ( int i = 1; i <= facesMap.Extent(); ++i )
2143 // if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i))))
2145 // SMDS_ElemIteratorPtr it = theSubMesh->GetElements();
2146 // while (it->more())
2148 // const SMDS_MeshElement *elem = it->next();
2149 // int nbCornerNodes = elem->NbCornerNodes();
2150 // if (nbCornerNodes == 3)
2152 // trianglesMap.Add(facesMap(i));
2155 // // else if (nbCornerNodes == 4)
2157 // // quadranglesMap.Add(facesMap(i));
2158 // // nbQuadrangles ++;
2163 // /* TRIANGLES ========================== */
2164 // if (nbTriangles) {
2165 // for ( int i = 1; i <= trianglesMap.Extent(); i++ )
2167 // aShape = trianglesMap(i);
2168 // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2169 // if ( !theSubMesh ) continue;
2170 // itOnSubMesh = theSubMesh->GetElements();
2171 // while ( itOnSubMesh->more() )
2173 // aFace = itOnSubMesh->next();
2174 // itOnSubFace = aFace->nodesIterator();
2176 // for ( int j = 0; j < 3; ++j ) {
2178 // node = castToNode( itOnSubFace->next() );
2179 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2180 // node = n2nDegenIt->second;
2181 // aSmdsID = node->GetID();
2182 // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2183 // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2184 // att.push_back((*itOnMap).second);
2186 // tt.push_back(att);
2191 // if (theEnforcedTriangles.size()) {
2192 // std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl;
2193 // // Iterate over the enforced triangles
2194 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2195 // aFace = (*elemIt);
2196 // itOnSubFace = aFace->nodesIterator();
2197 // bool isOK = true;
2200 // for ( int j = 0; j < 3; ++j ) {
2201 // node = castToNode( itOnSubFace->next() );
2202 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2203 // node = n2nDegenIt->second;
2204 // // std::cout << node;
2205 // double x = node->X();
2206 // double y = node->Y();
2207 // double z = node->Z();
2208 // // Test if point is inside shape to mesh
2209 // gp_Pnt myPoint(x,y,z);
2210 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2211 // scl.Perform(myPoint, 1e-7);
2212 // TopAbs_State result = scl.State();
2213 // if ( result != TopAbs_IN ) {
2215 // theEnforcedTriangles.erase(elemIt);
2218 // std::vector<double> coords;
2219 // coords.push_back(x);
2220 // coords.push_back(y);
2221 // coords.push_back(z);
2222 // if (VerMap.find(coords) != VerMap.end()) {
2223 // att.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2226 // VerTab.push_back(coords);
2227 // VerMap.insert(coords);
2229 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2230 // att.push_back(aGhs3dID);
2233 // tt.push_back(att);
2238 // /* ========================== EDGES ========================== */
2240 // if (theEnforcedEdges.size()) {
2241 // // Iterate over the enforced edges
2242 // std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl;
2243 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2244 // aFace = (*elemIt);
2245 // bool isOK = true;
2246 // itOnSubFace = aFace->nodesIterator();
2248 // for ( int j = 0; j < 2; ++j ) {
2249 // node = castToNode( itOnSubFace->next() );
2250 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2251 // node = n2nDegenIt->second;
2252 // double x = node->X();
2253 // double y = node->Y();
2254 // double z = node->Z();
2255 // // Test if point is inside shape to mesh
2256 // gp_Pnt myPoint(x,y,z);
2257 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2258 // scl.Perform(myPoint, 1e-7);
2259 // TopAbs_State result = scl.State();
2260 // if ( result != TopAbs_IN ) {
2262 // theEnforcedEdges.erase(elemIt);
2265 // std::vector<double> coords;
2266 // coords.push_back(x);
2267 // coords.push_back(y);
2268 // coords.push_back(z);
2269 // if (VerMap.find(coords) != VerMap.end()) {
2270 // aet.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2273 // VerTab.push_back(coords);
2274 // VerMap.insert(coords);
2277 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2278 // aet.push_back(aGhs3dID);
2281 // et.push_back(aet);
2286 // /* Write vertices number */
2287 // MESSAGE("Number of vertices: "<<aGhs3dID);
2288 // MESSAGE("Size of vector: "<<VerTab.size());
2289 // GmfSetKwd(idx, GmfVertices, aGhs3dID/*+solSize*/);
2290 // for (int i=0;i<aGhs3dID;i++)
2291 // GmfSetLin(idx, GmfVertices, VerTab[i][0], VerTab[i][1], VerTab[i][2], dummyint);
2292 // // for (int i=0;i<solSize;i++) {
2293 // // std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
2294 // // GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2298 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2299 // if (!idxRequired) {
2300 // GmfCloseMesh(idx);
2303 // idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2305 // GmfCloseMesh(idx);
2307 // GmfCloseMesh(idxRequired);
2311 // int TypTab[] = {GmfSca};
2312 // GmfSetKwd(idxRequired, GmfVertices, solSize);
2313 // GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
2315 // for (int i=0;i<solSize;i++) {
2316 // double solTab[] = {enfVertexSizes.at(i)};
2317 // GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2318 // GmfSetLin(idxSol, GmfSolAtVertices, solTab);
2320 // GmfCloseMesh(idxRequired);
2321 // GmfCloseMesh(idxSol);
2324 // /* Write triangles number */
2326 // GmfSetKwd(idx, GmfTriangles, tt.size());
2327 // for (int i=0;i<tt.size();i++)
2328 // GmfSetLin(idx, GmfTriangles, tt[i][0], tt[i][1], tt[i][2], dummyint);
2331 // /* Write edges number */
2333 // GmfSetKwd(idx, GmfEdges, et.size());
2334 // for (int i=0;i<et.size();i++)
2335 // GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
2338 // /* QUADRANGLES ========================== */
2339 // // TODO: add pyramids ?
2340 // // if (nbQuadrangles) {
2341 // // for ( int i = 1; i <= quadranglesMap.Extent(); i++ )
2343 // // aShape = quadranglesMap(i);
2344 // // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2345 // // if ( !theSubMesh ) continue;
2346 // // itOnSubMesh = theSubMesh->GetElements();
2347 // // for ( int j = 0; j < 4; ++j )
2349 // // aFace = itOnSubMesh->next();
2350 // // itOnSubFace = aFace->nodesIterator();
2352 // // while ( itOnSubFace->more() ) {
2353 // // // find GHS3D ID
2354 // // aSmdsID = itOnSubFace->next()->GetID();
2355 // // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2356 // // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2357 // // aqt.push_back((*itOnMap).second);
2359 // // qt.push_back(aqt);
2364 // // if (theEnforcedQuadrangles.size()) {
2365 // // // Iterate over the enforced triangles
2366 // // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) {
2367 // // aFace = (*elemIt);
2368 // // bool isOK = true;
2369 // // itOnSubFace = aFace->nodesIterator();
2371 // // for ( int j = 0; j < 4; ++j ) {
2372 // // int aNodeID = itOnSubFace->next()->GetID();
2373 // // itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
2374 // // if (itOnMap != theNodeId2NodeIndexMap.end())
2375 // // aqt.push_back((*itOnMap).second);
2378 // // theEnforcedQuadrangles.erase(elemIt);
2383 // // qt.push_back(aqt);
2388 // // /* Write quadrilaterals number */
2389 // // if (qt.size()) {
2390 // // GmfSetKwd(idx, GmfQuadrilaterals, qt.size());
2391 // // for (int i=0;i<qt.size();i++)
2392 // // GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint);
2395 // GmfCloseMesh(idx);
2400 //=======================================================================
2401 //function : writeFaces
2403 //=======================================================================
2405 static bool writeFaces (ofstream & theFile,
2406 const SMESH_ProxyMesh& theMesh,
2407 const TopoDS_Shape& theShape,
2408 const map <int,int> & theSmdsToGhs3dIdMap,
2409 const map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2410 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2411 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2413 // record structure:
2415 // NB_ELEMS DUMMY_INT
2416 // Loop from 1 to NB_ELEMS
2417 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
2419 TopoDS_Shape aShape;
2420 const SMESHDS_SubMesh* theSubMesh;
2421 const SMDS_MeshElement* aFace;
2422 const char* space = " ";
2423 const int dummyint = 0;
2424 map<int,int>::const_iterator itOnMap;
2425 SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2426 int nbNodes, aSmdsID;
2428 TIDSortedElemSet::const_iterator elemIt;
2429 int nbEnforcedEdges = theEnforcedEdges.size();
2430 int nbEnforcedTriangles = theEnforcedTriangles.size();
2432 // count triangles bound to geometry
2433 int nbTriangles = 0;
2435 TopTools_IndexedMapOfShape facesMap, trianglesMap;
2436 TopExp::MapShapes( theShape, TopAbs_FACE, facesMap );
2438 int nbFaces = facesMap.Extent();
2440 for ( int i = 1; i <= nbFaces; ++i )
2441 if (( theSubMesh = theMesh.GetSubMesh( facesMap(i))))
2442 nbTriangles += theSubMesh->NbElements();
2444 (nbFaces == 0 || nbFaces == 1) ? tmpStr = " shape " : tmpStr = " shapes " ;
2445 std::cout << " " << nbFaces << tmpStr << "of 2D dimension";
2446 int nbEnforcedElements = nbEnforcedEdges+nbEnforcedTriangles;
2447 if (nbEnforcedElements > 0) {
2448 (nbEnforcedElements == 1) ? tmpStr = "shape:" : tmpStr = "shapes:";
2449 std::cout << " and" << std::endl;
2450 std::cout << " " << nbEnforcedElements
2451 << " enforced " << tmpStr << std::endl;
2454 std::cout << std::endl;
2455 if (nbEnforcedEdges) {
2456 (nbEnforcedEdges == 1) ? tmpStr = "edge" : tmpStr = "edges";
2457 std::cout << " " << nbEnforcedEdges << " enforced " << tmpStr << std::endl;
2459 if (nbEnforcedTriangles) {
2460 (nbEnforcedTriangles == 1) ? tmpStr = "triangle" : tmpStr = "triangles";
2461 std::cout << " " << nbEnforcedTriangles << " enforced " << tmpStr << std::endl;
2463 std::cout << std::endl;
2465 // theFile << space << nbTriangles << space << dummyint << std::endl;
2466 std::ostringstream globalStream, localStream, aStream;
2468 for ( int i = 1; i <= facesMap.Extent(); i++ )
2470 aShape = facesMap(i);
2471 theSubMesh = theMesh.GetSubMesh(aShape);
2472 if ( !theSubMesh ) continue;
2473 itOnSubMesh = theSubMesh->GetElements();
2474 while ( itOnSubMesh->more() )
2476 aFace = itOnSubMesh->next();
2477 nbNodes = aFace->NbCornerNodes();
2479 localStream << nbNodes << space;
2481 itOnSubFace = aFace->nodesIterator();
2482 for ( int j = 0; j < 3; ++j ) {
2484 aSmdsID = itOnSubFace->next()->GetID();
2485 itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2486 // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) {
2487 // cout << "not found node: " << aSmdsID << endl;
2490 ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2492 localStream << (*itOnMap).second << space ;
2495 // (NB_NODES + 1) times: DUMMY_INT
2496 for ( int j=0; j<=nbNodes; j++)
2497 localStream << dummyint << space ;
2499 localStream << std::endl;
2503 globalStream << localStream.str();
2504 localStream.str("");
2511 // // ENFORCED EDGES : BEGIN
2514 // // Iterate over the enforced edges
2515 // int usedEnforcedEdges = 0;
2517 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2518 // aFace = (*elemIt);
2520 // itOnSubFace = aFace->nodesIterator();
2522 // aStream << "2" << space ;
2523 // for ( int j = 0; j < 2; ++j ) {
2524 // aSmdsID = itOnSubFace->next()->GetID();
2525 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2526 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2527 // aStream << (*itOnMap).second << space;
2534 // for ( int j=0; j<=2; j++)
2535 // aStream << dummyint << space ;
2536 // // aStream << dummyint << space << dummyint;
2537 // localStream << aStream.str() << std::endl;
2538 // usedEnforcedEdges++;
2542 // if (usedEnforcedEdges) {
2543 // globalStream << localStream.str();
2544 // localStream.str("");
2548 // // ENFORCED EDGES : END
2553 // // ENFORCED TRIANGLES : BEGIN
2555 // // Iterate over the enforced triangles
2556 // int usedEnforcedTriangles = 0;
2557 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2558 // aFace = (*elemIt);
2559 // nbNodes = aFace->NbCornerNodes();
2561 // itOnSubFace = aFace->nodesIterator();
2563 // aStream << nbNodes << space ;
2564 // for ( int j = 0; j < 3; ++j ) {
2565 // aSmdsID = itOnSubFace->next()->GetID();
2566 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2567 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2568 // aStream << (*itOnMap).second << space;
2575 // for ( int j=0; j<=3; j++)
2576 // aStream << dummyint << space ;
2577 // localStream << aStream.str() << std::endl;
2578 // usedEnforcedTriangles++;
2582 // if (usedEnforcedTriangles) {
2583 // globalStream << localStream.str();
2584 // localStream.str("");
2588 // // ENFORCED TRIANGLES : END
2592 << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/
2593 << " 0" << std::endl
2594 << globalStream.str();
2599 //=======================================================================
2600 //function : writePoints
2602 //=======================================================================
2604 static bool writePoints (ofstream & theFile,
2605 SMESH_MesherHelper& theHelper,
2606 map <int,int> & theSmdsToGhs3dIdMap,
2607 map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2608 map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2609 GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap,
2610 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices,
2611 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
2612 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2613 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2615 // record structure:
2618 // Loop from 1 to NB_NODES
2621 SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2622 int nbNodes = theMeshDS->NbNodes();
2626 int nbEnforcedVertices = theEnforcedVertices.size();
2627 int nbEnforcedNodes = theEnforcedNodes.size();
2629 const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh();
2632 SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
2633 const SMDS_MeshNode* node;
2635 // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2636 // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2637 // and replace not-free nodes on degenerated edges by the node on vertex
2638 TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2639 TNodeNodeMap::iterator n2nDegenIt;
2640 if ( theHelper.HasDegeneratedEdges() )
2643 for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2645 SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2646 if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2648 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2650 TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2651 const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2653 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2654 while ( nIt->more() )
2655 n2nDegen.insert( make_pair( nIt->next(), vNode ));
2660 nbNodes -= n2nDegen.size();
2663 const bool isQuadMesh =
2664 theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2665 theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2666 theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2669 // descrease nbNodes by nb of medium nodes
2670 while ( nodeIt->more() )
2672 node = nodeIt->next();
2673 if ( !theHelper.IsDegenShape( node->getshapeId() ))
2674 nbNodes -= int( theHelper.IsMedium( node ));
2676 nodeIt = theMeshDS->nodesIterator();
2679 const char* space = " ";
2680 const int dummyint = 0;
2683 (nbNodes == 0 || nbNodes == 1) ? tmpStr = " node" : tmpStr = " nodes";
2685 std::cout << std::endl;
2686 std::cout << "The initial 2D mesh contains :" << std::endl;
2687 std::cout << " " << nbNodes << tmpStr << std::endl;
2688 if (nbEnforcedVertices > 0) {
2689 (nbEnforcedVertices == 1) ? tmpStr = "vertex" : tmpStr = "vertices";
2690 std::cout << " " << nbEnforcedVertices << " enforced " << tmpStr << std::endl;
2692 if (nbEnforcedNodes > 0) {
2693 (nbEnforcedNodes == 1) ? tmpStr = "node" : tmpStr = "nodes";
2694 std::cout << " " << nbEnforcedNodes << " enforced " << tmpStr << std::endl;
2696 std::cout << std::endl;
2697 std::cout << "Start writing in 'points' file ..." << std::endl;
2699 theFile << nbNodes << std::endl;
2701 // Loop from 1 to NB_NODES
2703 while ( nodeIt->more() )
2705 node = nodeIt->next();
2706 if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2708 if ( n2nDegen.count( node ) ) // Issue 0020674
2711 theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2712 theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2717 << node->X() << space
2718 << node->Y() << space
2719 << node->Z() << space
2722 theFile << std::endl;
2726 // Iterate over the enforced nodes
2727 std::map<int,double> enfVertexIndexSizeMap;
2728 if (nbEnforcedNodes) {
2729 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin();
2730 for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) {
2731 double x = nodeIt->first->X();
2732 double y = nodeIt->first->Y();
2733 double z = nodeIt->first->Z();
2734 // Test if point is inside shape to mesh
2735 gp_Pnt myPoint(x,y,z);
2736 BRepClass3d_SolidClassifier scl(shapeToMesh);
2737 scl.Perform(myPoint, 1e-7);
2738 TopAbs_State result = scl.State();
2739 if ( result != TopAbs_IN )
2741 std::vector<double> coords;
2742 coords.push_back(x);
2743 coords.push_back(y);
2744 coords.push_back(z);
2745 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2748 double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
2749 // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) ));
2750 // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")");
2751 // X Y Z PHY_SIZE DUMMY_INT
2757 << dummyint << space;
2758 theFile << std::endl;
2759 theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID ));
2760 enfVertexIndexSizeMap[aGhs3dID] = -1;
2763 // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added ");
2767 if (nbEnforcedVertices) {
2768 // Iterate over the enforced vertices
2769 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin();
2770 for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2771 double x = vertexIt->first[0];
2772 double y = vertexIt->first[1];
2773 double z = vertexIt->first[2];
2774 // Test if point is inside shape to mesh
2775 gp_Pnt myPoint(x,y,z);
2776 BRepClass3d_SolidClassifier scl(shapeToMesh);
2777 scl.Perform(myPoint, 1e-7);
2778 TopAbs_State result = scl.State();
2779 if ( result != TopAbs_IN )
2781 MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second);
2782 // X Y Z PHY_SIZE DUMMY_INT
2787 << vertexIt->second << space
2788 << dummyint << space;
2789 theFile << std::endl;
2790 enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second;
2796 std::cout << std::endl;
2797 std::cout << "End writing in 'points' file." << std::endl;
2802 //=======================================================================
2803 //function : readResultFile
2804 //purpose : readResultFile with geometry
2805 //=======================================================================
2807 static bool readResultFile(const int fileOpen,
2809 const char* fileName,
2811 #ifdef WITH_SMESH_CANCEL_COMPUTE
2812 GHS3DPlugin_GHS3D* theAlgo,
2814 SMESH_MesherHelper& theHelper,
2815 TopoDS_Shape tabShape[],
2818 map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
2819 std::map <int,int> & theNodeId2NodeIndexMap,
2821 int nbEnforcedVertices,
2822 int nbEnforcedNodes,
2823 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2824 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2826 MESSAGE("GHS3DPlugin_GHS3D::readResultFile()");
2827 Kernel_Utils::Localizer loc;
2837 SMESHDS_Mesh* theMeshDS = theHelper.GetMeshDS();
2839 int nbElems, nbNodes, nbInputNodes;
2841 int ID, shapeID, ghs3dShapeID;
2844 nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
2846 int *tab, *tabID, *nodeID, *nodeAssigne;
2848 const SMDS_MeshNode **node;
2851 nodeID = new int[4];
2852 coord = new double[3];
2853 node = new const SMDS_MeshNode*[4];
2855 TopoDS_Shape aSolid;
2856 SMDS_MeshNode * aNewNode;
2857 map <int,const SMDS_MeshNode*>::iterator itOnNode;
2858 SMDS_MeshElement* aTet;
2863 // Read the file state
2864 fstat(fileOpen, &status);
2865 length = status.st_size;
2867 // Mapping the result file into memory
2869 HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
2870 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2871 HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
2872 0, (DWORD)length, NULL);
2873 ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
2875 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
2879 ptr = readMapIntLine(ptr, tab);
2884 nbInputNodes = tab[2];
2886 nodeAssigne = new int[ nbNodes+1 ];
2889 aSolid = tabShape[0];
2891 // Reading the nodeId
2892 for (int i=0; i < 4*nbElems; i++)
2893 strtol(ptr, &ptr, 10);
2895 MESSAGE("nbInputNodes: "<<nbInputNodes);
2896 MESSAGE("nbEnforcedVertices: "<<nbEnforcedVertices);
2897 MESSAGE("nbEnforcedNodes: "<<nbEnforcedNodes);
2898 // Reading the nodeCoor and update the nodeMap
2899 for (int iNode=1; iNode <= nbNodes; iNode++) {
2900 #ifdef WITH_SMESH_CANCEL_COMPUTE
2901 if(theAlgo->computeCanceled())
2904 for (int iCoor=0; iCoor < 3; iCoor++)
2905 coord[ iCoor ] = strtod(ptr, &ptr);
2906 nodeAssigne[ iNode ] = 1;
2907 if ( iNode > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes)) ) {
2908 // Creating SMESH nodes
2909 // - for enforced vertices
2910 // - for vertices of forced edges
2911 // - for ghs3d nodes
2912 nodeAssigne[ iNode ] = 0;
2913 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
2914 theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
2918 // Reading the number of triangles which corresponds to the number of sub-domains
2919 nbTriangle = strtol(ptr, &ptr, 10);
2921 tabID = new int[nbTriangle];
2922 for (int i=0; i < nbTriangle; i++) {
2923 #ifdef WITH_SMESH_CANCEL_COMPUTE
2924 if(theAlgo->computeCanceled())
2928 // find the solid corresponding to GHS3D sub-domain following
2929 // the technique proposed in GHS3D manual in chapter
2930 // "B.4 Subdomain (sub-region) assignment"
2931 int nodeId1 = strtol(ptr, &ptr, 10);
2932 int nodeId2 = strtol(ptr, &ptr, 10);
2933 int nodeId3 = strtol(ptr, &ptr, 10);
2934 if ( nbTriangle > 1 ) {
2935 const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
2936 const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
2937 const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
2938 if (!n1 || !n2 || !n3) {
2944 // tabID[i] = findShapeID( theHelper, n1, n2, n3, toMeshHoles );
2945 tabID[i] = findShapeID( *theHelper.GetMesh(), n1, n2, n3, toMeshHoles );
2946 // -- 0020330: Pb with ghs3d as a submesh
2947 // check that found shape is to be meshed
2948 if ( tabID[i] > 0 ) {
2949 const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
2950 bool isToBeMeshed = false;
2951 for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
2952 isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
2953 if ( !isToBeMeshed )
2956 // END -- 0020330: Pb with ghs3d as a submesh
2958 std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
2961 catch ( Standard_Failure & ex)
2964 std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
2969 std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
2977 if ( nbTriangle <= nbShape ) // no holes
2978 toMeshHoles = true; // not avoid creating tetras in holes
2980 // Associating the tetrahedrons to the shapes
2981 shapeID = compoundID;
2982 for (int iElem = 0; iElem < nbElems; iElem++) {
2983 #ifdef WITH_SMESH_CANCEL_COMPUTE
2984 if(theAlgo->computeCanceled())
2987 for (int iNode = 0; iNode < 4; iNode++) {
2988 ID = strtol(tetraPtr, &tetraPtr, 10);
2989 itOnNode = theGhs3dIdToNodeMap.find(ID);
2990 node[ iNode ] = itOnNode->second;
2991 nodeID[ iNode ] = ID;
2993 // We always run GHS3D with "to mesh holes"==TRUE but we must not create
2994 // tetras within holes depending on hypo option,
2995 // so we first check if aTet is inside a hole and then create it
2996 //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
2997 if ( nbTriangle > 1 ) {
2998 shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles
2999 ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef;
3000 if ( tabID[ ghs3dShapeID ] == 0 ) {
3002 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
3003 if ( toMeshHoles || state == TopAbs_IN )
3004 shapeID = theMeshDS->ShapeToIndex( aSolid );
3005 tabID[ ghs3dShapeID ] = shapeID;
3008 shapeID = tabID[ ghs3dShapeID ];
3010 else if ( nbShape > 1 ) {
3011 // Case where nbTriangle == 1 while nbShape == 2 encountered
3012 // with compound of 2 boxes and "To mesh holes"==False,
3013 // so there are no subdomains specified for each tetrahedron.
3014 // Try to guess a solid by a node already bound to shape
3016 for ( int i=0; i<4 && shapeID==0; i++ ) {
3017 if ( nodeAssigne[ nodeID[i] ] == 1 &&
3018 node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
3019 node[i]->getshapeId() > 1 )
3021 shapeID = node[i]->getshapeId();
3025 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
3026 shapeID = theMeshDS->ShapeToIndex( aSolid );
3029 // set new nodes and tetrahedron onto the shape
3030 for ( int i=0; i<4; i++ ) {
3031 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
3032 if ( shapeID != HOLE_ID )
3033 theMeshDS->SetNodeInVolume( node[i], shapeID );
3034 nodeAssigne[ nodeID[i] ] = shapeID;
3037 if ( toMeshHoles || shapeID != HOLE_ID ) {
3038 aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3],
3039 /*id=*/0, /*force3d=*/false);
3040 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3043 shapeIDs.insert( shapeID );
3047 // Add enforced elements
3048 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt;
3049 const SMDS_MeshElement* anElem;
3050 SMDS_ElemIteratorPtr itOnEnfElem;
3051 map<int,int>::const_iterator itOnMap;
3052 shapeID = compoundID;
3054 if (theEnforcedEdges.size()) {
3055 (theEnforcedEdges.size() <= 1) ? tmpStr = " enforced edge" : " enforced edges";
3056 std::cout << "Add " << theEnforcedEdges.size() << tmpStr << std::endl;
3057 std::vector< const SMDS_MeshNode* > node( 2 );
3058 // Iterate over the enforced edges
3059 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
3060 anElem = elemIt->first;
3061 bool addElem = true;
3062 itOnEnfElem = anElem->nodesIterator();
3063 for ( int j = 0; j < 2; ++j ) {
3064 int aNodeID = itOnEnfElem->next()->GetID();
3065 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3066 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3067 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3068 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3069 node.push_back((*itOnNode).second);
3070 // shapeID =(*itOnNode).second->getshapeId();
3079 aTet = theHelper.AddEdge( node[0], node[1], 0, false);
3080 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3085 if (theEnforcedTriangles.size()) {
3086 (theEnforcedTriangles.size() <= 1) ? tmpStr = " enforced triangle" : " enforced triangles";
3087 std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles" << std::endl;
3088 std::vector< const SMDS_MeshNode* > node( 3 );
3089 // Iterate over the enforced triangles
3090 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
3091 anElem = elemIt->first;
3092 bool addElem = true;
3093 itOnEnfElem = anElem->nodesIterator();
3094 for ( int j = 0; j < 3; ++j ) {
3095 int aNodeID = itOnEnfElem->next()->GetID();
3096 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3097 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3098 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3099 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3100 node.push_back((*itOnNode).second);
3101 // shapeID =(*itOnNode).second->getshapeId();
3110 aTet = theHelper.AddFace( node[0], node[1], node[2], 0, false);
3111 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3116 // Remove nodes of tetras inside holes if !toMeshHoles
3117 if ( !toMeshHoles ) {
3118 itOnNode = theGhs3dIdToNodeMap.find( nbInputNodes );
3119 for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
3120 ID = itOnNode->first;
3121 if ( nodeAssigne[ ID ] == HOLE_ID )
3122 theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
3128 (nbElems <= 1) ? tmpStr = " tetrahedra" : " tetrahedrons";
3129 cout << nbElems << tmpStr << " have been associated to " << nbShape;
3130 (nbShape <= 1) ? tmpStr = " shape" : " shapes";
3131 cout << tmpStr << endl;
3134 UnmapViewOfFile(mapPtr);
3135 CloseHandle(hMapObject);
3138 munmap(mapPtr, length);
3147 delete [] nodeAssigne;
3151 if ( shapeIDs.size() != nbShape ) {
3152 (shapeIDs.size() <= 1) ? tmpStr = " solid" : " solids";
3153 std::cout << "Only " << shapeIDs.size() << tmpStr << " of " << nbShape << " found" << std::endl;
3154 for (int i=0; i<nbShape; i++) {
3155 shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
3156 if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
3157 std::cout << " Solid #" << shapeID << " not found" << std::endl;
3166 //=============================================================================
3168 *Here we are going to use the GHS3D mesher with geometry
3170 //=============================================================================
3172 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3173 const TopoDS_Shape& theShape)
3176 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3178 // we count the number of shapes
3179 // _nbShape = countShape( meshDS, TopAbs_SOLID ); -- 0020330: Pb with ghs3d as a submesh
3181 TopExp_Explorer expBox ( theShape, TopAbs_SOLID );
3182 for ( ; expBox.More(); expBox.Next() )
3185 // create bounding box for every shape inside the compound
3188 TopoDS_Shape* tabShape;
3190 tabShape = new TopoDS_Shape[_nbShape];
3191 tabBox = new double*[_nbShape];
3192 for (int i=0; i<_nbShape; i++)
3193 tabBox[i] = new double[6];
3194 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
3196 for (expBox.ReInit(); expBox.More(); expBox.Next()) {
3197 tabShape[iShape] = expBox.Current();
3198 Bnd_Box BoundingBox;
3199 BRepBndLib::Add(expBox.Current(), BoundingBox);
3200 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3201 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
3202 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
3203 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
3207 // a unique working file name
3208 // to avoid access to the same files by eg different users
3209 TCollection_AsciiString aGenericName
3210 = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
3212 TCollection_AsciiString aResultFileName;
3213 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3214 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3215 // TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3216 // TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3218 // aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3219 // aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3220 // aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3221 // aSolFileName = aGenericName + "_required.sol"; // GMF solution file
3223 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3224 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3225 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3226 // aSolFileName = aGenericName + "_required.solb"; // GMF solution file
3229 TCollection_AsciiString aFacesFileName, aPointsFileName, aBadResFileName, aBbResFileName;
3231 aFacesFileName = aGenericName + ".faces"; // in faces
3232 aPointsFileName = aGenericName + ".points"; // in points
3233 aResultFileName = aGenericName + ".noboite";// out points and volumes
3234 aBadResFileName = aGenericName + ".boite"; // out bad result
3235 aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
3237 // -----------------
3239 // -----------------
3241 ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
3242 ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
3245 aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
3247 INFOS( "Can't write into " << aFacesFileName);
3248 return error(SMESH_Comment("Can't write into ") << aFacesFileName);
3251 std::map <int,int> aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap;
3252 std::map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
3253 std::map <int, int> nodeID2nodeIndexMap;
3254 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp);
3255 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3256 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3257 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3258 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3259 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3261 int nbEnforcedVertices = coordsSizeMap.size();
3262 int nbEnforcedNodes = enforcedNodes.size();
3265 (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes";
3266 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3267 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : "vertices";
3268 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3270 SMESH_MesherHelper helper( theMesh );
3271 helper.SetSubShape( theShape );
3274 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3276 // make prisms on quadrangles
3277 if ( theMesh.NbQuadrangles() > 0 )
3279 vector<SMESH_ProxyMesh::Ptr> components;
3280 for (expBox.ReInit(); expBox.More(); expBox.Next())
3282 if ( _viscousLayersHyp )
3284 proxyMesh = _viscousLayersHyp->Compute( theMesh, expBox.Current() );
3288 StdMeshers_QuadToTriaAdaptor* q2t = new StdMeshers_QuadToTriaAdaptor;
3289 q2t->Compute( theMesh, expBox.Current(), proxyMesh.get() );
3290 components.push_back( SMESH_ProxyMesh::Ptr( q2t ));
3292 proxyMesh.reset( new SMESH_ProxyMesh( components ));
3294 // build viscous layers
3295 else if ( _viscousLayersHyp )
3297 proxyMesh = _viscousLayersHyp->Compute( theMesh, theShape );
3302 Ok = (writePoints( aPointsFile, helper,
3303 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap,
3305 coordsSizeMap, enforcedNodes, enforcedEdges, enforcedTriangles)
3307 writeFaces ( aFacesFile, *proxyMesh, theShape,
3308 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap,
3309 enforcedEdges, enforcedTriangles ));
3310 // Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3311 // helper, *proxyMesh,
3312 // aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap,
3313 // enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/
3317 // Write aSmdsToGhs3dIdMap to temp file
3318 TCollection_AsciiString aSmdsToGhs3dIdMapFileName;
3319 aSmdsToGhs3dIdMapFileName = aGenericName + ".ids"; // ids relation
3320 ofstream aIdsFile ( aSmdsToGhs3dIdMapFileName.ToCString() , ios::out);
3321 Ok = aIdsFile.rdbuf()->is_open();
3323 INFOS( "Can't write into " << aSmdsToGhs3dIdMapFileName);
3324 return error(SMESH_Comment("Can't write into ") << aSmdsToGhs3dIdMapFileName);
3326 INFOS( "Writing ids relation into " << aSmdsToGhs3dIdMapFileName);
3327 aIdsFile << "Smds Ghs3d" << std::endl;
3328 map <int,int>::const_iterator myit;
3329 for (myit=aSmdsToGhs3dIdMap.begin() ; myit != aSmdsToGhs3dIdMap.end() ; ++myit) {
3330 aIdsFile << myit->first << " " << myit->second << std::endl;
3335 aPointsFile.close();
3338 if ( !_keepFiles ) {
3339 // removeFile( aGMFFileName );
3340 // removeFile( aRequiredVerticesFileName );
3341 // removeFile( aSolFileName );
3342 removeFile( aFacesFileName );
3343 removeFile( aPointsFileName );
3344 removeFile( aSmdsToGhs3dIdMapFileName );
3346 return error(COMPERR_BAD_INPUT_MESH);
3348 removeFile( aResultFileName ); // needed for boundary recovery module usage
3350 // -----------------
3352 // -----------------
3354 TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() );
3355 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
3356 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3357 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3358 // cmd += TCollection_AsciiString(" --in ") + aGenericName;
3359 // cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3360 // cmd += TCollection_AsciiString(" --out ") + aResultGMFFileName;
3361 // cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3363 std::cout << std::endl;
3364 std::cout << "Ghs3d execution..." << std::endl;
3365 std::cout << cmd << std::endl;
3367 #ifdef WITH_SMESH_CANCEL_COMPUTE
3368 _compute_canceled = false;
3371 system( cmd.ToCString() ); // run
3373 std::cout << std::endl;
3374 std::cout << "End of Ghs3d execution !" << std::endl;
3380 // Mapping the result file
3383 fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
3384 if ( fileOpen < 0 ) {
3385 std::cout << std::endl;
3386 std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl;
3387 std::cout << "Log: " << aLogFileName << std::endl;
3392 _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
3394 helper.IsQuadraticSubMesh( theShape );
3395 helper.SetElementsOnShape( false );
3397 Ok = readResultFile( fileOpen,
3399 aResultFileName.ToCString(),
3401 #ifdef WITH_SMESH_CANCEL_COMPUTE
3404 /*theMesh, */helper, tabShape, tabBox, _nbShape,
3405 aGhs3dIdToNodeMap, aNodeId2NodeIndexMap,
3407 nbEnforcedVertices, nbEnforcedNodes,
3408 enforcedEdges, enforcedTriangles );
3410 // Ok = readGMFFile(
3411 // #ifndef GMF_HAS_SUBDOMAIN_INFO
3414 // aGenericName.ToCString(), theMesh,
3415 // _nbShape, tabShape, tabBox,
3416 // aGhs3dIdToNodeMap, toMeshHoles,
3417 // nbEnforcedVertices, nbEnforcedNodes);
3423 // ---------------------
3424 // remove working files
3425 // ---------------------
3430 removeFile( aLogFileName );
3432 else if ( OSD_File( aLogFileName ).Size() > 0 )
3434 // get problem description from the log file
3435 _Ghs2smdsConvertor conv( aGhs3dIdToNodeMap );
3436 storeErrorDescription( aLogFileName, conv );
3440 // the log file is empty
3441 removeFile( aLogFileName );
3442 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3443 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3446 if ( !_keepFiles ) {
3447 #ifdef WITH_SMESH_CANCEL_COMPUTE
3449 if(_compute_canceled)
3450 removeFile( aLogFileName );
3452 removeFile( aFacesFileName );
3453 removeFile( aPointsFileName );
3454 removeFile( aResultFileName );
3455 removeFile( aBadResFileName );
3456 removeFile( aBbResFileName );
3457 removeFile( aSmdsToGhs3dIdMapFileName );
3459 std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
3461 std::cout << "not ";
3462 std::cout << "treated !" << std::endl;
3463 std::cout << std::endl;
3465 _nbShape = 0; // re-initializing _nbShape for the next Compute() method call
3472 //=============================================================================
3474 *Here we are going to use the GHS3D mesher w/o geometry
3476 //=============================================================================
3477 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3478 SMESH_MesherHelper* theHelper)
3480 MESSAGE("GHS3DPlugin_GHS3D::Compute()");
3482 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3483 TopoDS_Shape theShape = theHelper->GetSubShape();
3485 // a unique working file name
3486 // to avoid access to the same files by eg different users
3487 TCollection_AsciiString aGenericName
3488 = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
3489 TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3491 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3492 TCollection_AsciiString aResultFileName;
3495 TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3497 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3498 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3499 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3500 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
3502 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3503 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3504 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3505 // aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file
3508 std::map <int, int> nodeID2nodeIndexMap;
3509 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
3510 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap;
3511 TopoDS_Shape GeomShape;
3512 // TopAbs_ShapeEnum GeomType;
3513 std::vector<double> coords;
3515 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex;
3517 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp);
3518 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
3520 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
3522 enfVertex = (*enfVerIt);
3523 // if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) {
3524 if (enfVertex->coords.size()) {
3525 coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size));
3526 enfVerticesWithGroup.insert(make_pair(enfVertex->coords,enfVertex->groupName));
3527 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<enfVertex->coords[0]<<","<<enfVertex->coords[1]<<","<<enfVertex->coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3530 // if (!enfVertex->geomEntry.empty()) {
3531 GeomShape = entryToShape(enfVertex->geomEntry);
3532 // GeomType = GeomShape.ShapeType();
3534 // if (!enfVertex->isCompound) {
3535 // // if (GeomType == TopAbs_VERTEX) {
3537 // aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape));
3538 // coords.push_back(aPnt.X());
3539 // coords.push_back(aPnt.Y());
3540 // coords.push_back(aPnt.Z());
3541 // if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3542 // coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3543 // enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3547 // // Group Management
3549 // if (GeomType == TopAbs_COMPOUND){
3550 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
3552 if (it.Value().ShapeType() == TopAbs_VERTEX){
3553 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
3554 coords.push_back(aPnt.X());
3555 coords.push_back(aPnt.Y());
3556 coords.push_back(aPnt.Z());
3557 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3558 coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3559 enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3560 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<coords[0]<<","<<coords[1]<<","<<coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3568 // const SMDS_MeshNode* enfNode;
3569 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3570 // GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin();
3571 // for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt)
3573 // enfNode = enfNodeIt->first;
3575 // coords.push_back(enfNode->X());
3576 // coords.push_back(enfNode->Y());
3577 // coords.push_back(enfNode->Z());
3578 // if (enfVerticesWithGro
3579 // enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second));
3583 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3584 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3585 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3586 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3590 int nbEnforcedVertices = coordsSizeMap.size();
3591 int nbEnforcedNodes = enforcedNodes.size();
3592 (nbEnforcedNodes <= 1) ? tmpStr = "node" : tmpStr = "nodes";
3593 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3594 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : tmpStr = "vertices";
3595 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3597 std::vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
3598 std::map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
3599 std::vector<std::string> aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId;
3601 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3602 if ( theMesh.NbQuadrangles() > 0 )
3604 StdMeshers_QuadToTriaAdaptor* aQuad2Trias = new StdMeshers_QuadToTriaAdaptor;
3605 aQuad2Trias->Compute( theMesh );
3606 proxyMesh.reset( aQuad2Trias );
3609 Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3610 *proxyMesh, &theMesh,
3611 aNodeByGhs3dId, aNodeToGhs3dIdMap,
3612 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3613 enforcedNodes, enforcedEdges, enforcedTriangles,
3614 enfVerticesWithGroup, coordsSizeMap);
3617 // -----------------
3619 // -----------------
3621 TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str());
3623 cmd += TCollection_AsciiString(" --in ") + aGenericName;
3624 if ( nbEnforcedVertices + nbEnforcedNodes)
3625 cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3626 cmd += TCollection_AsciiString(" --out ") + aResultFileName;
3627 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3629 std::cout << std::endl;
3630 std::cout << "Ghs3d execution..." << std::endl;
3631 std::cout << cmd << std::endl;
3633 #ifdef WITH_SMESH_CANCEL_COMPUTE
3634 _compute_canceled = false;
3637 system( cmd.ToCString() ); // run
3639 std::cout << std::endl;
3640 std::cout << "End of Ghs3d execution !" << std::endl;
3645 GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp);
3647 Ok = readGMFFile(aResultFileName.ToCString(),
3648 #ifdef WITH_SMESH_CANCEL_COMPUTE
3651 theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap,
3652 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3655 updateMeshGroups(theHelper->GetMesh(), groupsToRemove);
3658 GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp;
3660 that->ClearGroupsToRemove();
3662 // ---------------------
3663 // remove working files
3664 // ---------------------
3669 removeFile( aLogFileName );
3671 else if ( OSD_File( aLogFileName ).Size() > 0 )
3673 // get problem description from the log file
3674 _Ghs2smdsConvertor conv( aNodeByGhs3dId );
3675 storeErrorDescription( aLogFileName, conv );
3678 // the log file is empty
3679 removeFile( aLogFileName );
3680 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3681 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3686 #ifdef WITH_SMESH_CANCEL_COMPUTE
3688 if(_compute_canceled)
3689 removeFile( aLogFileName );
3691 removeFile( aGMFFileName );
3692 removeFile( aResultFileName );
3693 removeFile( aRequiredVerticesFileName );
3694 removeFile( aSolFileName );
3699 #ifdef WITH_SMESH_CANCEL_COMPUTE
3700 void GHS3DPlugin_GHS3D::CancelCompute()
3702 _compute_canceled = true;
3705 TCollection_AsciiString aGenericName
3706 = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
3707 TCollection_AsciiString cmd =
3708 TCollection_AsciiString("ps ux | grep ") + aGenericName;
3709 cmd += TCollection_AsciiString(" | grep -v grep | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1");
3710 system( cmd.ToCString() );
3715 //================================================================================
3717 * \brief Provide human readable text by error code reported by ghs3d
3719 //================================================================================
3721 static string translateError(const int errNum)
3725 return "The surface mesh includes a face of type other than edge, "
3726 "triangle or quadrilateral. This face type is not supported.";
3728 return "Not enough memory for the face table.";
3730 return "Not enough memory.";
3732 return "Not enough memory.";
3734 return "Face is ignored.";
3736 return "End of file. Some data are missing in the file.";
3738 return "Read error on the file. There are wrong data in the file.";
3740 return "the metric file is inadequate (dimension other than 3).";
3742 return "the metric file is inadequate (values not per vertices).";
3744 return "the metric file contains more than one field.";
3746 return "the number of values in the \".bb\" (metric file) is incompatible with the expected"
3747 "value of number of mesh vertices in the \".noboite\" file.";
3749 return "Too many sub-domains.";
3751 return "the number of vertices is negative or null.";
3753 return "the number of faces is negative or null.";
3755 return "A face has a null vertex.";
3757 return "incompatible data.";
3759 return "the number of vertices is negative or null.";
3761 return "the number of vertices is negative or null (in the \".mesh\" file).";
3763 return "the number of faces is negative or null.";
3765 return "A face appears more than once in the input surface mesh.";
3767 return "An edge appears more than once in the input surface mesh.";
3769 return "A face has a vertex negative or null.";
3771 return "NOT ENOUGH MEMORY.";
3773 return "Not enough available memory.";
3775 return "Some initial points cannot be inserted. The surface mesh is probably very bad "
3776 "in terms of quality or the input list of points is wrong.";
3778 return "Some vertices are too close to one another or coincident.";
3780 return "Some vertices are too close to one another or coincident.";
3782 return "A vertex cannot be inserted.";
3784 return "There are at least two points considered as coincident.";
3786 return "Some vertices are too close to one another or coincident.";
3788 return "The surface mesh regeneration step has failed.";
3790 return "Constrained edge cannot be enforced.";
3792 return "Constrained face cannot be enforced.";
3794 return "Missing faces.";
3796 return "No guess to start the definition of the connected component(s).";
3798 return "The surface mesh includes at least one hole. The domain is not well defined.";
3800 return "Impossible to define a component.";
3802 return "The surface edge intersects another surface edge.";
3804 return "The surface edge intersects the surface face.";
3806 return "One boundary point lies within a surface face.";
3808 return "One surface edge intersects a surface face.";
3810 return "One boundary point lies within a surface edge.";
3812 return "Insufficient memory ressources detected due to a bad quality surface mesh leading "
3813 "to too many swaps.";
3815 return "Edge is unique (i.e., bounds a hole in the surface).";
3817 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3819 return "Too many components, too many sub-domain.";
3821 return "The surface mesh includes at least one hole. "
3822 "Therefore there is no domain properly defined.";
3824 return "Statistics.";
3826 return "Statistics.";
3828 return "Warning, it is dramatically tedious to enforce the boundary items.";
3830 return "Not enough memory at this time, nevertheless, the program continues. "
3831 "The expected mesh will be correct but not really as large as required.";
3833 return "see above error code, resulting quality may be poor.";
3835 return "Not enough memory at this time, nevertheless, the program continues (warning).";
3837 return "Unknown face type.";
3840 return "End of file. Some data are missing in the file.";
3842 return "A too small volume element is detected.";
3844 return "There exists at least a null or negative volume element.";
3846 return "There exist null or negative volume elements.";
3848 return "A too small volume element is detected. A face is considered being degenerated.";
3850 return "Some element is suspected to be very bad shaped or wrong.";
3852 return "A too bad quality face is detected. This face is considered degenerated.";
3854 return "A too bad quality face is detected. This face is degenerated.";
3856 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3858 return "Abnormal error occured, contact hotline.";
3860 return "Not enough memory for the face table.";
3862 return "The algorithm cannot run further. "
3863 "The surface mesh is probably very bad in terms of quality.";
3865 return "Bad vertex number.";
3870 //================================================================================
3872 * \brief Retrieve from a string given number of integers
3874 //================================================================================
3876 static char* getIds( char* ptr, int nbIds, vector<int>& ids )
3879 ids.reserve( nbIds );
3882 while ( !isdigit( *ptr )) ++ptr;
3883 if ( ptr[-1] == '-' ) --ptr;
3884 ids.push_back( strtol( ptr, &ptr, 10 ));
3890 //================================================================================
3892 * \brief Retrieve problem description form a log file
3893 * \retval bool - always false
3895 //================================================================================
3897 bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
3898 const _Ghs2smdsConvertor & toSmdsConvertor )
3900 #ifdef WITH_SMESH_CANCEL_COMPUTE
3901 if(_compute_canceled)
3902 return error(SMESH_Comment("interruption initiated by user"));
3906 int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
3908 int file = ::open (logFile.ToCString(), O_RDONLY);
3911 return error( SMESH_Comment("See ") << logFile << " for problem description");
3914 // struct stat status;
3915 // fstat(file, &status);
3916 // size_t length = status.st_size;
3917 off_t length = lseek( file, 0, SEEK_END);
3918 lseek( file, 0, SEEK_SET);
3921 vector< char > buf( length );
3922 int nBytesRead = ::read (file, & buf[0], length);
3924 char* ptr = & buf[0];
3925 char* bufEnd = ptr + nBytesRead;
3927 SMESH_Comment errDescription;
3929 enum { NODE = 1, EDGE, TRIA, VOL, ID = 1 };
3931 // look for errors "ERR #"
3933 set<string> foundErrorStr; // to avoid reporting same error several times
3934 set<int> elemErrorNums; // not to report different types of errors with bad elements
3935 while ( ++ptr < bufEnd )
3937 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
3940 list<const SMDS_MeshElement*> badElems;
3941 vector<int> nodeIds;
3945 int errNum = strtol(ptr, &ptr, 10);
3946 switch ( errNum ) { // we treat errors enumerated in [SALOME platform 0019316] issue
3948 // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
3949 ptr = getIds(ptr, NODE, nodeIds);
3950 ptr = getIds(ptr, TRIA, nodeIds);
3951 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3953 case 1000: // ERR 1000 : 1 3 2
3954 // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
3955 ptr = getIds(ptr, TRIA, nodeIds);
3956 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3959 // Edge (e1, e2) appears more than once in the input surface mesh
3960 ptr = getIds(ptr, EDGE, nodeIds);
3961 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3964 // Face (f 1, f 2, f 3) has a vertex negative or null
3965 ptr = getIds(ptr, TRIA, nodeIds);
3966 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3969 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
3970 ptr = getIds(ptr, NODE, nodeIds);
3971 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3972 ptr = getIds(ptr, NODE, nodeIds);
3973 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3976 // Vertex v1 cannot be inserted (warning).
3977 ptr = getIds(ptr, NODE, nodeIds);
3978 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3981 // There are at least two points whose distance is dist, i.e., considered as coincident
3982 case 2103: // ERR 2103 : 16 WITH 3
3983 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
3984 ptr = getIds(ptr, NODE, nodeIds);
3985 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3986 ptr = getIds(ptr, NODE, nodeIds);
3987 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3990 // Constrained edge (e1, e2) cannot be enforced (warning).
3991 ptr = getIds(ptr, EDGE, nodeIds);
3992 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3995 // Constrained face (f 1, f 2, f 3) cannot be enforced
3996 ptr = getIds(ptr, TRIA, nodeIds);
3997 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
3999 case 3103: // ERR 3103 : 1 2 WITH 7 3
4000 // The surface edge (e1, e2) intersects another surface edge (e3, e4)
4001 ptr = getIds(ptr, EDGE, nodeIds);
4002 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4003 ptr = getIds(ptr, EDGE, nodeIds);
4004 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4006 case 3104: // ERR 3104 : 9 10 WITH 1 2 3
4007 // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
4008 ptr = getIds(ptr, EDGE, nodeIds);
4009 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4010 ptr = getIds(ptr, TRIA, nodeIds);
4011 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4013 case 3105: // ERR 3105 : 8 IN 2 3 5
4014 // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
4015 ptr = getIds(ptr, NODE, nodeIds);
4016 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4017 ptr = getIds(ptr, TRIA, nodeIds);
4018 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4021 // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
4022 ptr = getIds(ptr, EDGE, nodeIds);
4023 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4024 ptr = getIds(ptr, TRIA, nodeIds);
4025 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4027 case 3107: // ERR 3107 : 2 IN 4 1
4028 // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
4029 ptr = getIds(ptr, NODE, nodeIds);
4030 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4031 ptr = getIds(ptr, EDGE, nodeIds);
4032 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4034 case 3109: // ERR 3109 : EDGE 5 6 UNIQUE
4035 // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
4036 ptr = getIds(ptr, EDGE, nodeIds);
4037 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4039 case 9000: // ERR 9000
4040 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
4041 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
4042 // A too small volume element is detected. Are reported the index of the element,
4043 // its four vertex indices, its volume and the tolerance threshold value
4044 ptr = getIds(ptr, ID, nodeIds);
4045 ptr = getIds(ptr, VOL, nodeIds);
4046 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4047 // even if all nodes found, volume it most probably invisible,
4048 // add its faces to demenstrate it anyhow
4050 vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
4051 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4052 faceNodes[2] = nodeIds[3]; // 013
4053 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4054 faceNodes[1] = nodeIds[2]; // 023
4055 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4056 faceNodes[0] = nodeIds[1]; // 123
4057 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4060 case 9001: // ERR 9001
4061 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
4062 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
4063 // %% NUMBER OF NULL VOLUME TETS : 0
4064 // There exists at least a null or negative volume element
4067 // There exist n null or negative volume elements
4070 // A too small volume element is detected
4073 // A too bad quality face is detected. This face is considered degenerated,
4074 // its index, its three vertex indices together with its quality value are reported
4075 break; // same as next
4076 case 9112: // ERR 9112
4077 // FACE 2 WITH VERTICES : 4 2 5
4078 // SMALL INRADIUS : 0.
4079 // A too bad quality face is detected. This face is degenerated,
4080 // its index, its three vertex indices together with its inradius are reported
4081 ptr = getIds(ptr, ID, nodeIds);
4082 ptr = getIds(ptr, TRIA, nodeIds);
4083 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4084 // add triangle edges as it most probably has zero area and hence invisible
4086 vector<int> edgeNodes(2);
4087 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
4088 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4089 edgeNodes[1] = nodeIds[2]; // 0-2
4090 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4091 edgeNodes[0] = nodeIds[1]; // 1-2
4092 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4097 bool isNewError = foundErrorStr.insert( string( errBeg, ptr )).second;
4099 continue; // not to report same error several times
4101 // const SMDS_MeshElement* nullElem = 0;
4102 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
4104 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
4105 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
4106 // if ( oneMoreErrorType )
4107 // continue; // not to report different types of errors with bad elements
4110 // store bad elements
4111 //if ( allElemsOk ) {
4112 list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
4113 for ( ; elem != badElems.end(); ++elem )
4114 addBadInputElement( *elem );
4118 string text = translateError( errNum );
4119 if ( errDescription.find( text ) == text.npos ) {
4120 if ( !errDescription.empty() )
4121 errDescription << "\n";
4122 errDescription << text;
4127 if ( errDescription.empty() ) { // no errors found
4128 char msgLic1[] = "connection to server failed";
4129 char msgLic2[] = " Dlim ";
4130 if ( search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
4131 search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
4132 errDescription << "Licence problems.";
4135 char msg2[] = "SEGMENTATION FAULT";
4136 if ( search( &buf[0], bufEnd, msg2, msg2 + strlen(msg2)) != bufEnd )
4137 errDescription << "ghs3d: SEGMENTATION FAULT. ";
4141 if ( errDescription.empty() )
4142 errDescription << "See " << logFile << " for problem description";
4144 errDescription << "\nSee " << logFile << " for more information";
4146 return error( errDescription );
4149 //================================================================================
4151 * \brief Creates _Ghs2smdsConvertor
4153 //================================================================================
4155 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const map <int,const SMDS_MeshNode*> & ghs2NodeMap)
4156 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
4160 //================================================================================
4162 * \brief Creates _Ghs2smdsConvertor
4164 //================================================================================
4166 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const vector <const SMDS_MeshNode*> & nodeByGhsId)
4167 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
4171 //================================================================================
4173 * \brief Return SMDS element by ids of GHS3D nodes
4175 //================================================================================
4177 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector<int>& ghsNodes) const
4179 size_t nbNodes = ghsNodes.size();
4180 vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
4181 for ( size_t i = 0; i < nbNodes; ++i ) {
4182 int ghsNode = ghsNodes[ i ];
4183 if ( _ghs2NodeMap ) {
4184 map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
4185 if ( in == _ghs2NodeMap->end() )
4187 nodes[ i ] = in->second;
4190 if ( ghsNode < 1 || ghsNode > _nodeByGhsId->size() )
4192 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
4198 if ( nbNodes == 2 ) {
4199 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
4201 edge = new SMDS_LinearEdge( nodes[0], nodes[1] );
4204 if ( nbNodes == 3 ) {
4205 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
4207 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
4211 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );
4217 //=============================================================================
4221 //=============================================================================
4222 bool GHS3DPlugin_GHS3D::Evaluate(SMESH_Mesh& aMesh,
4223 const TopoDS_Shape& aShape,
4224 MapShapeNbElems& aResMap)
4226 int nbtri = 0, nbqua = 0;
4227 double fullArea = 0.0;
4228 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
4229 TopoDS_Face F = TopoDS::Face( exp.Current() );
4230 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
4231 MapShapeNbElemsItr anIt = aResMap.find(sm);
4232 if( anIt==aResMap.end() ) {
4233 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
4234 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
4235 "Submesh can not be evaluated",this));
4238 std::vector<int> aVec = (*anIt).second;
4239 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
4240 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
4242 BRepGProp::SurfaceProperties(F,G);
4243 double anArea = G.Mass();
4247 // collect info from edges
4248 int nb0d_e = 0, nb1d_e = 0;
4249 bool IsQuadratic = false;
4250 bool IsFirst = true;
4251 TopTools_MapOfShape tmpMap;
4252 for (TopExp_Explorer exp(aShape, TopAbs_EDGE); exp.More(); exp.Next()) {
4253 TopoDS_Edge E = TopoDS::Edge(exp.Current());
4254 if( tmpMap.Contains(E) )
4257 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
4258 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
4259 std::vector<int> aVec = (*anIt).second;
4260 nb0d_e += aVec[SMDSEntity_Node];
4261 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
4263 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
4269 double ELen = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
4272 BRepGProp::VolumeProperties(aShape,G);
4273 double aVolume = G.Mass();
4274 double tetrVol = 0.1179*ELen*ELen*ELen;
4275 double CoeffQuality = 0.9;
4276 int nbVols = int(aVolume/tetrVol/CoeffQuality);
4277 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
4278 int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
4279 std::vector<int> aVec(SMDSEntity_Last);
4280 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
4282 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
4283 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
4284 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
4287 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
4288 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
4289 aVec[SMDSEntity_Pyramid] = nbqua;
4291 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
4292 aResMap.insert(std::make_pair(sm,aVec));
4297 bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh)
4299 SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh );
4300 // TopoDS_Shape theShape = theMesh.GetShapeToMesh();
4301 std::vector <const SMDS_MeshNode*> dummyNodeVector;
4302 std::map<const SMDS_MeshNode*,int> dummyNodeMap;
4303 std::map<std::vector<double>, std::string> dummyEnfVertGroup;
4304 std::vector<std::string> dummyElemGroup;
4305 std::set<std::string> dummyGroupsToRemove;
4307 bool ok = readGMFFile(theGMFFileName,
4308 #ifdef WITH_SMESH_CANCEL_COMPUTE
4311 helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove);
4312 theMesh.GetMeshDS()->Modified();