From: nge Date: Tue, 1 Sep 2009 13:56:44 +0000 (+0000) Subject: - Add group management for size maps X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=719f1be023f6eb54b4d4d1064da41692f8673bf6;p=plugins%2Fblsurfplugin.git - Add group management for size maps - Attractor available using ATTRACTOR(x;y;z;a;b;createNode) with: * x,y,z: coordinates of attractor point * a,b : parameters of attractor point (see BlSurf plugin doc) * createNode: boolean for creation of node on projection of attractor point on surface - HashCode bug was corrected --- diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 0e78127..e50e1f4 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -48,6 +48,7 @@ #include extern "C"{ +#include "distene/blsurf.h" #include } @@ -77,6 +78,8 @@ extern "C"{ #include #include #include +// #include +#include /* ================================== * =========== PYTHON ============== @@ -184,18 +187,24 @@ PyObject * newPyStdOut( std::string& out ) ////////////////////////END PYTHON/////////////////////////// //////////////////MY MAPS//////////////////////////////////////// +TopTools_IndexedMapOfShape FacesWithSizeMap; std::map FaceId2SizeMap; +TopTools_IndexedMapOfShape EdgesWithSizeMap; std::map EdgeId2SizeMap; +TopTools_IndexedMapOfShape VertecesWithSizeMap; std::map VertexId2SizeMap; + std::map FaceId2PythonSmp; std::map EdgeId2PythonSmp; std::map VertexId2PythonSmp; +std::map > FaceId2AttractorCoords; bool HasSizeMapOnFace=false; bool HasSizeMapOnEdge=false; bool HasSizeMapOnVertex=false; + //============================================================================= /*! * @@ -239,12 +248,17 @@ BLSURFPlugin_BLSURF::BLSURFPlugin_BLSURF(int hypId, int studyId, PyRun_SimpleString("from math import *"); PyGILState_Release(gstate); + FacesWithSizeMap.Clear(); FaceId2SizeMap.clear(); + EdgesWithSizeMap.Clear(); EdgeId2SizeMap.clear(); + VertecesWithSizeMap.Clear(); VertexId2SizeMap.clear(); FaceId2PythonSmp.clear(); EdgeId2PythonSmp.clear(); VertexId2PythonSmp.clear(); + FaceId2AttractorCoords.clear(); + } //============================================================================= @@ -332,9 +346,14 @@ status_t size_on_vertex(integer vertex_id, real *size, void *user_data); double my_u_min=1e6,my_v_min=1e6,my_u_max=-1e6,my_v_max=-1e6; +typedef struct { + gp_XY uv; + gp_XYZ xyz; +} projectionPoint; ///////////////////////////////////////////////////////// -gp_XY getUV(const TopoDS_Face& face, const gp_XYZ& point) +projectionPoint getUV(const TopoDS_Face& face, const gp_XYZ& point) { + projectionPoint myPoint; Handle(Geom_Surface) surface = BRep_Tool::Surface(face); GeomAPI_ProjectPointOnSurf projector( point, surface ); if ( !projector.IsDone() || projector.NbPoints()==0 ) @@ -342,7 +361,12 @@ gp_XY getUV(const TopoDS_Face& face, const gp_XYZ& point) Quantity_Parameter u,v; projector.LowerDistanceParameters(u,v); - return gp_XY(u,v); + myPoint.uv = gp_XY(u,v); + gp_Pnt aPnt = projector.NearestPoint(); + myPoint.xyz = gp_XYZ(aPnt.X(),aPnt.Y(),aPnt.Z()); + //return gp_XY(u,v); + return myPoint; + } ///////////////////////////////////////////////////////// @@ -389,6 +413,97 @@ TopoDS_Shape BLSURFPlugin_BLSURF::entryToShape(std::string entry) } return S; } + +///////////////////////////////////////////////////////// + +void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction) +{ + MESSAGE("Attractor function: "<< AttractorFunction); + double xa, ya, za; // Coordinates of attractor point + double a, b; // Attractor parameter + bool createNode=false; // To create a node on attractor projection + int pos1, pos2; + // atIt->second has the following pattern: + // ATTRACTOR(xa;ya;za;a;b) + // where: + // xa;ya;za : coordinates of attractor + // a : desired size on attractor + // b : distance of influence of attractor + // + // We search the parameters in the string + // xa + pos1 = AttractorFunction.find(";"); + if (pos1!=string::npos) + xa = atof(AttractorFunction.substr(10, pos1-10).c_str()); + // ya + pos2 = AttractorFunction.find(";", pos1+1); + if (pos2!=string::npos) { + ya = atof(AttractorFunction.substr(pos1+1, pos2-pos1-1).c_str()); + pos1 = pos2; + } + // za + pos2 = AttractorFunction.find(";", pos1+1); + if (pos2!=string::npos) { + za = atof(AttractorFunction.substr(pos1+1, pos2-pos1-1).c_str()); + pos1 = pos2; + } + // a + pos2 = AttractorFunction.find(";", pos1+1); + if (pos2!=string::npos) { + a = atof(AttractorFunction.substr(pos1+1, pos2-pos1-1).c_str()); + pos1 = pos2; + } + // b + pos2 = AttractorFunction.find(";", pos1+1); + if (pos2!=string::npos) { + b = atof(AttractorFunction.substr(pos1+1, pos2-pos1-1).c_str()); + pos1 = pos2; + } + // createNode + pos2 = AttractorFunction.find(")"); + if (pos2!=string::npos) { + string createNodeStr = AttractorFunction.substr(pos1+1, pos2-pos1-1); + MESSAGE("createNode: " << createNodeStr); + createNode = (AttractorFunction.substr(pos1+1, pos2-pos1-1) == "True"); + } + + // Get the (u,v) values of the attractor on the face + projectionPoint myPoint = getUV(TopoDS::Face(GeomShape),gp_XYZ(xa,ya,za)); + gp_XY uvPoint = myPoint.uv; + gp_XYZ xyzPoint = myPoint.xyz; + Standard_Real u0 = uvPoint.X(); + Standard_Real v0 = uvPoint.Y(); + Standard_Real x0 = xyzPoint.X(); + Standard_Real y0 = xyzPoint.Y(); + Standard_Real z0 = xyzPoint.Z(); + std::vector coords; + coords.push_back(u0); + coords.push_back(v0); + coords.push_back(x0); + coords.push_back(y0); + coords.push_back(z0); + // We construct the python function + ostringstream attractorFunctionStream; + attractorFunctionStream << "def f(u,v): return "; + attractorFunctionStream << _smp_phy_size << "-(" << _smp_phy_size <<"-" << a << ")"; + attractorFunctionStream << "*exp(-((u-("<first); GeomType = GeomShape.ShapeType(); MESSAGE("Geomtype is " << GeomType); + int key = -1; // Group Management if (GeomType == TopAbs_COMPOUND){ for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ + // Group of faces if (it.Value().ShapeType() == TopAbs_FACE){ HasSizeMapOnFace = true; - FaceId2SizeMap[TopoDS::Face(it.Value()).HashCode(471662)] = smIt->second; + if (! FacesWithSizeMap.Contains(TopoDS::Face(it.Value()))) { + key = FacesWithSizeMap.Add(TopoDS::Face(it.Value())); + } + else { + key = FacesWithSizeMap.FindIndex(TopoDS::Face(it.Value())); +// MESSAGE("Face with key " << key << " already in map"); + } + FaceId2SizeMap[key] = smIt->second; } + // Group of edges if (it.Value().ShapeType() == TopAbs_EDGE){ HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - EdgeId2SizeMap[TopoDS::Edge(it.Value()).HashCode(471662)] = smIt->second; + if (! EdgesWithSizeMap.Contains(TopoDS::Edge(it.Value()))) { + key = EdgesWithSizeMap.Add(TopoDS::Edge(it.Value())); + } + else { + key = EdgesWithSizeMap.FindIndex(TopoDS::Edge(it.Value())); +// MESSAGE("Edge with key " << key << " already in map"); + } + EdgeId2SizeMap[key] = smIt->second; } + // Group of verteces if (it.Value().ShapeType() == TopAbs_VERTEX){ HasSizeMapOnVertex = true; HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - VertexId2SizeMap[TopoDS::Vertex(it.Value()).HashCode(471662)] = smIt->second; + if (! VertecesWithSizeMap.Contains(TopoDS::Vertex(it.Value()))) { + key = VertecesWithSizeMap.Add(TopoDS::Vertex(it.Value())); + } + else { + key = VertecesWithSizeMap.FindIndex(TopoDS::Vertex(it.Value())); +// MESSAGE("Vertex with key " << key << " already in map"); + } + VertexId2SizeMap[key] = smIt->second; } } } + // Single face if (GeomType == TopAbs_FACE){ HasSizeMapOnFace = true; - FaceId2SizeMap[TopoDS::Face(GeomShape).HashCode(471662)] = smIt->second; + if (! FacesWithSizeMap.Contains(TopoDS::Face(GeomShape))) { + key = FacesWithSizeMap.Add(TopoDS::Face(GeomShape)); + } + else { + key = FacesWithSizeMap.FindIndex(TopoDS::Face(GeomShape)); +// MESSAGE("Face with key " << key << " already in map"); + } + FaceId2SizeMap[key] = smIt->second; } + // Single edge if (GeomType == TopAbs_EDGE){ HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - EdgeId2SizeMap[TopoDS::Edge(GeomShape).HashCode(471662)] = smIt->second; + if (! EdgesWithSizeMap.Contains(TopoDS::Edge(GeomShape))) { + key = EdgesWithSizeMap.Add(TopoDS::Edge(GeomShape)); + } + else { + key = EdgesWithSizeMap.FindIndex(TopoDS::Edge(GeomShape)); +// MESSAGE("Edge with key " << key << " already in map"); + } + EdgeId2SizeMap[key] = smIt->second; } + // Single vertex if (GeomType == TopAbs_VERTEX){ HasSizeMapOnVertex = true; HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - VertexId2SizeMap[TopoDS::Vertex(GeomShape).HashCode(471662)] = smIt->second; + if (! VertecesWithSizeMap.Contains(TopoDS::Vertex(GeomShape))) { + key = VertecesWithSizeMap.Add(TopoDS::Vertex(GeomShape)); + } + else { + key = VertecesWithSizeMap.FindIndex(TopoDS::Vertex(GeomShape)); +// MESSAGE("Vertex with key " << key << " already in map"); + } + VertexId2SizeMap[key] = smIt->second; } } } @@ -510,60 +674,32 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsu MESSAGE("blsurf_set_attractor(): " << atIt->first << " = " << atIt->second); GeomShape = entryToShape(atIt->first); GeomType = GeomShape.ShapeType(); - + // Group Management + if (GeomType == TopAbs_COMPOUND){ + for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ + if (it.Value().ShapeType() == TopAbs_FACE){ + HasSizeMapOnFace = true; + createAttractorOnFace(it.Value(), atIt->second); + } + } + } + if (GeomType == TopAbs_FACE){ HasSizeMapOnFace = true; - - double xa, ya, za; // Coordinates of attractor point - double a, b; // Attractor parameter - int pos1, pos2; - // atIt->second has the following pattern: - // ATTRACTOR(xa;ya;za;a;b) - // where: - // xa;ya;za : coordinates of attractor - // a : desired size on attractor - // b : distance of influence of attractor - // - // We search the parameters in the string - pos1 = atIt->second.find(";"); - xa = atof(atIt->second.substr(10, pos1-10).c_str()); - pos2 = atIt->second.find(";", pos1+1); - ya = atof(atIt->second.substr(pos1+1, pos2-pos1-1).c_str()); - pos1 = pos2; - pos2 = atIt->second.find(";", pos1+1); - za = atof(atIt->second.substr(pos1+1, pos2-pos1-1).c_str()); - pos1 = pos2; - pos2 = atIt->second.find(";", pos1+1); - a = atof(atIt->second.substr(pos1+1, pos2-pos1-1).c_str()); - pos1 = pos2; - pos2 = atIt->second.find(")"); - b = atof(atIt->second.substr(pos1+1, pos2-pos1-1).c_str()); - - // Get the (u,v) values of the attractor on the face - gp_XY uvPoint = getUV(TopoDS::Face(GeomShape),gp_XYZ(xa,ya,za)); - Standard_Real u0 = uvPoint.X(); - Standard_Real v0 = uvPoint.Y(); - // We construct the python function - ostringstream attractorFunction; - attractorFunction << "def f(u,v): return "; - attractorFunction << _smp_phy_size << "-(" << _smp_phy_size <<"-" << a << ")"; - attractorFunction << "*exp(-((u-("<second); } + /* if (GeomType == TopAbs_EDGE){ HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - EdgeId2SizeMap[TopoDS::Edge(GeomShape).HashCode(471662)] = atIt->second; + EdgeId2SizeMap[TopoDS::Edge(GeomShape).HashCode(IntegerLast())] = atIt->second; } if (GeomType == TopAbs_VERTEX){ HasSizeMapOnVertex = true; HasSizeMapOnEdge = true; HasSizeMapOnFace = true; - VertexId2SizeMap[TopoDS::Vertex(GeomShape).HashCode(471662)] = atIt->second; + VertexId2SizeMap[TopoDS::Vertex(GeomShape).HashCode(IntegerLast())] = atIt->second; } */ } @@ -596,6 +732,11 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsu blsurf_set_param(bls, "verb", to_string(_verb).c_str()); } + + + + + status_t curv_fun(real t, real *uv, real *dt, real *dtt, void *user_data); status_t surf_fun(real *uv, real *xyz, real*du, real *dv, real *duu, real *duv, real *dvv, void *user_data); @@ -625,8 +766,16 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) blsurf_session_t *bls = blsurf_session_new(ctx); + FacesWithSizeMap.Clear(); + FaceId2SizeMap.clear(); + EdgesWithSizeMap.Clear(); + EdgeId2SizeMap.clear(); + VertecesWithSizeMap.Clear(); + VertexId2SizeMap.clear(); + MESSAGE("BEGIN SetParameters"); SetParameters(_hypothesis, bls); + MESSAGE("END SetParameters"); TopTools_IndexedMapOfShape fmap; TopTools_IndexedMapOfShape emap; @@ -634,8 +783,6 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) vector curves; vector surfaces; - - fmap.Clear(); FaceId2PythonSmp.clear(); emap.Clear(); @@ -648,42 +795,25 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) assert(Py_IsInitialized()); PyGILState_STATE gstate; gstate = PyGILState_Ensure(); -/* - Standard_Real u_min; - Standard_Real v_min; - Standard_Real u_max; - Standard_Real v_max; -*/ + + string theSizeMapStr; + + /**************************************************************************************** + FACES + *****************************************************************************************/ int iface = 0; string bad_end = "return"; + int faceKey = -1; for (TopExp_Explorer face_iter(aShape,TopAbs_FACE);face_iter.More();face_iter.Next()) { TopoDS_Face f=TopoDS::Face(face_iter.Current()); + if (fmap.FindIndex(f) > 0) continue; fmap.Add(f); iface++; surfaces.push_back(BRep_Tool::Surface(f)); - // Get bound values of uv surface - //BRep_Tool::Surface(f)->Bounds(u_min,u_max,v_min,v_max); - //MESSAGE("BRep_Tool::Surface(f)->Bounds(u_min,u_max,v_min,v_max): " << u_min << ", " << u_max << ", " << v_min << ", " << v_max); - - if ((HasSizeMapOnFace) && FaceId2SizeMap.find(f.HashCode(471662))!=FaceId2SizeMap.end()){ - MESSAGE("FaceId2SizeMap[f.HashCode(471662)].find(bad_end): " << FaceId2SizeMap[f.HashCode(471662)].find(bad_end)); - MESSAGE("FaceId2SizeMap[f.HashCode(471662)].size(): " << FaceId2SizeMap[f.HashCode(471662)].size()); - MESSAGE("bad_end.size(): " << bad_end.size()); - // check if function ends with "return" - if (FaceId2SizeMap[f.HashCode(471662)].find(bad_end) == (FaceId2SizeMap[f.HashCode(471662)].size()-bad_end.size()-1)) - continue; - // Expr To Python function, verification is performed at validation in GUI - PyObject * obj = NULL; - obj= PyRun_String(FaceId2SizeMap[f.HashCode(471662)].c_str(), Py_file_input, main_dict, NULL); - Py_DECREF(obj); - PyObject * func = NULL; - func = PyObject_GetAttrString(main_mod, "f"); - FaceId2PythonSmp[iface]=func; - FaceId2SizeMap.erase(f.HashCode(471662)); - } + cad_face_t *fce = cad_face_new(c, iface, surf_fun, surfaces.back()); cad_face_set_tag(fce, iface); if(f.Orientation() != TopAbs_FORWARD){ @@ -691,26 +821,95 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) } else { cad_face_set_orientation(fce, CAD_ORIENTATION_FORWARD); } - + + if (HasSizeMapOnFace){ + // Classic size map + faceKey = FacesWithSizeMap.FindIndex(f); + if (FaceId2SizeMap.find(faceKey)!=FaceId2SizeMap.end()){ + theSizeMapStr = FaceId2SizeMap[faceKey]; + // check if function ends with "return" + if (theSizeMapStr.find(bad_end) == (theSizeMapStr.size()-bad_end.size()-1)) + continue; + // Expr To Python function, verification is performed at validation in GUI + PyObject * obj = NULL; + obj= PyRun_String(theSizeMapStr.c_str(), Py_file_input, main_dict, NULL); + Py_DECREF(obj); + PyObject * func = NULL; + func = PyObject_GetAttrString(main_mod, "f"); + FaceId2PythonSmp[iface]=func; + FaceId2SizeMap.erase(faceKey); + } + + // Specific size map = Attractor + std::map >::iterator attractor_iter = FaceId2AttractorCoords.begin(); + int iatt=0; + for ( ; attractor_iter != FaceId2AttractorCoords.end(); ++attractor_iter ) { + if (attractor_iter->first == faceKey) { + MESSAGE("Face indice: " << iface); + MESSAGE("Adding enforced verteces"); + + double xyzCoords[3] = {attractor_iter->second[2], + attractor_iter->second[3], + attractor_iter->second[4]}; + + MESSAGE("Check position of vertex =(" << xyzCoords[0] << "," << xyzCoords[1] << "," << xyzCoords[2] << ")"); + gp_Pnt P(xyzCoords[0],xyzCoords[1],xyzCoords[2]); + BRepClass_FaceClassifier scl(f,P,1e-7); + // scl.Perform() is bugged. The function was rewritten +// scl.Perform(); + BRepClass_FaceClassifierPerform(&scl,f,P,1e-7); + TopAbs_State result = scl.State(); + MESSAGE("Position of point on face: "<second[0],attractor_iter->second[1]}; + iatt++; + MESSAGE("Add cad point on (u,v)=(" << uvCoords[0] << "," << uvCoords[1] << ") with id = " << iatt); + cad_point_t* point_p = cad_point_new(fce, iatt, uvCoords); + cad_point_set_tag(point_p, iatt); + } + FaceId2AttractorCoords.erase(faceKey); + } + } + } + + + /**************************************************************************************** + EDGES + *****************************************************************************************/ + int edgeKey = -1; for (TopExp_Explorer edge_iter(f,TopAbs_EDGE);edge_iter.More();edge_iter.Next()) { TopoDS_Edge e = TopoDS::Edge(edge_iter.Current()); int ic = emap.FindIndex(e); if (ic <= 0) - ic = emap.Add(e); + ic = emap.Add(e); double tmin,tmax; curves.push_back(BRep_Tool::CurveOnSurface(e, f, tmin, tmax)); - if ((HasSizeMapOnEdge) && EdgeId2SizeMap.find(e.HashCode(471662))!=EdgeId2SizeMap.end()){ - if (EdgeId2SizeMap[e.HashCode(471662)].find(bad_end) == (EdgeId2SizeMap[e.HashCode(471662)].size()-bad_end.size()-1)) - continue; - // Expr To Python function, verification is performed at validation in GUI - PyObject * obj = NULL; - obj= PyRun_String(EdgeId2SizeMap[e.HashCode(471662)].c_str(), Py_file_input, main_dict, NULL); - Py_DECREF(obj); - PyObject * func = NULL; - func = PyObject_GetAttrString(main_mod, "f"); - EdgeId2PythonSmp[ic]=func; - EdgeId2SizeMap.erase(e.HashCode(471662)); + + if (HasSizeMapOnEdge){ + edgeKey = EdgesWithSizeMap.FindIndex(e); + if (EdgeId2SizeMap.find(edgeKey)!=EdgeId2SizeMap.end()) { + theSizeMapStr = EdgeId2SizeMap[faceKey]; + if (theSizeMapStr.find(bad_end) == (theSizeMapStr.size()-bad_end.size()-1)) + continue; + // Expr To Python function, verification is performed at validation in GUI + PyObject * obj = NULL; + obj= PyRun_String(theSizeMapStr.c_str(), Py_file_input, main_dict, NULL); + Py_DECREF(obj); + PyObject * func = NULL; + func = PyObject_GetAttrString(main_mod, "f"); + EdgeId2PythonSmp[ic]=func; + EdgeId2SizeMap.erase(edgeKey); + } } cad_edge_t *edg = cad_edge_new(fce, ic, tmin, tmax, curv_fun, curves.back()); cad_edge_set_tag(edg, ic); @@ -723,40 +922,52 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) gp_Pnt2d e0 = curves.back()->Value(tmin); gp_Pnt ee0 = surfaces.back()->Value(e0.X(), e0.Y()); Standard_Real d1=0,d2=0; + + + /**************************************************************************************** + VERTECES + *****************************************************************************************/ + int vertexKey = -1; for (TopExp_Explorer ex_edge(e ,TopAbs_VERTEX); ex_edge.More(); ex_edge.Next()) { - TopoDS_Vertex v = TopoDS::Vertex(ex_edge.Current()); - ++npts; - if (npts == 1){ - ip = &ip1; - d1 = ee0.SquareDistance(BRep_Tool::Pnt(v)); - } else { - ip = &ip2; + TopoDS_Vertex v = TopoDS::Vertex(ex_edge.Current()); + ++npts; + if (npts == 1){ + ip = &ip1; + d1 = ee0.SquareDistance(BRep_Tool::Pnt(v)); + } else { + ip = &ip2; d2 = ee0.SquareDistance(BRep_Tool::Pnt(v)); - } - *ip = pmap.FindIndex(v); - if(*ip <= 0) - *ip = pmap.Add(v); - if ((HasSizeMapOnVertex) && VertexId2SizeMap.find(v.HashCode(471662))!=VertexId2SizeMap.end()){ - if (VertexId2SizeMap[v.HashCode(471662)].find(bad_end) == (VertexId2SizeMap[v.HashCode(471662)].size()-bad_end.size()-1)) - continue; - // Expr To Python function, verification is performed at validation in GUI - PyObject * obj = NULL; - obj= PyRun_String(VertexId2SizeMap[v.HashCode(471662)].c_str(), Py_file_input, main_dict, NULL); - Py_DECREF(obj); - PyObject * func = NULL; - func = PyObject_GetAttrString(main_mod, "f"); - VertexId2PythonSmp[*ip]=func; - VertexId2SizeMap.erase(v.HashCode(471662)); + } + *ip = pmap.FindIndex(v); + if(*ip <= 0) + *ip = pmap.Add(v); + + vertexKey = VertecesWithSizeMap.FindIndex(v); + if (HasSizeMapOnVertex){ + vertexKey = VertecesWithSizeMap.FindIndex(v); + if (VertexId2SizeMap.find(vertexKey)!=VertexId2SizeMap.end()){ + theSizeMapStr = VertexId2SizeMap[faceKey]; + if (theSizeMapStr.find(bad_end) == (theSizeMapStr.size()-bad_end.size()-1)) + continue; + // Expr To Python function, verification is performed at validation in GUI + PyObject * obj = NULL; + obj= PyRun_String(theSizeMapStr.c_str(), Py_file_input, main_dict, NULL); + Py_DECREF(obj); + PyObject * func = NULL; + func = PyObject_GetAttrString(main_mod, "f"); + VertexId2PythonSmp[*ip]=func; +// VertexId2SizeMap.erase(vertexKey); // do not erase if using a vector + } } } if (npts != 2) { - // should not happen - MESSAGE("An edge does not have 2 extremities."); + // should not happen + MESSAGE("An edge does not have 2 extremities."); } else { - if (d1 < d2) - cad_edge_set_extremities(edg, ip1, ip2); - else - cad_edge_set_extremities(edg, ip2, ip1); + if (d1 < d2) + cad_edge_set_extremities(edg, ip1, ip2); + else + cad_edge_set_extremities(edg, ip2, ip1); } } // for edge } //for face @@ -776,7 +987,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) int oldFEFlags = fedisableexcept( FE_ALL_EXCEPT ); #endif - status_t status = STATUS_ERROR; + status_t status = STATUS_ERROR; try { OCC_CATCH_SIGNALS; @@ -923,7 +1134,14 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) feenableexcept( oldFEFlags ); feclearexcept( FE_ALL_EXCEPT ); #endif - + + std::cout << "FacesWithSizeMap" << std::endl; + FacesWithSizeMap.Statistics(std::cout); + std::cout << "EdgesWithSizeMap" << std::endl; + EdgesWithSizeMap.Statistics(std::cout); + std::cout << "VertecesWithSizeMap" << std::endl; + VertecesWithSizeMap.Statistics(std::cout); + return true; } @@ -1327,3 +1545,52 @@ bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, return true; } + +//============================================================================= +/*! + * Rewritting of the BRepClass_FaceClassifier::Perform function which is bugged (CAS 6.3sp6) + * Following line was added: + * myExtrem.Perform(P); + */ +//============================================================================= +void BLSURFPlugin_BLSURF::BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, + const TopoDS_Face& face, + const gp_Pnt& P, + const Standard_Real Tol) +{ + //-- Voir BRepExtrema_ExtPF.cxx + BRepAdaptor_Surface Surf(face); + Standard_Real U1, U2, V1, V2; + BRepTools::UVBounds(face, U1, U2, V1, V2); + Extrema_ExtPS myExtrem; + myExtrem.Initialize(Surf, U1, U2, V1, V2, Tol, Tol); + myExtrem.Perform(P); + //---------------------------------------------------------- + //-- On cherche le point le plus proche , PUIS + //-- On le classifie. + Standard_Integer nbv = 0; // xpu + Standard_Real MaxDist = RealLast(); + Standard_Integer indice = 0; + if(myExtrem.IsDone()) { + nbv = myExtrem.NbExt(); + for (Standard_Integer i = 1; i <= nbv; i++) { + Standard_Real d = myExtrem.Value(i); + d = Abs(d); + if(d <= MaxDist) { + MaxDist = d; + indice = i; + } + } + } + if(indice) { + gp_Pnt2d Puv; + Standard_Real U1,U2; + myExtrem.Point(indice).Parameter(U1, U2); + Puv.SetCoord(U1, U2); + fc->Perform(face, Puv, Tol); + } + else { + fc->Perform(face, gp_Pnt2d(U1-1.0,V1 - 1.0), Tol); //-- NYI etc BUG PAS BEAU En attendant l acces a rejected + //-- le resultat est TopAbs_OUT; + } +} diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx index 6ee99a3..dcea89f 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx @@ -26,6 +26,7 @@ #ifndef _BLSURFPlugin_BLSURF_HXX_ #define _BLSURFPlugin_BLSURF_HXX_ + #include #include "SMESH_2D_Algo.hxx" #include "SMESH_Mesh.hxx" @@ -37,12 +38,16 @@ #include CORBA_CLIENT_HEADER(SALOMEDS) #include CORBA_CLIENT_HEADER(GEOM_Gen) #include "Utils_SALOME_Exception.hxx" - extern "C"{ #include "distene/blsurf.h" #include "distene/api.h" } +#include +#include +#include +#include + class BLSURFPlugin_Hypothesis; class TopoDS_Shape; @@ -75,6 +80,7 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo { private: void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, SMDS_MeshNode* node, const TopoDS_Shape& ed); + void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol); private: PyObject * main_mod; diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx index 815ea9d..da746c5 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx @@ -31,6 +31,7 @@ #include "utilities.h" #include +#include "boost/regex.hpp" //============================================================================= /*! @@ -549,8 +550,12 @@ void BLSURFPlugin_Hypothesis_i::SetAttractorEntry(const char* entry,const char* bool valueChanged = false; try { valueChanged = ( this->GetImpl()->GetAttractorEntry(entry) != attractor ); - if ( valueChanged ) + if ( valueChanged ) { + boost::regex re("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)\\)$"); + if (!boost::regex_match(string(attractor), re)) + throw std::invalid_argument("Error: an attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b;True|False)"); this->GetImpl()->SetAttractorEntry(entry, attractor); + } } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -647,7 +652,7 @@ BLSURFPlugin::string_array* BLSURFPlugin_Hypothesis_i::GetSizeMapEntries() return result._retn(); } -//============================================================================= +//============================================================================= BLSURFPlugin::string_array* BLSURFPlugin_Hypothesis_i::GetAttractorEntries() { @@ -669,27 +674,27 @@ BLSURFPlugin::string_array* BLSURFPlugin_Hypothesis_i::GetAttractorEntries() return result._retn(); } -//============================================================================= - -void BLSURFPlugin_Hypothesis_i::SetSizeMapEntries(const BLSURFPlugin::string_array& sizeMaps) - throw (SALOME::SALOME_Exception) -{ - ASSERT(myBaseImpl); - for (int i = 0; i < sizeMaps.length(); ++i) - { - string entry_sizemap = sizeMaps[i].in(); - int colonPos = entry_sizemap.find( '|' ); - string entry, sizemap; - if ( colonPos == string::npos ) // '|' separator not found - entry = entry_sizemap; - else { - entry = entry_sizemap.substr( 0, colonPos); - if ( colonPos < entry_sizemap.size()-1 && entry_sizemap[colonPos] != ' ') - sizemap = entry_sizemap.substr( colonPos+1 ); - } - this->GetImpl()->SetSizeMapEntry( entry.c_str(), sizemap.c_str() ); - } -} +//============================================================================= + +void BLSURFPlugin_Hypothesis_i::SetSizeMapEntries(const BLSURFPlugin::string_array& sizeMaps) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + for (int i = 0; i < sizeMaps.length(); ++i) + { + string entry_sizemap = sizeMaps[i].in(); + int colonPos = entry_sizemap.find( '|' ); + string entry, sizemap; + if ( colonPos == string::npos ) // '|' separator not found + entry = entry_sizemap; + else { + entry = entry_sizemap.substr( 0, colonPos); + if ( colonPos < entry_sizemap.size()-1 && entry_sizemap[colonPos] != ' ') + sizemap = entry_sizemap.substr( colonPos+1 ); + } + this->GetImpl()->SetSizeMapEntry( entry.c_str(), sizemap.c_str() ); + } +} //============================================================================= diff --git a/src/BLSURFPlugin/Makefile.am b/src/BLSURFPlugin/Makefile.am index ab7d026..77a8cea 100644 --- a/src/BLSURFPlugin/Makefile.am +++ b/src/BLSURFPlugin/Makefile.am @@ -61,5 +61,6 @@ libBLSURFEngine_la_CPPFLAGS = \ libBLSURFEngine_la_LDFLAGS = \ ../../idl/libSalomeIDLBLSURFPLUGIN.la \ $(BLSURF_LIBS) \ + $(BOOST_LIBS) -lboost_regex \ $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lStdMeshersEngine \ $(KERNEL_LDFLAGS) -lSalomeGenericObj