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 "bbcreaVtkDistanceMap.h"
5 #include "bbcreaVtkPackage.h"
7 #include "creaVtk_MACROS.h"
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,DistanceMap)
13 BBTK_BLACK_BOX_IMPLEMENTATION(DistanceMap,bbtk::AtomicBlackBox);
15 // 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)
17 void DistanceMap::Process()
20 // THE MAIN PROCESSING METHOD BODY
21 // Here we simply set the input 'In' value to the output 'Out'
22 // And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 // void bbSet{Input|Output}NAME(const TYPE&)
25 // const TYPE& bbGet{Input|Output}NAME() const
27 // * NAME is the name of the input/output
28 // (the one provided in the attribute 'name' of the tag 'input')
29 // * TYPE is the C++ type of the input/output
30 // (the one provided in the attribute 'type' of the tag 'input')
32 if ( (bbGetInputIn()!=NULL) && (bbGetInputPoint1().size()==3) )
39 bbGetInputIn()->GetSpacing(spc);
40 bbGetInputIn()->GetExtent(ext);
41 dim[0] = ext[1]-ext[0]+1;
42 dim[1] = ext[3]-ext[2]+1;
43 dim[2] = ext[5]-ext[4]+1;
45 dimXY = dim[0]*dim[1];
46 if (imageoutput!=NULL)
48 imageoutput->Delete();
50 imageoutput = vtkImageData::New();
51 imageoutput->Initialize();
52 imageoutput->SetSpacing( spc );
53 imageoutput->SetDimensions( dim[0], dim[1], dim[2] );
55 //EED 2017-01-01 Migration VTK7
56 #if (VTK_MAJOR_VERSION <= 5)
57 imageoutput->SetScalarType( VTK_DOUBLE );
58 imageoutput->AllocateScalars();
60 #if (VTK_MAJOR_VERSION >= 6)
61 imageoutput->AllocateScalars( VTK_DOUBLE,1 );
63 imageoutput->Modified();
65 memset( imageoutput->GetScalarPointer() ,0, sizeof(double)*dim[0]*dim[1]*dim[2] );
66 std::vector<int> lst1X;
67 std::vector<int> lst1Y;
68 std::vector<int> lst1Z;
70 std::vector<int> lst2X;
71 std::vector<int> lst2Y;
72 std::vector<int> lst2Z;
74 lst1X.push_back( bbGetInputPoint1()[0] );
75 lst1Y.push_back( bbGetInputPoint1()[1]);
76 lst1Z.push_back( bbGetInputPoint1()[2]);
82 int pxOut,pyOut,pzOut;
86 DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())
87 DEF_POINTER_IMAGE_VTK_CREA(vOut,ssOut,pOut,stOut,imageoutput)
89 while (lst1X.size()>0)
91 depth=depth+bbGetInputSlope();
95 GETVALUE2_VTK_CREA(glIn,pIn,stIn, lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
97 // glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
100 GETVALUE2_VTK_CREA(glOut,pOut,stOut, lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
101 // glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
104 tmpValue = depth + (255-glIn)*bbGetInputAverageRadius()*2;
105 SETVALUE2_VTK_CREA(tmpValue,pOut,stOut, lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
106 // imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn)*bbGetInputAverageRadius()*2);
107 pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
110 for (px=lst1X[i]-1;px<=lst1X[i]+1;px++)
112 for (py=lst1Y[i]-1;py<=lst1Y[i]+1;py++)
114 for (pz=lst1Z[i]-1;pz<=lst1Z[i]+1;pz++)
116 if (!( (px==lst1X[i]) && (py==lst1Y[i]) && (pz==lst1Z[i]) ))
118 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
120 GETVALUE2_VTK_CREA(glOut,pOut,stOut, px + py*dimX + pz*dimXY )
121 // glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0);
124 } // if px py pz inside the image
125 if (glOut==0) { lst2X.push_back(px); lst2Y.push_back( py ); lst2Z.push_back( pz ); }
131 if ( bbGetInputPoint2().size()==3)
133 if ( (bbGetInputPoint2()[0]==lst1X[i]) && (bbGetInputPoint2()[1]==lst1Y[i]) && (bbGetInputPoint2()[2]==lst1Z[i]) )
135 i=size; // out of for lst1
139 } // if Arrive to Point2
155 lst1X.push_back( lst2X[i] );
156 lst1Y.push_back( lst2Y[i] );
157 lst1Z.push_back( lst2Z[i] );
167 std::vector<int> lstPointOut;
168 lstPointOut.push_back( pxOut );
169 lstPointOut.push_back( pyOut );
170 lstPointOut.push_back( pzOut );
172 std::vector<int> lstPathXOut;
173 std::vector<int> lstPathYOut;
174 std::vector<int> lstPathZOut;
176 lstPathXOut.push_back( pxOut );
177 lstPathYOut.push_back( pyOut );
178 lstPathZOut.push_back( pzOut );
183 double min = imageoutput->GetScalarComponentAsDouble( pxOut,pyOut,pzOut , 0);
190 for (px=pxOut-1;px<=pxOut+1;px++)
192 for (py=pyOut-1;py<=pyOut+1;py++)
194 for (pz=pzOut-1;pz<=pzOut+1;pz++)
196 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
198 GETVALUE2_VTK_CREA(glOut,pOut,stOut, px + py*dimX + pz*dimXY )
199 // glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0);
200 if ( (glOut<min) && (glOut!=0) )
218 lstPathXOut.push_back( pxOut );
219 lstPathYOut.push_back( pyOut );
220 lstPathZOut.push_back( pzOut );
226 bbSetOutputOut( imageoutput );
227 bbSetOutputFinalPoint( lstPointOut );
228 bbSetOutputLengthPixels( lstPathXOut.size() );
230 // invert list of points
231 size=lstPathXOut.size();
232 long int size2=size/2;
234 for (i=0; i<size2;i++)
236 tmp= lstPathXOut[i]; lstPathXOut[i]=lstPathXOut[size-1-i]; lstPathXOut[size-1-i]=tmp;
237 tmp= lstPathYOut[i]; lstPathYOut[i]=lstPathYOut[size-1-i]; lstPathYOut[size-1-i]=tmp;
238 tmp= lstPathZOut[i]; lstPathZOut[i]=lstPathZOut[size-1-i]; lstPathZOut[size-1-i]=tmp;
241 bbSetOutputLstPathXOut( lstPathXOut );
242 bbSetOutputLstPathYOut( lstPathYOut );
243 bbSetOutputLstPathZOut( lstPathZOut );
245 printf("EED Warnning! DistanceMap::Process In or Point1 is EMPTY\n");
250 // 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)
252 void DistanceMap::bbUserSetDefaultValues()
255 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
256 // Here we initialize the input 'In' to 0
258 bbSetInputAverageRadius(10);
264 // 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)
266 void DistanceMap::bbUserInitializeProcessing()
269 // THE INITIALIZATION METHOD BODY :
271 // but this is where you should allocate the internal/output pointers
277 // 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)
279 void DistanceMap::bbUserFinalizeProcessing()
282 // THE FINALIZATION METHOD BODY :
284 // but this is where you should desallocate the internal/output pointers
289 // EO namespace bbcreaVtk