#include "BLSURFPlugin_Attractor.hxx"
#include <utilities.h>
+#include <algorithm>
+#include <cmath>
// cascade include
#include "ShapeAnalysis.hxx"
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.),
_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.),
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
//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 = "<<i0<<" ,j0 = "<<j0);
TPnt[0]=0.;//.dist=0.; // Set distance to 0.
TPnt[1]=i0;//.Ti=i0;
// Initialization of _DMap
//std::vector<double> temp(_mapGrid+1,std::numeric_limits<double>::infinity()); // Set distance of all "far" points to Infinity
- std::vector<double> temp(_mapGrid+1,1.e+6); // Provisoirement infini = 10000
- for (i=0; i<=_mapGrid; i++){
+ std::vector<double> temp(_gridV+1,1.e+6); // Provisoirement infini = 10000
+ for (i=0; i<=_gridU; i++){
_DMap.push_back(temp);
}
- std::vector<bool> temp2(_mapGrid+1,false);
- for (i=0; i<=_mapGrid; i++){
+ std::vector<bool> temp2(_gridV+1,false);
+ for (i=0; i<=_gridU; i++){
_known.push_back(temp2);
}
MESSAGE("DMap(0,0) : "<< _DMap[0][0]);
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];
// double u_inf = _vectU[i_inf];
// double v_inf = _vectV[j_inf];
//
+// // MESSAGE("i_inf , i_sup, j_inf, j_sup = "<<i_inf<<" , "<<i_sup<<" , "<<j_inf<<" , "<<j_sup)
+// // MESSAGE("u = "<<u<<", _u1 ="<<_u1)
+// // MESSAGE("(u - _u1) / stepU = "<< (u - _u1) / stepU)
// double d1 = _DMap[i_sup][j_sup];
// double d2 = _DMap[i_sup][j_inf];
// double d3 = _DMap[i_inf][j_sup];
// double d4 = _DMap[i_inf][j_inf];
//
-// double P_inf = d4 * ( 1 + (u - u_inf) / (u_inf - u_sup) + (v - v_inf) / (v_inf - v_sup) )
-// + d3 * ( (v - v_inf) / (v_sup - v_inf) )
-// + d2 * ( (u - u_inf) / (u_sup - u_inf) ) ;
+// //double d = 0.25 * (d1 + d2 + d3 + d4);
+// //double d = d1;
+// //
+// // if (fabs(v_inf-v_sup) < 1e-14 || fabs(u_inf-u_sup) < 1e-14 ){
+// // MESSAGE("division par zero v_inf-v_sup = "<< fabs(v_inf-v_sup)<<" , u_inf-u_sup"<<fabs(u_inf-u_sup))
+// // MESSAGE("v_inf = "<< v_inf<<" , v_sup"<<v_sup)
+// // MESSAGE("u_inf = "<< u_inf<<" , u_sup"<<u_sup)
+// // }
+// double P_inf = d4 * ( 1 + (u_inf - u) / stepU + (v_inf - v) / stepV )
+// + d3 * ( (v - v_inf) / stepV )
+// + d2 * ( (u - u_inf) / stepU ) ;
//
-// double P_sup = d1 * ( 1 + (u - u_sup) / (u_sup - u_inf) + (v - v_sup) / (v_sup - v_inf) )
-// + d3 * ( (u - u_sup) / (u_inf - u_sup) )
-// + d2 * ( (v - v_sup) / (v_inf - v_sup) ) ;
+// double P_sup = d1 * ( 1 + (u - u_sup) / stepU + (v - v_sup) / stepV )
+// + d3 * ( (u_sup - u) / stepU )
+// + d2 * ( (v_sup - v) / stepV ) ;
//
// // calcul de la distance (interpolation lineaire)
// bool P_switch = (u+v > u_sup+v_sup);
// 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){
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 ) ;
}
//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++;
}
}
}
- 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;
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 = "<<k<<" ; kp = "<<kp);
for (n=j - 1 ; n <= j + 1 ; n++){
//MESSAGE("boucle for sur n");
if (!aSurf->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 = "<<n<<" ; np = "<<np);
// Current_Pnt[0] = kp;
// Current_Pnt[1] = np;
if (_known[kp][np]){//.find( Current_Pnt ) != _known.end()){ // If distance of the neighbour is known
// Calculate the distance from (k,n)
//MESSAGE("La distance du point ( "<<kp<<","<<np<<" ) de min(_trial) est connue");
- du = (k-i) * (_u2 - _u1) / _mapGrid;
- dv = (n-j) * (_v2 - _v1) / _mapGrid;
+ du = (k-i) * (_u2 - _u1) / _gridU;
+ dv = (n-j) * (_v2 - _v1) / _gridV;
Dist = _DMap[kp][np] + sqrt( Guu * du*du + Gvv * dv*dv + 2*Guv * du*dv); // ds**2 = du'Gdu + dv'Gdv + 2*du'Gdv (G is symetrical)
//MESSAGE("D_Ref = "<<D_Ref);
//MESSAGE("Dist = "<<Dist);
} // for
} // for
} // while (_trial)
-// _known.clear();
+ _known.clear();
_trial.clear();
_isMapBuilt = true;
std::map<int,PyObject*> VertexId2PythonSmp;
std::map<int,std::vector<double> > FaceId2AttractorCoords;
-std::map<int,BLSURFPlugin_Attractor> FaceId2ClassAttractor;
-std::map<int,BLSURFPlugin_Attractor> FaceIndex2ClassAttractor;
+std::map<int,BLSURFPlugin_Attractor*> FaceId2ClassAttractor;
+std::map<int,BLSURFPlugin_Attractor*> FaceIndex2ClassAttractor;
TopTools_IndexedMapOfShape FacesWithEnforcedVertices;
std::map< int, std::set< std::vector<double> > > FaceId2EnforcedVertexCoords;
int key=-1;
BLSURFPlugin_Hypothesis::TAttractorMap::const_iterator AtIt = class_attractors.begin();
for ( ; AtIt != class_attractors.end(); ++AtIt ) {
- if ( !AtIt->second.Empty() ) {
+ if ( !AtIt->second->Empty() ) {
// MESSAGE("blsurf_set_attractor(): " << AtIt->first << " = " << AtIt->second);
GeomShape = entryToShape(AtIt->first);
- AttShape = AtIt->second.GetAttractorShape();
+ AttShape = AtIt->second->GetAttractorShape();
GeomType = GeomShape.ShapeType();
// Group Management
// if (GeomType == TopAbs_COMPOUND){
}
// Class Attractors
- std::map<int,BLSURFPlugin_Attractor >::iterator clAttractor_iter = FaceId2ClassAttractor.find(faceKey);
+ std::map<int,BLSURFPlugin_Attractor* >::iterator clAttractor_iter = FaceId2ClassAttractor.find(faceKey);
if (clAttractor_iter != FaceId2ClassAttractor.end()){
MESSAGE("Face indice: " << iface);
MESSAGE("Adding attractor");
}
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);
}
#include <iostream>
#include <sstream>
+// cascade include
+#include "ShapeAnalysis.hxx"
+
//=============================================================================
BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
SMESH_Gen * gen)
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() ) {
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 = "<<Step)
+ myAttractor->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();
}