From 3dde232cb07625423d5f22899829aedd30abb4aa Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 2 Oct 2009 16:10:50 +0000 Subject: [PATCH] 020461: EDF 1102 GHS3DPLUGIN: Bad detection of volumes with Ghs3d mesh 1) in findShapeID(), check UV validity using tolerance of shape the node is on rather than tolerance of face 2) in findShape(), fix getting GC of tetra --- src/GHS3DPlugin_GHS3D.cxx | 97 +++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index 881912b..aa92530 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -24,8 +24,6 @@ // $Header$ //============================================================================= // -using namespace std; - #include "GHS3DPlugin_GHS3D.hxx" #include "GHS3DPlugin_Hypothesis.hxx" @@ -59,15 +57,20 @@ using namespace std; #include #include //#include -//#include -//#include +#include +#include +#include #include "utilities.h" -#ifndef WIN32 +#ifdef WIN32 +#include +#else #include #endif +using namespace std; + //#include @@ -177,7 +180,7 @@ static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[], aPnt = p; break; } - aPnt += p; + aPnt += p / nbNode; } BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion()); @@ -607,20 +610,23 @@ static int findShapeID(SMESH_Mesh& mesh, nNotOnSeamEdge = node3; else nNotOnSeamEdge = node2; - gp_XY uv = helper.GetNodeUV( geomFace, node1, nNotOnSeamEdge ); + bool uvOK; + gp_XY uv = helper.GetNodeUV( geomFace, node1, nNotOnSeamEdge, &uvOK ); // check that uv is correct + double tol = 1e-6; + TopoDS_Shape nodeShape = helper.GetSubShapeByNode( node1, meshDS ); + if ( !nodeShape.IsNull() ) + switch ( nodeShape.ShapeType() ) + { + case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break; + case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break; + case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break; + default:; + } BRepAdaptor_Surface surface( geomFace ); - double tol = BRep_Tool::Tolerance( geomFace ); - if ( node1Pnt.Distance( surface.Value( uv.X(), uv.Y() )) > 2 * tol ) { - GeomAPI_ProjectPointOnSurf projector( node1Pnt, surface.Surface().Surface(), 2 * tol ); - if ( !projector.IsDone() || projector.NbPoints() < 1 || projector.LowerDistance() > 2 * tol) + if ( !uvOK || node1Pnt.Distance( surface.Value( uv.X(), uv.Y() )) > 2 * tol ) return invalidID; - Quantity_Parameter U,V; - projector.LowerDistanceParameters(U,V); - if ( node1Pnt.Distance( surface.Value( U, V )) > 2 * tol ) - return invalidID; - uv.SetCoord( U,V ); - } + // normale to geomFace at UV gp_Vec du, dv; surface.D1( uv.X(), uv.Y(), node1Pnt, du, dv ); @@ -647,6 +653,9 @@ static int findShapeID(SMESH_Mesh& mesh, //======================================================================= static bool readResultFile(const int fileOpen, +#ifdef WNT + const char* fileName, +#endif SMESH_Mesh& theMesh, TopoDS_Shape tabShape[], double** tabBox, @@ -695,7 +704,15 @@ static bool readResultFile(const int fileOpen, 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); @@ -842,7 +859,13 @@ static bool readResultFile(const int fileOpen, if ( nbElems ) cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl; +#ifdef WNT + UnmapViewOfFile(mapPtr); + CloseHandle(hMapObject); + CloseHandle(fd); +#else munmap(mapPtr, length); +#endif close(fileOpen); delete [] tab; @@ -872,6 +895,9 @@ static bool readResultFile(const int fileOpen, //======================================================================= static bool readResultFile(const int fileOpen, +#ifdef WNT + const char* fileName, +#endif SMESHDS_Mesh* theMeshDS, TopoDS_Shape aSolid, vector & theNodeByGhs3dId) { @@ -906,7 +932,15 @@ static bool readResultFile(const int fileOpen, 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); @@ -954,7 +988,13 @@ static bool readResultFile(const int fileOpen, } 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; @@ -1028,11 +1068,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); Ok = -#ifdef WIN32 - aFacesFile->is_open() && aPointsFile->is_open(); -#else aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); -#endif if (!Ok) { INFOS( "Can't write into " << aFacesFileName); return error(SMESH_Comment("Can't write into ") << aFacesFileName); @@ -1045,7 +1081,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aFacesFile.close(); aPointsFile.close(); - + if ( ! Ok ) { if ( !_keepFiles ) { removeFile( aFacesFileName ); @@ -1089,7 +1125,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, else { bool toMeshHoles = _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles(); - Ok = readResultFile( fileOpen, theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, + Ok = readResultFile( fileOpen, +#ifdef WNT + aResultFileName.ToCString(), +#endif + theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, toMeshHoles ); } @@ -1170,11 +1210,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); bool Ok = -#ifdef WIN32 - aFacesFile->is_open() && aPointsFile->is_open(); -#else aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); -#endif if (!Ok) return error( SMESH_Comment("Can't write into ") << aPointsFileName); @@ -1220,7 +1256,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = false; } else { - Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId ); + Ok = readResultFile( fileOpen, +#ifdef WNT + aResultFileName.ToCString(), +#endif + meshDS, theShape ,aNodeByGhs3dId ); } // --------------------- @@ -1745,4 +1785,3 @@ const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector& ghsNod return 0; } - -- 2.39.2