1 // Copyright (C) 2007-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
20 // File : HexoticPlugin_Hexotic.cxx
21 // Author : Lioka RAZAFINDRAZAKA (CEA)
24 #include "HexoticPlugin_Hexotic.hxx"
25 #include "HexoticPlugin_Hypothesis.hxx"
27 #include "SMDS_MeshElement.hxx"
28 #include "SMDS_MeshNode.hxx"
31 #include <TopExp_Explorer.hxx>
32 #include <OSD_File.hxx>
34 #include "utilities.h"
37 #include <sys/sysinfo.h>
47 #include <SMESH_Gen.hxx>
48 #include <SMESHDS_Mesh.hxx>
49 #include <SMESH_ControlsDef.hxx>
55 #include <BRepClass3d_SolidClassifier.hxx>
56 #include <Bnd_Box.hxx>
57 #include <BRepBndLib.hxx>
58 #include <Precision.hxx>
60 #include <BRepBuilderAPI_MakeVertex.hxx>
61 #include <BRep_Tool.hxx>
62 #include <TopTools_MapOfShape.hxx>
63 #include <TopTools_Array1OfShape.hxx>
64 #include <BRepExtrema_DistShapeShape.hxx>
65 #include <TColStd_Array1OfReal.hxx>
66 #include <BRepExtrema_DistShapeShape.hxx>
68 //=============================================================================
72 //=============================================================================
74 HexoticPlugin_Hexotic::HexoticPlugin_Hexotic(int hypId, int studyId, SMESH_Gen* gen)
75 : SMESH_3D_Algo(hypId, studyId, gen)
77 MESSAGE("HexoticPlugin_Hexotic::HexoticPlugin_Hexotic");
79 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
80 // _onlyUnaryInput = false;
83 _hexoticFilesKept=false;
84 _compatibleHypothesis.push_back("Hexotic_Parameters");
87 //=============================================================================
91 //=============================================================================
93 HexoticPlugin_Hexotic::~HexoticPlugin_Hexotic()
95 MESSAGE("HexoticPlugin_Hexotic::~HexoticPlugin_Hexotic");
98 //=============================================================================
102 //=============================================================================
104 bool HexoticPlugin_Hexotic::CheckHypothesis( SMESH_Mesh& aMesh,
105 const TopoDS_Shape& aShape,
106 SMESH_Hypothesis::Hypothesis_Status& aStatus )
108 // MESSAGE("HexoticPlugin_Hexotic::CheckHypothesis");
111 std::list<const SMESHDS_Hypothesis*>::const_iterator itl;
112 const SMESHDS_Hypothesis* theHyp;
114 const std::list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
115 int nbHyp = hyps.size();
117 aStatus = SMESH_Hypothesis::HYP_OK;
118 return true; // can work with no hypothesis
122 theHyp = (*itl); // use only the first hypothesis
124 std::string hypName = theHyp->GetName();
125 if (hypName == "Hexotic_Parameters") {
126 _hypothesis = static_cast<const HexoticPlugin_Hypothesis*> (theHyp);
128 aStatus = SMESH_Hypothesis::HYP_OK;
131 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
133 return aStatus == SMESH_Hypothesis::HYP_OK;
136 //=======================================================================
137 //function : findShape
139 //=======================================================================
141 static TopoDS_Shape findShape(SMDS_MeshNode** t_Node,
143 const TopoDS_Shape* t_Shape,
147 int iShape, nbNode = 8;
149 pntCoor = new double[3];
150 for ( int i=0; i<3; i++ ) {
152 for ( int j=0; j<nbNode; j++ ) {
153 if ( i == 0) pntCoor[i] += t_Node[j]->X();
154 if ( i == 1) pntCoor[i] += t_Node[j]->Y();
155 if ( i == 2) pntCoor[i] += t_Node[j]->Z();
157 pntCoor[i] /= nbNode;
160 gp_Pnt aPnt(pntCoor[0], pntCoor[1], pntCoor[2]);
161 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
162 if ( not(SC.State() == TopAbs_IN) ) {
163 for (iShape = 0; iShape < nShape; iShape++) {
164 aShape = t_Shape[iShape];
165 if ( not( pntCoor[0] < t_Box[iShape][0] || t_Box[iShape][1] < pntCoor[0] ||
166 pntCoor[1] < t_Box[iShape][2] || t_Box[iShape][3] < pntCoor[1] ||
167 pntCoor[2] < t_Box[iShape][4] || t_Box[iShape][5] < pntCoor[2]) ) {
168 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
169 if (SC.State() == TopAbs_IN)
178 //=======================================================================
179 //function : findEdge
181 //=======================================================================
183 static int findEdge(const SMDS_MeshNode* aNode,
184 const SMESHDS_Mesh* theMesh,
186 const TopoDS_Shape* t_Edge) {
188 TopoDS_Shape aPntShape, foundEdge;
189 TopoDS_Vertex aVertex;
190 gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() );
193 double nearest = RealLast(), *t_Dist;
194 double epsilon = Precision::Confusion();
196 t_Dist = new double[ nEdge ];
197 aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
198 aVertex = TopoDS::Vertex( aPntShape );
200 for ( ind=0; ind < nEdge; ind++ ) {
201 BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] );
202 t_Dist[ind] = aDistance.Value();
203 if ( t_Dist[ind] < nearest ) {
204 nearest = t_Dist[ind];
205 foundEdge = t_Edge[ind];
207 if ( nearest < epsilon )
213 return theMesh->ShapeToIndex( foundEdge );
216 //=======================================================================
217 //function : getNbShape
219 //=======================================================================
221 static int getNbShape(std::string aFile, std::string aString) {
224 std::ifstream file(aFile.c_str());
225 while ( !file.eof() ) {
226 getline( file, aLine);
227 if ( aLine == aString ) {
228 getline( file, aLine);
229 std::istringstream stringFlux( aLine );
230 stringFlux >> number;
238 //=======================================================================
239 //function : countShape
241 //=======================================================================
243 template < class Mesh, class Shape >
244 static int countShape( Mesh* mesh, Shape shape ) {
245 TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
246 TopTools_MapOfShape mapShape;
248 for ( ; expShape.More(); expShape.Next() ) {
249 if (mapShape.Add(expShape.Current())) {
256 //=======================================================================
257 //function : getShape
259 //=======================================================================
261 template < class Mesh, class Shape, class Tab >
262 void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
263 TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
264 TopTools_MapOfShape mapShape;
265 for ( int i=0; expShape.More(); expShape.Next() ) {
266 if (mapShape.Add(expShape.Current())) {
267 t_Shape[i] = expShape.Current();
274 //=======================================================================
275 //function : printWarning
277 //=======================================================================
279 static void printWarning(const int nbExpected, std::string aString, const int nbFound) {
281 cout << "WARNING : " << nbExpected << " " << aString << " expected, Hexotic has found " << nbFound << std::endl;
282 cout << "=======" << std::endl;
287 //=======================================================================
288 //function : removeHexoticFiles
290 //=======================================================================
292 static void removeHexoticFiles(TCollection_AsciiString file_In, TCollection_AsciiString file_Out) {
293 OSD_File( file_In ).Remove();
294 OSD_File( file_Out ).Remove();
297 //=======================================================================
298 //function : writeHexoticFile
300 //=======================================================================
302 static bool writeHexoticFile (std::ofstream& theFile,
303 const SMESHDS_Mesh* theMesh,
304 std::map <int,int>& theSmdsToHexoticIdMap,
305 std::map <int,const SMDS_MeshNode*>& theHexoticIdToNodeMap,
306 const TCollection_AsciiString& Hexotic_In) {
308 cout << "Creating Hexotic processed mesh file : " << Hexotic_In << std::endl;
312 TopExp_Explorer expface(theMesh->ShapeToMesh(), TopAbs_FACE);
313 for ( ; expface.More(); expface.Next() )
318 TopoDS_Shape *tabShape, aShape;
325 const char* space = " ";
330 const SMDS_MeshNode* aNode;
331 SMDS_NodeIteratorPtr itOnNode;
333 std::list< const SMDS_MeshElement* > faces;
334 std::list< const SMDS_MeshElement* >::iterator itListFace;
335 const SMDS_MeshElement* aFace;
336 SMESHDS_SubMesh* theSubMesh;
337 std::map<int,int>::const_iterator itOnSmdsNode;
338 SMDS_ElemIteratorPtr itOnSubNode, itOnSubFace;
340 // Writing SMESH points into Hexotic File
342 nbVertices = theMesh->NbNodes();
344 theFile << "MeshVersionFormatted 1" << std::endl;
345 theFile << std::endl;
346 theFile << "Dimension" << std::endl;
347 theFile << 3 << std::endl;
348 theFile << "# Set of mesh vertices" << std::endl;
349 theFile << "Vertices" << std::endl;
350 theFile << nbVertices << std::endl;
352 tabID = new int[nbShape];
353 tabNodeId = new int[ nbVertices ];
354 tabShape = new TopoDS_Shape[nbShape];
356 itOnNode = theMesh->nodesIterator();
357 while ( itOnNode->more() ) {
358 aNode = itOnNode->next();
359 dummy_1D = aNode->GetPosition()->GetShapeId();
360 tabNodeId[ aSmdsNodeID - 1 ] = 0;
362 for ( int j=0; j< aSmdsNodeID; j++ ) {
363 if ( dummy_1D == tabNodeId[j] ) {
369 tabNodeId[ aSmdsNodeID - 1 ] = dummy_1D;
370 theSmdsToHexoticIdMap.insert(std::map <int,int>::value_type( aNode->GetID(), aSmdsNodeID ));
371 theHexoticIdToNodeMap.insert(std::map <int,const SMDS_MeshNode*>::value_type( aSmdsNodeID, aNode ));
373 theFile << aNode->X() << space << aNode->Y() << space << aNode->Z() << space << dummy_1D << std::endl;
376 // Writing SMESH faces into Hexotic File
378 nbTriangles = theMesh->NbFaces();
380 theFile << std::endl;
381 theFile << "# Set of mesh triangles (v1,v2,v3,tag)" << std::endl;
382 theFile << "Triangles" << std::endl;
383 theFile << nbTriangles << std::endl;
386 for ( int i = 0; expface.More(); expface.Next(), i++ ) {
388 aShape = expface.Current();
389 shapeID = theMesh->ShapeToIndex( aShape );
391 for ( int j=0; j<=i; j++) {
392 if ( shapeID == tabID[j] ) {
399 tabShape[i] = aShape;
402 for ( int i=0; i<nbShape; i++ ) {
403 if ( not (tabID[i] == 0) ) {
404 aShape = tabShape[i];
406 theSubMesh = theMesh->MeshElements( aShape );
407 itOnSubFace = theSubMesh->GetElements();
408 while ( itOnSubFace->more() ) {
409 aFace = itOnSubFace->next();
411 itOnSubNode = aFace->nodesIterator();
412 while ( itOnSubNode->more() ) {
413 aSmdsNodeID = itOnSubNode->next()->GetID();
414 itOnSmdsNode = theSmdsToHexoticIdMap.find( aSmdsNodeID );
415 ASSERT( itOnSmdsNode != theSmdsToHexoticIdMap.end() );
416 theFile << (*itOnSmdsNode).second << space;
418 theFile << dummy_2D << std::endl;
423 theFile << std::endl;
424 theFile << "End" << std::endl;
426 cout << "Processed mesh file created, it contains :" << std::endl;
427 cout << " " << nbVertices << " vertices" << std::endl;
428 cout << " " << nbTriangles << " triangles" << std::endl;
438 //=======================================================================
439 //function : readResult
441 //=======================================================================
443 static bool readResult(std::string theFile,
444 SMESHDS_Mesh* theMesh,
446 const TopoDS_Shape* tabShape,
449 // ---------------------------------
450 // Read generated elements and nodes
451 // ---------------------------------
454 TopoDS_Vertex aVertex;
456 int EndOfFile = 0, nbElem = 0, nField = 9, nbRef = 0;
457 int aHexoticNodeID = 0, shapeID, hexoticShapeID;
459 int *tabID, *tabRef, *nodeAssigne;
460 bool *tabDummy, hasDummy = false;
461 double epsilon = Precision::Confusion();
462 std::map <std::string,int> mapField;
463 SMDS_MeshNode** HexoticNode;
464 TopoDS_Shape *tabCorner, *tabEdge;
466 tabID = new int[nbShape];
467 tabRef = new int[nField];
468 tabDummy = new bool[nField];
470 for (int i=0; i<nbShape; i++)
473 tabID[0] = theMesh->ShapeToIndex( tabShape[0] );
475 mapField["MeshVersionFormatted"] = 0; tabRef[0] = 0; tabDummy[0] = false;
476 mapField["Dimension"] = 1; tabRef[1] = 0; tabDummy[1] = false;
477 mapField["Vertices"] = 2; tabRef[2] = 3; tabDummy[2] = true;
478 mapField["Corners"] = 3; tabRef[3] = 1; tabDummy[3] = false;
479 mapField["Edges"] = 4; tabRef[4] = 2; tabDummy[4] = true;
480 mapField["Ridges"] = 5; tabRef[5] = 1; tabDummy[5] = false;
481 mapField["Quadrilaterals"] = 6; tabRef[6] = 4; tabDummy[6] = true;
482 mapField["Hexahedra"] = 7; tabRef[7] = 8; tabDummy[7] = true;
483 mapField["End"] = 8; tabRef[8] = 0; tabDummy[0] = false;
485 SMDS_NodeIteratorPtr itOnHexoticInputNode = theMesh->nodesIterator();
486 while ( itOnHexoticInputNode->more() )
487 theMesh->RemoveNode( itOnHexoticInputNode->next() );
489 int nbVertices = getNbShape(theFile, "Vertices");
490 int nbHexCorners = getNbShape(theFile, "Corners");
491 int nbCorners = countShape( theMesh, TopAbs_VERTEX );
492 int nbShapeEdge = countShape( theMesh, TopAbs_EDGE );
494 if ( nbHexCorners != nbCorners ) {
495 printWarning(nbCorners, "corners", nbHexCorners);
496 if ( nbHexCorners > nbCorners )
497 nbCorners = nbHexCorners;
500 tabCorner = new TopoDS_Shape[ nbCorners ];
501 tabEdge = new TopoDS_Shape[ nbShapeEdge ];
502 nodeAssigne = new int[ nbVertices + 1 ];
503 HexoticNode = new SMDS_MeshNode*[ nbVertices + 1 ];
505 getShape(theMesh, TopAbs_VERTEX, tabCorner);
506 getShape(theMesh, TopAbs_EDGE, tabEdge);
508 MESSAGE("Read " << theFile << " file");
509 std::ifstream fileRes(theFile.c_str());
512 while ( EndOfFile == 0 ) {
516 if (mapField.count(token)) {
517 nField = mapField[token];
518 nbRef = tabRef[nField];
519 hasDummy = tabDummy[nField];
527 if ( nField < (mapField.size() - 1) && nField >= 0 )
531 case 0: { // "MeshVersionFormatted"
532 MESSAGE(token << " " << nbElem);
535 case 1: { // "Dimension"
536 MESSAGE("Mesh dimension " << nbElem << "D");
539 case 2: { // "Vertices"
540 MESSAGE("Read " << nbElem << " " << token);
543 SMDS_MeshNode * aHexoticNode;
545 coord = new double[nbRef];
546 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
547 aHexoticID = iElem + 1;
548 for ( int iCoord = 0; iCoord < 3; iCoord++ )
549 fileRes >> coord[ iCoord ];
551 aHexoticNode = theMesh->AddNode(coord[0], coord[1], coord[2]);
552 HexoticNode[ aHexoticID ] = aHexoticNode;
553 nodeAssigne[ aHexoticID ] = 0;
561 case 6: // "Quadrilaterals"
562 case 7: { // "Hexahedra"
563 MESSAGE("Read " << nbElem << " " << token);
564 SMDS_MeshNode** node;
565 int nodeDim, *nodeID;
566 SMDS_MeshElement * aHexoticElement;
568 node = new SMDS_MeshNode*[ nbRef ];
569 nodeID = new int[ nbRef ];
570 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
571 for ( int iRef = 0; iRef < nbRef; iRef++ ) {
572 fileRes >> aHexoticNodeID; // read nbRef aHexoticNodeID
573 node[ iRef ] = HexoticNode[ aHexoticNodeID ];
574 nodeID[ iRef ] = aHexoticNodeID;
579 case 3: { // "Corners"
581 gp_Pnt HexoticPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
582 for ( int i=0; i<nbElem; i++ ) {
583 aVertex = TopoDS::Vertex( tabCorner[i] );
584 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
585 if ( aPnt.Distance( HexoticPnt ) < epsilon )
592 aHexoticElement = theMesh->AddEdge( node[0], node[1] );
594 if ( nodeAssigne[ nodeID[0] ] == 0 || nodeAssigne[ nodeID[0] ] == 2 )
596 shapeID = findEdge( node[iNode], theMesh, nbShapeEdge, tabEdge );
599 case 5: { // "Ridges"
602 case 6: { // "Quadrilaterals"
604 aHexoticElement = theMesh->AddFace( node[0], node[1], node[2], node[3] );
608 case 7: { // "Hexahedra"
610 aHexoticElement = theMesh->AddVolume( node[0], node[3], node[2], node[1], node[4], node[7], node[6], node[5] );
612 hexoticShapeID = dummy - IdShapeRef;
613 if ( tabID[ hexoticShapeID ] == 0 ) {
615 aShape = tabShape[0];
616 aShape = findShape(node, aShape, tabShape, tabBox, nbShape);
617 shapeID = theMesh->ShapeToIndex( aShape );
618 tabID[ hexoticShapeID ] = shapeID;
621 shapeID = tabID[ hexoticShapeID ];
622 if ( iElem == (nbElem - 1) ) {
623 int shapeAssociated = 0;
624 for ( int i=0; i<nbShape; i++ ) {
626 shapeAssociated += 1;
628 if ( shapeAssociated != nbShape )
629 printWarning(nbShape, "domains", shapeAssociated);
638 if ( token != "Ridges" ) {
639 for ( int i=0; i<nbRef; i++ ) {
640 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
641 if ( token == "Corners" ) theMesh->SetNodeOnVertex( node[0], aVertex );
642 else if ( token == "Edges" ) theMesh->SetNodeOnEdge( node[i], shapeID );
643 else if ( token == "Quadrilaterals" ) theMesh->SetNodeOnFace( node[i], shapeID );
644 else if ( token == "Hexahedra" ) theMesh->SetNodeInVolume( node[i], shapeID );
645 nodeAssigne[ nodeID[i] ] = nodeDim;
648 if ( token != "Corners" )
649 theMesh->SetMeshElementOnShape( aHexoticElement, shapeID );
658 MESSAGE("End of " << theFile << " file");
662 MESSAGE("Unknown Token: " << token);
672 delete [] nodeAssigne;
673 delete [] HexoticNode;
677 //=============================================================================
679 * Pass parameters to Hexotic
681 //=============================================================================
683 void HexoticPlugin_Hexotic::SetParameters(const HexoticPlugin_Hypothesis* hyp) {
685 MESSAGE("HexoticPlugin_Hexotic::SetParameters");
687 _hexesMinLevel = hyp->GetHexesMinLevel();
688 _hexesMaxLevel = hyp->GetHexesMaxLevel();
689 _hexoticQuadrangles = hyp->GetHexoticQuadrangles();
690 _hexoticIgnoreRidges = hyp->GetHexoticIgnoreRidges();
691 _hexoticInvalidElements = hyp->GetHexoticInvalidElements();
692 _hexoticSharpAngleThreshold = hyp->GetHexoticSharpAngleThreshold();
696 cout << "WARNING : The Hexotic default parameters are taken into account" << std::endl;
697 cout << "=======" << std::endl;
698 _hexesMinLevel = hyp->GetDefaultHexesMinLevel();
699 _hexesMaxLevel = hyp->GetDefaultHexesMaxLevel();
700 _hexoticQuadrangles = hyp->GetDefaultHexoticQuadrangles();
701 _hexoticIgnoreRidges = hyp->GetDefaultHexoticIgnoreRidges();
702 _hexoticInvalidElements = hyp->GetDefaultHexoticInvalidElements();
703 _hexoticSharpAngleThreshold = hyp->GetDefaultHexoticSharpAngleThreshold();
707 //=======================================================================
708 //function : getTmpDir
710 //=======================================================================
712 static TCollection_AsciiString getTmpDir()
714 TCollection_AsciiString aTmpDir;
716 char *Tmp_dir = getenv("SALOME_TMP_DIR");
717 if(Tmp_dir != NULL) {
720 if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\';
722 if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/';
727 aTmpDir = TCollection_AsciiString("C:\\");
729 aTmpDir = TCollection_AsciiString("/tmp/");
735 //=============================================================================
737 * Here we are going to use the Hexotic mesher
739 //=============================================================================
741 bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& theMesh,
742 const TopoDS_Shape& theShape)
745 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
746 TCollection_AsciiString hexahedraMessage;
748 if (_iShape == 0 && _nbShape == 0) {
749 _nbShape = countShape( meshDS, TopAbs_SOLID ); // we count the number of shapes
750 _tabNode = new SMDS_MeshNode*[_nbShape]; // we declare the size of the node array
753 // to prevent from displaying error message after computing,
754 // we need to create one node for each shape theShape.
756 _tabNode[_iShape] = meshDS->AddNode(0, 0, 0);
757 meshDS->SetNodeInVolume( _tabNode[_iShape], meshDS->ShapeToIndex(theShape) );
761 if (_iShape == _nbShape ) {
763 for (int i=0; i<_nbShape; i++) // we destroy the (_nbShape - 1) nodes created and used
764 meshDS->RemoveNode( _tabNode[i] ); // to simulate successful mesh computing.
767 // create bounding box for each shape of the compound
770 TopoDS_Shape *tabShape;
773 tabShape = new TopoDS_Shape[_nbShape];
774 tabBox = new double*[_nbShape];
775 for (int i=0; i<_nbShape; i++)
776 tabBox[i] = new double[6];
777 double Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
779 TopExp_Explorer expBox (meshDS->ShapeToMesh(), TopAbs_SOLID);
780 for (; expBox.More(); expBox.Next()) {
781 tabShape[iShape] = expBox.Current();
783 BRepBndLib::Add(expBox.Current(), BoundingBox);
784 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
785 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
786 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
787 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
791 SetParameters(_hypothesis);
794 cout << "Hexotic execution..." << std::endl;
795 cout << _name << " parameters :" << std::endl;
796 cout << " " << _name << " Segments Min Level = " << _hexesMinLevel << std::endl;
797 cout << " " << _name << " Segments Max Level = " << _hexesMaxLevel << std::endl;
798 cout << " " << "Salome Quadrangles : " << (_hexoticQuadrangles ? "yes":"no") << std::endl;
799 cout << " " << "Hexotic can ignore ridges : " << (_hexoticIgnoreRidges ? "yes":"no") << std::endl;
800 cout << " " << "Hexotic authorize invalide elements : " << ( _hexoticInvalidElements ? "yes":"no") << std::endl;
801 cout << " " << _name << " Sharp angle threshold = " << _hexoticSharpAngleThreshold << " degrees" << std::endl;
803 TCollection_AsciiString aTmpDir = getTmpDir();
804 TCollection_AsciiString Hexotic_In, Hexotic_Out;
805 TCollection_AsciiString run_Hexotic( "hexotic" );
807 TCollection_AsciiString minl = " -minl ", maxl = " -maxl ", angle = " -ra ";
808 TCollection_AsciiString in = " -in ", out = " -out ";
809 TCollection_AsciiString ignoreRidges = " -nr ", invalideElements = " -inv ";
810 TCollection_AsciiString subdom = " -sd ";
812 TCollection_AsciiString minLevel, maxLevel, sharpAngle, mode;
813 minLevel = _hexesMinLevel;
814 maxLevel = _hexesMaxLevel;
815 sharpAngle = _hexoticSharpAngleThreshold;
818 std::map <int,int> aSmdsToHexoticIdMap;
819 std::map <int,const SMDS_MeshNode*> aHexoticIdToNodeMap;
821 Hexotic_In = aTmpDir + "Hexotic_In.mesh";
822 Hexotic_Out = aTmpDir + "Hexotic_Out.mesh";
824 if (_hexoticIgnoreRidges)
825 run_Hexotic += ignoreRidges;
827 if (_hexoticInvalidElements)
828 run_Hexotic += invalideElements;
830 run_Hexotic += angle + sharpAngle + minl + minLevel + maxl + maxLevel + in + Hexotic_In + out + Hexotic_Out;
831 run_Hexotic += subdom + mode;
834 cout << "Hexotic command : " << run_Hexotic << std::endl;
836 removeHexoticFiles(Hexotic_In, Hexotic_Out);
838 std::ofstream HexoticFile (Hexotic_In.ToCString(), std::ios::out);
840 Ok = ( writeHexoticFile(HexoticFile, meshDS, aSmdsToHexoticIdMap, aHexoticIdToNodeMap, Hexotic_In) );
843 aSmdsToHexoticIdMap.clear();
844 aHexoticIdToNodeMap.clear();
846 MESSAGE("HexoticPlugin_Hexotic::Compute");
848 system( run_Hexotic.ToCString() );
854 std::ifstream fileRes( Hexotic_Out.ToCString() );
855 if ( ! fileRes.fail() ) {
856 Ok = readResult( Hexotic_Out.ToCString(), meshDS, _nbShape, tabShape, tabBox );
857 hexahedraMessage = "success";
860 hexahedraMessage = "failed";
861 cout << "Problem with Hexotic output file " << Hexotic_Out.ToCString() << std::endl;
864 cout << "Hexahedra meshing " << hexahedraMessage << std::endl;
868 for (int i=0; i<_nbShape; i++)
877 //=============================================================================
881 //=============================================================================
883 std::ostream& HexoticPlugin_Hexotic::SaveTo(std::ostream& save)
888 //=============================================================================
892 //=============================================================================
894 std::istream& HexoticPlugin_Hexotic::LoadFrom(std::istream& load)
899 //=============================================================================
903 //=============================================================================
905 std::ostream& operator << (std::ostream& save, HexoticPlugin_Hexotic& hyp)
907 return hyp.SaveTo( save );
910 //=============================================================================
914 //=============================================================================
916 std::istream& operator >> (std::istream& load, HexoticPlugin_Hexotic& hyp)
918 return hyp.LoadFrom( load );