From: gdd Date: Mon, 2 May 2011 15:03:05 +0000 (+0000) Subject: Add enforced meshes only available on mesh w/o geometry for now. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=68c783fe23f5a01d375f7a76370936caf82d9f0e;p=plugins%2Fghs3dplugin.git Add enforced meshes only available on mesh w/o geometry for now. --- diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 5e5cf53..75c9984 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -184,13 +184,13 @@ bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh, return true; } -#if GHS3D_VERSION < 42 || !defined GMF_HAS_SUBDOMAIN_INFO + //======================================================================= //function : findShape //purpose : //======================================================================= -static TopoDS_Shape findShape(SMDS_MeshNode *aNode[], +static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[], TopoDS_Shape aShape, const TopoDS_Shape shape[], double** box, @@ -434,7 +434,7 @@ static int findShapeID(SMESH_Mesh& mesh, else return meshDS->ShapeToIndex( solids(2) ); } -#endif +// #endif //======================================================================= //function : countShape @@ -472,234 +472,538 @@ void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) { return; } +// //======================================================================= +// //function : findEdgeID +// //purpose : +// //======================================================================= +// +// static int findEdgeID(const SMDS_MeshNode* aNode, +// const SMESHDS_Mesh* theMesh, +// const int nEdge, +// const TopoDS_Shape* t_Edge) { +// +// TopoDS_Shape aPntShape, foundEdge; +// TopoDS_Vertex aVertex; +// gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() ); +// +// int foundInd, ind; +// double nearest = RealLast(), *t_Dist; +// double epsilon = Precision::Confusion(); +// +// t_Dist = new double[ nEdge ]; +// aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape(); +// aVertex = TopoDS::Vertex( aPntShape ); +// +// for ( ind=0; ind < nEdge; ind++ ) { +// BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] ); +// t_Dist[ind] = aDistance.Value(); +// if ( t_Dist[ind] < nearest ) { +// nearest = t_Dist[ind]; +// foundEdge = t_Edge[ind]; +// foundInd = ind; +// if ( nearest < epsilon ) +// ind = nEdge; +// } +// } +// +// delete [] t_Dist; +// return theMesh->ShapeToIndex( foundEdge ); +// } + + //======================================================================= -//function : findEdgeID -//purpose : +//function : readGMFFile +//purpose : read GMF file with geometry associated to mesh +// TODO //======================================================================= -static int findEdgeID(const SMDS_MeshNode* aNode, - const SMESHDS_Mesh* theMesh, - const int nEdge, - const TopoDS_Shape* t_Edge) { - - TopoDS_Shape aPntShape, foundEdge; - TopoDS_Vertex aVertex; - gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() ); - - int foundInd, ind; - double nearest = RealLast(), *t_Dist; - double epsilon = Precision::Confusion(); - - t_Dist = new double[ nEdge ]; - aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape(); - aVertex = TopoDS::Vertex( aPntShape ); - - for ( ind=0; ind < nEdge; ind++ ) { - BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] ); - t_Dist[ind] = aDistance.Value(); - if ( t_Dist[ind] < nearest ) { - nearest = t_Dist[ind]; - foundEdge = t_Edge[ind]; - foundInd = ind; - if ( nearest < epsilon ) - ind = nEdge; - } - } +// static bool readGMFFile( +// const int fileOpen, +// const char* theFileName, +// SMESH_Mesh& theMesh, +// const int nbShape, +// const TopoDS_Shape* tabShape, +// double** tabBox, +// map & theGhs3dIdToNodeMap, +// bool toMeshHoles, +// int nbEnforcedVertices, +// int nbEnforcedNodes, +// TIDSortedNodeSet & theEnforcedNodes, +// TIDSortedElemSet & theEnforcedTriangles, +// TIDSortedElemSet & theEnforcedQuadrangles) +// { +// TopoDS_Shape aShape; +// TopoDS_Vertex aVertex; +// SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS(); +// int nbElem = 0, nbRef = 0, IdShapeRef = 1; +// int *tabID; +// int aGMFNodeID = 0; +// int compoundID = +// nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() ); +// int tetraShapeID = compoundID; +// double epsilon = Precision::Confusion(); +// int *nodeAssigne, *GMFNodeAssigne; +// SMDS_MeshNode** GMFNode; +// TopoDS_Shape *tabCorner, *tabEdge; +// std::map tabRef; +// +// +// int ver, dim; +// MESSAGE("Read " << theFileName << " file"); +// int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim); +// if (!InpMsh) +// return false; +// +// // =========================== +// // Fill the tabID array: BEGIN +// // =========================== +// +// /* +// The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) +// */ +// Kernel_Utils::Localizer loc; +// struct stat status; +// size_t length; +// +// char *ptr, *mapPtr; +// char *tetraPtr; +// int *tab = new int[3]; +// +// // Read the file state +// fstat(fileOpen, &status); +// length = status.st_size; +// +// // Mapping the result file into memory +// #ifdef WNT +// HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ, +// NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +// HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY, +// 0, (DWORD)length, NULL); +// ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 ); +// #else +// ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0); +// #endif +// mapPtr = ptr; +// +// ptr = readMapIntLine(ptr, tab); +// tetraPtr = ptr; +// +// nbElem = tab[0]; +// int nbNodes = tab[1]; +// +// for (int i=0; i < 4*nbElem; i++) +// strtol(ptr, &ptr, 10); +// +// for (int iNode=1; iNode <= nbNodes; iNode++) +// for (int iCoor=0; iCoor < 3; iCoor++) +// strtod(ptr, &ptr); +// +// +// // Reading the number of triangles which corresponds to the number of sub-domains +// int nbTriangle = strtol(ptr, &ptr, 10); +// +// +// // The keyword does not exist yet => to update when it is created +// // int nbTriangle = GmfStatKwd(InpMsh, GmfSubdomain); +// // int id_tri[3]; +// +// +// tabID = new int[nbTriangle]; +// for (int i=0; i < nbTriangle; i++) { +// tabID[i] = 0; +// int nodeId1, nodeId2, nodeId3; +// // find the solid corresponding to GHS3D sub-domain following +// // the technique proposed in GHS3D manual in chapter +// // "B.4 Subdomain (sub-region) assignment" +// +// nodeId1 = strtol(ptr, &ptr, 10); +// nodeId2 = strtol(ptr, &ptr, 10); +// nodeId3 = strtol(ptr, &ptr, 10); +// +// // // The keyword does not exist yet => to update when it is created +// // GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]); +// // nodeId1 = id_tri[0]; +// // nodeId2 = id_tri[1]; +// // nodeId3 = id_tri[2]; +// +// if ( nbTriangle > 1 ) { +// // get the nodes indices +// const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ]; +// const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ]; +// const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ]; +// try { +// OCC_CATCH_SIGNALS; +// tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles ); +// // -- 0020330: Pb with ghs3d as a submesh +// // check that found shape is to be meshed +// if ( tabID[i] > 0 ) { +// const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] ); +// bool isToBeMeshed = false; +// for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS ) +// isToBeMeshed = foundShape.IsSame( tabShape[ iS ]); +// if ( !isToBeMeshed ) +// tabID[i] = HOLE_ID; +// } +// // END -- 0020330: Pb with ghs3d as a submesh +// #ifdef _DEBUG_ +// std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl; +// #endif +// } +// catch ( Standard_Failure & ex) +// { +// #ifdef _DEBUG_ +// std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl; +// #endif +// } +// catch (...) { +// #ifdef _DEBUG_ +// std::cout << i+1 << " subdomain: unknown exception caught " << std::endl; +// #endif +// } +// } +// } +// +// // =========================== +// // Fill the tabID array: END +// // =========================== +// +// +// tabRef[GmfVertices] = 3; +// tabRef[GmfCorners] = 1; +// tabRef[GmfEdges] = 2; +// tabRef[GmfRidges] = 1; +// tabRef[GmfTriangles] = 3; +// // tabRef[GmfQuadrilaterals] = 4; +// tabRef[GmfTetrahedra] = 4; +// // tabRef[GmfHexahedra] = 8; +// +// SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator(); +// while ( itOnGMFInputNode->more() ) +// theMeshDS->RemoveNode( itOnGMFInputNode->next() ); +// +// +// int nbVertices = GmfStatKwd(InpMsh, GmfVertices); +// int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners)); +// int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE ); +// +// tabCorner = new TopoDS_Shape[ nbCorners ]; +// tabEdge = new TopoDS_Shape[ nbShapeEdge ]; +// nodeAssigne = new int[ nbVertices + 1 ]; +// GMFNodeAssigne = new int[ nbVertices + 1 ]; +// GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ]; +// +// getShape(theMeshDS, TopAbs_VERTEX, tabCorner); +// getShape(theMeshDS, TopAbs_EDGE, tabEdge); +// +// 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]]; +// int ghs3dShapeID[nbElem]; +// +// 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; +// if (ver == GmfFloat) { +// GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]); +// aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]); +// } +// else { +// GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]); +// aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]); +// } +// GMFNode[ aGMFID ] = aGMFNode; +// nodeAssigne[ aGMFID ] = 0; +// GMFNodeAssigne[ aGMFID ] = 0; +// } +// } +// 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], &ghs3dShapeID[iElem]); +// } +// 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], &ghs3dShapeID[iElem]); +// } +// // 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], &ghs3dShapeID[iElem]); +// // } +// 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], +// &ghs3dShapeID[iElem]); +// } +// // 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], &ghs3dShapeID[iElem]); +// // } +// +// switch (token) { +// case GmfCorners: +// case GmfRidges: +// case GmfEdges: +// case GmfTriangles: +// // case GmfQuadrilaterals: +// case GmfTetrahedra: +// // case GmfHexahedra: +// { +// int nodeDim, shapeID, *nodeID; +// SMDS_MeshNode** node; +// // std::vector< SMDS_MeshNode* > enfNode( nbRef ); +// SMDS_MeshElement * aGMFElement; +// +// node = new SMDS_MeshNode*[nbRef]; +// nodeID = new int[ 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 GmfCorners: { +// nodeDim = 1; +// gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() ); +// for ( int i=0; iAddEdge( node[0], node[1] ); +// int iNode = 1; +// if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 ) +// iNode = 0; +// shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge ); +// break; +// } +// case GmfRidges: +// break; +// case GmfTriangles: { +// nodeDim = 3; +// aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]); +// shapeID = -1; +// break; +// } +// // case GmfQuadrilaterals: { +// // nodeDim = 4; +// // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] ); +// // shapeID = -1; +// // break; +// // } +// case GmfTetrahedra: { +// +// // IN WORK +// TopoDS_Shape aSolid; +// // We always run GHS3D with "to mesh holes"==TRUE but we must not create +// // tetras within holes depending on hypo option, +// // so we first check if aTet is inside a hole and then create it +// if ( nbTriangle > 1 ) { +// tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles +// int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef; +// if ( tabID[ aGhs3dShapeID ] == 0 ) { +// TopAbs_State state; +// aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state); +// if ( toMeshHoles || state == TopAbs_IN ) +// tetraShapeID = theMeshDS->ShapeToIndex( aSolid ); +// tabID[ aGhs3dShapeID ] = tetraShapeID; +// } +// else +// tetraShapeID = tabID[ aGhs3dShapeID ]; +// } +// else if ( nbShape > 1 ) { +// // Case where nbTriangle == 1 while nbShape == 2 encountered +// // with compound of 2 boxes and "To mesh holes"==False, +// // so there are no subdomains specified for each tetrahedron. +// // Try to guess a solid by a node already bound to shape +// tetraShapeID = 0; +// for ( int i=0; i<4 && tetraShapeID==0; i++ ) { +// if ( nodeAssigne[ nodeID[i] ] == 1 && +// node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE && +// node[i]->getshapeId() > 1 ) +// { +// tetraShapeID = node[i]->getshapeId(); +// } +// } +// if ( tetraShapeID==0 ) { +// aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape); +// tetraShapeID = theMeshDS->ShapeToIndex( aSolid ); +// } +// } +// // set new nodes and tetrahedron onto the shape +// for ( int i=0; i<4; i++ ) { +// if ( nodeAssigne[ nodeID[i] ] == 0 ) { +// if ( tetraShapeID != HOLE_ID ) +// theMeshDS->SetNodeInVolume( node[i], tetraShapeID ); +// nodeAssigne[ nodeID[i] ] = tetraShapeID; +// } +// } +// if ( toMeshHoles || tetraShapeID != HOLE_ID ) { +// aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); +// theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID ); +// } +// +// // IN WORK +// +// nodeDim = 5; +// break; +// } +// // case GmfHexahedra: { +// // nodeDim = 6; +// // aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1], +// // node[4], node[7], node[6], node[5] ); +// // break; +// // } +// default: continue; +// } +// if (token != GmfRidges) +// { +// for ( int i=0; iSetNodeOnVertex( node[0], aVertex ); +// else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID ); +// else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID ); +// GMFNodeAssigne[ nodeID[i] ] = nodeDim; +// } +// } +// if ( token != "Corners" ) +// theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID ); +// } +// } // for +// +// if ( !toMeshHoles ) { +// map ::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) ); +// for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) { +// if ( nodeAssigne[ itOnNode->first ] == HOLE_ID ) +// theMeshDS->RemoveFreeNode( itOnNode->second, 0 ); +// } +// } +// +// delete [] node; +// delete [] nodeID; +// break; +// } // case GmfTetrahedra +// } // switch(token) +// } // for +// cout << std::endl; +// +// #ifdef WNT +// UnmapViewOfFile(mapPtr); +// CloseHandle(hMapObject); +// CloseHandle(fd); +// #else +// munmap(mapPtr, length); +// #endif +// close(fileOpen); +// +// delete [] tabID; +// delete [] tabCorner; +// delete [] tabEdge; +// delete [] nodeAssigne; +// delete [] GMFNodeAssigne; +// delete [] GMFNode; +// +// return true; +// } - delete [] t_Dist; - return theMesh->ShapeToIndex( foundEdge ); -} -#if GHS3D_VERSION >= 42 //======================================================================= //function : readGMFFile -//purpose : +//purpose : read GMF file w/o geometry associated to mesh //======================================================================= -static bool readGMFFile( -#ifndef GMF_HAS_SUBDOMAIN_INFO - const int fileOpen, -#endif - const char* theFileName, - SMESH_Mesh& theMesh, - const int nbShape, - const TopoDS_Shape* tabShape, - double** tabBox, - map & theGhs3dIdToNodeMap, - bool toMeshHoles, - int nbEnforcedVertices, - int nbEnforcedNodes, - TIDSortedNodeSet & theEnforcedNodes, + +static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, + TIDSortedNodeSet & theEnforcedNodes, TIDSortedElemSet & theEnforcedTriangles, - TIDSortedElemSet & theEnforcedQuadrangles) + TIDSortedElemSet & theEnforcedQuadrangles) { - TopoDS_Shape aShape; - TopoDS_Vertex aVertex; - SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS(); - int nbElem = 0, nbRef = 0, IdShapeRef = 1; - int *tabID; - int aGMFNodeID = 0; - int compoundID = - nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() ); - int tetraShapeID = compoundID; - double epsilon = Precision::Confusion(); - int *nodeAssigne, *GMFNodeAssigne; - SMDS_MeshNode** GMFNode; - TopoDS_Shape *tabCorner, *tabEdge; - std::map tabRef; - - - int ver, dim; - MESSAGE("Read " << theFileName << " file"); - int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim); - if (!InpMsh) - return false; - - // =========================== - // Fill the tabID array: BEGIN - // =========================== - -#ifndef GMF_HAS_SUBDOMAIN_INFO - /* - The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) - */ - Kernel_Utils::Localizer loc; - struct stat status; - size_t length; - - char *ptr, *mapPtr; - char *tetraPtr; - int *tab = new int[3]; - - // Read the file state - fstat(fileOpen, &status); - length = status.st_size; - - // Mapping the result file into memory -#ifdef WNT - HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY, - 0, (DWORD)length, NULL); - ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 ); -#else - ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0); -#endif - mapPtr = ptr; - - ptr = readMapIntLine(ptr, tab); - tetraPtr = ptr; - - nbElem = tab[0]; - int nbNodes = tab[1]; - - for (int i=0; i < 4*nbElem; i++) - strtol(ptr, &ptr, 10); - - for (int iNode=1; iNode <= nbNodes; iNode++) - for (int iCoor=0; iCoor < 3; iCoor++) - strtod(ptr, &ptr); + SMESHDS_Mesh* theMesh = theHelper->GetMeshDS(); - - // Reading the number of triangles which corresponds to the number of sub-domains - int nbTriangle = strtol(ptr, &ptr, 10); -#else - // The keyword does not exist yet => to update when it is created - int nbTriangle = GmfStatKwd(InpMsh, GmfSubdomain); - int id_tri[3]; -#endif + // --------------------------------- + // Read generated elements and nodes + // --------------------------------- - tabID = new int[nbTriangle]; - for (int i=0; i < nbTriangle; i++) { - tabID[i] = 0; - int nodeId1, nodeId2, nodeId3; - // find the solid corresponding to GHS3D sub-domain following - // the technique proposed in GHS3D manual in chapter - // "B.4 Subdomain (sub-region) assignment" -#ifndef GMF_HAS_SUBDOMAIN_INFO - nodeId1 = strtol(ptr, &ptr, 10); - nodeId2 = strtol(ptr, &ptr, 10); - nodeId3 = strtol(ptr, &ptr, 10); -#else - // The keyword does not exist yet => to update when it is created - GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]); - nodeId1 = id_tri[0]; - nodeId2 = id_tri[1]; - nodeId3 = id_tri[2]; -#endif - if ( nbTriangle > 1 ) { - // get the nodes indices - const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ]; - const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ]; - const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ]; - try { - OCC_CATCH_SIGNALS; - tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles ); - // -- 0020330: Pb with ghs3d as a submesh - // check that found shape is to be meshed - if ( tabID[i] > 0 ) { - const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] ); - bool isToBeMeshed = false; - for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS ) - isToBeMeshed = foundShape.IsSame( tabShape[ iS ]); - if ( !isToBeMeshed ) - tabID[i] = HOLE_ID; - } - // END -- 0020330: Pb with ghs3d as a submesh -#ifdef _DEBUG_ - std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl; -#endif - } - catch ( Standard_Failure & ex) - { -#ifdef _DEBUG_ - std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl; -#endif - } - catch (...) { -#ifdef _DEBUG_ - std::cout << i+1 << " subdomain: unknown exception caught " << std::endl; -#endif - } - } - } - - // =========================== - // Fill the tabID array: END - // =========================== - + int nbElem = 0, nbRef = 0; + int aGMFNodeID = 0, shapeID; + int *nodeAssigne; + SMDS_MeshNode** GMFNode; + std::map tabRef; tabRef[GmfVertices] = 3; tabRef[GmfCorners] = 1; tabRef[GmfEdges] = 2; tabRef[GmfRidges] = 1; tabRef[GmfTriangles] = 3; -// tabRef[GmfQuadrilaterals] = 4; + tabRef[GmfQuadrilaterals] = 4; tabRef[GmfTetrahedra] = 4; -// tabRef[GmfHexahedra] = 8; - - SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator(); - while ( itOnGMFInputNode->more() ) - theMeshDS->RemoveNode( itOnGMFInputNode->next() ); + tabRef[GmfHexahedra] = 8; - - int nbVertices = GmfStatKwd(InpMsh, GmfVertices); - int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners)); - int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE ); + theHelper->GetMesh()->Clear(); - tabCorner = new TopoDS_Shape[ nbCorners ]; - tabEdge = new TopoDS_Shape[ nbShapeEdge ]; - nodeAssigne = new int[ nbVertices + 1 ]; - GMFNodeAssigne = new int[ nbVertices + 1 ]; - GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ]; + int ver, dim; + MESSAGE("Read " << theFile << " file"); + int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim); + if (!InpMsh) + return false; - getShape(theMeshDS, TopAbs_VERTEX, tabCorner); - getShape(theMeshDS, TopAbs_EDGE, tabEdge); + 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; + int dummy; GmfKwdCod token = it->first; nbRef = it->second; @@ -712,7 +1016,6 @@ static bool readGMFFile( continue; int id[nbElem*tabRef[token]]; - int ghs3dShapeID[nbElem]; if (token == GmfVertices) { std::cout << " vertices" << std::endl; @@ -725,16 +1028,15 @@ static bool readGMFFile( for ( int iElem = 0; iElem < nbElem; iElem++ ) { aGMFID = iElem + 1; if (ver == GmfFloat) { - GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]); - aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]); + 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]); } else { - GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]); - aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]); + 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]); } GMFNode[ aGMFID ] = aGMFNode; nodeAssigne[ aGMFID ] = 0; - GMFNodeAssigne[ aGMFID ] = 0; } } else if (token == GmfCorners && nbElem > 0) { @@ -750,51 +1052,42 @@ static bool readGMFFile( 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], &ghs3dShapeID[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], &ghs3dShapeID[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 == 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], &ghs3dShapeID[iElem]); -// } 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], - &ghs3dShapeID[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); } -// 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], &ghs3dShapeID[iElem]); -// } + std::cout << std::endl; switch (token) { case GmfCorners: case GmfRidges: case GmfEdges: case GmfTriangles: -// case GmfQuadrilaterals: + case GmfQuadrilaterals: case GmfTetrahedra: -// case GmfHexahedra: - { - int nodeDim, shapeID, *nodeID; - SMDS_MeshNode** node; -// std::vector< SMDS_MeshNode* > enfNode( nbRef ); - SMDS_MeshElement * aGMFElement; - - node = new SMDS_MeshNode*[nbRef]; - nodeID = new int[ nbRef ]; + 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++ ) { @@ -807,336 +1100,40 @@ static bool readGMFFile( switch (token) { - case GmfCorners: { - nodeDim = 1; - gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() ); - for ( int i=0; iAddEdge( node[0], node[1] ); - int iNode = 1; - if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 ) - iNode = 0; - shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge ); - break; - } - case GmfRidges: - break; + case GmfEdges: + theHelper->AddEdge( node[0], node[1] ); break; case GmfTriangles: { - nodeDim = 3; - aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]); - shapeID = -1; + theMesh->AddFace( node[0], node[1], node[2]); break; } -// case GmfQuadrilaterals: { -// nodeDim = 4; -// aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] ); -// shapeID = -1; -// break; -// } - case GmfTetrahedra: { - - // IN WORK - TopoDS_Shape aSolid; - // We always run GHS3D with "to mesh holes"==TRUE but we must not create - // tetras within holes depending on hypo option, - // so we first check if aTet is inside a hole and then create it - if ( nbTriangle > 1 ) { - tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles - int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef; - if ( tabID[ aGhs3dShapeID ] == 0 ) { - TopAbs_State state; - aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state); - if ( toMeshHoles || state == TopAbs_IN ) - tetraShapeID = theMeshDS->ShapeToIndex( aSolid ); - tabID[ aGhs3dShapeID ] = tetraShapeID; - } - else - tetraShapeID = tabID[ aGhs3dShapeID ]; - } - else if ( nbShape > 1 ) { - // Case where nbTriangle == 1 while nbShape == 2 encountered - // with compound of 2 boxes and "To mesh holes"==False, - // so there are no subdomains specified for each tetrahedron. - // Try to guess a solid by a node already bound to shape - tetraShapeID = 0; - for ( int i=0; i<4 && tetraShapeID==0; i++ ) { - if ( nodeAssigne[ nodeID[i] ] == 1 && - node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE && - node[i]->getshapeId() > 1 ) - { - tetraShapeID = node[i]->getshapeId(); - } - } - if ( tetraShapeID==0 ) { - aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape); - tetraShapeID = theMeshDS->ShapeToIndex( aSolid ); - } - } - // set new nodes and tetrahedron onto the shape - for ( int i=0; i<4; i++ ) { - if ( nodeAssigne[ nodeID[i] ] == 0 ) { - if ( tetraShapeID != HOLE_ID ) - theMeshDS->SetNodeInVolume( node[i], tetraShapeID ); - nodeAssigne[ nodeID[i] ] = tetraShapeID; - } - } - if ( toMeshHoles || tetraShapeID != HOLE_ID ) { - aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); - theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID ); - } - - // IN WORK - - nodeDim = 5; + case GmfQuadrilaterals: { + theMesh->AddFace( node[0], node[1], node[2], node[3] ); break; } -// case GmfHexahedra: { -// nodeDim = 6; -// aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1], -// node[4], node[7], node[6], node[5] ); -// 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 != GmfRidges) - { - for ( int i=0; iSetNodeOnVertex( node[0], aVertex ); - else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID ); - else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID ); - GMFNodeAssigne[ nodeID[i] ] = nodeDim; - } - } - if ( token != "Corners" ) - theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID ); - } - } // for - - if ( !toMeshHoles ) { - map ::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) ); - for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) { - if ( nodeAssigne[ itOnNode->first ] == HOLE_ID ) - theMeshDS->RemoveFreeNode( itOnNode->second, 0 ); - } + if ( token == GmfTriangles || token == GmfQuadrilaterals ) // "Quadrilaterals" and "Triangles" + for ( int iRef = 0; iRef < nbRef; iRef++ ) + nodeAssigne[ nodeID[ iRef ]] = 1; } - - delete [] node; - delete [] nodeID; break; - } // case GmfTetrahedra - } // switch(token) - } // for - cout << std::endl; - -#ifndef GMF_HAS_SUBDOMAIN_INFO -#ifdef WNT - UnmapViewOfFile(mapPtr); - CloseHandle(hMapObject); - CloseHandle(fd); -#else - munmap(mapPtr, length); -#endif - close(fileOpen); -#endif - - delete [] tabID; - delete [] tabCorner; - delete [] tabEdge; - delete [] nodeAssigne; - delete [] GMFNodeAssigne; + } + } + } + + shapeID = theHelper->GetSubShapeID(); + for ( int i = 0; i < nbVertices; ++i ) + if ( !nodeAssigne[ i+1 ]) + theMesh->SetNodeInVolume( GMFNode[ i+1 ], shapeID ); + + GmfCloseMesh(InpMsh); delete [] GMFNode; - - return true; -} - - -//======================================================================= -//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 - // --------------------------------- - - int nbElem = 0, nbRef = 0; - int aGMFNodeID = 0, shapeID; - int *nodeAssigne; - SMDS_MeshNode** GMFNode; - std::map tabRef; - - 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; - 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]); - } - 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]); - } - GMFNode[ aGMFID ] = aGMFNode; - nodeAssigne[ aGMFID ] = 0; - } - } - 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); - } - std::cout << std::endl; - - 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]); - break; - } - case GmfQuadrilaterals: { - theMesh->AddFace( node[0], node[1], node[2], node[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; - } - } - } - - 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; + delete [] nodeAssigne; return true; } @@ -1960,11 +1957,9 @@ static bool writeGMFFile(const char* theMeshFileName, return true; } -#else - //======================================================================= //function : writeFaces -//purpose : +//purpose : Write Faces in case if generate 3D mesh with geometry //======================================================================= static bool writeFaces (ofstream & theFile, @@ -2192,617 +2187,172 @@ static bool writeFaces (ofstream & theFile, } //======================================================================= -//function : writeFaces -//purpose : Write Faces in case if generate 3D mesh w/o geometry +//function : writePoints +//purpose : //======================================================================= -static bool writeFaces (ofstream & theFile, - const SMESH_ProxyMesh& theProxyMesh, - SMESH_Mesh * theMesh, - vector & theNodeByGhs3dId, - vector & theEnforcedNodeByGhs3dId, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles, - TIDSortedElemSet & theEnforcedQuadrangles) +static bool writePoints (ofstream & theFile, + SMESH_MesherHelper& theHelper, + map & theSmdsToGhs3dIdMap, + map & theEnforcedNodeIdToGhs3dIdMap, + map & theGhs3dIdToNodeMap, + GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, + GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices, + TIDSortedNodeSet & theEnforcedNodes) { - MESSAGE("writeFaces"); // record structure: // - // NB_ELEMS DUMMY_INT - // Loop from 1 to NB_ELEMS - // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT + // NB_NODES + // Loop from 1 to NB_NODES + // X Y Z DUMMY_INT - int nbTriangles = 0; - SMDS_ElemIteratorPtr nodeIt; + SMESHDS_Mesh * theMesh = theHelper.GetMeshDS(); + int nbNodes = theMesh->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(theMesh->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 nbEnforcedEdges = theEnforcedEdges.size(); - int nbEnforcedTriangles = theEnforcedTriangles.size(); - int nbEnforcedQuadrangles = theEnforcedQuadrangles.size(); - // count faces - nbTriangles = theProxyMesh.NbFaces(); - - if ( nbTriangles == 0 ) - return false; + int aGhs3dID = 1; + SMDS_NodeIteratorPtr it = theMesh->nodesIterator(); + const SMDS_MeshNode* node; - std::cout << "Start writing in 'faces' file ..." << std::endl; + // NB_NODES std::cout << std::endl; - std::cout << "The initial 2D mesh contains " << nbTriangles << " shapes of 2D dimension and " << std::endl; - if (nbEnforcedEdges+nbEnforcedTriangles+nbEnforcedQuadrangles) - std::cout << " " << nbEnforcedEdges+nbEnforcedTriangles+nbEnforcedQuadrangles - << " enforced shapes:" << std::endl; - if (nbEnforcedEdges) - 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; - - // NB_ELEMS DUMMY_INT -// theFile << nbTriangles << space << dummyint << 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 << std::endl; +// std::cout << "Start writing in 'points' file ..." << std::endl; + theFile << nbNodes << space << std::endl; - map aNodeToGhs3dIdMap, anEnforcedNodeToGhs3dIdMap; - map< const SMDS_MeshNode*,int >::iterator it; - TIDSortedElemSet anElemSet, anEnforcedElemSet; - TIDSortedElemSet::iterator elemIt; - const SMDS_MeshElement* elem; - auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); - bool isOK; - const SMDS_MeshNode* node; - int usedEnforcedEdges = 0; - int usedEnforcedTriangles = 0; - int usedEnforcedQuadrangles = 0; - - // - // FACES : BEGIN - // - - // Loop from 1 to NB_ELEMS - - SMDS_ElemIteratorPtr eIt = theProxyMesh.GetFaces(); - while ( eIt->more() ) - { - elem = eIt->next(); - anElemSet.insert(elem); - // NODE_NB_1 NODE_NB_2 ... - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) - { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 - aNodeToGhs3dIdMap.insert( make_pair( node, newId )); - } - } - - // - // FACES : END - // - - - // - // ENFORCED EDGES : BEGIN - // - - // Iterate over the enforced edges - for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { - elem = (*elemIt); - isOK = true; - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - node = castToNode( nodeIt->next() ); - // 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 ) { - isOK = false; - break; - } - } - if (isOK) { - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - int newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 - anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId )); - } - anEnforcedElemSet.insert(elem); - usedEnforcedEdges++; - } - } - - // - // ENFORCED EDGES : END - // - // - - - // - // ENFORCED TRIANGLES : BEGIN - // - // Iterate over the enforced triangles - for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { - elem = (*elemIt); - isOK = true; - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - // 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 ) { - isOK = false; - break; - } - } - if (isOK) { - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - int newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 - anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId )); - } - anEnforcedElemSet.insert(elem); - usedEnforcedTriangles++; - } - } - - // - // ENFORCED TRIANGLES : END - // - - // - // ENFORCED QUADRANGLES : BEGIN - // - // Iterate over the enforced quadrangles - for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { - elem = (*elemIt); - isOK = true; - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - // 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 ) { - isOK = false; - break; - } - } - if (isOK) { - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - const SMDS_MeshNode* node = castToNode( nodeIt->next() ); - int newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 - anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId )); - } - anEnforcedElemSet.insert(elem); - usedEnforcedQuadrangles++; - } - } - - // - // ENFORCED QUADRANGLES : END - // - - - // put nodes to theNodeByGhs3dId vector - std::cout << "aNodeToGhs3dIdMap.size(): "<::const_iterator n2id = aNodeToGhs3dIdMap.begin(); - for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id) - { -// std::cout << "n2id->first: "<first<second - 1 ] = n2id->first; // ghs3d ids count from 1 - } - - // put nodes to theNodeByGhs3dId vector - std::cout << "anEnforcedNodeToGhs3dIdMap.size(): "<first: "<first<second - aNodeToGhs3dIdMap.size() - 1 ] = n2id->first; // ghs3d ids count from 1 - } - - std::cout << "anElemSet.size(): " << anElemSet.size() << std::endl; - std::cout << "anEnforcedElemSet.size(): " << anEnforcedElemSet.size() << std::endl; - theFile << anElemSet.size() + anEnforcedElemSet.size() << space << "0" << std::endl; - for(elemIt = anElemSet.begin() ; elemIt != anElemSet.end() ; ++elemIt) { - elem = (*elemIt); - theFile << elem->NbNodes() << space ; - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - node = castToNode( nodeIt->next() ); - it = aNodeToGhs3dIdMap.find(node); - if (it == aNodeToGhs3dIdMap.end()) - throw "Node not found"; - - theFile << it->second << space ; - } - for ( int j=0; j<=elem->NbNodes(); j++) - theFile << dummyint << space ; - theFile << std::endl; - } - for(elemIt = anEnforcedElemSet.begin() ; elemIt != anEnforcedElemSet.end() ; ++elemIt) { - elem = (*elemIt); - theFile << elem->NbNodes() << space ; - nodeIt = elem->nodesIterator(); - while ( nodeIt->more() ) { - // find GHS3D ID - node = castToNode( nodeIt->next() ); - it = anEnforcedNodeToGhs3dIdMap.find(node); - if (it == anEnforcedNodeToGhs3dIdMap.end()) - throw "Node not found"; - - theFile << it->second << space ; - } - for ( int j=0; j<=elem->NbNodes(); j++) - theFile << dummyint << space ; - theFile << std::endl; - } - - return true; -} - - -//======================================================================= -//function : writePoints -//purpose : -//======================================================================= - -static bool writePoints (ofstream & theFile, - SMESH_MesherHelper& theHelper, - map & theSmdsToGhs3dIdMap, - map & theEnforcedNodeIdToGhs3dIdMap, - map & theGhs3dIdToNodeMap, - GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, - GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices, - TIDSortedNodeSet & theEnforcedNodes) -{ - // record structure: - // - // NB_NODES - // Loop from 1 to NB_NODES - // X Y Z DUMMY_INT - - SMESHDS_Mesh * theMesh = theHelper.GetMeshDS(); - int nbNodes = theMesh->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(theMesh->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 = theMesh->nodesIterator(); - const SMDS_MeshNode* node; - - // NB_NODES - 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 << std::endl; -// std::cout << "Start writing in 'points' file ..." << std::endl; - theFile << nbNodes << space << std::endl; - - // Loop from 1 to NB_NODES + // 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 nodes - TIDSortedNodeSet::const_iterator nodeIt; - std::map enfVertexIndexSizeMap; - if (nbEnforcedNodes) { - 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(theMesh->ShapeToMesh()); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result != TopAbs_IN ) - continue; - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) - continue; - - double size = theNodeIDToSizeMap.find((*nodeIt)->GetID())->second; - // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) )); - // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); - // X Y Z PHY_SIZE DUMMY_INT - theFile - << x << space - << y << space - << z << space - << size << space - << dummyint << space; - theFile << std::endl; - theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( (*nodeIt)->GetID(), aGhs3dID )); - enfVertexIndexSizeMap[aGhs3dID] = -1; - aGhs3dID++; - // else - // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); - } - } - - if (nbEnforcedVertices) { - // Iterate over the enforced vertices - GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; -// 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(theMesh->ShapeToMesh()); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result != TopAbs_IN ) - continue; - // MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second); - // X Y Z PHY_SIZE DUMMY_INT - theFile - << x << space - << y << space - << z << space - << vertexIt->second << space - << dummyint << space; - theFile << std::endl; - enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second; - aGhs3dID++; - - // 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 in 'points' file." << std::endl; - - return true; -} - -//======================================================================= -//function : writePoints -//purpose : -//======================================================================= - -static bool writePoints (ofstream & theFile, - SMESH_Mesh * theMesh, - const vector & theNodeByGhs3dId, - const vector & theEnforcedNodeByGhs3dId, - GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, - GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices, - TIDSortedNodeSet & theEnforcedNodes) -{ - // record structure: - // - // NB_NODES - // Loop from 1 to NB_NODES - // X Y Z DUMMY_INT - - int nbNodes = theNodeByGhs3dId.size(); - if ( nbNodes == 0 ) - return false; - - int nbEnforcedVertices = theEnforcedVertices.size(); - int nbEnforcedNodes = theEnforcedNodes.size(); - - const char* space = " "; - const int dummyint = 0; - - const SMDS_MeshNode* node; - std::set< std::vector > nodesCoords; - - // NB_NODES -// 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 << std::endl; - std::cout << "Start writing in 'points' file ..." << std::endl; - theFile << nbNodes << space << std::endl; - - // Loop from 1 to NB_NODES - - vector::const_iterator nodeIt = theNodeByGhs3dId.begin(); - vector::const_iterator after = theNodeByGhs3dId.end(); - - std::cout << theNodeByGhs3dId.size() << " nodes from mesh ..." << std::endl; - for ( ; nodeIt != after; ++nodeIt ) - { - node = *nodeIt; - - // X Y Z DUMMY_INT - theFile - << node->X() << space - << node->Y() << space - << node->Z() << space - << dummyint << std::endl; - - std::vector coords; - coords.push_back(node->X()); - coords.push_back(node->Y()); - coords.push_back(node->Z()); - 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 ) - { - node = *nodeIt; - - 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; - - // X Y Z DUMMY_INT - theFile - << node->X() << space - << node->Y() << space - << node->Z() << space - << theNodeIDToSizeMap.find(node->GetID())->second << space - << dummyint << std::endl; - - nodesCoords.insert(coords); - } - } - - 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 = *enfNodeIt; + if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE && + theHelper.IsDegenShape( node->getshapeId() )) // Issue 020674 + continue; - std::vector coords; - coords.push_back(node->X()); - coords.push_back(node->Y()); - coords.push_back(node->Z()); + theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); + theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); + aGhs3dID++; - if (nodesCoords.find(coords) != nodesCoords.end()) { - std::cout << "Node at " << node->X()<<", " <Y()<<", " <Z() << " found" << std::endl; - continue; - } + // X Y Z DUMMY_INT + theFile + << node->X() << space + << node->Y() << space + << node->Z() << space + << dummyint << space ; + theFile << std::endl; - if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) - continue; + } + + // Iterate over the enforced nodes + TIDSortedNodeSet::const_iterator nodeIt; + std::map enfVertexIndexSizeMap; + if (nbEnforcedNodes) { + 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(node->X(),node->Y(),node->Z()); - TopAbs_State result = pntCls->GetPointState( myPoint ); + gp_Pnt myPoint(x,y,z); + BRepClass3d_SolidClassifier scl(theMesh->ShapeToMesh()); + scl.Perform(myPoint, 1e-7); + TopAbs_State result = scl.State(); if ( result != TopAbs_IN ) continue; - - // X Y Z DUMMY_INT + std::vector coords; + coords.push_back(x); + coords.push_back(y); + coords.push_back(z); + if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) + continue; + + double size = theNodeIDToSizeMap.find((*nodeIt)->GetID())->second; + // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) )); + // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); + // X Y Z PHY_SIZE DUMMY_INT theFile - << node->X() << space - << node->Y() << space - << node->Z() << space - << theNodeIDToSizeMap.find(node->GetID())->second << space - << dummyint << std::endl; - - nodesCoords.insert(coords); + << x << space + << y << space + << z << space + << size << space + << dummyint << space; + theFile << std::endl; + theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( (*nodeIt)->GetID(), aGhs3dID )); + enfVertexIndexSizeMap[aGhs3dID] = -1; + aGhs3dID++; + // else + // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); } } if (nbEnforcedVertices) { - std::cout << theEnforcedVertices.size() << " nodes from enforced vertices ..." << std::endl; // Iterate over the enforced vertices GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; +// 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); - TopAbs_State result = pntCls->GetPointState( myPoint ); + BRepClass3d_SolidClassifier scl(theMesh->ShapeToMesh()); + scl.Perform(myPoint, 1e-7); + TopAbs_State result = scl.State(); if ( result != TopAbs_IN ) continue; - std::cout << "Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second << std::endl; - - // X Y Z PHY_SIZE DUMMY_INT + // MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second); + // X Y Z PHY_SIZE DUMMY_INT theFile - << x << space - << y << space + << x << space + << y << space << z << space - << vertexIt->second << space - << dummyint << std::endl; + << vertexIt->second << space + << dummyint << space; + theFile << std::endl; + enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second; + aGhs3dID++; - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - nodesCoords.insert(coords); - + // 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 in 'points' file." << std::endl; + +// std::cout << std::endl; +// std::cout << "End writing in 'points' file." << std::endl; return true; } + //======================================================================= //function : readResultFile //purpose : @@ -2812,7 +2362,8 @@ static bool readResultFile(const int fileOpen, #ifdef WNT const char* fileName, #endif - SMESH_Mesh& theMesh, + SMESH_MesherHelper& theMesh, +// SMESH_Mesh& theMesh, TopoDS_Shape tabShape[], double** tabBox, const int nbShape, @@ -2846,13 +2397,13 @@ static bool readResultFile(const int fileOpen, int *tab, *tabID, *nodeID, *nodeAssigne; double *coord; - SMDS_MeshNode **node; + const SMDS_MeshNode **node; tab = new int[3]; //tabID = new int[nbShape]; nodeID = new int[4]; coord = new double[3]; - node = new SMDS_MeshNode*[4]; + node = new const SMDS_MeshNode*[4]; TopoDS_Shape aSolid; SMDS_MeshNode * aNewNode; @@ -2894,6 +2445,8 @@ static bool readResultFile(const int fileOpen, for (int i=0; i < 4*nbElems; i++) nodeId = strtol(ptr, &ptr, 10); + MESSAGE("nbInputNodes: "< 0 ) { @@ -3067,165 +2621,10 @@ static bool readResultFile(const int fileOpen, return true; } -//======================================================================= -//function : readResultFile -//purpose : -//======================================================================= - -static bool readResultFile(const int fileOpen, -#ifdef WNT - const char* fileName, -#endif - SMESH_Mesh& theMesh, - TopoDS_Shape aSolid, - vector & theNodeByGhs3dId, - vector & theEnforcedNodeByGhs3dId, - int nbEnforcedVertices, - int nbEnforcedNodes, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles, - TIDSortedElemSet & theEnforcedQuadrangles) -{ - SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS(); - - Kernel_Utils::Localizer loc; - struct stat status; - size_t length; - - char *ptr, *mapPtr; - char *tetraPtr; - char *shapePtr; - - int fileStat; - int nbElems, nbNodes, nbInputNodes; - int nodeId, triangleId; - int nbTriangle; - int ID, shapeID; - - int *tab; - double *coord; - const SMDS_MeshNode **node; - - tab = new int[3]; - coord = new double[3]; - node = new const SMDS_MeshNode*[4]; - - SMDS_MeshNode * aNewNode; - map ::iterator IdNode; - SMDS_MeshElement* aTet; - - // Read the file state - fileStat = fstat(fileOpen, &status); - length = status.st_size; - - // Mapping the result file into memory -#ifdef WNT - HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY, - 0, (DWORD)length, NULL); - ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 ); -#else - ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0); -#endif - mapPtr = ptr; - - ptr = readMapIntLine(ptr, tab); - tetraPtr = ptr; - - nbElems = tab[0]; - nbNodes = tab[1]; - nbInputNodes = tab[2]; - - theNodeByGhs3dId.resize( nbNodes ); - - // Reading the nodeId - for (int i=0; i < 4*nbElems; i++) - nodeId = strtol(ptr, &ptr, 10); - - // Issue 0020682. Avoid creating nodes and tetras at place where - // volumic elements already exist - SMESH_ElementSearcher* elemSearcher = 0; - vector< const SMDS_MeshElement* > foundVolumes; - if ( theMesh.NbVolumes() > 0 ) - elemSearcher = SMESH_MeshEditor( &theMesh ).GetElementSearcher(); - - // Reading the nodeCoord and update the nodeMap - shapeID = theMeshDS->ShapeToIndex( aSolid ); - for (int iNode=0; iNode < nbNodes; iNode++) { - for (int iCoor=0; iCoor < 3; iCoor++) - coord[ iCoor ] = strtod(ptr, &ptr); - if ((iNode+1) > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes+theEnforcedNodeByGhs3dId.size()))) { - // Issue 0020682. Avoid creating nodes and tetras at place where - // volumic elements already exist - if ( elemSearcher && - elemSearcher->FindElementsByPoint( gp_Pnt(coord[0],coord[1],coord[2]), - SMDSAbs_Volume, foundVolumes )) - { - theNodeByGhs3dId[ iNode ] = 0; - } - else - { - aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] ); - theMeshDS->SetNodeInVolume( aNewNode, shapeID ); - theNodeByGhs3dId[ iNode ] = aNewNode; - } - } - } - - // Reading the triangles - nbTriangle = strtol(ptr, &ptr, 10); - - for (int i=0; i < 3*nbTriangle; i++) - triangleId = strtol(ptr, &ptr, 10); - - shapePtr = ptr; - - // Associating the tetrahedrons to the shapes - for (int iElem = 0; iElem < nbElems; iElem++) { - for (int iNode = 0; iNode < 4; iNode++) { - ID = strtol(tetraPtr, &tetraPtr, 10); - node[ iNode ] = theNodeByGhs3dId[ ID-1 ]; - } - if ( elemSearcher ) - { - // Issue 0020682. Avoid creating nodes and tetras at place where - // volumic elements already exist - if ( !node[1] || !node[0] || !node[2] || !node[3] ) - continue; - if ( elemSearcher->FindElementsByPoint(( SMESH_TNodeXYZ(node[0]) + - SMESH_TNodeXYZ(node[1]) + - SMESH_TNodeXYZ(node[2]) + - SMESH_TNodeXYZ(node[3]) ) / 4., - SMDSAbs_Volume, foundVolumes )) - continue; - } - aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); - shapeID = theMeshDS->ShapeToIndex( aSolid ); - theMeshDS->SetMeshElementOnShape( aTet, shapeID ); - } - if ( nbElems ) - cout << nbElems << " tetrahedrons have been associated to " << nbTriangle << " shapes" << endl; -#ifdef WNT - UnmapViewOfFile(mapPtr); - CloseHandle(hMapObject); - CloseHandle(fd); -#else - munmap(mapPtr, length); -#endif - close(fileOpen); - - delete [] tab; - delete [] coord; - delete [] node; - - return true; -} -#endif //============================================================================= /*! - *Here we are going to use the GHS3D mesher + *Here we are going to use the GHS3D mesher with geometry */ //============================================================================= @@ -3271,7 +2670,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString aResultFileName; TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 TCollection_AsciiString aFacesFileName, aPointsFileName; TCollection_AsciiString aBadResFileName, aBbResFileName; aFacesFileName = aGenericName + ".faces"; // in faces @@ -3279,7 +2678,6 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, 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 @@ -3294,37 +2692,27 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, INFOS( "Can't write into " << aFacesFileName); return error(SMESH_Comment("Can't write into ") << aFacesFileName); } -#else - TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; -#ifndef GMF_HAS_SUBDOMAIN_INFO - TCollection_AsciiString aResultGMFFileName; -#endif -#ifdef _DEBUG_ - aGMFFileName = aGenericName + ".mesh"; // GMF mesh file -#ifndef GMF_HAS_SUBDOMAIN_INFO - // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) - aResultGMFFileName = aGenericName + "Vol.mesh"; // GMF mesh file - aResultFileName = aGenericName + ".noboite";// out points and volumes -#else - aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file -#endif - aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file - aSolFileName = aGenericName + "_required.sol"; // GMF solution file -#else -#ifndef GMF_HAS_SUBDOMAIN_INFO - // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) +// #else +// TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; +// TCollection_AsciiString aResultGMFFileName; + +// #ifdef _DEBUG_ // aGMFFileName = aGenericName + ".mesh"; // GMF mesh file - aResultGMFFileName = aGenericName + "Vol.meshb"; // GMF mesh file - aResultFileName = aGenericName + ".noboite";// out points and volumes -#else +// // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) +// aResultGMFFileName = aGenericName + "Vol.mesh"; // GMF mesh file +// aResultFileName = aGenericName + ".noboite";// out points and volumes +// // 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 -#endif - aGMFFileName = aGenericName + ".meshb"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file - aSolFileName = aGenericName + ".solb"; // GMF solution file -#endif -#endif +// // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) +// aResultGMFFileName = aGenericName + "Vol.meshb"; // GMF mesh file +// aResultFileName = aGenericName + ".noboite";// out points and volumes +// // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file +// aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file +// aSolFileName = aGenericName + "_required.solb"; // GMF solution file +// #endif map aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap; map aGhs3dIdToNodeMap; std::map nodeID2nodeIndexMap; @@ -3370,7 +2758,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( !proxyMesh ) return false; } -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 Ok = (writePoints( aPointsFile, helper, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap, nodeIDToSizeMap, @@ -3379,14 +2767,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, writeFaces ( aFacesFile, *proxyMesh, theShape, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, enforcedEdges, enforcedTriangles, enforcedQuadrangles)); -#else - Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), - helper, *proxyMesh, - aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, - enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, - enforcedVertices); - -#endif +// #else +// Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), +// helper, *proxyMesh, +// aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, +// enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, +// enforcedVertices); +// #endif } // Write aSmdsToGhs3dIdMap to temp file @@ -3405,21 +2792,21 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } aIdsFile.close(); -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 aFacesFile.close(); aPointsFile.close(); -#endif +// #endif if ( ! Ok ) { if ( !_keepFiles ) { -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 removeFile( aFacesFileName ); removeFile( aPointsFileName ); -#else - removeFile( aGMFFileName ); - removeFile( aRequiredVerticesFileName ); - removeFile( aSolFileName ); -#endif +// #else +// removeFile( aGMFFileName ); +// removeFile( aRequiredVerticesFileName ); +// removeFile( aSolFileName ); +// #endif removeFile( aSmdsToGhs3dIdMapFileName ); } return error(COMPERR_BAD_INPUT_MESH); @@ -3432,15 +2819,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) -// #if GHS3D_VERSION < 42 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read -// #else -#if GHS3D_VERSION >= 42 cmd += TCollection_AsciiString(" -IM "); // cmd += TCollection_AsciiString(" --in ") + aGenericName; // cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; // cmd += TCollection_AsciiString(" --out ") + aGenericName; -#endif cmd += TCollection_AsciiString(" -Om 1>" ) + aLogFileName; // dump into file std::cout << std::endl; @@ -3457,7 +2840,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // -------------- bool toMeshHoles = _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles(); -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 // Mapping the result file int fileOpen; @@ -3473,37 +2856,37 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #ifdef WNT aResultFileName.ToCString(), #endif - theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, + /*theMesh, */helper, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, toMeshHoles, nbEnforcedVertices, nbEnforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles ); } -#else -#ifndef GMF_HAS_SUBDOMAIN_INFO - // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) - - int fileOpen = open( aResultFileName.ToCString(), O_RDONLY); - if ( fileOpen < 0 ) { - std::cout << std::endl; - std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl; - std::cout << "Log: " << aLogFileName << std::endl; - Ok = false; - } - else { -#endif - Ok = readGMFFile( -#ifndef GMF_HAS_SUBDOMAIN_INFO - fileOpen, -#endif - aGenericName.ToCString(), theMesh, - _nbShape, tabShape, tabBox, - aGhs3dIdToNodeMap, toMeshHoles, - nbEnforcedVertices, nbEnforcedNodes, - enforcedNodes, enforcedTriangles, enforcedQuadrangles); -#ifndef GMF_HAS_SUBDOMAIN_INFO - } -#endif -#endif +// /*/*#else +// #ifndef GMF_HAS_SUBDOMAIN_INFO +// // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) +// +// int fileOpen = open( aResultFileName.ToCString(), O_RDONLY); +// if ( fileOpen < 0 ) { +// std::cout << std::endl; +// std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl; +// std::cout << "Log: " << aLogFileName << std::endl; +// Ok = false; +// } +// else { +// #endif +// Ok = readGMFFile( +// #ifndef GMF_HAS_SUBDOMAIN_INFO +// fileOpen, +// #endif +// aGenericName.ToCString(), theMesh, +// _nbShape, tabShape, tabBox, +// aGhs3dIdToNodeMap, toMeshHoles, +// nbEnforcedVertices, nbEnforcedNodes, +// enforcedNodes, enforcedTriangles, enforcedQuadrangles); +// #ifndef GMF_HAS_SUBDOMAIN_INFO +// } +// #endif +// #endif*/*/ // --------------------- // remove working files @@ -3529,13 +2912,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } if ( !_keepFiles ) { -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 removeFile( aFacesFileName ); removeFile( aPointsFileName ); removeFile( aResultFileName ); removeFile( aBadResFileName ); removeFile( aBbResFileName ); -#endif +// #endif removeFile( aSmdsToGhs3dIdMapFileName ); // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) removeFile( aResultFileName );