#include <Basics_Utils.hxx>
-#include "SMESH_Gen.hxx"
+//#include "SMESH_Gen.hxx"
+#include <SMESH_Client.hxx>
#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"
// }
// 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 <GmfKwdCod,int> 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 <GmfKwdCod,int>::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<const SMDS_MeshNode*>& nodes = *grIt;
+// list<const SMDS_MeshNode*>::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 <const SMDS_MeshNode*> & theNodeByGhs3dId,
GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices)
{
MESSAGE("writeGMFFile");
- int idx;
+ int idx, idxRequired, idxSol;
const int dummyint = 0;
GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt;
std::vector<double> enfVertexSizes;
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();
if ( nbFaces == 0 )
return false;
- idx = GmfOpenMesh(theMeshFileName.ToCString(), GmfWrite, 3, 3);
+ idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3);
if (!idx)
return false;
/* ========================== NODES ========================== */
- vector<const SMDS_MeshNode*> theOrderedNodes;
+ vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
std::set< std::vector<double> > nodesCoords;
vector<const SMDS_MeshNode*>::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin();
vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
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;
nodesCoords.insert(coords);
theOrderedNodes.push_back(node);
+ theRequiredNodes.push_back(node);
}
-
- GmfSetKwd(idx, GmfVertices, theOrderedNodes.size());
-// std::set< std::vector<double> >::const_iterator coordsIt = nodesCoords.begin();
+ int requiredNodes = theRequiredNodes.size();
+ int solSize = 0;
+ std::vector<std::vector<double> > 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<double> 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;i<solSize;i++) {
+ std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
+ GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
+ }
+ std::cout << "End writting required nodes in GmfVertices" << std::endl;
+
+ if (requiredNodes + solSize) {
+ GmfSetKwd(idx, GmfRequiredVertices, requiredNodes+solSize);
+ if (requiredNodes) {
+ std::cout << "Begin writting required nodes in GmfRequiredVertices" << std::endl;
+ int startId = theOrderedNodes.size()-requiredNodes+1;
+ std::cout << "startId: " << startId << std::endl;
+ for (int i=0;i<requiredNodes;i++)
+ GmfSetLin(idx, GmfRequiredVertices, startId+i);
+ std::cout << "End writting required nodes in GmfRequiredVertices" << std::endl;
+ }
+ if (solSize) {
+ std::cout << "Begin writting required vertices in GmfRequiredVertices" << std::endl;
+ int startId = theOrderedNodes.size()+1;
+ std::cout << "startId: " << startId << std::endl;
+ for (int i=0;i<solSize;i++)
+ GmfSetLin(idx, GmfRequiredVertices, startId+i);
+ 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);
+ if (!idxSol) {
+ GmfCloseMesh(idx);
+ if (idxRequired)
+ GmfCloseMesh(idxRequired);
+ return false;
+ }
+ int TypTab[] = {GmfSca};
+ GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
+ for (int i=0;i<solSize;i++) {
+ std::cout << "enfVertexSizes.at(i): " << enfVertexSizes.at(i) << std::endl;
+ double solTab[] = {enfVertexSizes.at(i)};
+ GmfSetLin(idxSol, GmfSolAtVertices, solTab);
+ }
+ std::cout << "End writting in sol file" << std::endl;
+ }
+ }
+
+// // GmfRequiredVertices + GmfSolAtVertices
+//// std::cout << "theRequiredNodes.size() + solSize: " << theRequiredNodes.size()+ solSize << std::endl;
+//// std::cout << "theRequiredNodes.size(): " << theRequiredNodes.size() << std::endl;
+// std::cout << "solSize: " << solSize << std::endl;
+//// if (theRequiredNodes.size()+ solSize) {
+//// GmfSetKwd(idx, GmfRequiredVertices, theRequiredNodes.size()+solSize);
+////
+//// if (theRequiredNodes.size()) {
+//// std::cout << "Begin writting required nodes in GmfRequiredVertices" << std::endl;
+//// int startId = theOrderedNodes.size()-theRequiredNodes.size();
+//// std::cout << "startId: " << startId << std::endl;
+//// for (int i=1;i<=theRequiredNodes.size();i++)
+//// GmfSetLin(idx, GmfRequiredVertices, startId+i);
+//// std::cout << "End writting required nodes in GmfRequiredVertices" << std::endl;
+//// }
+//
+// if (solSize) {
+// std::cout << "Begin writting in sol file" << std::endl;
+// GmfSetKwd(idx, GmfRequiredVertices, solSize);
+// idxSol = GmfOpenMesh(theSolFileName, GmfWrite, 3, 3);
+// if (!idxSol) {
+// GmfCloseMesh(idx);
+// if (idxRequired)
+// GmfCloseMesh(idxRequired);
+// return false;
+// }
+//
+// int TypTab[] = {GmfSca};
+//// GmfSetKwd(idxRequired, GmfVertices, solSize);
+// GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
+//
+// for (int i=0;i<solSize;i++) {
+// double solTab[] = {enfVertexSizes.at(i)};
+// GmfSetLin(idx, GmfRequiredVertices, theOrderedNodes.size()+i+1);
+// GmfSetLin(idxSol, GmfSolAtVertices, solTab);
+//// GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
+// }
+// std::cout << "End writting in sol file" << std::endl;
+// }
+//
+//// }
int nedge[2], ntri[3], nquad[4];
+ int usedEnforcedEdges = 0;
if (anEnforcedEdgeSet.size()) {
+// idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, 3, 3);
+// if (!idxRequired)
+// return false;
GmfSetKwd(idx, GmfEdges, anEnforcedEdgeSet.size());
+// GmfSetKwd(idxRequired, GmfEdges, anEnforcedEdgeSet.size());
for(elemIt = anEnforcedEdgeSet.begin() ; elemIt != anEnforcedEdgeSet.end() ; ++elemIt) {
elem = (*elemIt);
nodeIt = elem->nodesIterator();
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);
}
}
}
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);
index++;
}
GmfSetLin(idx, GmfQuadrilaterals, nquad[0], nquad[1], nquad[2], nquad[3], dummyint);
+ usedEnforcedQuadrilaterals++;
}
- }
-
- GmfCloseMesh(idx);
-
- if (nbEnforcedVertices) {
- std::vector<std::vector<double> > ReqVerTab;
- ReqVerTab.clear();
- std::vector<double> 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<double> 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<solSize;i++) {
- double solTab[] = {enfVertexSizes.at(i)};
- GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
- GmfSetLin(idxSol, GmfSolAtVertices, solTab);
- }
- GmfCloseMesh(idxRequired);
- GmfCloseMesh(idxSol);
+ if (usedEnforcedQuadrilaterals) {
+ GmfSetKwd(idx, GmfRequiredQuadrilaterals, usedEnforcedQuadrilaterals);
+ for (int enfID=1;enfID<=usedEnforcedQuadrilaterals;enfID++)
+ GmfSetLin(idx, GmfRequiredQuadrilaterals, enfID);
}
}
-
+
+ GmfCloseMesh(idx);
+ if (idxRequired)
+ GmfCloseMesh(idxRequired);
+ if (idxSol)
+ GmfCloseMesh(idxSol);
return true;
}
-static bool writeGMFFile(const TCollection_AsciiString& theMeshFileName,
- const TCollection_AsciiString& theRequiredVerticesFileName,
- const TCollection_AsciiString& theSolFileName,
+static bool writeGMFFile(const char* theMeshFileName,
+ const char* theRequiredFileName,
+ const char* theSolFileName,
SMESH_MesherHelper& theHelper,
const SMESH_ProxyMesh& theProxyMesh,
map <int,int> & theSmdsToGhs3dIdMap,
SMDS_NodeIteratorPtr nodeIt;
std::map<int,int> theNodeId2NodeIndexMap;
- idx = GmfOpenMesh(theMeshFileName.ToCString(), GmfWrite, 3, 3);
+ idx = GmfOpenMesh(theMeshFileName, GmfWrite, 3, 3);
if (!idx)
return false;
}
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;
GmfCloseMesh(idxSol);
}
}
-
- /* ========================== EDGES ========================== */
-
-
+
/* ========================== FACES ========================== */
SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
const SMDS_MeshElement* aFace;
map<int,int>::const_iterator itOnMap;
- std::vector<std::vector<int> > tt, qt;
+ std::vector<std::vector<int> > tt, qt,et;
tt.clear();
qt.clear();
- std::vector<int> att, aqt;
+ et.clear();
+ std::vector<int> att, aqt, aet;
TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap );
}
}
}
-
- int nbEnforcedTriangles = theEnforcedTriangles.size();
- if (nbEnforcedTriangles) {
+
+ if (theEnforcedTriangles.size()) {
// Iterate over the enforced triangles
for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
aFace = (*elemIt);
att.push_back((*itOnMap).second);
else {
isOK = false;
+ theEnforcedTriangles.erase(elemIt);
break;
}
}
}
}
}
-
- int nbEnforcedQuadrangles = theEnforcedQuadrangles.size();
- if (nbEnforcedQuadrangles) {
+
+ if (theEnforcedQuadrangles.size()) {
// Iterate over the enforced triangles
for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) {
aFace = (*elemIt);
aqt.push_back((*itOnMap).second);
else {
isOK = false;
+ theEnforcedQuadrangles.erase(elemIt);
break;
}
}
if (isOK)
- qt.push_back(att);
+ qt.push_back(aqt);
}
}
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<et.size();i++)
+ GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
+ }
+
GmfCloseMesh(idx);
return true;
}
// Loop from 1 to NB_ELEMS
// NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
- int nbNodes, nbTriangles = 0;
+ int nbTriangles = 0;
SMDS_ElemIteratorPtr nodeIt;
const char* space = " ";
nodesCoords.insert(coords);
}
- 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)
+ 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<double> coords;
coords.push_back(node->X());
std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->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
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<double> 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()<<", " <<node->Y()<<", " <<node->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);
}
}
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];
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);
}
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;
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
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);
GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
int nbEnforcedVertices = enforcedVertices.size();
-
vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
{
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( 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);
// #endif
}
+ TIDSortedNodeSet enforcedNodesFromEnforcedElem;
int nbEnforcedNodes = enforcedNodes.size();
- int nbEnforcedEdges = enforcedEdges.size();
- int nbEnforcedTriangles = enforcedTriangles.size();
- int nbEnforcedQuadrangles = enforcedQuadrangles.size();
+ for (int i=0;i<anEnforcedNodeByGhs3dId.size();i++) {
+ enforcedNodesFromEnforcedElem.insert(anEnforcedNodeByGhs3dId[i]);
+// if (!enforcedNodesFromEnforcedElem.insert(anEnforcedNodeByGhs3dId[i]).second)
+// std::cout << "Node not inserted in enforcedNodesFromEnforcedElem: " << anEnforcedNodeByGhs3dId[i];
+// else
+// std::cout << "GHS3D ID " << i+1 << " " << anEnforcedNodeByGhs3dId[i];
+ }
+// int nbEnforcedEdges = enforcedEdges.size();
+// int nbEnforcedTriangles = enforcedTriangles.size();
+// int nbEnforcedQuadrangles = enforcedQuadrangles.size();
// aGMFFile.close();
// aSolFile.close();
cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName;
cmd += TCollection_AsciiString(" --out ") + aGenericName;
#else
- cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
+ cmd += TCollection_AsciiString(" -Om -f ") + aGenericName; // file to read
#endif
- cmd += TCollection_AsciiString(" -Om 1>" ) + aLogFileName; // dump into file
+ cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
std::cout << std::endl;
std::cout << "Ghs3d execution..." << std::endl;
// --------------
// read a result
// --------------
+ Ok = readGMFFile(aGMFFileName.ToCString(), aHelper, enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles);
+
int fileOpen;
fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
if ( fileOpen < 0 ) {
theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
nbEnforcedVertices, nbEnforcedNodes,
enforcedEdges, enforcedTriangles, enforcedQuadrangles );
+// Ok = readGMFFile(aGMFVolFileName.ToCString(), aHelper, anEnforcedNodeByGhs3dId, enforcedTriangles, enforcedQuadrangles);
}
// ---------------------
removeFile( aBadResFileName );
removeFile( aBbResFileName );
}
-
+
return Ok;
}
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);
+}