]> Creatis software - creaVtk.git/commitdiff
#3472 MeshDeformation
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 27 Oct 2021 15:17:54 +0000 (17:17 +0200)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 27 Oct 2021 15:17:54 +0000 (17:17 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h [new file with mode: 0644]

diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx
new file mode 100644 (file)
index 0000000..b5b4294
--- /dev/null
@@ -0,0 +1,147 @@
+//===== 
+// 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)
+//===== 
+#include "bbcreaVtkMeshDeformation.h"
+#include "bbcreaVtkPackage.h"
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MeshDeformation)
+BBTK_BLACK_BOX_IMPLEMENTATION(MeshDeformation,bbtk::AtomicBlackBox);
+//===== 
+// 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::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+//   Here we simply set the input 'In' value to the output 'Out'
+//   And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+//    void bbSet{Input|Output}NAME(const TYPE&)
+//    const TYPE& bbGet{Input|Output}NAME() const 
+//    Where :
+//    * NAME is the name of the input/output
+//      (the one provided in the attribute 'name' of the tag 'input')
+//    * TYPE is the C++ type of the input/output
+//      (the one provided in the attribute 'type' of the tag 'input')
+//    bbSetOutputOut( bbGetInputIn() );
+//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+  
+    double s = bbGetInputS();
+    bool ok=true;
+    if (bbGetInputDirection().size()==3)
+    {
+        ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
+    }
+    if ( (bbGetInputIn()!=NULL) && (ok==true))
+    {
+        vtkPoints* points=bbGetInputIn()->GetPoints();
+        long    i,size=points->GetNumberOfPoints();
+        double  p[3];  // point
+        double  pb[3]; // point base
+        double  np[3]; // new point
+        double  sx,sy,sz;
+        sx = s*2;
+        sy = sx;
+        sz = sy;
+
+        points->GetPoint( bbGetInputEdgeId() , pb );
+
+        if (EdgeIdBack!=bbGetInputEdgeId() )
+        {
+            voiIdPoints.clear();
+            EdgeIdBack = bbGetInputEdgeId();
+            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)) )
+                {
+                    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++)
+        {
+            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();
+    } // In != NULL
+}
+//===== 
+// 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::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+   bbSetInputIn(NULL);
+    std::vector<double> direction;
+    direction.push_back(1);
+    direction.push_back(0);
+    direction.push_back(0);
+    bbSetInputDirection(direction);
+    EdgeIdBack=-1;
+    bbSetInputEdgeId(EdgeIdBack);
+    bbSetInputS(10);
+}
+//===== 
+// 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::bbUserInitializeProcessing()
+{
+
+//  THE INITIALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should allocate the internal/output pointers 
+//    if any 
+
+  
+}
+//===== 
+// 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
+
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h
new file mode 100644 (file)
index 0000000..22bb17c
--- /dev/null
@@ -0,0 +1,58 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbcreaVtkMeshDeformation_h_INCLUDED__
+#define __bbcreaVtkMeshDeformation_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkPolyData.h"
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT MeshDeformation
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(MeshDeformation,bbtk::AtomicBlackBox);
+//===== 
+// 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)
+//=====
+  BBTK_DECLARE_INPUT(In,vtkPolyData*);
+  BBTK_DECLARE_INPUT(EdgeId, long);
+  BBTK_DECLARE_INPUT(S, double);
+  BBTK_DECLARE_INPUT(Direction, std::vector<double>);
+//  BBTK_DECLARE_OUTPUT(Out,double);
+  BBTK_PROCESS(Process);
+  void Process();
+  
+  long EdgeIdBack;
+    std::vector<int>  voiIdPoints;
+
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(MeshDeformation,bbtk::AtomicBlackBox);
+  BBTK_NAME("MeshDeformation");
+  BBTK_AUTHOR("Info-Dev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+  BBTK_INPUT(MeshDeformation,In,"vtk PolyData",vtkPolyData*,"");
+  BBTK_INPUT(MeshDeformation,EdgeId,"Edge Id",long,"");
+  BBTK_INPUT(MeshDeformation,S,"Deformation",double,"");
+  BBTK_INPUT(MeshDeformation,Direction,"(default [1,0,0])   [X,Y,Z]",std::vector<double>,"");
+//  BBTK_OUTPUT(MeshDeformation,Out,"First output",double,"");
+BBTK_END_DESCRIBE_BLACK_BOX(MeshDeformation);
+//===== 
+// 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)
+//===== 
+}
+// EO namespace bbcreaVtk
+
+#endif // __bbcreaVtkMeshDeformation_h_INCLUDED__
+