1 // Copyright (C) 2004-2008 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
19 //=============================================================================
20 // File : GHS3DPlugin_GHS3D.cxx
22 // Author : Edward AGAPOV, modified by Lioka RAZAFINDRAZAKA (CEA) 09/02/2007
25 //=============================================================================
29 #include "GHS3DPlugin_GHS3D.hxx"
30 #include "GHS3DPlugin_Hypothesis.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_MesherHelper.hxx"
36 #include "SMESH_MeshEditor.hxx"
38 #include "SMDS_MeshElement.hxx"
39 #include "SMDS_MeshNode.hxx"
40 #include "SMDS_FaceOfNodes.hxx"
41 #include "SMDS_VolumeOfNodes.hxx"
43 #include <BRepAdaptor_Surface.hxx>
44 #include <BRepBndLib.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
46 #include <BRepTools.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Bnd_Box.hxx>
49 #include <GeomAPI_ProjectPointOnSurf.hxx>
50 #include <OSD_File.hxx>
51 #include <Precision.hxx>
52 #include <Quantity_Parameter.hxx>
53 #include <Standard_ErrorHandler.hxx>
54 #include <Standard_Failure.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_IndexedMapOfShape.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
60 //#include <BRepClass_FaceClassifier.hxx>
61 //#include <BRepGProp.hxx>
62 //#include <GProp_GProps.hxx>
64 #include "utilities.h"
67 #include <sys/sysinfo.h>
70 //#include <Standard_Stream.hxx>
73 #define castToNode(n) static_cast<const SMDS_MeshNode *>( n );
94 //=============================================================================
98 //=============================================================================
100 GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen)
101 : SMESH_3D_Algo(hypId, studyId, gen)
103 MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D");
105 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
106 _onlyUnaryInput = false; // Compute() will be called on a compound of solids
109 _compatibleHypothesis.push_back("GHS3D_Parameters");
110 _requireShape = false; // can work without shape
113 //=============================================================================
117 //=============================================================================
119 GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D()
121 MESSAGE("GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D");
124 //=============================================================================
128 //=============================================================================
130 bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh,
131 const TopoDS_Shape& aShape,
132 Hypothesis_Status& aStatus )
134 aStatus = SMESH_Hypothesis::HYP_OK;
136 // there is only one compatible Hypothesis so far
139 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
141 _hyp = static_cast<const GHS3DPlugin_Hypothesis*> ( hyps.front() );
143 _keepFiles = _hyp->GetKeepFiles();
148 //=======================================================================
149 //function : findShape
151 //=======================================================================
153 static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[],
155 const TopoDS_Shape shape[],
158 TopAbs_State * state = 0)
161 int j, iShape, nbNode = 4;
163 for ( j=0; j<nbNode; j++ )
164 aPnt += gp_XYZ( aNode[j]->X(), aNode[j]->Y(), aNode[j]->Z() );
167 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
168 if (state) *state = SC.State();
169 if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) {
170 for (iShape = 0; iShape < nShape; iShape++) {
171 aShape = shape[iShape];
172 if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() ||
173 aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() ||
174 aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) {
175 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
176 if (state) *state = SC.State();
177 if (SC.State() == TopAbs_IN)
185 //=======================================================================
186 //function : readMapIntLine
188 //=======================================================================
190 static char* readMapIntLine(char* ptr, int tab[]) {
194 for ( int i=0; i<17; i++ ) {
195 intVal = strtol(ptr, &ptr, 10);
202 //=======================================================================
203 //function : countShape
205 //=======================================================================
207 template < class Mesh, class Shape >
208 static int countShape( Mesh* mesh, Shape shape ) {
209 TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
211 for ( ; expShape.More(); expShape.Next() ) {
217 //=======================================================================
218 //function : writeFaces
220 //=======================================================================
222 static bool writeFaces (ofstream & theFile,
223 SMESHDS_Mesh * theMesh,
224 const map <int,int> & theSmdsToGhs3dIdMap)
228 // NB_ELEMS DUMMY_INT
229 // Loop from 1 to NB_ELEMS
230 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
232 int nbShape = countShape( theMesh, TopAbs_FACE );
234 int *tabID; tabID = new int[nbShape];
235 TopoDS_Shape *tabShape; tabShape = new TopoDS_Shape[nbShape];
237 SMESHDS_SubMesh* theSubMesh;
238 const SMDS_MeshElement* aFace;
239 const char* space = " ";
240 const int dummyint = 0;
241 map<int,int>::const_iterator itOnMap;
242 SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
243 int shapeID, nbNodes, aSmdsID;
246 cout << " " << theMesh->NbFaces() << " shapes of 2D dimension" << endl;
249 theFile << space << theMesh->NbFaces() << space << dummyint << endl;
251 TopExp_Explorer expface( theMesh->ShapeToMesh(), TopAbs_FACE );
252 for ( int i = 0; expface.More(); expface.Next(), i++ ) {
254 aShape = expface.Current();
255 shapeID = theMesh->ShapeToIndex( aShape );
257 for ( int j=0; j<=i; j++) {
258 if ( shapeID == tabID[j] ) {
265 tabShape[i] = aShape;
268 for ( int i =0; i < nbShape; i++ ) {
269 if ( tabID[i] != 0 ) {
270 aShape = tabShape[i];
272 theSubMesh = theMesh->MeshElements( aShape );
273 if ( !theSubMesh ) continue;
274 itOnSubMesh = theSubMesh->GetElements();
275 while ( itOnSubMesh->more() ) {
276 aFace = itOnSubMesh->next();
277 nbNodes = aFace->NbNodes();
279 theFile << space << nbNodes;
281 itOnSubFace = aFace->nodesIterator();
282 while ( itOnSubFace->more() ) {
284 aSmdsID = itOnSubFace->next()->GetID();
285 itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
286 ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
288 theFile << space << (*itOnMap).second;
291 // (NB_NODES + 1) times: DUMMY_INT
292 for ( int j=0; j<=nbNodes; j++)
293 theFile << space << dummyint;
306 //=======================================================================
307 //function : writeFaces
308 //purpose : Write Faces in case if generate 3D mesh w/o geometry
309 //=======================================================================
311 static bool writeFaces (ofstream & theFile,
312 SMESHDS_Mesh * theMesh,
313 vector <const SMDS_MeshNode*> & theNodeByGhs3dId)
317 // NB_ELEMS DUMMY_INT
318 // Loop from 1 to NB_ELEMS
319 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
323 list< const SMDS_MeshElement* > faces;
324 list< const SMDS_MeshElement* >::iterator f;
325 map< const SMDS_MeshNode*,int >::iterator it;
326 SMDS_ElemIteratorPtr nodeIt;
327 const SMDS_MeshElement* elem;
330 const char* space = " ";
331 const int dummyint = 0;
333 //get all faces from mesh
334 SMDS_FaceIteratorPtr eIt = theMesh->facesIterator();
335 while ( eIt->more() ) {
336 const SMDS_MeshElement* elem = eIt->next();
339 faces.push_back( elem );
346 cout << "The initial 2D mesh contains " << nbFaces << " faces and ";
348 // NB_ELEMS DUMMY_INT
349 theFile << space << nbFaces << space << dummyint << endl;
351 // Loop from 1 to NB_ELEMS
353 map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
355 for ( ; f != faces.end(); ++f )
359 nbNodes = elem->NbNodes();
360 theFile << space << nbNodes;
362 // NODE_NB_1 NODE_NB_2 ...
363 nodeIt = elem->nodesIterator();
364 while ( nodeIt->more() )
367 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
368 int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
369 it = aNodeToGhs3dIdMap.insert( make_pair( node, newId )).first;
370 theFile << space << it->second;
373 // (NB_NODES + 1) times: DUMMY_INT
374 for ( int i=0; i<=nbNodes; i++)
375 theFile << space << dummyint;
380 // put nodes to theNodeByGhs3dId vector
381 theNodeByGhs3dId.resize( aNodeToGhs3dIdMap.size() );
382 map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToGhs3dIdMap.begin();
383 for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id)
385 theNodeByGhs3dId[ n2id->second - 1 ] = n2id->first; // ghs3d ids count from 1
391 //=======================================================================
392 //function : writePoints
394 //=======================================================================
396 static bool writePoints (ofstream & theFile,
397 SMESHDS_Mesh * theMesh,
398 map <int,int> & theSmdsToGhs3dIdMap,
399 map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap)
404 // Loop from 1 to NB_NODES
407 int nbNodes = theMesh->NbNodes();
411 const char* space = " ";
412 const int dummyint = 0;
415 SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
416 const SMDS_MeshNode* node;
419 theFile << space << nbNodes << endl;
421 cout << "The initial 2D mesh contains :" << endl;
422 cout << " " << nbNodes << " vertices" << endl;
424 // Loop from 1 to NB_NODES
429 theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
430 theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
435 << space << node->X()
436 << space << node->Y()
437 << space << node->Z()
438 << space << dummyint;
446 //=======================================================================
447 //function : writePoints
449 //=======================================================================
451 static bool writePoints (ofstream & theFile,
452 SMESHDS_Mesh * theMesh,
453 const vector <const SMDS_MeshNode*> & theNodeByGhs3dId)
458 // Loop from 1 to NB_NODES
461 //int nbNodes = theMesh->NbNodes();
462 int nbNodes = theNodeByGhs3dId.size();
466 const char* space = " ";
467 const int dummyint = 0;
469 const SMDS_MeshNode* node;
472 theFile << space << nbNodes << endl;
473 cout << nbNodes << " nodes" << endl;
475 // Loop from 1 to NB_NODES
477 vector<const SMDS_MeshNode*>::const_iterator nodeIt = theNodeByGhs3dId.begin();
478 vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
479 for ( ; nodeIt != after; ++nodeIt )
485 << space << node->X()
486 << space << node->Y()
487 << space << node->Z()
488 << space << dummyint;
496 //=======================================================================
497 //function : findShapeID
498 //purpose : find the solid corresponding to GHS3D sub-domain following
499 // the technique proposed in GHS3D manual in chapter
500 // "B.4 Subdomain (sub-region) assignment"
501 //=======================================================================
503 static int findShapeID(SMESH_Mesh& mesh,
504 const SMDS_MeshNode* node1,
505 const SMDS_MeshNode* node2,
506 const SMDS_MeshNode* node3,
507 const bool toMeshHoles)
509 const int invalidID = 0;
510 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
512 // face th enodes belong to
513 const SMDS_MeshElement * face = meshDS->FindFace(node1,node2,node3);
517 // geom face the face assigned to
518 SMESH_MeshEditor editor(&mesh);
519 int geomFaceID = editor.FindShape( face );
522 TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID );
523 if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE )
525 TopoDS_Face geomFace = TopoDS::Face( shape );
527 // solids bounded by geom face
528 TopTools_IndexedMapOfShape solids, shells;
529 TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace);
530 for ( ; ansIt.More(); ansIt.Next() ) {
531 switch ( ansIt.Value().ShapeType() ) {
533 solids.Add( ansIt.Value() ); break;
535 shells.Add( ansIt.Value() ); break;
539 // analyse found solids
540 if ( solids.Extent() == 0 || shells.Extent() == 0)
543 const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) );
544 if ( solids.Extent() == 1 )
547 return meshDS->ShapeToIndex( solid1 );
549 // - Are we at a hole boundary face?
550 if ( shells(1).IsSame( BRepTools::OuterShell( solid1 )) )
551 { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell?
553 TopExp_Explorer eExp( shells(1), TopAbs_EDGE );
554 // check if any edge of shells(1) belongs to another shell
555 for ( ; eExp.More() && !touch; eExp.Next() ) {
556 ansIt = mesh.GetAncestors( eExp.Current() );
557 for ( ; ansIt.More() && !touch; ansIt.Next() ) {
558 if ( ansIt.Value().ShapeType() == TopAbs_SHELL )
559 touch = ( !ansIt.Value().IsSame( shells(1) ));
563 return meshDS->ShapeToIndex( solid1 );
566 // find orientation of geom face within the first solid
567 TopExp_Explorer fExp( solid1, TopAbs_FACE );
568 for ( ; fExp.More(); fExp.Next() )
569 if ( geomFace.IsSame( fExp.Current() )) {
570 geomFace = TopoDS::Face( fExp.Current() );
574 return invalidID; // face not found
576 // find UV of the center of triangle on geomFace
577 SMESH_MesherHelper helper( mesh );
578 BRepAdaptor_Surface surface( geomFace );
580 const SMDS_MeshNode* nodes[3] = { node1, node2, node3 };
581 for ( int n = 0; n < 3; ++n )
583 const SMDS_MeshNode* node = nodes[n];
584 gp_XY uv = helper.GetNodeUV( geomFace, node );
586 // check that uv is correct
587 gp_Pnt nodePnt ( node->X(), node->Y(), node->Z() );
588 double tol = BRep_Tool::Tolerance( geomFace );
589 if ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) > 2 * tol ) {
590 // project node onto geomFace to get right UV
591 GeomAPI_ProjectPointOnSurf projector( nodePnt, surface.Surface().Surface() );
592 if ( !projector.IsDone() || projector.NbPoints() < 1 )
594 Quantity_Parameter U,V;
595 projector.LowerDistanceParameters(U,V);
600 // normale to face at node1
601 gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() );
602 gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() );
603 gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() );
604 gp_Vec vec12( node1Pnt, node2Pnt );
605 gp_Vec vec13( node1Pnt, node3Pnt );
606 gp_Vec meshNormal = vec12 ^ vec13;
607 if ( meshNormal.SquareMagnitude() < DBL_MIN )
610 // normale to geomFace at UV
612 surface.D1( UV.X(), UV.Y(), node1Pnt, du, dv );
613 gp_Vec geomNormal = du ^ dv;
614 if ( geomNormal.SquareMagnitude() < DBL_MIN )
615 return findShapeID( mesh, node2, node3, node1, toMeshHoles );
616 if ( geomFace.Orientation() == TopAbs_REVERSED )
617 geomNormal.Reverse();
620 bool isReverse = ( meshNormal * geomNormal ) < 0;
622 return meshDS->ShapeToIndex( solid1 );
624 if ( solids.Extent() == 1 )
625 return HOLE_ID; // we are inside a hole
627 return meshDS->ShapeToIndex( solids(2) );
630 //=======================================================================
631 //function : readResultFile
633 //=======================================================================
635 static bool readResultFile(const int fileOpen,
637 TopoDS_Shape tabShape[],
640 map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
650 SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS();
653 int nbElems, nbNodes, nbInputNodes;
654 int nodeId/*, triangleId*/;
656 int ID, shapeID, ghs3dShapeID;
659 nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
661 int *tab, *tabID, *nodeID, *nodeAssigne;
663 const SMDS_MeshNode **node;
666 //tabID = new int[nbShape];
668 coord = new double[3];
669 node = new const SMDS_MeshNode*[4];
672 SMDS_MeshNode * aNewNode;
673 map <int,const SMDS_MeshNode*>::iterator itOnNode;
674 SMDS_MeshElement* aTet;
679 // Read the file state
680 fileStat = fstat(fileOpen, &status);
681 length = status.st_size;
683 // Mapping the result file into memory
684 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
687 ptr = readMapIntLine(ptr, tab);
692 nbInputNodes = tab[2];
694 nodeAssigne = new int[ nbNodes+1 ];
697 aSolid = tabShape[0];
699 // Reading the nodeId
700 for (int i=0; i < 4*nbElems; i++)
701 nodeId = strtol(ptr, &ptr, 10);
703 // Reading the nodeCoor and update the nodeMap
704 for (int iNode=1; iNode <= nbNodes; iNode++) {
705 for (int iCoor=0; iCoor < 3; iCoor++)
706 coord[ iCoor ] = strtod(ptr, &ptr);
707 nodeAssigne[ iNode ] = 1;
708 if ( iNode > nbInputNodes ) {
709 nodeAssigne[ iNode ] = 0;
710 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
711 theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
715 // Reading the number of triangles which corresponds to the number of sub-domains
716 nbTriangle = strtol(ptr, &ptr, 10);
718 tabID = new int[nbTriangle];
719 for (int i=0; i < nbTriangle; i++) {
721 // find the solid corresponding to GHS3D sub-domain following
722 // the technique proposed in GHS3D manual in chapter
723 // "B.4 Subdomain (sub-region) assignment"
724 int nodeId1 = strtol(ptr, &ptr, 10);
725 int nodeId2 = strtol(ptr, &ptr, 10);
726 int nodeId3 = strtol(ptr, &ptr, 10);
727 if ( nbTriangle > 1 ) {
728 const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
729 const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
730 const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
733 tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
735 cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << endl;
737 } catch ( Standard_Failure ) {
744 if ( nbTriangle <= nbShape ) // no holes
745 toMeshHoles = true; // not avoid creating tetras in holes
747 // Associating the tetrahedrons to the shapes
748 shapeID = compoundID;
749 for (int iElem = 0; iElem < nbElems; iElem++) {
750 for (int iNode = 0; iNode < 4; iNode++) {
751 ID = strtol(tetraPtr, &tetraPtr, 10);
752 itOnNode = theGhs3dIdToNodeMap.find(ID);
753 node[ iNode ] = itOnNode->second;
754 nodeID[ iNode ] = ID;
756 // We always run GHS3D with "to mesh holes'==TRUE but we must not create
757 // tetras within holes depending on hypo option,
758 // so we first check if aTet is inside a hole and then create it
759 //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
760 if ( nbTriangle > 1 ) {
761 shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles
762 ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef;
763 if ( tabID[ ghs3dShapeID ] == 0 ) {
765 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
766 if ( toMeshHoles || state == TopAbs_IN )
767 shapeID = theMeshDS->ShapeToIndex( aSolid );
768 tabID[ ghs3dShapeID ] = shapeID;
771 shapeID = tabID[ ghs3dShapeID ];
773 else if ( nbShape > 1 ) {
774 // Case where nbTriangle == 1 while nbShape == 2 encountered
775 // with compound of 2 boxes and "To mesh holes"==False,
776 // so there are no subdomains specified for each tetrahedron.
777 // Try to guess a solid by a node already bound to shape
779 for ( int i=0; i<4 && shapeID==0; i++ ) {
780 if ( nodeAssigne[ nodeID[i] ] == 1 &&
781 node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
782 node[i]->GetPosition()->GetShapeId() > 1 )
784 shapeID = node[i]->GetPosition()->GetShapeId();
788 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
789 shapeID = theMeshDS->ShapeToIndex( aSolid );
792 // set new nodes and tetrahedron onto the shape
793 for ( int i=0; i<4; i++ ) {
794 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
795 if ( shapeID != HOLE_ID )
796 theMeshDS->SetNodeInVolume( node[i], shapeID );
797 nodeAssigne[ nodeID[i] ] = shapeID;
800 if ( toMeshHoles || shapeID != HOLE_ID ) {
801 aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
802 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
805 shapeIDs.insert( shapeID );
808 // Remove nodes of tetras inside holes if !toMeshHoles
809 if ( !toMeshHoles ) {
810 itOnNode = theGhs3dIdToNodeMap.find( nbInputNodes );
811 for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
812 ID = itOnNode->first;
813 if ( nodeAssigne[ ID ] == HOLE_ID )
814 theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
819 cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl;
820 munmap(mapPtr, length);
828 delete [] nodeAssigne;
831 if ( shapeIDs.size() != nbShape ) {
832 cout << "Only " << shapeIDs.size() << " solids of " << nbShape << " found" << endl;
833 for (int i=0; i<nbShape; i++) {
834 shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
835 if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
836 cout << " Solid #" << shapeID << " not found" << endl;
844 //=======================================================================
845 //function : readResultFile
847 //=======================================================================
849 static bool readResultFile(const int fileOpen,
850 SMESHDS_Mesh* theMeshDS,
852 vector <const SMDS_MeshNode*>& theNodeByGhs3dId) {
862 int nbElems, nbNodes, nbInputNodes;
863 int nodeId, triangleId;
869 const SMDS_MeshNode **node;
872 coord = new double[3];
873 node = new const SMDS_MeshNode*[4];
875 SMDS_MeshNode * aNewNode;
876 map <int,const SMDS_MeshNode*>::iterator IdNode;
877 SMDS_MeshElement* aTet;
879 // Read the file state
880 fileStat = fstat(fileOpen, &status);
881 length = status.st_size;
883 // Mapping the result file into memory
884 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
887 ptr = readMapIntLine(ptr, tab);
892 nbInputNodes = tab[2];
894 theNodeByGhs3dId.resize( nbNodes );
896 // Reading the nodeId
897 for (int i=0; i < 4*nbElems; i++)
898 nodeId = strtol(ptr, &ptr, 10);
900 // Reading the nodeCoor and update the nodeMap
901 shapeID = theMeshDS->ShapeToIndex( aSolid );
902 for (int iNode=0; iNode < nbNodes; iNode++) {
903 for (int iCoor=0; iCoor < 3; iCoor++)
904 coord[ iCoor ] = strtod(ptr, &ptr);
905 if ((iNode+1) > nbInputNodes) {
906 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
907 theMeshDS->SetNodeInVolume( aNewNode, shapeID );
908 theNodeByGhs3dId[ iNode ] = aNewNode;
912 // Reading the triangles
913 nbTriangle = strtol(ptr, &ptr, 10);
915 for (int i=0; i < 3*nbTriangle; i++)
916 triangleId = strtol(ptr, &ptr, 10);
920 // Associating the tetrahedrons to the shapes
921 for (int iElem = 0; iElem < nbElems; iElem++) {
922 for (int iNode = 0; iNode < 4; iNode++) {
923 ID = strtol(tetraPtr, &tetraPtr, 10);
924 node[ iNode ] = theNodeByGhs3dId[ ID-1 ];
926 aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
927 shapeID = theMeshDS->ShapeToIndex( aSolid );
928 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
931 cout << nbElems << " tetrahedrons have been associated to " << nbTriangle << " shapes" << endl;
932 munmap(mapPtr, length);
942 //=============================================================================
944 *Here we are going to use the GHS3D mesher
946 //=============================================================================
948 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
949 const TopoDS_Shape& theShape)
952 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
954 _nbShape = countShape( meshDS, TopAbs_SOLID ); // we count the number of shapes
956 // create bounding box for every shape inside the compound
959 TopoDS_Shape* tabShape;
961 tabShape = new TopoDS_Shape[_nbShape];
962 tabBox = new double*[_nbShape];
963 for (int i=0; i<_nbShape; i++)
964 tabBox[i] = new double[6];
965 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
967 TopExp_Explorer expBox (meshDS->ShapeToMesh(), TopAbs_SOLID);
968 for (; expBox.More(); expBox.Next()) {
969 tabShape[iShape] = expBox.Current();
971 BRepBndLib::Add(expBox.Current(), BoundingBox);
972 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
973 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
974 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
975 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
979 // a unique working file name
980 // to avoid access to the same files by eg different users
981 TCollection_AsciiString aGenericName
982 = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
984 TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName;
985 TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName;
986 aFacesFileName = aGenericName + ".faces"; // in faces
987 aPointsFileName = aGenericName + ".points"; // in points
988 aResultFileName = aGenericName + ".noboite";// out points and volumes
989 aBadResFileName = aGenericName + ".boite"; // out bad result
990 aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
991 aLogFileName = aGenericName + ".log"; // log
997 ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
998 ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
1002 aFacesFile->is_open() && aPointsFile->is_open();
1004 aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
1007 INFOS( "Can't write into " << aFacesFileName);
1008 return error(SMESH_Comment("Can't write into ") << aFacesFileName);
1010 map <int,int> aSmdsToGhs3dIdMap;
1011 map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
1013 Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap ) &&
1014 writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap );
1017 aPointsFile.close();
1020 if ( !_keepFiles ) {
1021 OSD_File( aFacesFileName ).Remove();
1022 OSD_File( aPointsFileName ).Remove();
1024 return error(COMPERR_BAD_INPUT_MESH);
1026 OSD_File( aResultFileName ).Remove(); // needed for boundary recovery module usage
1028 // -----------------
1030 // -----------------
1032 TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() );
1033 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
1034 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
1037 cout << "Ghs3d execution..." << endl;
1038 cout << cmd << endl;
1040 system( cmd.ToCString() ); // run
1043 cout << "End of Ghs3d execution !" << endl;
1049 // Mapping the result file
1052 fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
1053 if ( fileOpen < 0 ) {
1055 cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << endl;
1056 cout << "Log: " << aLogFileName << endl;
1061 _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
1062 Ok = readResultFile( fileOpen, theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap,
1066 // ---------------------
1067 // remove working files
1068 // ---------------------
1073 OSD_File( aLogFileName ).Remove();
1075 else if ( OSD_File( aLogFileName ).Size() > 0 )
1077 // get problem description from the log file
1078 _Ghs2smdsConvertor conv( aGhs3dIdToNodeMap );
1079 storeErrorDescription( aLogFileName, conv );
1083 // the log file is empty
1084 OSD_File( aLogFileName ).Remove();
1085 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
1086 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
1089 if ( !_keepFiles ) {
1090 OSD_File( aFacesFileName ).Remove();
1091 OSD_File( aPointsFileName ).Remove();
1092 OSD_File( aResultFileName ).Remove();
1093 OSD_File( aBadResFileName ).Remove();
1094 OSD_File( aBbResFileName ).Remove();
1096 cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
1099 cout << "treated !" << endl;
1102 _nbShape = 0; // re-initializing _nbShape for the next Compute() method call
1109 //=============================================================================
1111 *Here we are going to use the GHS3D mesher w/o geometry
1113 //=============================================================================
1114 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
1115 SMESH_MesherHelper* aHelper)
1117 MESSAGE("GHS3DPlugin_GHS3D::Compute()");
1119 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
1120 TopoDS_Shape theShape = aHelper->GetSubShape();
1122 // a unique working file name
1123 // to avoid access to the same files by eg different users
1124 TCollection_AsciiString aGenericName
1125 = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
1127 TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName;
1128 TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName;
1129 aFacesFileName = aGenericName + ".faces"; // in faces
1130 aPointsFileName = aGenericName + ".points"; // in points
1131 aResultFileName = aGenericName + ".noboite";// out points and volumes
1132 aBadResFileName = aGenericName + ".boite"; // out bad result
1133 aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
1134 aLogFileName = aGenericName + ".log"; // log
1136 // -----------------
1138 // -----------------
1140 ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
1141 ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
1144 aFacesFile->is_open() && aPointsFile->is_open();
1146 aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
1150 return error( SMESH_Comment("Can't write into ") << aPointsFileName);
1152 vector <const SMDS_MeshNode*> aNodeByGhs3dId;
1154 Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) &&
1155 writePoints( aPointsFile, meshDS, aNodeByGhs3dId));
1158 aPointsFile.close();
1161 if ( !_keepFiles ) {
1162 OSD_File( aFacesFileName ).Remove();
1163 OSD_File( aPointsFileName ).Remove();
1165 return error(COMPERR_BAD_INPUT_MESH);
1167 OSD_File( aResultFileName ).Remove(); // needed for boundary recovery module usage
1169 // -----------------
1171 // -----------------
1173 TCollection_AsciiString cmd =
1174 (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str();
1175 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
1176 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
1178 system( cmd.ToCString() ); // run
1184 fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
1185 if ( fileOpen < 0 ) {
1187 cout << "Error when opening the " << aResultFileName.ToCString() << " file" << endl;
1188 cout << "Log: " << aLogFileName << endl;
1193 Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId );
1196 // ---------------------
1197 // remove working files
1198 // ---------------------
1203 OSD_File( aLogFileName ).Remove();
1205 else if ( OSD_File( aLogFileName ).Size() > 0 )
1207 // get problem description from the log file
1208 _Ghs2smdsConvertor conv( aNodeByGhs3dId );
1209 storeErrorDescription( aLogFileName, conv );
1212 // the log file is empty
1213 OSD_File( aLogFileName ).Remove();
1214 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
1215 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
1220 OSD_File( aFacesFileName ).Remove();
1221 OSD_File( aPointsFileName ).Remove();
1222 OSD_File( aResultFileName ).Remove();
1223 OSD_File( aBadResFileName ).Remove();
1224 OSD_File( aBbResFileName ).Remove();
1230 //================================================================================
1232 * \brief Provide human readable text by error code reported by ghs3d
1234 //================================================================================
1236 static string translateError(const int errNum)
1240 return "The surface mesh includes a face of type other than edge, "
1241 "triangle or quadrilateral. This face type is not supported.";
1243 return "Not enough memory for the face table.";
1245 return "Not enough memory.";
1247 return "Not enough memory.";
1249 return "Face is ignored.";
1251 return "End of file. Some data are missing in the file.";
1253 return "Read error on the file. There are wrong data in the file.";
1255 return "the metric file is inadequate (dimension other than 3).";
1257 return "the metric file is inadequate (values not per vertices).";
1259 return "the metric file contains more than one field.";
1261 return "the number of values in the \".bb\" (metric file) is incompatible with the expected"
1262 "value of number of mesh vertices in the \".noboite\" file.";
1264 return "Too many sub-domains.";
1266 return "the number of vertices is negative or null.";
1268 return "the number of faces is negative or null.";
1270 return "A face has a null vertex.";
1272 return "incompatible data.";
1274 return "the number of vertices is negative or null.";
1276 return "the number of vertices is negative or null (in the \".mesh\" file).";
1278 return "the number of faces is negative or null.";
1280 return "A face appears more than once in the input surface mesh.";
1282 return "An edge appears more than once in the input surface mesh.";
1284 return "A face has a vertex negative or null.";
1286 return "NOT ENOUGH MEMORY.";
1288 return "Not enough available memory.";
1290 return "Some initial points cannot be inserted. The surface mesh is probably very bad "
1291 "in terms of quality or the input list of points is wrong.";
1293 return "Some vertices are too close to one another or coincident.";
1295 return "Some vertices are too close to one another or coincident.";
1297 return "A vertex cannot be inserted.";
1299 return "There are at least two points considered as coincident.";
1301 return "Some vertices are too close to one another or coincident.";
1303 return "The surface mesh regeneration step has failed.";
1305 return "Constrained edge cannot be enforced.";
1307 return "Constrained face cannot be enforced.";
1309 return "Missing faces.";
1311 return "No guess to start the definition of the connected component(s).";
1313 return "The surface mesh includes at least one hole. The domain is not well defined.";
1315 return "Impossible to define a component.";
1317 return "The surface edge intersects another surface edge.";
1319 return "The surface edge intersects the surface face.";
1321 return "One boundary point lies within a surface face.";
1323 return "One surface edge intersects a surface face.";
1325 return "One boundary point lies within a surface edge.";
1327 return "Insufficient memory ressources detected due to a bad quality surface mesh leading "
1328 "to too many swaps.";
1330 return "Edge is unique (i.e., bounds a hole in the surface).";
1332 return "Presumably, the surface mesh is not compatible with the domain being processed.";
1334 return "Too many components, too many sub-domain.";
1336 return "The surface mesh includes at least one hole. "
1337 "Therefore there is no domain properly defined.";
1339 return "Statistics.";
1341 return "Statistics.";
1343 return "Warning, it is dramatically tedious to enforce the boundary items.";
1345 return "Not enough memory at this time, nevertheless, the program continues. "
1346 "The expected mesh will be correct but not really as large as required.";
1348 return "see above error code, resulting quality may be poor.";
1350 return "Not enough memory at this time, nevertheless, the program continues (warning).";
1352 return "Unknown face type.";
1355 return "End of file. Some data are missing in the file.";
1357 return "A too small volume element is detected.";
1359 return "There exists at least a null or negative volume element.";
1361 return "There exist null or negative volume elements.";
1363 return "A too small volume element is detected. A face is considered being degenerated.";
1365 return "Some element is suspected to be very bad shaped or wrong.";
1367 return "A too bad quality face is detected. This face is considered degenerated.";
1369 return "A too bad quality face is detected. This face is degenerated.";
1371 return "Presumably, the surface mesh is not compatible with the domain being processed.";
1373 return "Abnormal error occured, contact hotline.";
1375 return "Not enough memory for the face table.";
1377 return "The algorithm cannot run further. "
1378 "The surface mesh is probably very bad in terms of quality.";
1380 return "Bad vertex number.";
1385 //================================================================================
1387 * \brief Retrieve from a string given number of integers
1389 //================================================================================
1391 static char* getIds( char* ptr, int nbIds, vector<int>& ids )
1394 ids.reserve( nbIds );
1397 while ( !isdigit( *ptr )) ++ptr;
1398 if ( ptr[-1] == '-' ) --ptr;
1399 ids.push_back( strtol( ptr, &ptr, 10 ));
1405 //================================================================================
1407 * \brief Retrieve problem description form a log file
1408 * \retval bool - always false
1410 //================================================================================
1412 bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
1413 const _Ghs2smdsConvertor & toSmdsConvertor )
1417 int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
1419 int file = ::open (logFile.ToCString(), O_RDONLY);
1422 return error( SMESH_Comment("See ") << logFile << " for problem description");
1425 // struct stat status;
1426 // fstat(file, &status);
1427 // size_t length = status.st_size;
1428 off_t length = lseek( file, 0, SEEK_END);
1429 lseek( file, 0, SEEK_SET);
1432 vector< char > buf( length );
1433 int nBytesRead = ::read (file, & buf[0], length);
1435 char* ptr = & buf[0];
1436 char* bufEnd = ptr + nBytesRead;
1438 SMESH_Comment errDescription;
1440 enum { NODE = 1, EDGE, TRIA, VOL, ID = 1 };
1442 // look for errors "ERR #"
1444 set<string> foundErrorStr; // to avoid reporting same error several times
1445 set<int> elemErrorNums; // not to report different types of errors with bad elements
1446 while ( ++ptr < bufEnd )
1448 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
1451 list<const SMDS_MeshElement*> badElems;
1452 vector<int> nodeIds;
1456 int errNum = strtol(ptr, &ptr, 10);
1457 switch ( errNum ) { // we treat errors enumerated in [SALOME platform 0019316] issue
1459 // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
1460 ptr = getIds(ptr, NODE, nodeIds);
1461 ptr = getIds(ptr, TRIA, nodeIds);
1462 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1464 case 1000: // ERR 1000 : 1 3 2
1465 // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
1466 ptr = getIds(ptr, TRIA, nodeIds);
1467 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1470 // Edge (e1, e2) appears more than once in the input surface mesh
1471 ptr = getIds(ptr, EDGE, nodeIds);
1472 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1475 // Face (f 1, f 2, f 3) has a vertex negative or null
1476 ptr = getIds(ptr, TRIA, nodeIds);
1477 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1480 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
1481 ptr = getIds(ptr, NODE, nodeIds);
1482 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1483 ptr = getIds(ptr, NODE, nodeIds);
1484 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1487 // Vertex v1 cannot be inserted (warning).
1488 ptr = getIds(ptr, NODE, nodeIds);
1489 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1492 // There are at least two points whose distance is dist, i.e., considered as coincident
1493 case 2103: // ERR 2103 : 16 WITH 3
1494 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
1495 ptr = getIds(ptr, NODE, nodeIds);
1496 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1497 ptr = getIds(ptr, NODE, nodeIds);
1498 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1501 // Constrained edge (e1, e2) cannot be enforced (warning).
1502 ptr = getIds(ptr, EDGE, nodeIds);
1503 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1506 // Constrained face (f 1, f 2, f 3) cannot be enforced
1507 ptr = getIds(ptr, TRIA, nodeIds);
1508 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1510 case 3103: // ERR 3103 : 1 2 WITH 7 3
1511 // The surface edge (e1, e2) intersects another surface edge (e3, e4)
1512 ptr = getIds(ptr, EDGE, nodeIds);
1513 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1514 ptr = getIds(ptr, EDGE, nodeIds);
1515 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1517 case 3104: // ERR 3104 : 9 10 WITH 1 2 3
1518 // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
1519 ptr = getIds(ptr, EDGE, nodeIds);
1520 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1521 ptr = getIds(ptr, TRIA, nodeIds);
1522 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1524 case 3105: // ERR 3105 : 8 IN 2 3 5
1525 // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
1526 ptr = getIds(ptr, NODE, nodeIds);
1527 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1528 ptr = getIds(ptr, TRIA, nodeIds);
1529 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1532 // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
1533 ptr = getIds(ptr, EDGE, nodeIds);
1534 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1535 ptr = getIds(ptr, TRIA, nodeIds);
1536 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1538 case 3107: // ERR 3107 : 2 IN 4 1
1539 // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
1540 ptr = getIds(ptr, NODE, nodeIds);
1541 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1542 ptr = getIds(ptr, EDGE, nodeIds);
1543 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1545 case 3109: // ERR 3109 : EDGE 5 6 UNIQUE
1546 // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
1547 ptr = getIds(ptr, EDGE, nodeIds);
1548 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1550 case 9000: // ERR 9000
1551 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
1552 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
1553 // A too small volume element is detected. Are reported the index of the element,
1554 // its four vertex indices, its volume and the tolerance threshold value
1555 ptr = getIds(ptr, ID, nodeIds);
1556 ptr = getIds(ptr, VOL, nodeIds);
1557 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1558 // even if all nodes found, volume it most probably invisible,
1559 // add its faces to demenstrate it anyhow
1561 vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
1562 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
1563 faceNodes[2] = nodeIds[3]; // 013
1564 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
1565 faceNodes[1] = nodeIds[2]; // 023
1566 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
1567 faceNodes[0] = nodeIds[1]; // 123
1568 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
1571 case 9001: // ERR 9001
1572 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
1573 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
1574 // %% NUMBER OF NULL VOLUME TETS : 0
1575 // There exists at least a null or negative volume element
1578 // There exist n null or negative volume elements
1581 // A too small volume element is detected
1584 // A too bad quality face is detected. This face is considered degenerated,
1585 // its index, its three vertex indices together with its quality value are reported
1586 break; // same as next
1587 case 9112: // ERR 9112
1588 // FACE 2 WITH VERTICES : 4 2 5
1589 // SMALL INRADIUS : 0.
1590 // A too bad quality face is detected. This face is degenerated,
1591 // its index, its three vertex indices together with its inradius are reported
1592 ptr = getIds(ptr, ID, nodeIds);
1593 ptr = getIds(ptr, TRIA, nodeIds);
1594 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1595 // add triangle edges as it most probably has zero area and hence invisible
1597 vector<int> edgeNodes(2);
1598 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
1599 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
1600 edgeNodes[1] = nodeIds[2]; // 0-2
1601 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
1602 edgeNodes[0] = nodeIds[1]; // 1-2
1603 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
1608 bool isNewError = foundErrorStr.insert( string( errBeg, ptr )).second;
1610 continue; // not to report same error several times
1612 // const SMDS_MeshElement* nullElem = 0;
1613 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
1615 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
1616 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
1617 // if ( oneMoreErrorType )
1618 // continue; // not to report different types of errors with bad elements
1621 // store bad elements
1622 //if ( allElemsOk ) {
1623 list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
1624 for ( ; elem != badElems.end(); ++elem )
1625 addBadInputElement( *elem );
1629 string text = translateError( errNum );
1630 if ( errDescription.find( text ) == text.npos ) {
1631 if ( !errDescription.empty() )
1632 errDescription << "\n";
1633 errDescription << text;
1638 if ( errDescription.empty() ) { // no errors found
1639 char msg[] = "connection to server failed";
1640 if ( search( &buf[0], bufEnd, msg, msg + strlen(msg)) != bufEnd )
1641 errDescription << "Licence problems.";
1644 if ( errDescription.empty() )
1645 errDescription << "See " << logFile << " for problem description";
1647 errDescription << "\nSee " << logFile << " for more information";
1649 return error( errDescription );
1652 //================================================================================
1654 * \brief Creates _Ghs2smdsConvertor
1656 //================================================================================
1658 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const map <int,const SMDS_MeshNode*> & ghs2NodeMap)
1659 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
1663 //================================================================================
1665 * \brief Creates _Ghs2smdsConvertor
1667 //================================================================================
1669 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const vector <const SMDS_MeshNode*> & nodeByGhsId)
1670 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
1674 //================================================================================
1676 * \brief Return SMDS element by ids of GHS3D nodes
1678 //================================================================================
1680 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector<int>& ghsNodes) const
1682 size_t nbNodes = ghsNodes.size();
1683 vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
1684 for ( size_t i = 0; i < nbNodes; ++i ) {
1685 int ghsNode = ghsNodes[ i ];
1686 if ( _ghs2NodeMap ) {
1687 map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
1688 if ( in == _ghs2NodeMap->end() )
1690 nodes[ i ] = in->second;
1693 if ( ghsNode < 1 || ghsNode > _nodeByGhsId->size() )
1695 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
1701 if ( nbNodes == 2 ) {
1702 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
1704 edge = new SMDS_MeshEdge( nodes[0], nodes[1] );
1707 if ( nbNodes == 3 ) {
1708 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
1710 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
1714 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );