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"
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,DistanceMap)
10 BBTK_BLACK_BOX_IMPLEMENTATION(DistanceMap,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 DistanceMap::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')
29 if ( (bbGetInputIn()!=NULL) && (bbGetInputPoint1().size()==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)
42 imageoutput->Delete();
44 imageoutput = vtkImageData::New();
45 imageoutput->Initialize();
46 imageoutput->SetSpacing( spc );
47 imageoutput->SetDimensions( dim[0], dim[1], dim[2] );
49 //EED 2017-01-01 Migration VTK7
50 #if (VTK_MAJOR_VERSION <= 5)
51 imageoutput->SetScalarType( VTK_DOUBLE );
52 imageoutput->AllocateScalars();
54 #if (VTK_MAJOR_VERSION >= 6)
55 imageoutput->AllocateScalars( VTK_DOUBLE,1 );
57 imageoutput->Modified();
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;
64 std::vector<int> lst2X;
65 std::vector<int> lst2Y;
66 std::vector<int> lst2Z;
68 lst1X.push_back( bbGetInputPoint1()[0] );
69 lst1Y.push_back( bbGetInputPoint1()[1]);
70 lst1Z.push_back( bbGetInputPoint1()[2]);
76 int pxOut,pyOut,pzOut;
78 while (lst1X.size()>0)
80 depth=depth+bbGetInputSlope();
84 glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
87 glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
90 imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn));
91 pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
94 for (px=lst1X[i]-1;px<=lst1X[i]+1;px++)
96 for (py=lst1Y[i]-1;py<=lst1Y[i]+1;py++)
98 for (pz=lst1Z[i]-1;pz<=lst1Z[i]+1;pz++)
100 if (!( (px==lst1X[i]) && (py==lst1Y[i]) && (pz==lst1Z[i]) ))
102 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
103 { glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); } else { glOut=-1; }
104 if (glOut==0) { lst2X.push_back(px); lst2Y.push_back( py ); lst2Z.push_back( pz ); }
110 if ( bbGetInputPoint2().size()==3)
112 if ( (bbGetInputPoint2()[0]==lst1X[i]) && (bbGetInputPoint2()[1]==lst1Y[i]) && (bbGetInputPoint2()[2]==lst1Z[i]) )
114 i=size; // out of for lst1
118 } // if Arrive to Point2
134 lst1X.push_back( lst2X[i] );
135 lst1Y.push_back( lst2Y[i] );
136 lst1Z.push_back( lst2Z[i] );
146 std::vector<int> lstPointOut;
147 lstPointOut.push_back( pxOut );
148 lstPointOut.push_back( pyOut );
149 lstPointOut.push_back( pzOut );
151 std::vector<int> lstPathXOut;
152 std::vector<int> lstPathYOut;
153 std::vector<int> lstPathZOut;
155 lstPathXOut.push_back( pxOut );
156 lstPathYOut.push_back( pyOut );
157 lstPathZOut.push_back( pzOut );
162 double min = imageoutput->GetScalarComponentAsDouble( pxOut,pyOut,pzOut , 0);
169 for (px=pxOut-1;px<=pxOut+1;px++)
171 for (py=pyOut-1;py<=pyOut+1;py++)
173 for (pz=pzOut-1;pz<=pzOut+1;pz++)
175 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
177 glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0);
178 if ( (glOut<min) && (glOut!=0) )
196 lstPathXOut.push_back( pxOut );
197 lstPathYOut.push_back( pyOut );
198 lstPathZOut.push_back( pzOut );
204 bbSetOutputOut( imageoutput );
205 bbSetOutputFinalPoint( lstPointOut );
207 bbSetOutputLstPathXOut( lstPathXOut );
208 bbSetOutputLstPathYOut( lstPathYOut );
209 bbSetOutputLstPathZOut( lstPathZOut );
211 printf("EED Warnning! DistanceMap::Process In or Point1 is EMPTY\n");
216 // 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)
218 void DistanceMap::bbUserSetDefaultValues()
221 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
222 // Here we initialize the input 'In' to 0
229 // 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)
231 void DistanceMap::bbUserInitializeProcessing()
234 // THE INITIALIZATION METHOD BODY :
236 // but this is where you should allocate the internal/output pointers
242 // 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)
244 void DistanceMap::bbUserFinalizeProcessing()
247 // THE FINALIZATION METHOD BODY :
249 // but this is where you should desallocate the internal/output pointers
254 // EO namespace bbcreaVtk