]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx
#3276 creaVtk Feature New Normal - DistanceMap Box
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkDistanceMap.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 "bbcreaVtkDistanceMap.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,DistanceMap)
10 BBTK_BLACK_BOX_IMPLEMENTATION(DistanceMap,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 DistanceMap::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
29         if ( (bbGetInputIn()!=NULL) && (bbGetInputPoint1().size()==3) )
30         {
31
32                 int     ext[6];
33                 int     dim[3];
34                 double  spc[3];
35                 bbGetInputIn()->GetSpacing(spc);
36                 bbGetInputIn()->GetExtent(ext);
37                 dim[0]= ext[1]-ext[0]+1;
38                 dim[1]= ext[3]-ext[2]+1;
39                 dim[2]= ext[5]-ext[4]+1;
40                 if (imageoutput!=NULL) 
41                 {
42                         imageoutput->Delete();
43                 }       
44                 imageoutput = vtkImageData::New();
45                 imageoutput->Initialize();
46                 imageoutput->SetSpacing( spc );
47                 imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
48
49         //EED 2017-01-01 Migration VTK7
50         #if (VTK_MAJOR_VERSION <= 5) 
51                 imageoutput->SetScalarType( VTK_DOUBLE );       
52                 imageoutput->AllocateScalars();
53         #endif
54         #if (VTK_MAJOR_VERSION >= 6) 
55                 imageoutput->AllocateScalars( VTK_DOUBLE,1 );
56         #endif
57                 imageoutput->Modified();
58
59                 memset( imageoutput->GetScalarPointer() ,0, sizeof(double)*dim[0]*dim[1]*dim[2] );
60                 std::vector<int> lst1X;         
61                 std::vector<int> lst1Y;         
62                 std::vector<int> lst1Z;         
63
64                 std::vector<int> lst2X;         
65                 std::vector<int> lst2Y;         
66                 std::vector<int> lst2Z;         
67
68                 lst1X.push_back( bbGetInputPoint1()[0] );
69                 lst1Y.push_back( bbGetInputPoint1()[1]);
70                 lst1Z.push_back( bbGetInputPoint1()[2]);
71
72                 long int i,size;
73                 double glIn,glOut;
74                 double depth=0;
75                 int px,py,pz;           
76                 int pxOut,pyOut,pzOut;  
77
78
79 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
80 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
81 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
82 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
83 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
84 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
85 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
86 printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
87
88                 while (lst1X.size()>0)
89                 {
90                         depth=depth+bbGetInputSlope();
91                         size=lst1X.size();
92                         for (i=0;i<size;i++)
93                         {
94                                 glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
95                                 if (glIn!=0)
96                                 {
97                                         glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
98                                         if (glOut==0)
99                                         {
100                                                 imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn));
101                                                 pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
102
103
104                                                 for (px=lst1X[i]-1;px<=lst1X[i]+1;px++)
105                                                 {
106                                                         for (py=lst1Y[i]-1;py<=lst1Y[i]+1;py++)
107                                                         {
108                                                                 for (pz=lst1Z[i]-1;pz<=lst1Z[i]+1;pz++)
109                                                                 {
110                                                                         if (!( (px==lst1X[i]) && (py==lst1Y[i]) && (pz==lst1Z[i]) )) 
111                                                                         {
112                                                                                 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) &&  (pz>=0) && (pz<dim[2]) )
113                                                                                         { glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); } else { glOut=-1; }
114                                                                                 if (glOut==0) { lst2X.push_back(px); lst2Y.push_back(  py ); lst2Z.push_back(  pz ); }
115                                                                         } // if 
116                                                                 } // for kk
117                                                         } // fo jj
118                                                 } // for ii
119
120                                                 if ( bbGetInputPoint2().size()==3)
121                                                 {
122                                                         if ( (bbGetInputPoint2()[0]==lst1X[i]) && (bbGetInputPoint2()[1]==lst1Y[i]) && (bbGetInputPoint2()[2]==lst1Z[i]) )
123                                                         {
124                                                                 i=size;  // out of for lst1
125                                                                 lst2X.clear();
126                                                                 lst2Y.clear();
127                                                                 lst2Z.clear();
128                                                         } // if Arrive to Point2
129                                                 } // Point size 3
130
131                                         }
132
133                                 }// If glIn
134
135                         }  // for lst1
136
137                         lst1X.clear();
138                         lst1Y.clear();
139                         lst1Z.clear();
140
141                         size=lst2X.size();
142                         for (i=0;i<size;i++)
143                         {
144                                 lst1X.push_back( lst2X[i] );
145                                 lst1Y.push_back( lst2Y[i] );
146                                 lst1Z.push_back( lst2Z[i] );
147                         } // for lst2
148
149                         lst2X.clear();
150                         lst2Y.clear();
151                         lst2Z.clear();
152
153                 } // while lstX
154
155
156                 std::vector<int> lstPointOut;
157                 lstPointOut.push_back( pxOut );
158                 lstPointOut.push_back( pyOut );
159                 lstPointOut.push_back( pzOut );
160
161                 std::vector<int> lstPathXOut;
162                 std::vector<int> lstPathYOut;
163                 std::vector<int> lstPathZOut;
164         
165                 lstPathXOut.push_back( pxOut );
166                 lstPathYOut.push_back( pyOut );
167                 lstPathZOut.push_back( pzOut );
168
169                 // find Path
170                 bool    ok2;
171                 bool    ok      = true;
172                 double  min     = imageoutput->GetScalarComponentAsDouble( pxOut,pyOut,pzOut , 0);
173                 int pxOutBack;
174                 int pyOutBack;
175                 int pzOutBack;
176                 int length=0;
177                 while (ok==true)
178                 {       
179                         ok2=false;
180                         for (px=pxOut-1;px<=pxOut+1;px++)
181                         {
182                                 for (py=pyOut-1;py<=pyOut+1;py++)
183                                 {
184                                         for (pz=pzOut-1;pz<=pzOut+1;pz++)
185                                         {
186                                                 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
187                                                 { 
188                                                                 glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); 
189                                                                 if ( (glOut<min) && (glOut!=0) )
190                                                                 {
191                                                                         min                     = glOut;
192                                                                         pxOutBack       = px;
193                                                                         pyOutBack       = py;
194                                                                         pzOutBack       = pz;
195                                                                         ok2                     = true;
196                                                                 } // if min
197                                                 } // if 
198                                         } // for pz
199                                 } // fo py
200                         } // for px
201
202                         if (ok2==true)
203                         {
204                                 pxOut=pxOutBack;
205                                 pyOut=pyOutBack;
206                                 pzOut=pzOutBack;
207                                 lstPathXOut.push_back( pxOut );
208                                 lstPathYOut.push_back( pyOut );
209                                 lstPathZOut.push_back( pzOut );
210                                 length++;
211                         } else {
212                                 ok=false;
213                         }
214                 } // while
215
216                 bbSetOutputOut( imageoutput );
217                 bbSetOutputFinalPoint( lstPointOut );
218                 bbSetOutputLength( length );
219                 bbSetOutputLstPathXOut( lstPathXOut );
220                 bbSetOutputLstPathYOut( lstPathYOut );
221                 bbSetOutputLstPathZOut( lstPathZOut );
222         } else {
223                 printf("EED Warnning! DistanceMap::Process  In or Point1 is EMPTY\n");
224         }  // if In Point1  
225
226 }
227 //===== 
228 // 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)
229 //===== 
230 void DistanceMap::bbUserSetDefaultValues()
231 {
232
233 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
234 //    Here we initialize the input 'In' to 0
235         bbSetInputIn(NULL);
236         bbSetInputSlope(10);
237         imageoutput=NULL;
238   
239 }
240 //===== 
241 // 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)
242 //===== 
243 void DistanceMap::bbUserInitializeProcessing()
244 {
245
246 //  THE INITIALIZATION METHOD BODY :
247 //    Here does nothing 
248 //    but this is where you should allocate the internal/output pointers 
249 //    if any 
250
251   
252 }
253 //===== 
254 // 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)
255 //===== 
256 void DistanceMap::bbUserFinalizeProcessing()
257 {
258
259 //  THE FINALIZATION METHOD BODY :
260 //    Here does nothing 
261 //    but this is where you should desallocate the internal/output pointers 
262 //    if any
263   
264 }
265 }
266 // EO namespace bbcreaVtk
267
268