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)
4 #include "bbcreaVtkMeshDeformation.h"
5 #include "bbcreaVtkPackage.h"
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MeshDeformation)
10 BBTK_BLACK_BOX_IMPLEMENTATION(MeshDeformation,bbtk::AtomicBlackBox);
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)
14 void MeshDeformation::Process()
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
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;
32 std::vector<double> lstCenter = bbGetInputCenter();
34 double s = bbGetInputS();
36 if (bbGetInputTypeIn()==0) // direction
38 if (bbGetInputDirection().size()==3)
40 ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) );
44 if (bbGetInputTypeIn()==1) // center
46 ok = ( lstCenter.size()==3 );
49 if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0) && (bbGetInputActive()==true) )
51 vtkPoints* points=bbGetInputIn()->GetPoints();
52 long i,size=points->GetNumberOfPoints();
54 double pb[3]; // point base
55 double np[3]; // new point
61 double displcement_x = 0;
62 double displcement_y = 0;
63 double displcement_z = 0;
65 if (bbGetInputTypeIn()==0) // Direction
67 displcement_x = bbGetInputDirection()[0];
68 displcement_y = bbGetInputDirection()[1];
69 displcement_z = bbGetInputDirection()[2];
70 } // if TypeIn 0 Direction
72 printf(" EED MeshDeformation::Process %ld %ld - %f %f %f \n", EdgeIdBack, bbGetInputEdgeId() , lstCenter[0],lstCenter[1],lstCenter[2] );
74 if (bbGetInputTypeIn()==1) // Center
76 if (EdgeIdBack==bbGetInputEdgeId() )
78 displcement_x = (lstCenter[0]-backLstCenter[0])/1.0;
79 displcement_y = (lstCenter[1]-backLstCenter[1])/1.0;
80 displcement_z = (lstCenter[2]-backLstCenter[2])/1.0;
81 } // if EdgeIdBack!=bbGetInputEdgeId()
82 backLstCenter[0] = lstCenter[0];
83 backLstCenter[1] = lstCenter[1];
84 backLstCenter[2] = lstCenter[2];
85 } // if TypeIn 1 Center
86 points->GetPoint( bbGetInputEdgeId() , pb );
87 if (EdgeIdBack!=bbGetInputEdgeId() )
89 EdgeIdBack = bbGetInputEdgeId();
91 for ( i=0 ; i<size ; i++)
93 points->GetPoint(i,p);
94 if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) &&
95 (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) &&
96 (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) )
98 voiIdPoints.push_back( i );
101 backLstCenter[0] = lstCenter[0];
102 backLstCenter[1] = lstCenter[1];
103 backLstCenter[2] = lstCenter[2];
106 if ( !((displcement_x==0) &&(displcement_y==0) && (displcement_z==0)) )
108 size=voiIdPoints.size();
111 points->GetPoint( voiIdPoints[i] , p );
112 double x = p[0] - pb[0]; //distance between a point and seed point
113 double y = p[1] - pb[1];
114 double z = p[2] - pb[2];
115 double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
117 // https://en.wikipedia.org/wiki/Generalized_normal_distribution
118 // with Gama function
120 double weight = exp(-distance * 1. / s);
123 np[0] = p[0] + weight*displcement_x;
124 np[1] = p[1] + weight*displcement_y;
125 np[2] = p[2] + weight*displcement_z;
126 points->SetPoint( voiIdPoints[i] , np );
130 bbGetInputIn()->Modified();
131 } // if distance_x y z != 0
132 } // In != NULL ok active
135 // 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)
137 void MeshDeformation::bbUserSetDefaultValues()
140 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
141 // Here we initialize the input 'In' to 0
142 bbSetInputActive(true);
145 std::vector<double> direction;
146 direction.push_back(1);
147 direction.push_back(0);
148 direction.push_back(0);
149 bbSetInputDirection(direction);
151 bbSetInputEdgeId(EdgeIdBack);
154 backLstCenter.push_back(0);
155 backLstCenter.push_back(0);
156 backLstCenter.push_back(0);
160 // 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)
162 void MeshDeformation::bbUserInitializeProcessing()
165 // THE INITIALIZATION METHOD BODY :
167 // but this is where you should allocate the internal/output pointers
174 // 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)
176 void MeshDeformation::bbUserFinalizeProcessing()
178 // THE FINALIZATION METHOD BODY :
180 // but this is where you should desallocate the internal/output pointers
184 }// EO namespace bbcreaVtk