From 4f38a00a8e37b1636d0fba62a86e6ae92f253767 Mon Sep 17 00:00:00 2001 From: gdd Date: Mon, 11 Apr 2011 13:47:39 +0000 Subject: [PATCH] rnc : Make possible to define an attractor as a Wire --- src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx | 206 +++++++++++--------- src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx | 6 +- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 5 +- 3 files changed, 119 insertions(+), 98 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx index 0f9478f..364adb1 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx @@ -99,7 +99,6 @@ bool BLSURFPlugin_Attractor::init(){ _known.clear(); _trial.clear(); Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face); - Trial_Pnt TPnt(3,0); // Calculation of the bounds of the face ShapeAnalysis::GetFaceUVBounds(_face,_u1,_u2,_v1,_v2); @@ -130,7 +129,8 @@ bool BLSURFPlugin_Attractor::init(){ } // Determination of the starting points - if (_attractorShape.ShapeType() == TopAbs_VERTEX){ + if (_attractorShape.ShapeType() == TopAbs_VERTEX){ + Trial_Pnt TPnt(3,0); gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(_attractorShape)); GeomAPI_ProjectPointOnSurf projector( P, aSurf ); projector.LowerDistanceParameters(u0,v0); @@ -144,32 +144,48 @@ bool BLSURFPlugin_Attractor::init(){ _trial.insert(TPnt); // Move starting point to _trial } else if (_attractorShape.ShapeType() == TopAbs_EDGE){ - gp_Pnt2d P2; - double first; - double last; - Handle(Geom2d_Curve) aCurve2d; - Handle(Geom_Curve) aCurve3d = BRep_Tool::Curve (TopoDS::Edge(_attractorShape), first, last); - ShapeConstruct_ProjectCurveOnSurface curveProjector; - curveProjector.Init(aSurf, Precision::Confusion()); - curveProjector.PerformAdvanced (aCurve3d, first, last, aCurve2d); - // TEST - //int N = 20 * (last - first) / _step; // If the edge is a circle : 4>Pi so the number of points on the edge should be good -> 5 for ellipses - int N = 1200; - MESSAGE("Initialisation des points de départ") - for (i=0; i<=N; i++){ - P2 = aCurve2d->Value(first + i * (last-first) / N); - i0 = floor( (P2.X() - _u1) * _gridU / (_u2 - _u1) + 0.5 ); - j0 = floor( (P2.Y() - _v1) * _gridV / (_v2 - _v1) + 0.5 ); - //MESSAGE("i0 = "<Value(first + i * (last-first) / N); + i0 = floor( (P2.X() - _u1) * _gridU / (_u2 - _u1) + 0.5 ); + j0 = floor( (P2.Y() - _v1) * _gridV / (_v2 - _v1) + 0.5 ); +// MESSAGE("i0 = "<IsUPeriodic()){ // Periodic conditions in U - if (i > _gridU ){ - break; } - else if (i < 0){ - i++; } - } + if (i > _gridU ){ + break; } + else if (i < 0){ + i++; } + } ip = (i + _gridU + 1) % (_gridU+1); // We get a periodic index : for (j=j0 - 1 ; j <= j0 + 1 ; j++){ // ip=modulo(i,N+2) so that i=-1->ip=N; i=0 -> ip=0 ; ... ; i=N+1 -> ip=0; - if (!aSurf->IsVPeriodic()){ // Periodic conditions in V . - if (j > _gridV ){ - break; } - else if (j < 0){ - j++; - } - } - jp = (j + _gridV + 1) % (_gridV+1); - - if (!_known[ip][jp]){ // If the distance is not known yet - aSurf->D1(_vectU[ip],_vectV[jp],P,D1U,D1V); // Calculate the metric at (i,j) - // G(i,j) = | ||dS/du||**2 * | - // | ||dS/dv||**2 | - Guu = D1U.X()*D1U.X() + D1U.Y()*D1U.Y() + D1U.Z()*D1U.Z(); // Guu = ||dS/du||**2 - Gvv = D1V.X()*D1V.X() + D1V.Y()*D1V.Y() + D1V.Z()*D1V.Z(); // Gvv = ||dS/dv||**2 - Guv = D1U.X()*D1V.X() + D1U.Y()*D1V.Y() + D1U.Z()*D1V.Z(); // Guv = Gvu = < dS/du,dS/dv > - D_Ref = _DMap[ip][jp]; // Set a ref. distance of the point to its value in _DMap - TPnt[0] = D_Ref; // (may be infinite or uncertain) - TPnt[1] = ip; - TPnt[2] = jp; - Dist_changed = false; - // Loop on neighbours to calculate the min distance from them --------------------------------------------------------------------------------- - for (k=i - 1 ; k <= i + 1 ; k++){ - if (!aSurf->IsUPeriodic()){ // Periodic conditions in U - if(k > _gridU ){ - break; - } - else if (k < 0){ - k++; } - } - kp = (k + _gridU + 1) % (_gridU+1); // periodic index - for (n=j - 1 ; n <= j + 1 ; n++){ - if (!aSurf->IsVPeriodic()){ // Periodic conditions in V - if(n > _gridV){ - break; - } - else if (n < 0){ - n++; } - } - np = (n + _gridV + 1) % (_gridV+1); - if (_known[kp][np]){ // If the distance of the neighbour is known - // Calculate the distance from (k,n) - du = (k-i) * (_u2 - _u1) / _gridU; - dv = (n-j) * (_v2 - _v1) / _gridV; - Dist = _DMap[kp][np] + sqrt( Guu * du*du + 2*Guv * du*dv + Gvv * dv*dv ); // ds**2 = du'Gdu + 2*du'Gdv + dv'Gdv (G is always symetrical) - if (Dist < D_Ref) { // If smaller than ref. distance -> update ref. distance - D_Ref = Dist; - Dist_changed = true; - } - } - } - } // End of the loop on neighbours -------------------------------------------------------------------------------------------------------------- - if (Dist_changed) { // If distance has been updated, update _trial - found=_trial.find(TPnt); - if (found != _trial.end()){ - _trial.erase(found); // Erase the point if it was already in _trial - } - TPnt[0] = D_Ref; - TPnt[1] = ip; - TPnt[2] = jp; - _DMap[ip][jp] = D_Ref; // Set it distance to the minimum distance found during the loop above - _trial.insert(TPnt); // Insert it (or reinsert it) in _trial - } - } // if + if (!aSurf->IsVPeriodic()){ // Periodic conditions in V . + if (j > _gridV ){ + break; } + else if (j < 0){ + j++; + } + } + jp = (j + _gridV + 1) % (_gridV+1); + + if (!_known[ip][jp]){ // If the distance is not known yet + aSurf->D1(_vectU[ip],_vectV[jp],P,D1U,D1V); // Calculate the metric at (i,j) + // G(i,j) = | ||dS/du||**2 * | + // | ||dS/dv||**2 | + Guu = D1U.X()*D1U.X() + D1U.Y()*D1U.Y() + D1U.Z()*D1U.Z(); // Guu = ||dS/du||**2 + Gvv = D1V.X()*D1V.X() + D1V.Y()*D1V.Y() + D1V.Z()*D1V.Z(); // Gvv = ||dS/dv||**2 + Guv = D1U.X()*D1V.X() + D1U.Y()*D1V.Y() + D1U.Z()*D1V.Z(); // Guv = Gvu = < dS/du,dS/dv > + D_Ref = _DMap[ip][jp]; // Set a ref. distance of the point to its value in _DMap + TPnt[0] = D_Ref; // (may be infinite or uncertain) + TPnt[1] = ip; + TPnt[2] = jp; + Dist_changed = false; + // Loop on neighbours to calculate the min distance from them --------------------------------------------------------------------------------- + for (k=i - 1 ; k <= i + 1 ; k++){ + if (!aSurf->IsUPeriodic()){ // Periodic conditions in U + if(k > _gridU ){ + break; + } + else if (k < 0){ + k++; } + } + kp = (k + _gridU + 1) % (_gridU+1); // periodic index + for (n=j - 1 ; n <= j + 1 ; n++){ + if (!aSurf->IsVPeriodic()){ // Periodic conditions in V + if(n > _gridV){ + break; + } + else if (n < 0){ + n++; } + } + np = (n + _gridV + 1) % (_gridV+1); + if (_known[kp][np]){ // If the distance of the neighbour is known + // Calculate the distance from (k,n) + du = (k-i) * (_u2 - _u1) / _gridU; + dv = (n-j) * (_v2 - _v1) / _gridV; + Dist = _DMap[kp][np] + sqrt( Guu * du*du + 2*Guv * du*dv + Gvv * dv*dv ); // ds**2 = du'Gdu + 2*du'Gdv + dv'Gdv (G is always symetrical) + if (Dist < D_Ref) { // If smaller than ref. distance -> update ref. distance + D_Ref = Dist; + Dist_changed = true; + } + } + } + } // End of the loop on neighbours -------------------------------------------------------------------------------------------------------------- + if (Dist_changed) { // If distance has been updated, update _trial + found=_trial.find(TPnt); + if (found != _trial.end()){ + _trial.erase(found); // Erase the point if it was already in _trial + } + TPnt[0] = D_Ref; + TPnt[1] = ip; + TPnt[2] = jp; + _DMap[ip][jp] = D_Ref; // Set it distance to the minimum distance found during the loop above + _trial.insert(TPnt); // Insert it (or reinsert it) in _trial + } + } // end if (!_known[ip][jp]) } // for } // for } // while (_trial) diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx index 74260d6..12e2691 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx @@ -91,6 +91,8 @@ class BLSURFPlugin_Attractor { BLSURFPlugin_Attractor (const TopoDS_Face& Face, const TopoDS_Shape& Attractor, const std::string& attEntry, double Step = 0.015); bool init(); // Calculates the discrete points correponding to attractor // and intialises the map of distances + void edgeInit(Handle(Geom_Surface) aSurf, const TopoDS_Edge& anEdge); + double GetSize (double u, double v); TopoDS_Face GetFace() const { return _face; } TopoDS_Shape GetAttractorShape() const { return _attractorShape; } @@ -108,7 +110,7 @@ class BLSURFPlugin_Attractor { void BuildMap(); // Builds the map of distances between source point and any point P(u,v) bool IsMapBuilt() const { return _isMapBuilt; } // Controls if the map has been built - bool Empty() const { return _isEmpty; } + bool Empty() const { return _isEmpty; } typedef std::vector TDiscreteParam; typedef std::vector< std::vector > TDistMap; @@ -128,7 +130,7 @@ class BLSURFPlugin_Attractor { TPointSet _known; TTrialSet _trial; int _type; // Type of function used to calculate the size from the distance (unused for now) - double _step; // Step between to value of the discretized parametric space in U or V direction + double _step; // Step between two values of the discretized parametric space in U or V direction int _gridU; // Number of grid points in U direction int _gridV; // Number of grid points in V direction double _u1, _u2, _v1, _v2; // Bounds of the parametric space of the face diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 0ddcb93..b5b631d 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -899,7 +899,10 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, // } // } - if (GeomType == TopAbs_FACE && (AttShape.ShapeType() == TopAbs_VERTEX || AttShape.ShapeType() == TopAbs_EDGE)){ + if (GeomType == TopAbs_FACE + && (AttShape.ShapeType() == TopAbs_VERTEX + || AttShape.ShapeType() == TopAbs_EDGE + || AttShape.ShapeType() == TopAbs_WIRE)){ HasSizeMapOnFace = true; if (! FacesWithSizeMap.Contains(TopoDS::Face(GeomShape)) ) { key = FacesWithSizeMap.Add(TopoDS::Face(GeomShape) ); -- 2.39.2