From 8c4f7988da41a8edc24d0e6a06d7114a7ea9bc5d Mon Sep 17 00:00:00 2001 From: gdd Date: Wed, 9 Feb 2011 13:54:43 +0000 Subject: [PATCH] rnc : first prototype working on a Sphere of radius 100 --- src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx | 221 +++++++++++++++----- src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx | 90 ++++---- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 11 + 3 files changed, 226 insertions(+), 96 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx index a4bc3d7..566fd25 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx @@ -1,4 +1,5 @@ #include "BLSURFPlugin_Attractor.hxx" +#include BLSURFPlugin_Attractor::BLSURFPlugin_Attractor () : _face(), @@ -14,7 +15,7 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor () _u1 (0.), _u2 (0.), _v1 (0.), - _v2 (0.){} + _v2 (0.){MESSAGE("construction d'un attracteur vide");} BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor) : _face(), @@ -34,47 +35,55 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape A { _face = Face; _attractorShape = Attractor; - _mapGrid = 50; + _mapGrid = 200; init(); } bool BLSURFPlugin_Attractor::init(){ - + MESSAGE("construction d'un attracteur"); Standard_Real u0,v0; int i,j ; _known.clear(); _trial.clear(); Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face); - Trial_Pnt TPnt(0,0,0); + Trial_Pnt TPnt(3,0); //TPnt(0,0,0); // Discretization of the parameters + MESSAGE("Calcul des bornes de la surface : "); aSurf->Bounds(_u1, _u2, _v1, _v2); // unusable in the generic case because the surface may be infinite (ok for prototype on a Sphere) + MESSAGE("u1 = "<<_u1<<" ,u2 = "<<_u2); + MESSAGE("v1 = "<<_v1<<" ,v2 = "<<_v2); double Ustep = (_u2 - _u1) / _mapGrid; double Vstep = (_v2 - _v1) / _mapGrid; for (i=0; i<=_mapGrid; i++){ _vectU.push_back(_u1+i*(_u2-_u1)/_mapGrid) ; - _vectV.push_back(_u1+i*(_u2-_u1)/_mapGrid) ; + _vectV.push_back(_v1+i*(_v2-_v1)/_mapGrid) ; } // Determination of the starting point - GeomAPI_ProjectPointOnSurf projector( point, surface ); + gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(_attractorShape)); + GeomAPI_ProjectPointOnSurf projector( P, aSurf ); projector.LowerDistanceParameters(u0,v0); + MESSAGE("u0 = "< temp(_mapGrid+1,std::numeric_limits::infinity()); // Set distance of all "far" points to Infinity + std::vector temp(_mapGrid+1,1.e+6); // Provisoirement infini = 10000 for (i=0; i<=_mapGrid; i++){ _DMap.push_back(temp); } + MESSAGE("DMap(0,0) : "<< _DMap[0][0]); _DMap[i0][j0] = 0.; // Set distance of starting point to 0. _buildMap(); // Computes the distance for all points of the discrete surface @@ -83,99 +92,199 @@ bool BLSURFPlugin_Attractor::init(){ 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 + return 0.1 * ( 1. + ( 0.5 * (_DMap[i][j] - 20. + abs(_DMap[i][j] - 20.)) ) ); // more generally: function of _DMap } -bool BLSURFPlugin_Attractor::_buildMap(){ - int i, j, k, n; - int ip, jp, kp, np; +bool BLSURFPlugin_Attractor::_buildMap(){ + + MESSAGE("building the map"); + int i, j, k, n; + int count = 0; + TPointSet::iterator pIt; + int ip, jp, kp, np; + int i0, j0; gp_Pnt P; gp_Vec D1U,D1V; double Guu, Gvv; //Diagonal components of the local metric tensor double du, dv; double D_Ref = 0.; double Dist = 0.; - bool Dist_changed = false; - IJ_Pnt Current_Pnt(0,0); - Trial_Pnt TPnt(0,0,0); + bool Dist_changed; + IJ_Pnt Current_Pnt(2,0); + Trial_Pnt TPnt(3,0);//TPnt(0,0,0); TTrialSet::iterator min; + TTrialSet::iterator found; + //TPointSet::iterator kn_found; Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face); - while (_trial.size() > 0){ - + while (_trial.size() > 0 && count < 40000){ + count++; + MESSAGE("boucle while : "<Ti; - int j0 = min->Tj; - Current_Pnt.Pi = i0; // Define it as the current point - Current_Pnt.Pj = j0; + i0 = (*min)[1];//min->Ti;//static_cast((*min)[1]); + j0 = (*min)[2];//min->Tj;//static_cast((*min)[2]); + MESSAGE("i0 = "< probleme"); + break; + } _known.insert(Current_Pnt); // Move it to _known and remove it from _trial + //MESSAGE(Current_Pnt[0]<<" , "<IsUPeriodic()){ // Periodic conditions in U - if (i > _mapGrid + 1){ + //MESSAGE("surface is not U periodique"); + if (i > _mapGrid ){ break; } else if (i < 0){ i++; } } - ip = i % _mapGrid+2; // We get a periodic index ip=modulo(i,N+2) so that i=-1->ip=N+1; i=0 -> ip=0 ; ... ; i=N+2 -> ip=0; - for (j=j0 - 1 ; j < j0 + 1 ; j++){ - if (!aSurf->IsVPeriodic()){ // Periodic conditions in V . - if (j > _mapGrid + 1){ + ip = (i + _mapGrid + 1) % (_mapGrid+1); // We get a periodic index ip=modulo(i,N+2) so that i=-1->ip=N; i=0 -> ip=0 ; ... ; i=N+1 -> ip=0; + for (j=j0 - 1 ; j <= j0 + 1 ; j++){ + //MESSAGE("boucle for sur j"); + if (!aSurf->IsVPeriodic()){ // Periodic conditions in V . + //MESSAGE("surface is not V periodique"); + if (j > _mapGrid ){ break; } else if (j < 0){ - j++; } + j++; + if (j<0){ + MESSAGE("j = "<D1(_vectU[ip],_vectV[jp],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 | + //MESSAGE("u ("<IsUPeriodic()){ // Periodic conditions in U - if(k > _mapGrid + 1){ - break; } + if(k > _mapGrid ){ + MESSAGE("Break"); + break; + } else if (k < 0){ k++; } } - kp = k % _mapGrid+2; // periodic index - for (n=j - 1 ; n < j + 1 ; n++){ - if (!aSurf->IsUPeriodic()){ // Periodic conditions in V - if(n > _mapGrid + 1){ - break; } + kp = (k + _mapGrid + 1) % (_mapGrid+1); // periodic index + //MESSAGE(" k = "<IsVPeriodic()){ // Periodic conditions in V + if(n > _mapGrid){ + MESSAGE("Break"); + break; + } else if (n < 0){ n++; } } - np = k % _mapGrid+2; - Current_Pnt.Pi = kp; - Current_Pnt.Pj = np; + np = (n + _mapGrid + 1) % (_mapGrid+1); + //MESSAGE(" n = "<(ip); + TPnt[2] = jp;//.Tj = jp;//[2] = static_cast(jp); + _DMap[ip][jp] = D_Ref; + //MESSAGE("TPnt[0] = "< result = _trial.insert(TPnt); +// if (result.second) { +// MESSAGE("Pnt : "< -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 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) const { +// if (&p1 && &p2){ +// return ( (p1.Pi < p2.Pi) || (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 p1, const Trial_Pnt p2) const { +// if (&p1 && &p2){ +// return ( (p1.dist < p2.dist) || +// (p1.dist == p2.dist && p1.Ti < p2.Ti) || +// (p1.dist == p2.dist && p1.Ti == p2.Ti && p1.Tj < p2.Tj) ) ; +// } +// else +// return false; +// } +// }; class BLSURFPlugin_Attractor { public: @@ -126,8 +133,11 @@ class BLSURFPlugin_Attractor { typedef std::vector TDiscreteParam; typedef std::vector< std::vector > TDistMap; - typedef std::set< IJ_Pnt, IJ_comp > TPointSet; - typedef std::set< Trial_Pnt, Trial_comp> TTrialSet; + typedef std::set< std::vector > TPointSet; + typedef std::set< std::vector > TTrialSet; + //typedef std::set< Trial_Pnt, Trial_comp > TTrialSet; + typedef std::vector Trial_Pnt; + typedef std::vector IJ_Pnt; private: diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index c75a0d7..89391e1 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -611,6 +611,17 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction TopoDS_Vertex myV = BRepBuilderAPI_MakeVertex(myP); BLSURFPlugin_Attractor myAttractor(TopoDS::Face(GeomShape),myV); FaceId2ClassAttractor[key] = myAttractor; + if(FaceId2ClassAttractor[key].GetFace().IsNull()){ + MESSAGE("face nulle "); + } + else + MESSAGE("face OK"); + + if (FaceId2ClassAttractor[key].GetAttractorShape().IsNull()){ + MESSAGE("pas de point"); + } + else + MESSAGE("point OK"); } ///////////////////////////////////////////////////////// -- 2.39.2