From d586622e4ef8b6e279254fb5b54f2c3ba47457b0 Mon Sep 17 00:00:00 2001 From: gdd Date: Sun, 6 Mar 2011 20:06:03 +0000 Subject: [PATCH] - Fix of bugs - Now .meshb files can be read - New IDL function to test reading of GMF .mesh files: bool importGMFMesh(const char* fileName) - In .smesh file, add entries in keywords "RequiredVertices", "RequiredTriangles" and "RequiredQuadrangulars" --- configure.ac | 2 +- idl/GHS3DPlugin_Algorithm.idl | 1 + src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 670 ++++++++++++++++++------ src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx | 3 + src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx | 37 ++ src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx | 2 + 6 files changed, 566 insertions(+), 149 deletions(-) diff --git a/configure.ac b/configure.ac index ce67fd5..5bf9edf 100644 --- a/configure.ac +++ b/configure.ac @@ -353,7 +353,7 @@ echo CHECK_GHS3D if test "${GHS3D_ok}" = "yes"; then - GHS3D_VERSION=`ghs3d --help |grep "TETMESH-GHS3D SOFTWARE"|awk '{print $3}'|awk -F- '{print $1}'|awk -F. '{print $1$2}'` + GHS3D_VERSION=`ghs3d -u |grep "TETMESH-GHS3D SOFTWARE"|awk '{print $3}'|awk -F- '{print $1}'|awk -F. '{print $1$2}'` AC_DEFINE_UNQUOTED(GHS3D_VERSION,${GHS3D_VERSION}) fi diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 9c22a44..99db25e 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -46,6 +46,7 @@ module GHS3DPlugin */ interface GHS3DPlugin_GHS3D : SMESH::SMESH_3D_Algo { + boolean importGMFMesh(in string aGMFFileName); }; /*! diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 64e1cdd..2941791 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -33,11 +33,13 @@ extern "C" #include -#include "SMESH_Gen.hxx" +//#include "SMESH_Gen.hxx" +#include #include "SMESH_Mesh.hxx" #include "SMESH_Comment.hxx" #include "SMESH_MesherHelper.hxx" #include "SMESH_MeshEditor.hxx" +#include "SMESH_OctreeNode.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -256,14 +258,239 @@ static char* readMapIntLine(char* ptr, int tab[]) { // } // return nbShape; // } -// Ok = writeGMFFile(aGMFFileName, aRequiredVerticesFileName, aSolFileName, &theMesh, *proxyMesh, -// aNodeByGhs3dId, -// enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, -// enforcedVertices); - -static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, - const TCollection_AsciiString& theRequiredVerticesFileName, - const TCollection_AsciiString& theSolFileName, + +//======================================================================= +//function : readGMFFile +//purpose : +//======================================================================= + + +static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, + TIDSortedNodeSet & theEnforcedNodes, + TIDSortedElemSet & theEnforcedTriangles, + TIDSortedElemSet & theEnforcedQuadrangles) +{ + SMESHDS_Mesh* theMesh = theHelper->GetMeshDS(); + + // --------------------------------- + // Read generated elements and nodes + // --------------------------------- + +// std::string token; + int nbElem = 0, nbRef = 0; + int aGMFNodeID = 0, shapeID; + int *nodeAssigne; + std::map tabRef; + SMDS_MeshNode** GMFNode; + +// int nbEnfTri = theEnforcedTriangles.size(); +// int nbEnfQuad = theEnforcedQuadrangles.size(); + + tabRef[GmfVertices] = 3; + tabRef[GmfCorners] = 1; + tabRef[GmfEdges] = 2; + tabRef[GmfRidges] = 1; + tabRef[GmfTriangles] = 3; + tabRef[GmfQuadrilaterals] = 4; + tabRef[GmfTetrahedra] = 4; + tabRef[GmfHexahedra] = 8; + + theHelper->GetMesh()->Clear(); + + int ver, dim; + MESSAGE("Read " << theFile << " file"); + int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim); + if (!InpMsh) + return false; + + int nbVertices = GmfStatKwd(InpMsh, GmfVertices); + GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ]; + nodeAssigne = new int[ nbVertices + 1 ]; + + std::map ::const_iterator it = tabRef.begin(); + for ( ; it != tabRef.end() ; ++it) + { + int dummy; + GmfKwdCod token = it->first; + nbRef = it->second; + + + nbElem = GmfStatKwd(InpMsh, token); + if (nbElem > 0) { + GmfGotoKwd(InpMsh, token); + std::cout << "Read " << nbElem; + } + else + continue; + + int id[nbElem*tabRef[token]]; + + if (token == GmfVertices) { + std::cout << " vertices" << std::endl; + int aGMFID; + + float VerTab_f[nbElem][3]; + double VerTab_d[nbElem][3]; + SMDS_MeshNode * aGMFNode; + + for ( int iElem = 0; iElem < nbElem; iElem++ ) { + aGMFID = iElem + 1; +// TIDSortedNodeSet theEnforcedNodesCopy = theEnforcedNodes; +// SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes; + if (ver == GmfFloat) { + GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &dummy); + aGMFNode = theMesh->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]); +// theEnforcedNodesCopy.insert(aGMFNode); +// if (!theEnforcedNodesCopy.insert(aGMFNode).second) +// std::cout << "No added into theEnforcedNodesCopy: " << aGMFNode; +// SMESH_OctreeNode::FindCoincidentNodes ( theEnforcedNodesCopy, &aGroupsOfNodes, 1e-5); + } + else { + GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &dummy); + aGMFNode = theMesh->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]); +// theEnforcedNodesCopy.insert(aGMFNode); +// if (!theEnforcedNodesCopy.insert(aGMFNode).second) +// std::cout << "No added into theEnforcedNodesCopy: " << aGMFNode; +// SMESH_OctreeNode::FindCoincidentNodes ( theEnforcedNodesCopy, &aGroupsOfNodes, 1e-5); + } + GMFNode[ aGMFID ] = aGMFNode; + nodeAssigne[ aGMFID ] = 0; +// if (aGroupsOfNodes.size()) { +// std::cout << "Coincident node found when adding " << aGMFNode; +// SMESH_MeshEditor::TListOfListOfNodes::iterator grIt = aGroupsOfNodes.begin(); +// for ( ; grIt != aGroupsOfNodes.end(); grIt++) { +// list& nodes = *grIt; +// list::iterator nIt = nodes.begin(); +// for ( ; nIt != nodes.end(); nIt++ ) +// std::cout << *nIt; +// } +//// theMesh->RemoveNode(aGMFNode); +// } + } + } + else if (token == GmfCorners && nbElem > 0) { + std::cout << " corners" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]); + } + else if (token == GmfRidges && nbElem > 0) { + std::cout << " ridges" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]); + } + else if (token == GmfEdges && nbElem > 0) { + std::cout << " edges" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &dummy); + } + else if (token == GmfTriangles && nbElem > 0) { + std::cout << " triangles" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &dummy); + } + else if (token == GmfQuadrilaterals && nbElem > 0) { + std::cout << " Quadrilaterals" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy); + } + else if (token == GmfTetrahedra && nbElem > 0) { + std::cout << " Tetrahedra" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy); + } + else if (token == GmfHexahedra && nbElem > 0) { + std::cout << " Hexahedra" << std::endl; + for ( int iElem = 0; iElem < nbElem; iElem++ ) + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], + &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &dummy); + } + + switch (token) { + case GmfCorners: + case GmfRidges: + case GmfEdges: + case GmfTriangles: + case GmfQuadrilaterals: + case GmfTetrahedra: + case GmfHexahedra: { + std::vector< SMDS_MeshNode* > node( nbRef ); + std::vector< int > nodeID( nbRef ); + std::vector< SMDS_MeshNode* > enfNode( nbRef ); + + for ( int iElem = 0; iElem < nbElem; iElem++ ) + { + for ( int iRef = 0; iRef < nbRef; iRef++ ) + { + aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID + node [ iRef ] = GMFNode[ aGMFNodeID ]; + nodeID[ iRef ] = aGMFNodeID; + } + + switch (token) + { + case GmfEdges: + theHelper->AddEdge( node[0], node[1] ); break; + case GmfTriangles: { + theMesh->AddFace( node[0], node[1], node[2]); + // Enforced triangles +// for ( int iEnfElem = nbElem; iEnfElem < nbElem+nbEnfTri; iEnfElem++ ) +// { +// for ( int iRef = 0; iRef < nbRef; iRef++ ) +// { +// aGMFNodeID = id[iEnfElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID +// enfNode [ iRef ] = GMFNode[ aGMFNodeID ]; +// nodeAssigne[ aGMFNodeID] = 1; +// } +// theMesh->AddFace( enfNode[0], enfNode[1], enfNode[2]); +// } + break; + } + case GmfQuadrilaterals: { + theMesh->AddFace( node[0], node[1], node[2], node[3] ); + // Enforced Quadrilaterals +// for ( int iEnfElem = nbElem+nbEnfTri; iEnfElem < nbElem+nbEnfTri+nbEnfQuad; iEnfElem++ ) +// { +// for ( int iRef = 0; iRef < nbRef; iRef++ ) +// { +// aGMFNodeID = id[iEnfElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID +// enfNode [ iRef ] = GMFNode[ aGMFNodeID ]; +// nodeAssigne[ aGMFNodeID] = 1; +// } +// theMesh->AddFace( enfNode[0], enfNode[1], enfNode[2], enfNode[3]); +// } + break; + } + case GmfTetrahedra: + theHelper->AddVolume( node[0], node[1], node[2], node[3] ); break; + case GmfHexahedra: + theHelper->AddVolume( node[0], node[3], node[2], node[1], + node[4], node[7], node[6], node[5] ); break; + default: continue; + } + if ( token == GmfTriangles || token == GmfQuadrilaterals ) // "Quadrilaterals" and "Triangles" + for ( int iRef = 0; iRef < nbRef; iRef++ ) + nodeAssigne[ nodeID[ iRef ]] = 1; + } + break; + } + } + } + cout << std::endl; + + shapeID = theHelper->GetSubShapeID(); + for ( int i = 0; i < nbVertices; ++i ) + if ( !nodeAssigne[ i+1 ]) + theMesh->SetNodeInVolume( GMFNode[ i+1 ], shapeID ); + + GmfCloseMesh(InpMsh); + delete [] GMFNode; + delete [] nodeAssigne; + return true; +} + +static bool writeGMFFile(const char* theMeshFileName, + const char* theRequiredFileName, + const char* theSolFileName, const SMESH_ProxyMesh& theProxyMesh, SMESH_Mesh * theMesh, vector & theNodeByGhs3dId, @@ -275,7 +502,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices) { MESSAGE("writeGMFFile"); - int idx; + int idx, idxRequired, idxSol; const int dummyint = 0; GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; std::vector enfVertexSizes; @@ -288,10 +515,10 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); int nbEnforcedVertices = theEnforcedVertices.size(); - int nbEnforcedNodes = theEnforcedNodes.size(); - int nbEnforcedEdges = theEnforcedEdges.size(); - int nbEnforcedTriangles = theEnforcedTriangles.size(); - int nbEnforcedQuadrangles = theEnforcedQuadrangles.size(); +// int nbEnforcedNodes = theEnforcedNodes.size(); +// int nbEnforcedEdges = theEnforcedEdges.size(); +// int nbEnforcedTriangles = theEnforcedTriangles.size(); +// int nbEnforcedQuadrangles = theEnforcedQuadrangles.size(); // count faces int nbFaces = theProxyMesh.NbFaces(); @@ -299,7 +526,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, if ( nbFaces == 0 ) return false; - idx = GmfOpenMesh(theMeshFileName.ToCString(), GmfWrite, 3, 3); + idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3); if (!idx) return false; @@ -435,7 +662,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, /* ========================== NODES ========================== */ - vector theOrderedNodes; + vector theOrderedNodes, theRequiredNodes; std::set< std::vector > nodesCoords; vector::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin(); vector::const_iterator after = theNodeByGhs3dId.end(); @@ -479,11 +706,12 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, nodesCoords.insert(coords); theOrderedNodes.push_back(node); + theRequiredNodes.push_back(node); } // Iterate over the enforced nodes given by enforced elements ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin(); after = theEnforcedNodeByGhs3dId.end(); - std::cout << theEnforcedNodes.size() << " nodes from enforced elements ..." << std::endl; + std::cout << theEnforcedNodeByGhs3dId.size() << " nodes from enforced elements ..." << std::endl; for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt ) { const SMDS_MeshNode* node = *ghs3dNodeIt; @@ -502,18 +730,134 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, nodesCoords.insert(coords); theOrderedNodes.push_back(node); + theRequiredNodes.push_back(node); } - - GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()); -// std::set< std::vector >::const_iterator coordsIt = nodesCoords.begin(); + int requiredNodes = theRequiredNodes.size(); + int solSize = 0; + std::vector > ReqVerTab; + if (nbEnforcedVertices) { +// ReqVerTab.clear(); + std::cout << theEnforcedVertices.size() << " nodes from enforced vertices ..." << std::endl; + // Iterate over the enforced vertices + 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); + TopAbs_State result = pntCls->GetPointState( myPoint ); + if ( result != TopAbs_IN ) + continue; + std::vector coords; + coords.push_back(x); + coords.push_back(y); + coords.push_back(z); + ReqVerTab.push_back(coords); + enfVertexSizes.push_back(vertexIt->second); + solSize++; + } + } + + // GmfVertices + std::cout << "Begin writting required nodes in GmfVertices" << std::endl; + GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()+solSize); for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint); + for (int i=0;inodesIterator(); @@ -528,6 +872,16 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, index++; } GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint); +// GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint); + usedEnforcedEdges++; + } +// GmfCloseMesh(idxRequired); + } + + if (usedEnforcedEdges) { + GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges); + for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) { + GmfSetLin(idx, GmfRequiredEdges, enfID); } } @@ -548,24 +902,34 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, } GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint); } - for(elemIt = anEnforcedTriangleSet.begin() ; elemIt != anEnforcedTriangleSet.end() ; ++elemIt) { - elem = (*elemIt); - nodeIt = elem->nodesIterator(); - int index=0; - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); - if (it == anEnforcedNodeToGhs3dIdMap.end()) - throw "Node not found"; - ntri[index] = it->second; - index++; + if (anEnforcedTriangleSet.size()) { + int usedEnforcedTriangles = 0; + for(elemIt = anEnforcedTriangleSet.begin() ; elemIt != anEnforcedTriangleSet.end() ; ++elemIt) { + elem = (*elemIt); + nodeIt = elem->nodesIterator(); + int index=0; + while ( nodeIt->more() ) { + // find GHS3D ID + const SMDS_MeshNode* node = castToNode( nodeIt->next() ); + map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); + if (it == anEnforcedNodeToGhs3dIdMap.end()) + throw "Node not found"; + ntri[index] = it->second; + index++; + } + GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint); + usedEnforcedTriangles++; + } + if (usedEnforcedTriangles) { + GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles); + for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++) + GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID); } - GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint); } } if (anEnforcedQuadrangleSet.size()) { + int usedEnforcedQuadrilaterals = 0; GmfSetKwd(idx, GmfQuadrilaterals, anEnforcedQuadrangleSet.size()); for(elemIt = anEnforcedQuadrangleSet.begin() ; elemIt != anEnforcedQuadrangleSet.end() ; ++elemIt) { elem = (*elemIt); @@ -581,66 +945,28 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, index++; } GmfSetLin(idx, GmfQuadrilaterals, nquad[0], nquad[1], nquad[2], nquad[3], dummyint); + usedEnforcedQuadrilaterals++; } - } - - GmfCloseMesh(idx); - - if (nbEnforcedVertices) { - std::vector > ReqVerTab; - ReqVerTab.clear(); - std::vector enfVertexSizes; - int solSize = 0; - std::cout << theEnforcedVertices.size() << " nodes from enforced vertices ..." << std::endl; - // Iterate over the enforced vertices - 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); - TopAbs_State result = pntCls->GetPointState( myPoint ); - if ( result != TopAbs_IN ) - continue; - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - ReqVerTab.push_back(coords); - enfVertexSizes.push_back(vertexIt->second); - solSize++; - } - - if (solSize) { - int idxRequired = GmfOpenMesh(theRequiredVerticesFileName.ToCString(), GmfWrite, 3, 3); - if (!idxRequired) - return false; - int idxSol = GmfOpenMesh(theSolFileName.ToCString(), GmfWrite, 3, 3); - if (!idxSol) - return false; - - int TypTab[] = {GmfSca}; - GmfSetKwd(idxRequired, GmfVertices, solSize); - GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab); - - for (int i=0;i & theSmdsToGhs3dIdMap, @@ -660,7 +986,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, SMDS_NodeIteratorPtr nodeIt; std::map theNodeId2NodeIndexMap; - idx = GmfOpenMesh(theMeshFileName.ToCString(), GmfWrite, 3, 3); + idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3); if (!idx) return false; @@ -777,10 +1103,10 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, } if (solSize) { - int idxRequired = GmfOpenMesh(theRequiredVerticesFileName.ToCString(), GmfWrite, 3, 3); + int idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, 3, 3); if (!idxRequired) return false; - int idxSol = GmfOpenMesh(theSolFileName.ToCString(), GmfWrite, 3, 3); + int idxSol = GmfOpenMesh(theSolFileName, GmfWrite, 3, 3); if (!idxSol) return false; @@ -797,10 +1123,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, GmfCloseMesh(idxSol); } } - - /* ========================== EDGES ========================== */ - - + /* ========================== FACES ========================== */ @@ -812,10 +1135,11 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; const SMDS_MeshElement* aFace; map::const_iterator itOnMap; - std::vector > tt, qt; + std::vector > tt, qt,et; tt.clear(); qt.clear(); - std::vector att, aqt; + et.clear(); + std::vector att, aqt, aet; TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap ); @@ -863,9 +1187,8 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, } } } - - int nbEnforcedTriangles = theEnforcedTriangles.size(); - if (nbEnforcedTriangles) { + + if (theEnforcedTriangles.size()) { // Iterate over the enforced triangles for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { aFace = (*elemIt); @@ -879,6 +1202,7 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, att.push_back((*itOnMap).second); else { isOK = false; + theEnforcedTriangles.erase(elemIt); break; } } @@ -917,9 +1241,8 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, } } } - - int nbEnforcedQuadrangles = theEnforcedQuadrangles.size(); - if (nbEnforcedQuadrangles) { + + if (theEnforcedQuadrangles.size()) { // Iterate over the enforced triangles for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { aFace = (*elemIt); @@ -933,11 +1256,12 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, aqt.push_back((*itOnMap).second); else { isOK = false; + theEnforcedQuadrangles.erase(elemIt); break; } } if (isOK) - qt.push_back(att); + qt.push_back(aqt); } } @@ -947,7 +1271,38 @@ static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName, GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint); } - + + /* ========================== EDGES ========================== */ + + if (theEnforcedEdges.size()) { + // Iterate over the enforced edges + for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { + aFace = (*elemIt); + bool isOK = true; + itOnSubFace = aFace->nodesIterator(); + aet.clear(); + while ( itOnSubFace->more() ) { + int aNodeID = itOnSubFace->next()->GetID(); + itOnMap = theNodeId2NodeIndexMap.find(aNodeID); + if (itOnMap != theNodeId2NodeIndexMap.end()) + aet.push_back((*itOnMap).second); + else { + isOK = false; + theEnforcedEdges.erase(elemIt); + break; + } + } + if (isOK) + et.push_back(aet); + } + } + + if (et.size()) { + GmfSetKwd(idx, GmfEdges, et.size()); + for (int i=0;i pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); - for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) + if (theEnforcedNodeByGhs3dId.size()) { + std::cout << theEnforcedNodeByGhs3dId.size() << " nodes from enforced elements ..." << std::endl; + // Iterate over the enforced nodes given by enforced elements + nodeIt = theEnforcedNodeByGhs3dId.begin(); + after = theEnforcedNodeByGhs3dId.end(); + for ( ; nodeIt != after; ++nodeIt ) { - node = *enfNodeIt; + node = *nodeIt; std::vector coords; coords.push_back(node->X()); @@ -2148,14 +2503,9 @@ static bool writePoints (ofstream & theFile, std::cout << "Node at " << node->X()<<", " <Y()<<", " <Z() << " found" << std::endl; continue; } - + if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; - // Test if point is inside shape to mesh - gp_Pnt myPoint(node->X(),node->Y(),node->Z()); - TopAbs_State result = pntCls->GetPointState( myPoint ); - if ( result != TopAbs_IN ) - continue; // X Y Z DUMMY_INT theFile @@ -2168,37 +2518,43 @@ static bool writePoints (ofstream & theFile, nodesCoords.insert(coords); } } - - if (theEnforcedNodeByGhs3dId.size()) { - std::cout << theEnforcedNodeByGhs3dId.size() << " nodes from enforced elements ..." << std::endl; - // Iterate over the enforced nodes given by enforced elements - nodeIt = theEnforcedNodeByGhs3dId.begin(); - after = theEnforcedNodeByGhs3dId.end(); - for ( ; nodeIt != after; ++nodeIt ) + + auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); + if (nbEnforcedNodes) { + std::cout << theEnforcedNodes.size() << " nodes from enforced nodes ..." << std::endl; + // Iterate over the enforced nodes + TIDSortedNodeSet::const_iterator enfNodeIt; +// auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); + for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) { - node = *nodeIt; - + node = *enfNodeIt; + std::vector coords; coords.push_back(node->X()); coords.push_back(node->Y()); coords.push_back(node->Z()); - + if (nodesCoords.find(coords) != nodesCoords.end()) { std::cout << "Node at " << node->X()<<", " <Y()<<", " <Z() << " found" << std::endl; continue; } - + if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; + // Test if point is inside shape to mesh + gp_Pnt myPoint(node->X(),node->Y(),node->Z()); + TopAbs_State result = pntCls->GetPointState( myPoint ); + if ( result != TopAbs_IN ) + continue; // X Y Z DUMMY_INT theFile - << node->X() << space - << node->Y() << space - << node->Z() << space + << node->X() << space + << node->Y() << space + << node->Z() << space << theNodeIDToSizeMap.find(node->GetID())->second << space << dummyint << std::endl; - + nodesCoords.insert(coords); } } @@ -2207,7 +2563,6 @@ static bool writePoints (ofstream & theFile, std::cout << theEnforcedVertices.size() << " nodes from enforced vertices ..." << std::endl; // Iterate over the enforced vertices GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; - auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { double x = vertexIt->first[0]; double y = vertexIt->first[1]; @@ -2978,7 +3333,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return false; } // #if GHS3D_VERSION >= 42 - Ok = writeGMFFile(aGMFFileName, aRequiredVerticesFileName, aSolFileName, helper, *proxyMesh, + Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), + helper, *proxyMesh, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, enforcedVertices); @@ -3006,9 +3362,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } int nbEnforcedNodes = enforcedNodes.size(); - int nbEnforcedEdges = enforcedEdges.size(); - int nbEnforcedTriangles = enforcedTriangles.size(); - int nbEnforcedQuadrangles = enforcedQuadrangles.size(); +// int nbEnforcedEdges = enforcedEdges.size(); +// int nbEnforcedTriangles = enforcedTriangles.size(); +// int nbEnforcedQuadrangles = enforcedQuadrangles.size(); // Write aSmdsToGhs3dIdMap to temp file TCollection_AsciiString aSmdsToGhs3dIdMapFileName; @@ -3156,13 +3512,15 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName; TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName; - TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; + 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 @@ -3182,9 +3540,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); bool 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); @@ -3200,7 +3556,6 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); int nbEnforcedVertices = enforcedVertices.size(); - vector aNodeByGhs3dId, anEnforcedNodeByGhs3dId; { SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh )); @@ -3212,7 +3567,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } // #if GHS3D_VERSION >= 42 - Ok = writeGMFFile(aGMFFileName, aRequiredVerticesFileName, aSolFileName, *proxyMesh, &theMesh, + Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), + *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, enforcedVertices); @@ -3226,10 +3582,18 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // #endif } + TIDSortedNodeSet enforcedNodesFromEnforcedElem; int nbEnforcedNodes = enforcedNodes.size(); - int nbEnforcedEdges = enforcedEdges.size(); - int nbEnforcedTriangles = enforcedTriangles.size(); - int nbEnforcedQuadrangles = enforcedQuadrangles.size(); + for (int i=0;i" ) + aLogFileName; // dump into file + cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file std::cout << std::endl; std::cout << "Ghs3d execution..." << std::endl; @@ -3271,6 +3635,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 ( fileOpen < 0 ) { @@ -3288,6 +3654,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId, nbEnforcedVertices, nbEnforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles ); +// Ok = readGMFFile(aGMFVolFileName.ToCString(), aHelper, anEnforcedNodeByGhs3dId, enforcedTriangles, enforcedQuadrangles); } // --------------------- @@ -3320,7 +3687,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, removeFile( aBadResFileName ); removeFile( aBbResFileName ); } - + return Ok; } @@ -3900,3 +4267,10 @@ bool GHS3DPlugin_GHS3D::Evaluate(SMESH_Mesh& aMesh, return true; } +bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh) +{ + SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh ); + TIDSortedElemSet dummyElemSet; + TIDSortedNodeSet dummyNodeSet; + return readGMFFile(theGMFFileName, helper, dummyNodeSet , dummyElemSet, dummyElemSet); +} diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 2054a79..906b6a9 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -27,6 +27,7 @@ #define _GHS3DPlugin_GHS3D_HXX_ #include "SMESH_3D_Algo.hxx" +#include "SMESH_Gen.hxx" #include #include @@ -57,6 +58,8 @@ public: virtual bool Compute(SMESH_Mesh& theMesh, SMESH_MesherHelper* aHelper); + bool importGMFMesh(const char* aGMFFileName, SMESH_Mesh& aMesh); + private: bool storeErrorDescription(const TCollection_AsciiString& logFile, diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx index c63525a..cee9677 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx @@ -25,9 +25,13 @@ // #include "GHS3DPlugin_GHS3D_i.hxx" #include "SMESH_Gen.hxx" +#include "SMESH_Mesh_i.hxx" +#include "SMESH_Gen_i.hxx" #include "GHS3DPlugin_GHS3D.hxx" +#include "SMESH_PythonDump.hxx" #include "utilities.h" +#include using namespace std; @@ -80,3 +84,36 @@ GHS3DPlugin_GHS3D_i::~GHS3DPlugin_GHS3D_i() return ( ::GHS3DPlugin_GHS3D* )myBaseImpl; } +//============================================================================= +/*! + * GHS3DPlugin_GHS3D_i::~GHS3DPlugin_GHS3D_i + * + * Destructor + */ +//============================================================================= + +bool GHS3DPlugin_GHS3D_i::importGMFMesh(const char* theGMFFileName) +{ + MESSAGE( "GHS3DPlugin_GHS3D_i::importGMFMesh" ); + + SMESH::SMESH_Mesh_ptr theMesh = SMESH_Gen_i::GetSMESHGen()->CreateEmptyMesh(); + SMESH_Gen_i::GetSMESHGen()->RemoveLastFromPythonScript(SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy()->StudyId()); + SALOMEDS::SObject_ptr theSMesh = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy(), theMesh); +#ifdef WINNT +#define SEP '\\' +#else +#define SEP '/' +#endif + string strFileName (theGMFFileName); + strFileName = strFileName.substr(strFileName.rfind(SEP)+1); + strFileName.erase(strFileName.rfind('.')); + SMESH_Gen_i::GetSMESHGen()->SetName(theSMesh, strFileName.c_str()); + SMESH_Mesh_i* meshServant = dynamic_cast( SMESH_Gen_i::GetSMESHGen()->GetServant( theMesh ).in() ); + ASSERT( meshServant ); + if ( meshServant ) { + bool res = GetImpl()->importGMFMesh(theGMFFileName, meshServant->GetImpl()); + SMESH::TPythonDump() << "isDone = " << _this() << ".importGMFMesh( \"" << theGMFFileName << "\")"; + return res; + } + return false; +} diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx index e61fb45..9de897f 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx @@ -49,6 +49,8 @@ public: // Get implementation ::GHS3DPlugin_GHS3D* GetImpl(); + + virtual bool importGMFMesh(const char* theGMFFileName); }; #endif -- 2.39.2