_known(),
_trial(),
_mapGrid(-1),
- _i0(-1),
- _j0(-1),
_u1 (0.),
_u2 (0.),
_v1 (0.),
- _v2 (0.){MESSAGE("construction d'un attracteur vide");}
+ _v2 (0.),
+ _startSize(-1),
+ _endSize(-1),
+ _actionRadius(-1),
+ _constantRadius(-1),
+ _type(-1),
+ _isMapBuilt(false),
+ _isEmpty(true){ MESSAGE("construction of a void attractor"); }
-BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor)
+BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (const TopoDS_Face& Face, const TopoDS_Shape& Attractor, int MapGrid)
: _face(),
_attractorShape(),
_vectU(),
_DMap(),
_known(),
_trial(),
- _mapGrid(-1),
- _i0(-1),
- _j0(-1),
+ _mapGrid(MapGrid),
_u1 (0.),
_u2 (0.),
_v1 (0.),
- _v2 (0.)
+ _v2 (0.),
+ _startSize(-1),
+ _endSize(-1),
+ _actionRadius(-1),
+ _constantRadius(-1),
+ _type(0),
+ _isMapBuilt(false),
+ _isEmpty(false)
{
_face = Face;
_attractorShape = Attractor;
- _mapGrid = 200;
+ //_mapGrid = 200;
init();
}
MESSAGE("construction d'un attracteur");
Standard_Real u0,v0;
int i,j ;
- _known.clear();
+ //_known.clear();
_trial.clear();
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face);
Trial_Pnt TPnt(3,0); //TPnt(0,0,0);
for (i=0; i<=_mapGrid; i++){
_DMap.push_back(temp);
}
+ std::vector<bool> temp2(_mapGrid+1,false);
+ for (i=0; i<=_mapGrid; i++){
+ _known.push_back(temp2);
+ }
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
+ // _buildMap(); // Computes the distance for all points of the discrete surface
}
-double BLSURFPlugin_Attractor::GetSize(double u, double v){
+
+void BLSURFPlugin_Attractor::SetParameters(double Start_Size, double End_Size, double Action_Radius, double Constant_Radius){
+ _startSize = Start_Size;
+ _endSize = End_Size;
+ _actionRadius = Action_Radius;
+ _constantRadius = Constant_Radius;
+ MESSAGE("_startSize = "<<_startSize<<"; _endSize = "<<_endSize<<" ; _actionRadius = "<<_actionRadius<<" ; _constantRadius = "<<_constantRadius)
+}
+
+double BLSURFPlugin_Attractor::_distance(double u, double v){
// // calcul des coins du carre
// int i_sup = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 1. );
int i = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 0.5 );
int j = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) + 0.5 );
- double d = _DMap[i][j];
-
- return 1 + ( 0.5 * (d - 20. + abs(d - 20.)) ) ; // more generally: function of _DMap
+ return _DMap[i][j];
+
+}
+double BLSURFPlugin_Attractor::GetSize(double u, double v){
+
+ double myDist = 0.5 * (_distance(u,v) - _constantRadius + abs(_distance(u,v) - _constantRadius));
+ switch(_type)
+ {
+ case TYPE_EXP:
+ return _endSize - (_endSize - _startSize) * exp(- myDist * myDist / (_actionRadius * _actionRadius) );
+ break;
+ case TYPE_LIN:
+ 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 ) ;
+
}
-bool BLSURFPlugin_Attractor::_buildMap(){
+
+void BLSURFPlugin_Attractor::BuildMap(){
MESSAGE("building the map");
int i, j, k, n;
int count = 0;
- TPointSet::iterator pIt;
+ //TPointSet::iterator pIt;
int ip, jp, kp, np;
int i0, j0;
gp_Pnt P;
//TPointSet::iterator kn_found;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face);
- while (_trial.size() > 0 && count < 40000){
+ while (_trial.size() > 0 && count < 1000000){
count++;
MESSAGE("boucle while : "<<count);
min = _trial.begin(); // Get trial point with min distance from start
j0 = (*min)[2];//min->Tj;//static_cast<int>((*min)[2]);
MESSAGE("i0 = "<<i0<<" ,j0 = "<<j0<<" *min[0] = "<<(*min)[0]);
//MESSAGE("d(i0,j0) = "<<min->dist);//(*min)[0]);
- Current_Pnt[0] = i0; // Define it as the current point
- Current_Pnt[1] = j0;
+// Current_Pnt[0] = i0; // Define it as the current point
+// Current_Pnt[1] = j0;
//if (i0 == 23 && j0 == 49){
//MESSAGE(" point 23 49 insere dans known");
//break;
//}
- pIt =_known.find( Current_Pnt );
+// pIt =_known.find( Current_Pnt );
/*if (*pIt == test){
MESSAGE(" point 23 49 insere dans known");
break;
}*/
- if (pIt != _known.end()){
- MESSAGE("point "<<(*pIt)[0]<<" , "<<(*pIt)[1]<<" deja dans _known -> probleme");
- break;
- }
- _known.insert(Current_Pnt); // Move it to _known and remove it from _trial
+// if (pIt != _known.end()){
+// MESSAGE("point "<<(*pIt)[0]<<" , "<<(*pIt)[1]<<" deja dans _known -> probleme");
+// break;
+// }
+// _known.insert(Current_Pnt); // Move it to _known and remove it from _trial
+ _known[i0][j0] = true; // Move point to "Known"
//MESSAGE(Current_Pnt[0]<<" , "<<Current_Pnt[1]<<" insere dans known")
//MESSAGE("known contient : "<<_known.size()<<"elements");
//MESSAGE(" d("<<i0<<" , "<<j0<<") ="<<_DMap[i0][j0]);
}
jp = (j + _mapGrid + 1) % (_mapGrid+1);
//jp=j;
- Current_Pnt[0] = ip; // Define the neighbour as current point
- Current_Pnt[1] = jp;
+// Current_Pnt[0] = ip; // Define the neighbour as current point
+// Current_Pnt[1] = jp;
//MESSAGE("i = "<<i<<" ; j = "<<j);
//MESSAGE("ip = "<<ip<<" ; jp = "<<jp);
- pIt = _known.find( Current_Pnt );
+// pIt = _known.find( Current_Pnt );
//MESSAGE("found a point in Known with i = "<<(*pIt)[0]<<"j = "<<(*pIt)[1]);
- if (_known.find( Current_Pnt ) == _known.end()){ // If the distance is not known
+ if (!_known[ip][jp]){ //.find( Current_Pnt ) == _known.end()){ // If the distance is not known
//MESSAGE("Le voisin "<<ip<<","<<jp<<" de min(_trial) n'est pas dans _known");
aSurf->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 * |
}
np = (n + _mapGrid + 1) % (_mapGrid+1);
//MESSAGE(" n = "<<n<<" ; np = "<<np);
- Current_Pnt[0] = kp;
- Current_Pnt[1] = np;
- if (_known.find( Current_Pnt ) != _known.end()){ // If distance of the neighbour is known
+// 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;
} // for
} // for
} // while (_trial)
+// _known.clear();
+ _trial.clear();
+ _isMapBuilt = true;
-} // _buildMap()
+} // end of BuildMap()
// File : BLSURFPlugin_Attractor.hxx
// Authors : Renaud Nédélec (OCC)
// ---
+//
+// The algorithm used to calculate the distance on a non-euclidian parametric surface has been found in the ref. below:
+//
+// Ref:"Accurate Anisotropic Fast Marching for Diffusion-Based Geodesic Tractography"
+// S. Jbabdi, P. Bellec, R. Toro, Daunizeau, M. Pélégrini-Issac, and H. Benali1
//
+
#ifndef _BLSURFPlugin_Attractor_HXX_
#define _BLSURFPlugin_Attractor_HXX_
#include <stdexcept>
#include <string>
#include <limits>
+#include <utilities.h>
// OPENCASCADE includes
#include <BRep_Tool.hxx>
#include <gp_XYZ.hxx>
#include <TopTools_MapOfShape.hxx>
+#define TYPE_EXP 0
+#define TYPE_LIN 1
+
// class IJ_Pnt{
// public:
public:
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
+ BLSURFPlugin_Attractor (const TopoDS_Face& Face, const TopoDS_Shape& Attractor, int MapGrid = 200);
+ 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 GetAttractorShape(){ return _attractorShape; }
+ TopoDS_Face GetFace() const { return _face; }
+ TopoDS_Shape GetAttractorShape() const { return _attractorShape; }
+
+ void SetParameters(double Start_Size, double End_Size, double Action_Radius, double Constant_Radius);
+ void SetType(int type){ _type = type; }
// bool SetAttractorShape(TopoDS_Shape Attractor){
// _attractorShape = Attractor;
// }
+ void BuildMap(); // Builds the map of distances between source point and any point P(u,v)
+ bool IsMapBuilt() const { return _isMapBuilt; }
+ bool Empty() const { return _isEmpty; }
+
typedef std::vector<double> TDiscreteParam;
typedef std::vector< std::vector<double> > TDistMap;
- typedef std::set< std::vector<int> > TPointSet;
+ //typedef std::set< std::vector<int> > TPointSet;
+ typedef std::vector< std::vector<bool> > TPointSet;
typedef std::set< std::vector<double> > TTrialSet;
//typedef std::set< Trial_Pnt, Trial_comp > TTrialSet;
typedef std::vector<double> Trial_Pnt;
TDistMap _DMap;
TPointSet _known;
TTrialSet _trial;
- int _mapGrid; // Number of grid points in U and V directions
- double _u1, _u2, _v1, _v2; // Bounds of the parametric space of the face
- int _i0, _j0; // Indices of the starting point
+ int _type; // Type of function used to calculate the size from the distance
+ int _mapGrid; // Number of grid points in U and V directions
+ double _u1, _u2, _v1, _v2; // Bounds of the parametric space of the face
+ double _startSize, _endSize;
+ double _actionRadius, _constantRadius;
- bool _buildMap(); // Builds the map of distances between source point and any point P(u,v)
+ //bool _buildMap(); // Builds the map of distances between source point and any point P(u,v)
+ bool _isMapBuilt;
+ bool _isEmpty;
+ double _distance(double u, double v);
};
std::map<int,std::vector<double> > FaceId2AttractorCoords;
std::map<int,BLSURFPlugin_Attractor> FaceId2ClassAttractor;
+std::map<int,BLSURFPlugin_Attractor> FaceIndex2ClassAttractor;
TopTools_IndexedMapOfShape FacesWithEnforcedVertices;
std::map< int, std::set< std::vector<double> > > FaceId2EnforcedVertexCoords;
bool HasSizeMapOnFace=false;
bool HasSizeMapOnEdge=false;
bool HasSizeMapOnVertex=false;
-bool HasAttractorOnFace=false;
+//bool HasAttractorOnFace=false;
//=============================================================================
/*!
EdgeId2PythonSmp.clear();
VertexId2PythonSmp.clear();
FaceId2AttractorCoords.clear();
+ FaceId2ClassAttractor.clear();
FacesWithEnforcedVertices.Clear();
FaceId2EnforcedVertexCoords.clear();
EnfVertex2ProjVertex.clear();
attractorFunctionStream << "def f(u,v): return ";
attractorFunctionStream << _smp_phy_size << "-(" << _smp_phy_size <<"-" << a << ")";
//attractorFunctionStream << "*exp(-((u-("<<u0<<"))*(u-("<<u0<<"))+(v-("<<v0<<"))*(v-("<<v0<<")))/(" << b << "*" << b <<"))";
- // rnc make possible to keep the size constant until
- // a defined distance distance is expressed as the positiv part
+ // rnc: make possible to keep the size constant until
+ // a defined distance. Distance is expressed as the positiv part
// of r-d where r is the distance to (u0,v0)
attractorFunctionStream << "*exp(-(0.5*(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"+abs(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"))/(" << b << "))**2)";
MESSAGE("Creating node on ("<<x0<<","<<y0<<","<<z0<<")");
FaceId2AttractorCoords[key] = coords;
}
- // Test for new attractors
- gp_Pnt myP(xyzPoint);
- 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");
+// // Test for new attractors
+// gp_Pnt myP(xyzPoint);
+// TopoDS_Vertex myV = BRepBuilderAPI_MakeVertex(myP);
+// BLSURFPlugin_Attractor myAttractor(TopoDS::Face(GeomShape),myV,200);
+// myAttractor.SetParameters(a, _smp_phy_size, b, d);
+// myAttractor.SetType(1);
+// 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");
}
/////////////////////////////////////////////////////////
//
// Attractors
//
+ // TODO appeler le constructeur des attracteurs directement ici
MESSAGE("Setting Attractors");
const BLSURFPlugin_Hypothesis::TSizeMap attractors = BLSURFPlugin_Hypothesis::GetAttractorEntries(hyp);
BLSURFPlugin_Hypothesis::TSizeMap::const_iterator atIt = attractors.begin();
}
// Class Attractors
- // TODO temporary commented out for testing
+ // temporary commented out for testing
+ // TODO
+ // - Fill in the BLSURFPlugin_Hypothesis::TAttractorMap map in the hypothesis
+ // - Uncomment and complete this part to construct the attractors from the attractor shape and the passed parameters on each face of the map
+ // - To do this use the public methodss: SetParameters(several double parameters) and SetType(int type)
+ // OR, even better:
+ // - Construct the attractors with an empty dist. map in the hypothesis
+ // - build the map here for each face with an attractor set and only if the attractor shape as changed since the last call to _buildmap()
+ // -> define a bool _mapbuilt in the class that is set to false by default and set to true when calling _buildmap() OK
-// BLSURFPlugin_Attractor myAttractor;
-// const BLSURFPlugin_Hypothesis::TAttractorMap class_attractors = BLSURFPlugin_Hypothesis::GetClassAttractorEntries(hyp);
-// BLSURFPlugin_Hypothesis::TSizeMap::const_iterator AtIt = class_attractors.begin();
-// for ( ; AtIt != class_attractors.end(); ++atIt ) {
-// if ( !AtIt->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);
+ const BLSURFPlugin_Hypothesis::TAttractorMap class_attractors = BLSURFPlugin_Hypothesis::GetClassAttractorEntries(hyp);
+ int key=-1;
+ BLSURFPlugin_Hypothesis::TAttractorMap::const_iterator AtIt = class_attractors.begin();
+ for ( ; AtIt != class_attractors.end(); ++AtIt ) {
+ if ( !AtIt->second.Empty() ) {
+ // MESSAGE("blsurf_set_attractor(): " << AtIt->first << " = " << AtIt->second);
+ GeomShape = entryToShape(AtIt->first);
+ AttShape = AtIt->second.GetAttractorShape();
+ 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 && AttShape.ShapeType() == TopAbs_VERTEX){
+ HasSizeMapOnFace = true;
+ if (! FacesWithSizeMap.Contains(TopoDS::Face(GeomShape)) ) {
+ key = FacesWithSizeMap.Add(TopoDS::Face(GeomShape) );
+ }
+ else {
+ key = FacesWithSizeMap.FindIndex(TopoDS::Face(GeomShape));
+// MESSAGE("Face with key " << key << " already in map");
+ }
+ FaceId2ClassAttractor[key] = AtIt->second;
+ }
+ else{
+ MESSAGE("Wrong shape type !!")
+ }
+
+ }
+ }
+
//
FacesWithSizeMap.Clear();
FaceId2SizeMap.clear();
+ FaceId2ClassAttractor.clear();
EdgesWithSizeMap.Clear();
EdgeId2SizeMap.clear();
VerticesWithSizeMap.Clear();
string bad_end = "return";
int faceKey = -1;
int ienf = 0;
+ BLSURFPlugin_Attractor myAttractor;
for (TopExp_Explorer face_iter(aShape,TopAbs_FACE);face_iter.More();face_iter.Next()) {
TopoDS_Face f=TopoDS::Face(face_iter.Current());
}
if (HasSizeMapOnFace){
+ MESSAGE("A size map is defined on a face")
// std::cout << "A size map is defined on a face" << std::endl;
// Classic size map
faceKey = FacesWithSizeMap.FindIndex(f);
}
}
+ // Class Attractors
+ std::map<int,BLSURFPlugin_Attractor >::iterator clAttractor_iter = FaceId2ClassAttractor.find(faceKey);
+ if (clAttractor_iter != FaceId2ClassAttractor.end()){
+ MESSAGE("Face indice: " << iface);
+ MESSAGE("Adding attractor");
+ FaceIndex2ClassAttractor[iface]=clAttractor_iter->second;
+ FaceId2ClassAttractor.erase(clAttractor_iter);
+ }
+ }
+
// Enforced Vertices
faceKey = FacesWithEnforcedVertices.FindIndex(f);
std::map<int,std::set<std::vector<double> > >::const_iterator evmIt = FaceId2EnforcedVertexCoords.find(faceKey);
}
// else
// std::cout << "No enforced vertex defined" << std::endl;
- }
+// }
/****************************************************************************************
}
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],(char *)"(f,f)",uv[0],uv[1]);
-// double result;
-// if ( pyresult == NULL){
-// fflush(stderr);
-// string err_description="";
-// new_stderr = newPyStdOut(err_description);
-// PySys_SetObject((char *)"stderr", new_stderr);
-// PyErr_Print();
-// PySys_SetObject((char *)"stderr", PySys_GetObject((char *)"__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;
+ PyObject * pyresult = NULL;
+ PyObject* new_stderr = NULL;
+ assert(Py_IsInitialized());
+ PyGILState_STATE gstate;
+ gstate = PyGILState_Ensure();
+ pyresult = PyObject_CallFunction(FaceId2PythonSmp[face_id],(char *)"(f,f)",uv[0],uv[1]);
+ double result;
+ if ( pyresult == NULL){
+ fflush(stderr);
+ string err_description="";
+ new_stderr = newPyStdOut(err_description);
+ PySys_SetObject((char *)"stderr", new_stderr);
+ PyErr_Print();
+ PySys_SetObject((char *)"stderr", PySys_GetObject((char *)"__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);
+ }
//MESSAGE("f(" << uv[0] << "," << uv[1] << ")" << " = " << result);
//PyGILState_Release(gstate);
}
+ 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]);
+ *size = result;
+ MESSAGE("f(" << uv[0] << "," << uv[1] << ")" << " = " << result);
+ }
else {
+ MESSAGE("List of attractor is empty !!!")
*size = *((double*)user_data);
}
return STATUS_OK;
//=======================================================================
//function : SetClassAttractorEntry
//=======================================================================
-void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry,const std::string& att_entry) // TODO finir
+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
{
- if (!_classAttractors[entry].compare(att_entry)){
- _classAttractors[entry] = att_entry;
+
+ // The new attractor can't be defined on the same face as another sizemap
+ TSizeMap::iterator it = _sizeMap.find( entry );
+ if ( it != _sizeMap.end() ) {
+ _sizeMap.erase(it);
NotifySubMeshesHypothesisModification();
}
+ else {
+ TSizeMap::iterator itAt = _attractors.find( entry );
+ if ( itAt != _attractors.end() ) {
+ _attractors.erase(itAt);
+ 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);
+ _classAttractors[entry] = myAttractor;
+ NotifySubMeshesHypothesisModification();
+ }
+ else {
+ _classAttractors[entry].SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
+ if (!myAttractor.IsMapBuilt()){
+ myAttractor.BuildMap();
+ }
+ 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";
-}
-
+// //=======================================================================
+// //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
+ * \brief Return the map of attractor instances
*/
BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
{
#include <set>
#include <stdexcept>
#include <string>
+#include "BLSURFPlugin_Attractor.hxx"
// Parameters for work of BLSURF
const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; }
*/
- typedef std::map<std::string, std::string> TAttractorMap;
+ typedef std::map<std::string, BLSURFPlugin_Attractor> TAttractorMap;
- void SetClassAttractorEntry(const std::string& entry,const std::string& att_entry);
+ 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);
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
}
+//=============================================================================
+
+void BLSURFPlugin_Hypothesis_i::SetClassAttractorEntry(const char* entry, const TopoDS_Face& FaceShape, const TopoDS_Shape& AttractorShape, double StartSize, double EndSize, double ActionRadius, double ConstantRadius) //TODO à finir
+ throw (SALOME::SALOME_Exception)
+{
+ ASSERT(myBaseImpl);
+ MESSAGE("ENGINE : SETATTRACTOR START ENTRY : " << entry);
+ // bool valueChanged = false;
+ try {
+ this->GetImpl()->SetClassAttractorEntry(entry, FaceShape, AttractorShape, StartSize, EndSize, ActionRadius, ConstantRadius);
+ }
+ catch (const std::invalid_argument& ex) {
+ SALOME::ExceptionStruct ExDescription;
+ ExDescription.text = ex.what();
+ ExDescription.type = SALOME::BAD_PARAM;
+ ExDescription.sourceFile = "BLSURFPlugin_Hypothesis::SetClassAttractorEntry(entry,att_entry)";
+ ExDescription.lineNumber = 0;
+ throw SALOME::SALOME_Exception(ExDescription);
+ }
+ catch (SALOME_Exception& ex) {
+ THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+ }
+ MESSAGE("ENGINE : SETATTRACTOR END ENTRY : " << entry);
+ //if ( valueChanged )
+ //SMESH::TPythonDump() << _this() << ".SetAttractor("
+ // << entry << ", '" << attractor << "' )";
+ // TODO enable dump
+}
+
+
//=============================================================================
char* BLSURFPlugin_Hypothesis_i::GetSizeMapEntry(const char* entry)
//=============================================================================
+// TODO coder cette fonction (utilisée pour savoir si la valeur a changé
+
+// char* BLSURFPlugin_Hypothesis_i::GetClassAttractorEntry(const char* entry)
+// throw (SALOME::SALOME_Exception)
+// {
+// ASSERT(myBaseImpl);
+// try {
+// return CORBA::string_dup( this->GetImpl()->GetClassAttractorEntry(entry).c_str());
+// }
+// catch (const std::invalid_argument& ex) {
+// SALOME::ExceptionStruct ExDescription;
+// ExDescription.text = ex.what();
+// ExDescription.type = SALOME::BAD_PARAM;
+// ExDescription.sourceFile = "BLSURFPlugin_Hypothesis::GetClassAttractorEntry(name)";
+// ExDescription.lineNumber = 0;
+// throw SALOME::SALOME_Exception(ExDescription);
+// }
+// catch (SALOME_Exception& ex) {
+// THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+// }
+// return 0;
+// }
+
+//=============================================================================
+
void BLSURFPlugin_Hypothesis_i::UnsetEntry(const char* entry)
{
ASSERT(myBaseImpl);
}
+void BLSURFPlugin_Hypothesis_i::SetAttractor_Geom(GEOM::GEOM_Object_ptr GeomObj, GEOM::GEOM_Object_ptr Attractor, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
+{
+ ASSERT(myBaseImpl);
+ string entry;
+// string att_entry;
+ entry=GeomObj->GetStudyEntry();
+// att_entry=Attractor->GetStudyEntry();
+ TopoDS_Face FaceShape = TopoDS::Face(SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( GeomObj ));
+ TopoDS_Shape AttractorShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( Attractor );
+ MESSAGE("IDL : GetName : " << GeomObj->GetName());
+ MESSAGE("IDL : SETATTRACTOR () ");//<< entry << " , " << att_entry << ")");
+ SetClassAttractorEntry( entry.c_str(), FaceShape, AttractorShape, StartSize, EndSize, ActionRadius, ConstantRadius);
+}
+
+void BLSURFPlugin_Hypothesis_i::UnsetAttractor_Geom(GEOM::GEOM_Object_ptr GeomObj)
+{
+ ASSERT(myBaseImpl);
+ string entry;
+ entry=GeomObj->GetStudyEntry();
+ MESSAGE("IDL : GetName : " << GeomObj->GetName());
+ MESSAGE("IDL : UNSETATTRACTOR ( "<< entry << ")");
+ UnsetEntry( entry.c_str());
+ SMESH::TPythonDump() << _this() << ".UnsetAttractor( " << entry.c_str() << " )";
+}
/*
MESSAGE("Coords not found: add it in coordsList")
newValue = true;
}
- else
- MESSAGE("Coords already found")
+ else {
+ MESSAGE("Coords already found");
+ }
}
catch (const std::invalid_argument& ex) {
// no enforced vertex for entry
char* GetAttractorEntry(const char* entry) throw (SALOME::SALOME_Exception);
BLSURFPlugin::string_array* GetAttractorEntries();
+
+
+ void SetAttractor_Geom(GEOM::GEOM_Object_ptr GeomObj, GEOM::GEOM_Object_ptr Attractor, double StartSize, double EndSize, double ActionRadius, double ConstantRadius );
+
+ void UnsetAttractor_Geom(GEOM::GEOM_Object_ptr GeomObj);
+
+ void SetClassAttractorEntry(const char* entry,const TopoDS_Face& FaceShape, const TopoDS_Shape& AttractorShape, double StartSize, double EndSize, double ActionRadius, double ConstantRadius) throw (SALOME::SALOME_Exception);
+
+ //char* GetAttractorEntry(const char* entry) throw (SALOME::SALOME_Exception);
+
+ //BLSURFPlugin_Attractor GetClassAttractorEntries();
/*