From c4e2a48fefb03aec3bf772c0ea77d4106f9419c6 Mon Sep 17 00:00:00 2001 From: gdd Date: Thu, 3 Feb 2011 09:56:06 +0000 Subject: [PATCH] rnc : first modifications to test the building of Attractors and the evaluation of the size --- src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx | 67 ++++++++-- src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx | 122 +++++++++++++------ src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 90 ++++++++++---- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx | 47 ++++++- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx | 15 ++- src/BLSURFPlugin/Makefile.am | 6 +- 6 files changed, 267 insertions(+), 80 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx index ccce23a..a4bc3d7 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx @@ -1,17 +1,52 @@ -BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor, int MapGrid){ +#include "BLSURFPlugin_Attractor.hxx" + +BLSURFPlugin_Attractor::BLSURFPlugin_Attractor () + : _face(), + _attractorShape(), + _vectU(), + _vectV(), + _DMap(), + _known(), + _trial(), + _mapGrid(-1), + _i0(-1), + _j0(-1), + _u1 (0.), + _u2 (0.), + _v1 (0.), + _v2 (0.){} + +BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor) + : _face(), + _attractorShape(), + _vectU(), + _vectV(), + _DMap(), + _known(), + _trial(), + _mapGrid(-1), + _i0(-1), + _j0(-1), + _u1 (0.), + _u2 (0.), + _v1 (0.), + _v2 (0.) +{ _face = Face; _attractorShape = Attractor; - _mapGrid = MapGrid; + _mapGrid = 50; init(); } bool BLSURFPlugin_Attractor::init(){ + Standard_Real u0,v0; + int i,j ; _known.clear(); _trial.clear(); Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face); - TPnt Trial_Pnt(0,0,0); + Trial_Pnt TPnt(0,0,0); // Discretization of the parameters aSurf->Bounds(_u1, _u2, _v1, _v2); // unusable in the generic case because the surface may be infinite (ok for prototype on a Sphere) @@ -23,6 +58,11 @@ bool BLSURFPlugin_Attractor::init(){ } // Determination of the starting point + GeomAPI_ProjectPointOnSurf projector( point, surface ); + projector.LowerDistanceParameters(u0,v0); + //gp_Pnt2d P = BRep_Tool::Parameters(TopoDS::Vertex(_attractorShape),_face); + //u0 = P.X(); + //v0 = P.Y(); int i0 = floor ( (u0 - _u1) * _mapGrid / (_u2 - _u1) + 0.5 ); int j0 = floor ( (v0 - _v1) * _mapGrid / (_v2 - _v1) + 0.5 ); TPnt.dist=0.; // Set distance to 0. @@ -31,16 +71,16 @@ bool BLSURFPlugin_Attractor::init(){ _trial.insert(TPnt); // Move starting point to _trial // Initialization of _DMap - std:vector temp(_mapGrid+1,numeric_limits::infinity()); // Set distance of all "far" points to Infinity + std::vector temp(_mapGrid+1,std::numeric_limits::infinity()); // Set distance of all "far" points to Infinity for (i=0; i<=_mapGrid; i++){ - DMap.push_back(temp); + _DMap.push_back(temp); } _DMap[i0][j0] = 0.; // Set distance of starting point to 0. _buildMap(); // Computes the distance for all points of the discrete surface } -double BLSURFPlugin_BLSURF::GetSize(double u, double v){ +double BLSURFPlugin_Attractor::GetSize(double u, double v){ int i = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 0.5 ); int j = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) + 0.5 ); return _DMap[i][j]; // more generally: function of _DMap @@ -57,15 +97,16 @@ bool BLSURFPlugin_Attractor::_buildMap(){ double D_Ref = 0.; double Dist = 0.; bool Dist_changed = false; - Current_Pnt = IJ_Pnt(0,0); - TPnt Trial_Pnt(0,0,0); + IJ_Pnt Current_Pnt(0,0); + Trial_Pnt TPnt(0,0,0); TTrialSet::iterator min; + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face); while (_trial.size() > 0){ min = _trial.begin(); // Get trial point with min distance from start - i0 = min->Ti; - j0 = min->Tj; + int i0 = min->Ti; + int j0 = min->Tj; Current_Pnt.Pi = i0; // Define it as the current point Current_Pnt.Pj = j0; _known.insert(Current_Pnt); // Move it to _known and remove it from _trial @@ -93,7 +134,7 @@ bool BLSURFPlugin_Attractor::_buildMap(){ aSurf->D1(_vectU[i],_vectV[j],P,D1U,D1V); // Calculate the metric at (i,j) Guu = D1U.X()*D1U.X() + D1U.Y()*D1U.Y() + D1U.Z()*D1U.Z(); // Guu = ||dS/du||**2 G(i,j)= | ||dS/du||**2 0 | assuming that the isolines are orthogonal in 3D space Gvv = D1V.X()*D1V.X() + D1V.Y()*D1V.Y() + D1V.Z()*D1V.Z(); // Gvv = ||dS/dv||**2 | 0 ||dS/dv||**2 | - D_Ref = DMap[ip][jp]; // Set a ref. distance to the value in DMap (may be infinite or uncertain) + D_Ref = _DMap[ip][jp]; // Set a ref. distance to the value in DMap (may be infinite or uncertain) TPnt.dist = D_Ref; // Store the point as a trial point TPnt.Ti = ip; TPnt.Tj = jp; @@ -118,8 +159,8 @@ bool BLSURFPlugin_Attractor::_buildMap(){ Current_Pnt.Pj = np; if (_known.find( Current_Pnt ) != _known.end()){ // If distance of the neighbour is known // Calculate the distance from (k,n) - du = (k-i) * Ustep; - dv = (n-j) * Vstep; + du = (k-i) * (_u2 - _u1) / _mapGrid; + dv = (n-j) * (_v2 - _v1) / _mapGrid; Dist = _DMap[kp][np] + Guu * du*du + Gvv * dv*dv; // ds**2 = du'Gdu + dv'Gdv (we assume Guv=Gvu=0) if (Dist < D_Ref) { // If smaller than ref. distance -> update ref. distance D_Ref = Dist; diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx index ece0508..26844b0 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx @@ -30,18 +30,99 @@ #include #include #include +#include + +// OPENCASCADE includes +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifndef WNT +#include +#endif +#include +#include +#include +#include +#include +#include +class IJ_Pnt{ + public: + IJ_Pnt(int i,int j){ + Pi=i; + Pj=j; + } + int Pi; + int Pj; +}; + +class IJ_comp{ + public: + bool operator() (const IJ_Pnt p1, const IJ_Pnt p2) { + if (&p1 && &p2) + return ((p1.Pi < p2.Pi) && (p1.Pj < p2.Pj)); + else + return (&p1 < &p2); + } +}; + +class Trial_Pnt{ + public: + Trial_Pnt(int i,int j,double d){ + Ti=i; + Tj=j; + dist=d; + } + int Ti; + int Tj; + double dist; +}; + +class Trial_comp { + public: + bool operator() (const Trial_Pnt me, const Trial_Pnt other) const { + return (&me && &other) ? (me.dist < other.dist) : (&me < &other); + } +}; + class BLSURFPlugin_Attractor { public: - BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor, int MapGrid); + BLSURFPlugin_Attractor (); + // TODO ~BLSURFPlugin_Attractor (); + BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor); bool init(); // Calculates the discrete points correponding to attractor, initialises the map and calls _buildMap double GetSize (double u, double v); TopoDS_Face GetFace(){ return _face;} - TopoDS_Shape GetAttractor(){ return _attractorShape;} - bool SetAttractor(TopoDS_Shape Attractor){ _attractorShape = Attractor; } + TopoDS_Shape GetAttractorShape(){ return _attractorShape;} + bool SetAttractorShape(TopoDS_Shape Attractor){ _attractorShape = Attractor; } typedef std::vector TDiscreteParam; typedef std::vector< std::vector > TDistMap; @@ -64,42 +145,7 @@ class BLSURFPlugin_Attractor { bool _buildMap(); // Builds the map of distances between source point and any point (u,v) }; -class IJ_Pnt{ - public: - IJ_Pnt(int i,int j){ - Pi=i; - Pj=j; - } - int Pi; - int Pj; -}; - -class IJ_comp{ - bool operator() (const IJ_Pnt p1, const IJ_Pnt p2) { - if (&p1 && &p2) - return ((p1.Pi < p2.Pi) && (p1.Pj < p2.Pj)); - else - return (&p1 < &p2); - } -}; - -class Trial_Pnt{ - public: - Trial_Pnt(int i,int j,double d){ - Ti=i; - Tj=j; - dist=d; - } - int Ti; - int Tj; - double dist; -}; -class Trial_comp { - bool operator() (const Trial_Pnt me, const Trial_Pnt other) const { - return (&me && &other) ? (me.dist < other.dist) : (&me < &other); - } -}; diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 12d7146..f0ff61e 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -26,6 +26,7 @@ // #include "BLSURFPlugin_BLSURF.hxx" #include "BLSURFPlugin_Hypothesis.hxx" +#include "BLSURFPlugin_Attractor.hxx" extern "C"{ #include @@ -72,9 +73,11 @@ extern "C"{ #include #include +#include #include #include #include +#include #include #include @@ -211,6 +214,7 @@ std::map EdgeId2PythonSmp; std::map VertexId2PythonSmp; std::map > FaceId2AttractorCoords; +std::map FaceId2ClassAttractor; TopTools_IndexedMapOfShape FacesWithEnforcedVertices; std::map< int, std::set< std::vector > > FaceId2EnforcedVertexCoords; @@ -219,6 +223,7 @@ std::map< std::vector, std::vector > EnfVertex2ProjVertex; bool HasSizeMapOnFace=false; bool HasSizeMapOnEdge=false; bool HasSizeMapOnVertex=false; +bool HasAttractorOnFace=false; //============================================================================= /*! @@ -600,6 +605,11 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction MESSAGE("Creating node on ("<second.empty() ) { +// // MESSAGE("blsurf_set_attractor(): " << AtIt->first << " = " << AtIt->second); +// GeomShape = entryToShape(AtIt->first); +// AttShape = entryToShape(AtIt->second); +// GeomType = GeomShape.ShapeType(); +// // Group Management +// // if (GeomType == TopAbs_COMPOUND){ +// // for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ +// // if (it.Value().ShapeType() == TopAbs_FACE){ +// // HasAttractorOnFace = true; +// // myAttractor = BLSURFPluginAttractor(GeomShape, AttShape); +// // } +// // } +// // } +// +// if (GeomType == TopAbs_FACE){ +// HasAttractorOnFace = true; +// myAttractor = BLSURFPlugin_Attractor(TopoDS::Face(GeomShape), AttShape); +// } +// +// } +// } + // // Enforced Vertices @@ -1668,31 +1709,32 @@ status_t size_on_surface(integer face_id, real *uv, real *size, void *user_data) } if (FaceId2PythonSmp.count(face_id) != 0){ - PyObject * pyresult = NULL; - PyObject* new_stderr = NULL; - assert(Py_IsInitialized()); - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - pyresult = PyObject_CallFunction(FaceId2PythonSmp[face_id],"(f,f)",uv[0],uv[1]); - double result; - if ( pyresult == NULL){ - fflush(stderr); - string err_description=""; - new_stderr = newPyStdOut(err_description); - PySys_SetObject("stderr", new_stderr); - PyErr_Print(); - PySys_SetObject("stderr", PySys_GetObject("__stderr__")); - Py_DECREF(new_stderr); - MESSAGE("Can't evaluate f(" << uv[0] << "," << uv[1] << ")" << " error is " << err_description); - result = *((double*)user_data); - } - else { - result = PyFloat_AsDouble(pyresult); - Py_DECREF(pyresult); - } +// PyObject * pyresult = NULL; +// PyObject* new_stderr = NULL; +// assert(Py_IsInitialized()); +// PyGILState_STATE gstate; +// gstate = PyGILState_Ensure(); +// pyresult = PyObject_CallFunction(FaceId2PythonSmp[face_id],"(f,f)",uv[0],uv[1]); +// double result; +// if ( pyresult == NULL){ +// fflush(stderr); +// string err_description=""; +// new_stderr = newPyStdOut(err_description); +// PySys_SetObject("stderr", new_stderr); +// PyErr_Print(); +// PySys_SetObject("stderr", PySys_GetObject("__stderr__")); +// Py_DECREF(new_stderr); +// MESSAGE("Can't evaluate f(" << uv[0] << "," << uv[1] << ")" << " error is " << err_description); +// result = *((double*)user_data); +// } +// else { +// result = PyFloat_AsDouble(pyresult); +// Py_DECREF(pyresult); +// } + double result = FaceId2ClassAttractor[face_id].GetSize(uv[0],uv[1]); *size = result; //MESSAGE("f(" << uv[0] << "," << uv[1] << ")" << " = " << result); - PyGILState_Release(gstate); + //PyGILState_Release(gstate); } else { *size = *((double*)user_data); diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index bcb0a0e..3ac6ce4 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -25,6 +25,7 @@ // --- // #include "BLSURFPlugin_Hypothesis.hxx" +#include "BLSURFPlugin_Attractor.hxx" #include #include #include @@ -50,6 +51,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, _verb( GetDefaultVerbosity() ), _sizeMap(GetDefaultSizeMap()), _attractors(GetDefaultSizeMap()), + _classAttractors(GetDefaultAttractorMap()), _enfVertexList(GetDefaultEnfVertexList()), _entryEnfVertexListMap(GetDefaultEntryEnfVertexListMap()) /* TODO GROUPS @@ -418,12 +420,45 @@ BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(c return hyp ? hyp->_GetAttractorEntries():GetDefaultSizeMap(); } +//======================================================================= +//function : SetClassAttractorEntry +//======================================================================= +void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry,const std::string& att_entry) // TODO finir +{ + if (!_classAttractors[entry].compare(att_entry)){ + _classAttractors[entry] = att_entry; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetClassAttractorEntry +//======================================================================= +std::string BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry) +{ + TAttractorMap::iterator it = _classAttractors.find( entry ); + if ( it != _classAttractors.end() ) + return it->second; + else + return "No_Such_Entry"; +} + + /*! + * \brief Return the attractor instances + */ +BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) +{ + return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap(); +} + + //======================================================================= //function : ClearEntry //======================================================================= void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) { TSizeMap::iterator it = _sizeMap.find( entry ); + if ( it != _sizeMap.end() ) { _sizeMap.erase(it); NotifySubMeshesHypothesisModification(); @@ -434,8 +469,15 @@ void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) _attractors.erase(itAt); NotifySubMeshesHypothesisModification(); } - else - std::cout<<"No_Such_Entry"< TAttractorMap; + + void SetClassAttractorEntry(const std::string& entry,const std::string& att_entry); + std::string GetClassAttractorEntry(const std::string& entry); + const TAttractorMap& _GetClassAttractorEntries() const { return _classAttractors; } + /*! + * \brief Return the attractors entries + */ + static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp); + /*! * To set/get/unset an enforced vertex @@ -192,7 +203,8 @@ public: static bool GetDefaultQuadAllowed(); static bool GetDefaultDecimesh(); static int GetDefaultVerbosity() { return 10; } - static TSizeMap GetDefaultSizeMap() { return TSizeMap();} + static TSizeMap GetDefaultSizeMap() { return TSizeMap(); } + static TAttractorMap GetDefaultAttractorMap() { return TAttractorMap(); } static TEnfVertexList GetDefaultEnfVertexList() { return TEnfVertexList(); } static TEntryEnfVertexListMap GetDefaultEntryEnfVertexListMap() { return TEntryEnfVertexListMap(); } /* TODO GROUPS @@ -250,6 +262,7 @@ private: TOptionNames _doubleOptions, _charOptions; TSizeMap _sizeMap; TSizeMap _attractors; + TAttractorMap _classAttractors; TEnfVertexList _enfVertexList; TEntryEnfVertexListMap _entryEnfVertexListMap; /* TODO GROUPS diff --git a/src/BLSURFPlugin/Makefile.am b/src/BLSURFPlugin/Makefile.am index 5be9a3f..e0c37eb 100644 --- a/src/BLSURFPlugin/Makefile.am +++ b/src/BLSURFPlugin/Makefile.am @@ -29,7 +29,8 @@ salomeinclude_HEADERS = \ BLSURFPlugin_BLSURF.hxx \ BLSURFPlugin_BLSURF_i.hxx \ BLSURFPlugin_Hypothesis.hxx \ - BLSURFPlugin_Hypothesis_i.hxx + BLSURFPlugin_Hypothesis_i.hxx \ + BLSURFPlugin_Attractor.hxx # Libraries targets lib_LTLIBRARIES = libBLSURFEngine.la @@ -39,7 +40,8 @@ dist_libBLSURFEngine_la_SOURCES = \ BLSURFPlugin_BLSURF_i.cxx \ BLSURFPlugin_Hypothesis.cxx \ BLSURFPlugin_Hypothesis_i.cxx \ - BLSURFPlugin_i.cxx + BLSURFPlugin_i.cxx \ + BLSURFPlugin_Attractor.cxx libBLSURFEngine_la_CPPFLAGS = \ $(QT_INCLUDES) \ -- 2.39.2