]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx
3fac0f90d851f8ab9d628e89cea451159796c259
[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     
32     double s = bbGetInputS();
33     bool ok=true;
34     if (bbGetInputDirection().size()==3)
35     {
36         ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
37     }
38     if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0))
39     {
40
41         vtkPoints* points=bbGetInputIn()->GetPoints();
42         long    i,size=points->GetNumberOfPoints();
43         double  p[3];  // point
44         double  pb[3]; // point base
45         double  np[3]; // new point
46         double  sx,sy,sz;
47         sx = s*2;
48         sy = sx;
49         sz = sy;
50
51         points->GetPoint( bbGetInputEdgeId() , pb );
52
53         if (EdgeIdBack!=bbGetInputEdgeId() )
54         {
55             voiIdPoints.clear();
56             EdgeIdBack = bbGetInputEdgeId();
57             for ( i=0 ; i<size ; i++)
58             {
59                 points->GetPoint(i,p);
60
61                 if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) &&
62                      (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) &&
63                      (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) )
64                 {
65                     voiIdPoints.push_back( i );
66                 } // if
67             } // for i
68         } // back
69         double displcement_x = 0;
70         double displcement_y = 0;
71         double displcement_z = 0;
72         
73         if (bbGetInputDirection().size()==3)
74         {
75             displcement_x = bbGetInputDirection()[0];
76             displcement_y = bbGetInputDirection()[1];
77             displcement_z = bbGetInputDirection()[2];
78         }
79         
80         size=voiIdPoints.size();
81         for (i=0;i<size;i++)
82         {
83             points->GetPoint( voiIdPoints[i] , p );
84             double x = p[0] - pb[0]; //distance between a point and seed point
85             double y = p[1] - pb[1];
86             double z = p[2] - pb[2];
87             double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
88
89 //        https://en.wikipedia.org/wiki/Generalized_normal_distribution
90 // with Gama function
91             
92             double weight = exp(-distance * 1. / s);
93             if (weight > 0.0001)
94             {
95                 np[0] = p[0] + weight*displcement_x;
96                 np[1] = p[1] + weight*displcement_y;
97                 np[2] = p[2] + weight*displcement_z;
98                 points->SetPoint( voiIdPoints[i] , np );
99             } // if
100         } // for
101         points->Modified();
102         bbGetInputIn()->Modified();
103     } // In != NULL
104 }
105 //===== 
106 // 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)
107 //===== 
108 void MeshDeformation::bbUserSetDefaultValues()
109 {
110
111 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
112 //    Here we initialize the input 'In' to 0
113    bbSetInputIn(NULL);
114     std::vector<double> direction;
115     direction.push_back(1);
116     direction.push_back(0);
117     direction.push_back(0);
118     bbSetInputDirection(direction);
119     EdgeIdBack=-1;
120     bbSetInputEdgeId(EdgeIdBack);
121     bbSetInputS(10);
122 }
123 //===== 
124 // 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)
125 //===== 
126 void MeshDeformation::bbUserInitializeProcessing()
127 {
128
129 //  THE INITIALIZATION METHOD BODY :
130 //    Here does nothing 
131 //    but this is where you should allocate the internal/output pointers 
132 //    if any 
133
134   
135 }
136 //===== 
137 // 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)
138 //===== 
139 void MeshDeformation::bbUserFinalizeProcessing()
140 {
141
142 //  THE FINALIZATION METHOD BODY :
143 //    Here does nothing 
144 //    but this is where you should desallocate the internal/output pointers 
145 //    if any
146   
147 }
148 }
149 // EO namespace bbcreaVtk
150
151