From: gdd Date: Thu, 24 Mar 2011 19:47:57 +0000 (+0000) Subject: Fix bugs X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=722310a9e774a655bfaf4936de051a4f1a9d7cf6;p=plugins%2Fghs3dplugin.git Fix bugs Add #ifdef GHS3DVERSION < 42 instructions --- diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 2941791..7cbfa81 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -185,6 +185,7 @@ bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh, return true; } +#if GHS3D_VERSION < 42 //======================================================================= //function : findShape //purpose : @@ -243,7 +244,7 @@ static char* readMapIntLine(char* ptr, int tab[]) { } return ptr; } - +#endif //======================================================================= //function : countShape //purpose : @@ -259,6 +260,7 @@ static char* readMapIntLine(char* ptr, int tab[]) { // return nbShape; // } +#if GHS3D_VERSION >= 42 //======================================================================= //function : readGMFFile //purpose : @@ -526,7 +528,7 @@ static bool writeGMFFile(const char* theMeshFileName, if ( nbFaces == 0 ) return false; - idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3); + idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION); if (!idx) return false; @@ -789,7 +791,7 @@ static bool writeGMFFile(const char* theMeshFileName, std::cout << "End writting required vertices in GmfRequiredVertices" << std::endl; std::cout << "Begin writting in sol file" << std::endl; - idxSol = GmfOpenMesh(theSolFileName, GmfWrite, 3, 3); + idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION); if (!idxSol) { GmfCloseMesh(idx); if (idxRequired) @@ -826,7 +828,7 @@ static bool writeGMFFile(const char* theMeshFileName, // if (solSize) { // std::cout << "Begin writting in sol file" << std::endl; // GmfSetKwd(idx, GmfRequiredVertices, solSize); -// idxSol = GmfOpenMesh(theSolFileName, GmfWrite, 3, 3); +// idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION); // if (!idxSol) { // GmfCloseMesh(idx); // if (idxRequired) @@ -853,7 +855,7 @@ static bool writeGMFFile(const char* theMeshFileName, int usedEnforcedEdges = 0; if (anEnforcedEdgeSet.size()) { -// idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, 3, 3); +// idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION); // if (!idxRequired) // return false; GmfSetKwd(idx, GmfEdges, anEnforcedEdgeSet.size()); @@ -986,7 +988,7 @@ static bool writeGMFFile(const char* theMeshFileName, SMDS_NodeIteratorPtr nodeIt; std::map theNodeId2NodeIndexMap; - idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3); + idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION); if (!idx) return false; @@ -1103,10 +1105,10 @@ static bool writeGMFFile(const char* theMeshFileName, } if (solSize) { - int idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, 3, 3); + int idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION); if (!idxRequired) return false; - int idxSol = GmfOpenMesh(theSolFileName, GmfWrite, 3, 3); + int idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION); if (!idxSol) return false; @@ -1307,454 +1309,7 @@ static bool writeGMFFile(const char* theMeshFileName, return true; } -/* -static bool writeGMFHeader (ofstream &theFile, - int thePrecision) -{ - theFile << "MeshVersionFormatted " << thePrecision << std::endl; - theFile << std::endl; - theFile << "Dimension" << std::endl; - theFile << "3" << std::endl; - theFile << std::endl; - return true; -} - -static bool writeGMFEnd (ofstream &theFile) -{ - theFile << std::endl; - theFile << "End" << std::endl; - return true; -} - -static bool writeGMFVertices (ofstream & theFile, - ofstream & theSolFile, - SMESH_MesherHelper& theHelper, - map & theSmdsToGhs3dIdMap, - map & theGhs3dIdToNodeMap, - GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices, - TIDSortedNodeSet & theEnforcedNodes, - std::map & theNodeId2NodeIndexMap) -{ - SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); - // NB_NODES - int nbNodes = theMeshDS->NbNodes(); - if ( nbNodes == 0 ) - return false; - int nbEnforcedVertices = theEnforcedVertices.size(); - int nbEnforcedNodes = theEnforcedNodes.size(); - - // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D - // The problem is in nodes on degenerated edges, we need to skip them - if ( theHelper.HasDegeneratedEdges() ) - { - // here we decrease total nb of nodes by nb of nodes on degenerated edges - set checkedSM; - for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next()) - { - SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() ); - if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() )) { - if ( sm->GetSubMeshDS() ) - nbNodes -= sm->GetSubMeshDS()->NbNodes(); - } - } - } - const char* space = " "; - const int dummyint = 0; - - int aGhs3dID = 1; - SMDS_NodeIteratorPtr it = theMeshDS->nodesIterator(); - const SMDS_MeshNode* node; - - - std::cout << std::endl; - std::cout << "The initial 2D mesh contains :" << std::endl; - std::cout << " " << nbNodes << " nodes" << std::endl; - if (nbEnforcedVertices > 0) - std::cout << " " << nbEnforcedVertices << " enforced vertices" << std::endl; - if (nbEnforcedNodes > 0) - std::cout << " " << nbEnforcedNodes << " enforced nodes" << std::endl; -// std::cout << "Start writing vertices in 'mesh' file ..." << std::endl; - theFile << "Vertices" << std::endl; - theFile << nbNodes+nbEnforcedVertices+nbEnforcedNodes << std::endl; - - // Loop from 1 to NB_NODES - - while ( it->more() ) - { - node = it->next(); - if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE && - theHelper.IsDegenShape( node->getshapeId() )) // Issue 020674 - continue; - - theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); - theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); - aGhs3dID++; - - // X Y Z DUMMY_INT - theFile - << node->X() << space - << node->Y() << space - << node->Z() << space - << dummyint << space ; - theFile << std::endl; - } - - // Iterate over the enforced vertices - GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; - const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh(); - std::map enfVertexIndexSizeMap; - int i = 1; - for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { - double x = vertexIt->first[0]; - double y = vertexIt->first[1]; - double z = vertexIt->first[2]; - // Test if point is inside shape to mesh - gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(shapeToMesh); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result == TopAbs_IN ) { -// MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second); - // X Y Z PHY_SIZE DUMMY_INT - theFile - << x << space - << y << space - << z << space - << dummyint << space; - theFile << std::endl; - enfVertexIndexSizeMap[nbNodes + i] = vertexIt->second; - i++; - } -// else -// MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); - } - nbNodes = nbNodes + enfVertexIndexSizeMap.size()-1; - - // Iterate over the enforced nodes - TIDSortedNodeSet::const_iterator nodeIt; - int usedEnforcedNodes = 0; - for(nodeIt = theEnforcedNodes.begin() ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) { - double x = (*nodeIt)->X(); - double y = (*nodeIt)->Y(); - double z = (*nodeIt)->Z(); - // Test if point is inside shape to mesh - gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(shapeToMesh); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result == TopAbs_IN ) { -// MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); - // X Y Z PHY_SIZE DUMMY_INT - theFile - << x << space - << y << space - << z << space - << dummyint << space; - theFile << std::endl; - enfVertexIndexSizeMap[nbNodes + i] = -1; - theNodeId2NodeIndexMap.insert( make_pair( (*nodeIt)->GetID(), nbNodes + i )); - i++; - usedEnforcedNodes++; - } -// else -// MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); - } - theFile << std::endl; -// std::cout << std::endl; -// std::cout << "End writing vertices in 'mesh' file." << std::endl; - - if (!nbEnforcedVertices) - return true; - -// std::cout << "Start writing required vertices in 'mesh' file ..." << std::endl; - writeGMFHeader(theSolFile, 1); - theSolFile << "SolAtVertices" << std::endl; - theSolFile << enfVertexIndexSizeMap.size()-usedEnforcedNodes << std::endl; - theSolFile << "1 1" << std::endl; - theFile << std::endl; - theFile << "RequiredVertices" << std::endl; - theFile << enfVertexIndexSizeMap.size() << std::endl; - for (std::map::const_iterator it = enfVertexIndexSizeMap.begin();it != enfVertexIndexSizeMap.end();++it) { - theFile << it->first << std::endl; - if (it->second != -1) - theSolFile << it->second << std::endl; - } - theFile << std::endl; - theSolFile << std::endl; - writeGMFEnd(theSolFile); -// std::cout << "End writing required vertices in 'mesh' file." << std::endl; - - return true; -} - -static bool writeGMFFaces (ofstream & theFile, - const SMESH_ProxyMesh& theMesh, - const TopoDS_Shape& theShape, - const map & theSmdsToGhs3dIdMap, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles, - TIDSortedElemSet & theEnforcedQuadrangles, - std::map & theNodeId2NodeIndexMap) -{ - // record structure: - // - // NB_ELEMS DUMMY_INT - // Loop from 1 to NB_ELEMS - // NB_NODES NODE_NB_1 NODE_NB_2 ... DUMMY_INT - - TopoDS_Shape aShape; - const SMESHDS_SubMesh* theSubMesh; - const SMDS_MeshElement* aFace; - const char* space = " "; - const int dummyint = 0; - map::const_iterator itOnMap; - SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; - int aSmdsID, aNodeID; - - TIDSortedElemSet::const_iterator elemIt; - int nbEnforcedEdges = theEnforcedEdges.size(); - int nbEnforcedTriangles = theEnforcedTriangles.size(); - int nbEnforcedQuadrangles = theEnforcedQuadrangles.size(); - // count triangles bound to geometry - int nbTriangles = 0; - int nbQuadrangles = 0; - ostringstream aStream,aLocalStream; - aStream.clear(); - aLocalStream.clear(); - - TopTools_IndexedMapOfShape facesMap, trianglesMap, quadranglesMap; - TopExp::MapShapes( theShape, TopAbs_FACE, facesMap ); - - for ( int i = 1; i <= facesMap.Extent(); ++i ) - if (( theSubMesh = theMesh.GetSubMesh( facesMap(i)))) - { - SMDS_ElemIteratorPtr it = theSubMesh->GetElements(); - while (it->more()) - { - const SMDS_MeshElement *elem = it->next(); - if (elem->NbNodes() == 3) - { - trianglesMap.Add(facesMap(i)); - nbTriangles ++; - } - else if (elem->NbNodes() == 4) - { - quadranglesMap.Add(facesMap(i)); - nbQuadrangles ++; - } - } - } - - std::cout << " " << facesMap.Extent() << " shapes of 2D dimension:" << std::endl; - std::cout << " " << nbTriangles << " triangles" << std::endl; - std::cout << " " << nbQuadrangles << " quadrangles" << std::endl; - if (nbEnforcedEdges) { - std::cout << " " << nbEnforcedEdges+nbEnforcedTriangles+nbEnforcedQuadrangles - << " enforced shapes:" << std::endl; - std::cout << " " << nbEnforcedEdges << " enforced edges" << std::endl; - } - if (nbEnforcedTriangles) - std::cout << " " << nbEnforcedTriangles << " enforced triangles" << std::endl; - if (nbEnforcedQuadrangles) - std::cout << " " << nbEnforcedQuadrangles << " enforced quadrangles" << std::endl; - std::cout << std::endl; - - // - // EDGES : BEGIN - // - -// std::cout << "Start writing edges in 'mesh' file ..." << std::endl; - - // Iterate over the enforced edges - int usedEnforcedEdges = 0; - bool isOK; - for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { - aFace = (*elemIt); - isOK = true; - itOnSubFace = aFace->nodesIterator(); - aStream.clear(); - while ( itOnSubFace->more() ) { - aNodeID = itOnSubFace->next()->GetID(); - itOnMap = theNodeId2NodeIndexMap.find(aNodeID); - if (itOnMap != theNodeId2NodeIndexMap.end()) - aStream << (*itOnMap).second << space; - else { - isOK = false; - break; - } - } - if (isOK) { - aLocalStream << aStream.str() << dummyint << std::endl; - usedEnforcedEdges++; - } - } - - if (usedEnforcedEdges) { - theFile << std::endl; - theFile << "Edges" << std::endl; - theFile << usedEnforcedEdges << std::endl; - theFile << aLocalStream.str(); - aLocalStream.clear(); - - theFile << std::endl; - theFile << "RequiredEdges" << std::endl; - theFile << usedEnforcedEdges << std::endl; - - // Iterate over the enforced edges - for (int i=0;iGetElements(); - while ( itOnSubMesh->more() ) - { - aFace = itOnSubMesh->next(); - if (aFace->NbNodes() != 3) - continue; - - itOnSubFace = aFace->nodesIterator(); - while ( itOnSubFace->more() ) { - // find GHS3D ID - aSmdsID = itOnSubFace->next()->GetID(); - itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); - // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) { - // cout << "not found node: " << aSmdsID << endl; - // return false; - // } - ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); - - aLocalStream << (*itOnMap).second << space; - } - aLocalStream << dummyint << std::endl; - } - } - - // Iterate over the enforced triangles - int usedEnforcedTriangles = 0; - for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { - aFace = (*elemIt); - isOK = true; - itOnSubFace = aFace->nodesIterator(); - aStream.clear(); - while ( itOnSubFace->more() ) { - aNodeID = itOnSubFace->next()->GetID(); - itOnMap = theNodeId2NodeIndexMap.find(aNodeID); - if (itOnMap != theNodeId2NodeIndexMap.end()) - aStream << (*itOnMap).second << space; - else { - isOK = false; - break; - } - } - if (isOK) { - aLocalStream << aStream.str() << dummyint << std::endl; - usedEnforcedTriangles++; - } - } - if (nbTriangles+usedEnforcedTriangles) { - theFile << std::endl; - theFile << "Triangles" << std::endl; - theFile << nbTriangles+usedEnforcedTriangles << std::endl; - theFile << aLocalStream.str(); - aLocalStream.clear(); - - theFile << std::endl; - } - - // - // TRIANGLES : END - // - - // - // QUADRANGLES : BEGIN - // - -// std::cout << "Start writing quadrangles in 'mesh' file ..." << std::endl; - - for ( int i = 1; i <= quadranglesMap.Extent(); i++ ) - { - aShape = quadranglesMap(i); - theSubMesh = theMesh.GetSubMesh(aShape); - if ( !theSubMesh ) continue; - itOnSubMesh = theSubMesh->GetElements(); - while ( itOnSubMesh->more() ) - { - aFace = itOnSubMesh->next(); - if (aFace->NbNodes() != 4) - continue; - - itOnSubFace = aFace->nodesIterator(); - while ( itOnSubFace->more() ) { - // find GHS3D ID - aSmdsID = itOnSubFace->next()->GetID(); - itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); - // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) { - // cout << "not found node: " << aSmdsID << endl; - // return false; - // } - ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); - - aLocalStream << (*itOnMap).second << space; - } - aLocalStream << dummyint << std::endl; - } - } - - // Iterate over the enforced quadrangles - int usedEnforcedQuadrangles = 0; - for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { - aFace = (*elemIt); - isOK = true; - itOnSubFace = aFace->nodesIterator(); - aStream.clear(); - while ( itOnSubFace->more() ) { - aNodeID = itOnSubFace->next()->GetID(); - itOnMap = theNodeId2NodeIndexMap.find(aNodeID); - if (itOnMap != theNodeId2NodeIndexMap.end()) - aStream << (*itOnMap).second << space; - else { - isOK = false; - break; - } - } - if (isOK) { - aLocalStream << aStream.str() << dummyint << std::endl; - usedEnforcedQuadrangles++; - } - } - if (nbQuadrangles+usedEnforcedQuadrangles) { - theFile << std::endl; - theFile << "Quadrilaterals" << std::endl; - theFile << nbQuadrangles+usedEnforcedQuadrangles << std::endl; - theFile << aLocalStream.str(); - aLocalStream.clear(); - - theFile << std::endl; - } - - // - // QUADRANGLES : END - // - - return true; -} -*/ +#else //======================================================================= //function : writeFaces @@ -3206,6 +2761,7 @@ static bool readResultFile(const int fileOpen, return true; } +#endif //============================================================================= /*! @@ -3253,18 +2809,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString aGenericName = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); - TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName; - TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName; - TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; -#ifdef _DEBUG_ - aGMFFileName = aGenericName + ".mesh"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file - aSolFileName = aGenericName + "_required.sol"; // GMF solution file -#else - aGMFFileName = aGenericName + ".meshb"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file - aSolFileName = aGenericName + ".solb"; // GMF solution file -#endif + TCollection_AsciiString aLogFileName, aResultFileName; +#if GHS3D_VERSION < 42 + TCollection_AsciiString aFacesFileName, aPointsFileName; + TCollection_AsciiString aBadResFileName, aBbResFileName; aFacesFileName = aGenericName + ".faces"; // in faces aPointsFileName = aGenericName + ".points"; // in points aResultFileName = aGenericName + ".noboite";// out points and volumes @@ -3276,19 +2824,29 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // make input files // ----------------- -// ofstream aGMFFile ( aGMFFileName.ToCString() , ios::out); -// ofstream aSolFile ( aSolFileName.ToCString() , ios::out); ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); Ok = - aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open() - /*&& aGMFFile.rdbuf()->is_open() - && aSolFile.rdbuf()->is_open()*/; + aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aFacesFileName); return error(SMESH_Comment("Can't write into ") << aFacesFileName); } +#else + TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; +#ifdef _DEBUG_ + aGMFFileName = aGenericName + ".mesh"; // GMF mesh file + aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file + aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file + aSolFileName = aGenericName + "_required.sol"; // GMF solution file +#else + aGMFFileName = aGenericName + ".meshb"; // GMF mesh file + aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file + aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file + aSolFileName = aGenericName + ".solb"; // GMF solution file +#endif +#endif map aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap; map aGhs3dIdToNodeMap; std::map nodeID2nodeIndexMap; @@ -3299,7 +2857,6 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); // GHS3DPlugin_Hypothesis::TID2SizeMap elemIDToSizeMap = GHS3DPlugin_Hypothesis::GetElementIDToSizeMap(_hyp); - int nbEnforcedVertices = enforcedVertices.size(); SMESH_MesherHelper helper( theMesh ); helper.SetSubShape( theShape ); @@ -3332,24 +2889,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( !proxyMesh ) return false; } -// #if GHS3D_VERSION >= 42 - Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), - helper, *proxyMesh, - aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, - enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, - enforcedVertices); -/* - Ok = (writeGMFHeader( aGMFFile, 1) && - writeGMFVertices( aGMFFile, aSolFile, helper, - aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, - enforcedVertices, enforcedNodes, nodeID2nodeIndexMap) && - writeGMFFaces( aGMFFile, *proxyMesh, theShape, - aSmdsToGhs3dIdMap, - enforcedEdges, enforcedTriangles, enforcedQuadrangles, - nodeID2nodeIndexMap) && - writeGMFEnd( aGMFFile )); -*/ -// #else +#if GHS3D_VERSION < 42 Ok = (writePoints( aPointsFile, helper, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap, nodeIDToSizeMap, @@ -3358,20 +2898,23 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, writeFaces ( aFacesFile, *proxyMesh, theShape, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, enforcedEdges, enforcedTriangles, enforcedQuadrangles)); -// #endif + int nbEnforcedVertices = enforcedVertices.size(); + int nbEnforcedNodes = enforcedNodes.size(); +#else + Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), + helper, *proxyMesh, + aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, + enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, + enforcedVertices); + +#endif } - - int nbEnforcedNodes = enforcedNodes.size(); -// int nbEnforcedEdges = enforcedEdges.size(); -// int nbEnforcedTriangles = enforcedTriangles.size(); -// int nbEnforcedQuadrangles = enforcedQuadrangles.size(); // Write aSmdsToGhs3dIdMap to temp file TCollection_AsciiString aSmdsToGhs3dIdMapFileName; aSmdsToGhs3dIdMapFileName = aGenericName + ".ids"; // ids relation ofstream aIdsFile ( aSmdsToGhs3dIdMapFileName.ToCString() , ios::out); - Ok = - aIdsFile.rdbuf()->is_open(); + Ok = aIdsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aSmdsToGhs3dIdMapFileName); return error(SMESH_Comment("Can't write into ") << aSmdsToGhs3dIdMapFileName); @@ -3382,16 +2925,18 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aIdsFile << myit->first << " " << myit->second << std::endl; } -// aGMFFile.close(); -// aSolFile.close(); + aIdsFile.close(); +#if GHS3D_VERSION < 42 aFacesFile.close(); aPointsFile.close(); - aIdsFile.close(); +#endif if ( ! Ok ) { if ( !_keepFiles ) { +#if GHS3D_VERSION < 42 removeFile( aFacesFileName ); removeFile( aPointsFileName ); +#endif removeFile( aSmdsToGhs3dIdMapFileName ); } return error(COMPERR_BAD_INPUT_MESH); @@ -3403,12 +2948,12 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // ----------------- TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); -#if GHS3D_VERSION >= 42 +#if GHS3D_VERSION < 42 + cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read +#else cmd += TCollection_AsciiString(" --in ") + aGenericName; - cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; +// cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; cmd += TCollection_AsciiString(" --out ") + aGenericName; -#else - cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read #endif cmd += TCollection_AsciiString(" -Om 1>" ) + aLogFileName; // dump into file @@ -3425,6 +2970,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // read a result // -------------- +#if GHS3D_VERSION < 42 // Mapping the result file int fileOpen; @@ -3447,6 +2993,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, nbEnforcedVertices, nbEnforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles ); } +#else + // TODO +// Ok = readGMFFile(aResultFileName.ToCString(), theMesh, enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles); +#endif // --------------------- // remove working files @@ -3472,11 +3022,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } if ( !_keepFiles ) { +#if GHS3D_VERSION < 42 removeFile( aFacesFileName ); removeFile( aPointsFileName ); removeFile( aResultFileName ); removeFile( aBadResFileName ); removeFile( aBbResFileName ); +#endif removeFile( aSmdsToGhs3dIdMapFileName ); } std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file "; @@ -3510,42 +3062,43 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString aGenericName = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); - TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName; - TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName; - TCollection_AsciiString aGMFFileName, aGMFVolFileName, aRequiredVerticesFileName, aSolFileName; -#ifdef _DEBUG_ - aGMFFileName = aGenericName + ".mesh"; // GMF mesh file - aGMFVolFileName = aGenericName + "Vol.mesh"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file - aSolFileName = aGenericName + "_required.sol"; // GMF solution file -#else - aGMFFileName = aGenericName + ".meshb"; // GMF mesh file - aGMFVolFileName = aGenericName + "Vol.meshb"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file - aSolFileName = aGenericName + ".solb"; // GMF solution file -#endif + TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log + TCollection_AsciiString aResultFileName; + bool Ok; +#if GHS3D_VERSION < 42 + TCollection_AsciiString aFacesFileName, aPointsFileName; + TCollection_AsciiString aBadResFileName, aBbResFileName; aFacesFileName = aGenericName + ".faces"; // in faces aPointsFileName = aGenericName + ".points"; // in points aResultFileName = aGenericName + ".noboite";// out points and volumes aBadResFileName = aGenericName + ".boite"; // out bad result aBbResFileName = aGenericName + ".bb"; // out vertex stepsize - aLogFileName = aGenericName + ".log"; // log // ----------------- // make input files // ----------------- -// ofstream aGMFFile ( aGMFFileName.ToCString() , ios::out); -// ofstream aSolFile ( aSolFileName.ToCString() , ios::out); ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); - bool Ok = - aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); - + Ok = aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aFacesFileName); return error( SMESH_Comment("Can't write into ") << aFacesFileName); } +#else + TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; +#ifdef _DEBUG_ + aGMFFileName = aGenericName + ".mesh"; // GMF mesh file + aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file + aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file + aSolFileName = aGenericName + "_required.sol"; // GMF solution file +#else + aGMFFileName = aGenericName + ".meshb"; // GMF mesh file + aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file + aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file + aSolFileName = aGenericName + ".solb"; // GMF solution file +#endif +#endif std::map nodeID2nodeIndexMap; GHS3DPlugin_Hypothesis::TEnforcedVertexValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); @@ -3554,7 +3107,6 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TIDSortedElemSet enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp); TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); - int nbEnforcedVertices = enforcedVertices.size(); vector aNodeByGhs3dId, anEnforcedNodeByGhs3dId; { @@ -3565,38 +3117,27 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aQuad2Trias->Compute( theMesh ); proxyMesh.reset( aQuad2Trias ); } - -// #if GHS3D_VERSION >= 42 +#if GHS3D_VERSION < 42 + Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, + enforcedEdges, enforcedTriangles, enforcedQuadrangles ) && + writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, + nodeIDToSizeMap, enforcedVertices, enforcedNodes)); + int nbEnforcedVertices = enforcedVertices.size(); + int nbEnforcedNodes = enforcedNodes.size(); +#else Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, enforcedVertices); - -// #else - - Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, - enforcedEdges, enforcedTriangles, enforcedQuadrangles ) && - writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, - nodeIDToSizeMap, enforcedVertices, enforcedNodes)); -// #endif - } +#endif + } TIDSortedNodeSet enforcedNodesFromEnforcedElem; - int nbEnforcedNodes = enforcedNodes.size(); - for (int i=0;i= 42 - cmd += TCollection_AsciiString(" --in ") + aGenericName; - cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; - cmd += TCollection_AsciiString(" --out ") + aGenericName; +#if GHS3D_VERSION < 42 + cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read #else - cmd += TCollection_AsciiString(" -Om -f ") + aGenericName; // file to read + cmd += TCollection_AsciiString(" --in ") + aGenericName; +// cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; + cmd += TCollection_AsciiString(" --out ") + aResultFileName; #endif cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file @@ -3635,10 +3177,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // -------------- // read a result // -------------- - Ok = readGMFFile(aGMFFileName.ToCString(), aHelper, enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles); - - int fileOpen; - fileOpen = open( aResultFileName.ToCString(), O_RDONLY); +#if GHS3D_VERSION < 42 + int fileOpen = open( aResultFileName.ToCString(), O_RDONLY); if ( fileOpen < 0 ) { std::cout << std::endl; std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl; @@ -3654,8 +3194,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId, nbEnforcedVertices, nbEnforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles ); -// Ok = readGMFFile(aGMFVolFileName.ToCString(), aHelper, anEnforcedNodeByGhs3dId, enforcedTriangles, enforcedQuadrangles); } +#else + Ok = readGMFFile(aResultFileName.ToCString(), aHelper, enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles); +#endif // --------------------- // remove working files @@ -3678,7 +3220,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" ); error(COMPERR_ALGO_FAILED, "ghs3d: command not found" ); } - +#if GHS3D_VERSION < 42 if ( !_keepFiles ) { removeFile( aFacesFileName ); @@ -3687,7 +3229,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, removeFile( aBadResFileName ); removeFile( aBbResFileName ); } - +#endif return Ok; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 906b6a9..3378ffb 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -32,6 +32,9 @@ #include #include +#define GMFVERSION 2 +#define GMFDIMENSION 3 + class GHS3DPlugin_Hypothesis; class SMDS_MeshNode; class SMESH_Mesh;