]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx
Merge branch 'vtk9itk5wx3-macos' of ssh://git.creatis.insa-lyon.fr/creaVtk into vtk9i...
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkMeshDeformation.cxx
index 3fac0f90d851f8ab9d628e89cea451159796c259..865a6fae82f8b9c352c2b34c0ef45908e14e2055 100644 (file)
@@ -27,17 +27,30 @@ void MeshDeformation::Process()
 //      (the one provided in the attribute 'type' of the tag 'input')
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
-  
+
+
+    std::vector<double> lstCenter = bbGetInputCenter();
+
+    double  s   = bbGetInputS();
+    bool    ok  = false;
+    if (bbGetInputTypeIn()==0) // direction
+    {
+        if (bbGetInputDirection().size()==3)
+        {
+            ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
+        }
+    } // if TypeIn 0
     
-    double s = bbGetInputS();
-    bool ok=true;
-    if (bbGetInputDirection().size()==3)
+    if (bbGetInputTypeIn()==1)  // center
     {
-        ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
-    }
-    if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0))
+        ok = ( lstCenter.size()==3 );
+    } // if TypeIn 1
+
+    if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0) && (bbGetInputActive()==true) )
     {
 
+        printf(" EED MeshDeformation::Process   %ld   %ld  -   %f %f %f \n", EdgeIdBack, bbGetInputEdgeId() , lstCenter[0],lstCenter[1],lstCenter[2] );
+
         vtkPoints* points=bbGetInputIn()->GetPoints();
         long    i,size=points->GetNumberOfPoints();
         double  p[3];  // point
@@ -48,16 +61,39 @@ void MeshDeformation::Process()
         sy = sx;
         sz = sy;
 
+        double displcement_x = 0;
+        double displcement_y = 0;
+        double displcement_z = 0;
+        
+        if (bbGetInputTypeIn()==0) // Direction
+        {
+            displcement_x = bbGetInputDirection()[0];
+            displcement_y = bbGetInputDirection()[1];
+            displcement_z = bbGetInputDirection()[2];
+        } // if TypeIn 0 Direction
+               
+               printf(" EED MeshDeformation::Process   %ld   %ld  -   %f %f %f \n", EdgeIdBack, bbGetInputEdgeId() , lstCenter[0],lstCenter[1],lstCenter[2] );
+               
+        if (bbGetInputTypeIn()==1) // Center
+        {
+            if (EdgeIdBack==bbGetInputEdgeId() )
+            {
+                displcement_x = (lstCenter[0]-backLstCenter[0])/1.0;
+                displcement_y = (lstCenter[1]-backLstCenter[1])/1.0;
+                displcement_z = (lstCenter[2]-backLstCenter[2])/1.0;
+            } // if EdgeIdBack!=bbGetInputEdgeId()
+            backLstCenter[0] = lstCenter[0];
+            backLstCenter[1] = lstCenter[1];
+            backLstCenter[2] = lstCenter[2];
+        } // if TypeIn 1 Center
         points->GetPoint( bbGetInputEdgeId() , pb );
-
         if (EdgeIdBack!=bbGetInputEdgeId() )
         {
-            voiIdPoints.clear();
             EdgeIdBack = bbGetInputEdgeId();
+            voiIdPoints.clear();
             for ( i=0 ; i<size ; i++)
             {
                 points->GetPoint(i,p);
-
                 if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) &&
                      (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) &&
                      (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) )
@@ -65,42 +101,38 @@ void MeshDeformation::Process()
                     voiIdPoints.push_back( i );
                 } // if
             } // for i
-        } // back
-        double displcement_x = 0;
-        double displcement_y = 0;
-        double displcement_z = 0;
-        
-        if (bbGetInputDirection().size()==3)
-        {
-            displcement_x = bbGetInputDirection()[0];
-            displcement_y = bbGetInputDirection()[1];
-            displcement_z = bbGetInputDirection()[2];
-        }
-        
-        size=voiIdPoints.size();
-        for (i=0;i<size;i++)
+                       backLstCenter[0] = lstCenter[0];
+                       backLstCenter[1] = lstCenter[1];
+                       backLstCenter[2] = lstCenter[2];
+        } // if EdgeIdBack
+
+        if ( !((displcement_x==0) &&(displcement_y==0) && (displcement_z==0)) )
         {
-            points->GetPoint( voiIdPoints[i] , p );
-            double x = p[0] - pb[0]; //distance between a point and seed point
-            double y = p[1] - pb[1];
-            double z = p[2] - pb[2];
-            double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
-
-//        https://en.wikipedia.org/wiki/Generalized_normal_distribution
-// with Gama function
-            
-            double weight = exp(-distance * 1. / s);
-            if (weight > 0.0001)
+            size=voiIdPoints.size();
+            for (i=0;i<size;i++)
             {
-                np[0] = p[0] + weight*displcement_x;
-                np[1] = p[1] + weight*displcement_y;
-                np[2] = p[2] + weight*displcement_z;
-                points->SetPoint( voiIdPoints[i] , np );
-            } // if
-        } // for
-        points->Modified();
-        bbGetInputIn()->Modified();
-    } // In != NULL
+                points->GetPoint( voiIdPoints[i] , p );
+                double x = p[0] - pb[0]; //distance between a point and seed point
+                double y = p[1] - pb[1];
+                double z = p[2] - pb[2];
+                double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
+
+    //        https://en.wikipedia.org/wiki/Generalized_normal_distribution
+    // with Gama function
+                
+                double weight = exp(-distance * 1. / s);
+                if (weight > 0.0001)
+                {
+                    np[0] = p[0] + weight*displcement_x;
+                    np[1] = p[1] + weight*displcement_y;
+                    np[2] = p[2] + weight*displcement_z;
+                    points->SetPoint( voiIdPoints[i] , np );
+                } // if
+            } // for
+            points->Modified();
+            bbGetInputIn()->Modified();
+        } // if distance_x y z  != 0
+    } // In != NULL    ok    active
 }
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
@@ -110,7 +142,9 @@ void MeshDeformation::bbUserSetDefaultValues()
 
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
-   bbSetInputIn(NULL);
+    bbSetInputActive(true);
+    bbSetInputTypeIn(0);
+    bbSetInputIn(NULL);
     std::vector<double> direction;
     direction.push_back(1);
     direction.push_back(0);
@@ -119,7 +153,12 @@ void MeshDeformation::bbUserSetDefaultValues()
     EdgeIdBack=-1;
     bbSetInputEdgeId(EdgeIdBack);
     bbSetInputS(10);
+    
+    backLstCenter.push_back(0);
+    backLstCenter.push_back(0);
+    backLstCenter.push_back(0);
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
@@ -133,19 +172,18 @@ void MeshDeformation::bbUserInitializeProcessing()
 
   
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void MeshDeformation::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
 }
-}
-// EO namespace bbcreaVtk
+
+}// EO namespace bbcreaVtk