]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
rnc : working prototype with idl interface and a computation time of the distance...
authorgdd <gdd>
Mon, 14 Feb 2011 10:44:02 +0000 (10:44 +0000)
committergdd <gdd>
Mon, 14 Feb 2011 10:44:02 +0000 (10:44 +0000)
src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx
src/BLSURFPlugin/BLSURFPlugin_Attractor.hxx
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx

index 47e8c2437163f09042065684f5b594d2c09fd048..eabda4798fb7df653c13e674ae7178180c6a5760 100644 (file)
@@ -13,14 +13,19 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor ()
   _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(),
@@ -28,17 +33,22 @@ BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape A
   _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();
 }
@@ -47,7 +57,7 @@ bool BLSURFPlugin_Attractor::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); 
@@ -89,13 +99,26 @@ bool BLSURFPlugin_Attractor::init(){
   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. );
@@ -136,18 +159,34 @@ 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 );
   
-  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;
@@ -164,7 +203,7 @@ bool BLSURFPlugin_Attractor::_buildMap(){
   //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
@@ -172,22 +211,23 @@ bool BLSURFPlugin_Attractor::_buildMap(){
     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]);
@@ -223,13 +263,13 @@ bool BLSURFPlugin_Attractor::_buildMap(){
        }
        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          *     | 
@@ -274,9 +314,9 @@ bool BLSURFPlugin_Attractor::_buildMap(){
              }
              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;
@@ -340,8 +380,11 @@ bool BLSURFPlugin_Attractor::_buildMap(){
       } // for
     } // for
   } // while (_trial)
+//  _known.clear();
+  _trial.clear();
+  _isMapBuilt = true;
   
-} // _buildMap()
+} // end of BuildMap()
 
 
 
index 4f1f116cd839b4e9dd793ef2aef8860170fd9b13..7b599de9a829aafca913ca8bcfc8694b24e3e590 100644 (file)
 // 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_
 
@@ -31,6 +37,7 @@
 #include <stdexcept>
 #include <string>
 #include <limits>
+#include <utilities.h>
 
 // OPENCASCADE includes
 #include <BRep_Tool.hxx>
@@ -72,6 +79,9 @@
 #include <gp_XYZ.hxx>
 #include <TopTools_MapOfShape.hxx>
 
+#define TYPE_EXP 0
+#define TYPE_LIN 1
+
 
 // class IJ_Pnt{
 //   public:
@@ -123,19 +133,27 @@ class BLSURFPlugin_Attractor {
   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;
@@ -150,11 +168,16 @@ class BLSURFPlugin_Attractor {
     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);
 };    
 
 
index 89391e18b5f16a9305603c14d837e68db4f6445e..d7cc9bd3ab8e085454b81daa0b2768cf11e9dfa4 100644 (file)
@@ -215,6 +215,7 @@ std::map<int,PyObject*> VertexId2PythonSmp;
 
 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;
@@ -223,7 +224,7 @@ std::map< std::vector<double>, std::vector<double> > EnfVertex2ProjVertex;
 bool HasSizeMapOnFace=false;
 bool HasSizeMapOnEdge=false;
 bool HasSizeMapOnVertex=false;
-bool HasAttractorOnFace=false;
+//bool HasAttractorOnFace=false;
 
 //=============================================================================
 /*!
@@ -279,6 +280,7 @@ BLSURFPlugin_BLSURF::BLSURFPlugin_BLSURF(int hypId, int studyId,
   EdgeId2PythonSmp.clear();
   VertexId2PythonSmp.clear();
   FaceId2AttractorCoords.clear();
+  FaceId2ClassAttractor.clear();
   FacesWithEnforcedVertices.Clear();
   FaceId2EnforcedVertexCoords.clear();
   EnfVertex2ProjVertex.clear();
@@ -587,8 +589,8 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction
   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)"; 
 
@@ -606,22 +608,24 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction
     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");
 }
 
 /////////////////////////////////////////////////////////
@@ -793,6 +797,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
     //
     // 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();
@@ -832,34 +837,53 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
     }
     
     // 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 !!")
+       }
+
+      }
+    }
+
     
 
     //
@@ -957,6 +981,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
 
   FacesWithSizeMap.Clear();
   FaceId2SizeMap.clear();
+  FaceId2ClassAttractor.clear();
   EdgesWithSizeMap.Clear();
   EdgeId2SizeMap.clear();
   VerticesWithSizeMap.Clear();
@@ -1002,6 +1027,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   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());
 
@@ -1035,6 +1061,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
     }
     
     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);
@@ -1094,6 +1121,16 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
         }
       }
       
+      // 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);
@@ -1152,7 +1189,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
       }
 //       else
 //         std::cout << "No enforced vertex defined" << std::endl;
-    }
+//     }
     
     
     /****************************************************************************************
@@ -1721,34 +1758,40 @@ status_t size_on_surface(integer face_id, real *uv, real *size, void *user_data)
   }
 
   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;
index 8c9daf6dc04dadd15ae340d1e51c5b6e49fc178e..0b2bbb265d412752f490e16b8984a8ce4b7ae718 100644 (file)
@@ -425,28 +425,54 @@ BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(c
 //=======================================================================
 //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)
 {
index b30789d95aaa486671f79b528dee695bac4a9419..743f90db214eb5b4809f1c57e699bf74c351ed25 100644 (file)
@@ -33,6 +33,7 @@
 #include <set>
 #include <stdexcept>
 #include <string>
+#include "BLSURFPlugin_Attractor.hxx"
 
 //  Parameters for work of BLSURF
 
@@ -129,16 +130,15 @@ public:
   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
index 05e00610fd4d1b379e93e7fa4443449aa5539f12..4e5a339f938bbf8903ec91d2cde36ee45efe5ad8 100644 (file)
@@ -579,6 +579,36 @@ void BLSURFPlugin_Hypothesis_i::SetAttractorEntry(const char* entry,const char*
 }
 
 
+//=============================================================================
+
+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) 
@@ -627,6 +657,31 @@ char* BLSURFPlugin_Hypothesis_i::GetAttractorEntry(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); 
@@ -756,6 +811,30 @@ void BLSURFPlugin_Hypothesis_i::UnsetAttractor(GEOM::GEOM_Object_ptr GeomObj)
 }
 
 
+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() << " )";
+}
 
 
 /*
@@ -1113,8 +1192,9 @@ bool BLSURFPlugin_Hypothesis_i::_setEnfVertex(const char* theFaceEntry, CORBA::D
       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
index e3c2c606281f73f8c1703e732d97479ff92658ee..8c9e2a62a22686bbe40de03e3b50d0a8c114ad0c 100644 (file)
@@ -127,6 +127,17 @@ class BLSURFPlugin_Hypothesis_i:
   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();
 
 
 /*