]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx
#3472 MeshDeformation
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkMeshDeformation.cxx
1 //===== 
2 // 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)
3 //===== 
4 #include "bbcreaVtkMeshDeformation.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MeshDeformation)
10 BBTK_BLACK_BOX_IMPLEMENTATION(MeshDeformation,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void MeshDeformation::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28 //    bbSetOutputOut( bbGetInputIn() );
29 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
30   
31     double s = bbGetInputS();
32     bool ok=true;
33     if (bbGetInputDirection().size()==3)
34     {
35         ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
36     }
37     if ( (bbGetInputIn()!=NULL) && (ok==true))
38     {
39         vtkPoints* points=bbGetInputIn()->GetPoints();
40         long    i,size=points->GetNumberOfPoints();
41         double  p[3];  // point
42         double  pb[3]; // point base
43         double  np[3]; // new point
44         double  sx,sy,sz;
45         sx = s*2;
46         sy = sx;
47         sz = sy;
48
49         points->GetPoint( bbGetInputEdgeId() , pb );
50
51         if (EdgeIdBack!=bbGetInputEdgeId() )
52         {
53             voiIdPoints.clear();
54             EdgeIdBack = bbGetInputEdgeId();
55             for ( i=0 ; i<size ; i++)
56             {
57                 points->GetPoint(i,p);
58
59                 if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) &&
60                      (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) &&
61                      (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) )
62                 {
63                     voiIdPoints.push_back( i );
64                 } // if
65             } // for i
66         } // back
67         double displcement_x = 0;
68         double displcement_y = 0;
69         double displcement_z = 0;
70         if (bbGetInputDirection().size()==3)
71         {
72             displcement_x = bbGetInputDirection()[0];
73             displcement_y = bbGetInputDirection()[1];
74             displcement_z = bbGetInputDirection()[2];
75         }
76         size=voiIdPoints.size();
77         for (i=0;i<size;i++)
78         {
79             points->GetPoint( voiIdPoints[i] , p );
80             double x = p[0] - pb[0]; //distance between a point and seed point
81             double y = p[1] - pb[1];
82             double z = p[2] - pb[2];
83             double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
84
85 //        https://en.wikipedia.org/wiki/Generalized_normal_distribution
86 // with Gama function
87             
88             double weight = exp(-distance * 1. / s);
89             if (weight > 0.0001)
90             {
91                 np[0] = p[0] + weight*displcement_x;
92                 np[1] = p[1] + weight*displcement_y;
93                 np[2] = p[2] + weight*displcement_z;
94                 points->SetPoint( voiIdPoints[i] , np );
95             } // if
96         } // for
97         points->Modified();
98         bbGetInputIn()->Modified();
99     } // In != NULL
100 }
101 //===== 
102 // 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)
103 //===== 
104 void MeshDeformation::bbUserSetDefaultValues()
105 {
106
107 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
108 //    Here we initialize the input 'In' to 0
109    bbSetInputIn(NULL);
110     std::vector<double> direction;
111     direction.push_back(1);
112     direction.push_back(0);
113     direction.push_back(0);
114     bbSetInputDirection(direction);
115     EdgeIdBack=-1;
116     bbSetInputEdgeId(EdgeIdBack);
117     bbSetInputS(10);
118 }
119 //===== 
120 // 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)
121 //===== 
122 void MeshDeformation::bbUserInitializeProcessing()
123 {
124
125 //  THE INITIALIZATION METHOD BODY :
126 //    Here does nothing 
127 //    but this is where you should allocate the internal/output pointers 
128 //    if any 
129
130   
131 }
132 //===== 
133 // 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)
134 //===== 
135 void MeshDeformation::bbUserFinalizeProcessing()
136 {
137
138 //  THE FINALIZATION METHOD BODY :
139 //    Here does nothing 
140 //    but this is where you should desallocate the internal/output pointers 
141 //    if any
142   
143 }
144 }
145 // EO namespace bbcreaVtk
146
147