From 7be417ddab5116fd9497a525947ccb68a41a7e73 Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 15 Feb 2011 14:43:08 +0000 Subject: [PATCH] rnc : added a rule to calculate the refinement of the discretized surface used to estimate distances on the surface. --- src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx | 112 ++++++++++++------- src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx | 15 ++- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 14 +-- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx | 25 +++-- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx | 2 +- 5 files changed, 110 insertions(+), 58 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx index eabda47..0a67798 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx @@ -1,5 +1,7 @@ #include "BLSURFPlugin_Attractor.hxx" #include +#include +#include // cascade include #include "ShapeAnalysis.hxx" @@ -7,12 +9,14 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor () : _face(), _attractorShape(), + _step(0), + _gridU(0), + _gridV(0), _vectU(), _vectV(), _DMap(), _known(), _trial(), - _mapGrid(-1), _u1 (0.), _u2 (0.), _v1 (0.), @@ -25,15 +29,17 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor () _isMapBuilt(false), _isEmpty(true){ MESSAGE("construction of a void attractor"); } -BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (const TopoDS_Face& Face, const TopoDS_Shape& Attractor, int MapGrid) +BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (const TopoDS_Face& Face, const TopoDS_Shape& Attractor, double Step) : _face(), _attractorShape(), + _step(Step), + _gridU(), + _gridV(), _vectU(), _vectV(), _DMap(), _known(), _trial(), - _mapGrid(MapGrid), _u1 (0.), _u2 (0.), _v1 (0.), @@ -70,11 +76,15 @@ bool BLSURFPlugin_Attractor::init(){ ShapeAnalysis::GetFaceUVBounds(_face,_u1,_u2,_v1,_v2); 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(_v1+i*(_v2-_v1)/_mapGrid) ; + _gridU = floor (_u2 - _u1) / _step; + _gridV = floor (_v2 - _v1) / _step; +// double Ustep = (_u2 - _u1) / _mapGrid; +// double Vstep = (_v2 - _v1) / _mapGrid; + for (i=0; i<=_gridU; i++){ + _vectU.push_back(_u1+i*(_u2-_u1)/_gridU) ; + } + for (j=0; j<=_gridV; j++){ + _vectV.push_back(_v1+j*(_v2-_v1)/_gridV) ; } // Determination of the starting point @@ -85,8 +95,8 @@ bool BLSURFPlugin_Attractor::init(){ //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 ); + int i0 = floor ( (u0 - _u1) * _gridU / (_u2 - _u1) + 0.5 ); + int j0 = floor ( (v0 - _v1) * _gridV / (_v2 - _v1) + 0.5 ); MESSAGE("i0 = "< temp(_mapGrid+1,1.e+6); // Provisoirement infini = 10000 - for (i=0; i<=_mapGrid; i++){ + std::vector temp(_gridV+1,1.e+6); // Provisoirement infini = 10000 + for (i=0; i<=_gridU; i++){ _DMap.push_back(temp); } - std::vector temp2(_mapGrid+1,false); - for (i=0; i<=_mapGrid; i++){ + std::vector temp2(_gridV+1,false); + for (i=0; i<=_gridU; i++){ _known.push_back(temp2); } MESSAGE("DMap(0,0) : "<< _DMap[0][0]); @@ -121,11 +131,19 @@ void BLSURFPlugin_Attractor::SetParameters(double Start_Size, double End_Size, d double BLSURFPlugin_Attractor::_distance(double u, double v){ // // calcul des coins du carre -// int i_sup = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 1. ); -// int j_sup = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) + 1. ); +// double stepU = (_u2 - _u1) / _gridU ; +// double stepV = (_v2 - _v1) / _gridV ; +// +// int i_sup = floor ( fabs(u - _u1) / stepU ) + 1; +// int j_sup = floor ( fabs(v - _v1) / stepV ) + 1; +// i_sup = std::min( i_sup, _gridU); +// j_sup = std::min( j_sup, _gridV); +// // -// int i_inf = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) ); -// int j_inf = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) ); +// // int i_inf = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) ); +// // int j_inf = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) ); +// int i_inf = i_sup - 1; +// int j_inf = j_sup - 1; // // double u_sup = _vectU[i_sup]; // double v_sup = _vectV[j_sup]; @@ -133,18 +151,29 @@ double BLSURFPlugin_Attractor::_distance(double u, double v){ // double u_inf = _vectU[i_inf]; // double v_inf = _vectV[j_inf]; // +// // MESSAGE("i_inf , i_sup, j_inf, j_sup = "< u_sup+v_sup); @@ -155,12 +184,19 @@ double BLSURFPlugin_Attractor::_distance(double u, double v){ // else { // d = P_sup; // } +// +// return d; - int i = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 0.5 ); - int j = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) + 0.5 ); + // BLSURF seems to perform a linear interpolation so it's sufficient to give it a non-continuous distance map + int i = floor ( (u - _u1) * _gridU / (_u2 - _u1) + 0.5 ); + int j = floor ( (v - _v1) * _gridV / (_v2 - _v1) + 0.5 ); + +// int i = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) ); +// int j = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) ); return _DMap[i][j]; + } double BLSURFPlugin_Attractor::GetSize(double u, double v){ @@ -175,8 +211,6 @@ double BLSURFPlugin_Attractor::GetSize(double u, double v){ return _startSize + ( 0.5 * (_distance(u,v) - _constantRadius + abs(_distance(u,v) - _constantRadius)) ) ; break; } - //return 1 + ( 0.5 * (_distance(u,v) - _constantRadius + abs(_distance(u,v) - _constantRadius)) ) ; - //return 30 - 29 * exp( - 0.5 * (_distance(u,v) - _constantRadius + abs(_distance(u,v) - _constantRadius)) / _actionRadius ) ; } @@ -241,17 +275,17 @@ void BLSURFPlugin_Attractor::BuildMap(){ //MESSAGE("boucle for sur i"); if (!aSurf->IsUPeriodic()){ // Periodic conditions in U //MESSAGE("surface is not U periodique"); - if (i > _mapGrid ){ + if (i > _gridU ){ break; } else if (i < 0){ i++; } } - 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; + ip = (i + _gridU + 1) % (_gridU+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 ){ + if (j > _gridV ){ break; } else if (j < 0){ j++; @@ -261,7 +295,7 @@ void BLSURFPlugin_Attractor::BuildMap(){ } } } - jp = (j + _mapGrid + 1) % (_mapGrid+1); + jp = (j + _gridV + 1) % (_gridV+1); //jp=j; // Current_Pnt[0] = ip; // Define the neighbour as current point // Current_Pnt[1] = jp; @@ -293,34 +327,34 @@ void BLSURFPlugin_Attractor::BuildMap(){ for (k=i - 1 ; k <= i + 1 ; k++){ //MESSAGE("boucle for sur k"); if (!aSurf->IsUPeriodic()){ // Periodic conditions in U - if(k > _mapGrid ){ + if(k > _gridU ){ MESSAGE("Break"); break; } else if (k < 0){ k++; } } - kp = (k + _mapGrid + 1) % (_mapGrid+1); // periodic index + kp = (k + _gridU + 1) % (_gridU+1); // periodic index //MESSAGE(" k = "<IsVPeriodic()){ // Periodic conditions in V - if(n > _mapGrid){ + if(n > _gridV){ MESSAGE("Break"); break; } else if (n < 0){ n++; } } - np = (n + _mapGrid + 1) % (_mapGrid+1); + np = (n + _gridV + 1) % (_gridV+1); //MESSAGE(" n = "<first << " = " << AtIt->second); GeomShape = entryToShape(AtIt->first); - AttShape = AtIt->second.GetAttractorShape(); + AttShape = AtIt->second->GetAttractorShape(); GeomType = GeomShape.ShapeType(); // Group Management // if (GeomType == TopAbs_COMPOUND){ @@ -1122,7 +1122,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) } // Class Attractors - std::map::iterator clAttractor_iter = FaceId2ClassAttractor.find(faceKey); + std::map::iterator clAttractor_iter = FaceId2ClassAttractor.find(faceKey); if (clAttractor_iter != FaceId2ClassAttractor.end()){ MESSAGE("Face indice: " << iface); MESSAGE("Adding attractor"); @@ -1785,8 +1785,8 @@ status_t size_on_surface(integer face_id, real *uv, real *size, void *user_data) } if (FaceIndex2ClassAttractor.count(face_id) !=0){ MESSAGE("List of attractor is not empty") - MESSAGE("Attractor empty : "<< FaceIndex2ClassAttractor[face_id].Empty()) - double result = FaceIndex2ClassAttractor[face_id].GetSize(uv[0],uv[1]); + MESSAGE("Attractor empty : "<< FaceIndex2ClassAttractor[face_id]->Empty()) + double result = FaceIndex2ClassAttractor[face_id]->GetSize(uv[0],uv[1]); *size = result; MESSAGE("f(" << uv[0] << "," << uv[1] << ")" << " = " << result); } diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index 0b2bbb2..e1775c9 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -31,6 +31,9 @@ #include #include +// cascade include +#include "ShapeAnalysis.hxx" + //============================================================================= BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, SMESH_Gen * gen) @@ -428,6 +431,7 @@ BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(c void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const TopoDS_Face& FaceShape, const TopoDS_Shape& AttractorShape, double StartSize, double EndSize, double ActionRadius, double ConstantRadius) // TODO finir { + //double Step = _phyMin; pas connu a ce stade // The new attractor can't be defined on the same face as another sizemap TSizeMap::iterator it = _sizeMap.find( entry ); if ( it != _sizeMap.end() ) { @@ -441,18 +445,23 @@ void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, NotifySubMeshesHypothesisModification(); } } - BLSURFPlugin_Attractor myAttractor; - if (!_classAttractors[entry].GetAttractorShape().IsSame(AttractorShape)){ - myAttractor = BLSURFPlugin_Attractor(FaceShape, AttractorShape); //TODO calculer MapGrid - myAttractor.BuildMap(); - myAttractor.SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); + + bool attExists = (_classAttractors.find(entry) != _classAttractors.end()); + double u1,u2,v1,v2, diag; + if ( !attExists || (attExists && !_classAttractors[entry]->GetAttractorShape().IsSame(AttractorShape))){ + ShapeAnalysis::GetFaceUVBounds(FaceShape,u1,u2,v1,v2); + diag = sqrt((u2 - u1) * (u2 - u1) + (v2 - v1) * (v2 - v1)); + BLSURFPlugin_Attractor* myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, 0.005 * diag); //TODO calculer MapGrid + myAttractor->BuildMap(); + //MESSAGE("Step = "<SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); _classAttractors[entry] = myAttractor; NotifySubMeshesHypothesisModification(); } else { - _classAttractors[entry].SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); - if (!myAttractor.IsMapBuilt()){ - myAttractor.BuildMap(); + _classAttractors[entry]->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); + if (!_classAttractors[entry]->IsMapBuilt()){ + _classAttractors[entry]->BuildMap(); } NotifySubMeshesHypothesisModification(); } diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx index 743f90d..b8eec1b 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx @@ -130,7 +130,7 @@ public: const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; } */ - typedef std::map TAttractorMap; + typedef std::map TAttractorMap; void SetClassAttractorEntry(const std::string& entry, const TopoDS_Face& FaceShape, const TopoDS_Shape& AttractorShape, double StartSize, double EndSize, double ActionRadius, double ConstantRadius); std::string GetClassAttractorEntry(const std::string& entry); -- 2.39.2