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;
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");
88 while (lst1X.size()>0)
90 depth=depth+bbGetInputSlope();
94 glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
97 glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
100 imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn));
101 pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
104 for (px=lst1X[i]-1;px<=lst1X[i]+1;px++)
106 for (py=lst1Y[i]-1;py<=lst1Y[i]+1;py++)
108 for (pz=lst1Z[i]-1;pz<=lst1Z[i]+1;pz++)
110 if (!( (px==lst1X[i]) && (py==lst1Y[i]) && (pz==lst1Z[i]) ))
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 ); }
120 if ( bbGetInputPoint2().size()==3)
122 if ( (bbGetInputPoint2()[0]==lst1X[i]) && (bbGetInputPoint2()[1]==lst1Y[i]) && (bbGetInputPoint2()[2]==lst1Z[i]) )
124 i=size; // out of for lst1
128 } // if Arrive to Point2
144 lst1X.push_back( lst2X[i] );
145 lst1Y.push_back( lst2Y[i] );
146 lst1Z.push_back( lst2Z[i] );
156 std::vector<int> lstPointOut;
157 lstPointOut.push_back( pxOut );
158 lstPointOut.push_back( pyOut );
159 lstPointOut.push_back( pzOut );
161 std::vector<int> lstPathXOut;
162 std::vector<int> lstPathYOut;
163 std::vector<int> lstPathZOut;
165 lstPathXOut.push_back( pxOut );
166 lstPathYOut.push_back( pyOut );
167 lstPathZOut.push_back( pzOut );
172 double min = imageoutput->GetScalarComponentAsDouble( pxOut,pyOut,pzOut , 0);
180 for (px=pxOut-1;px<=pxOut+1;px++)
182 for (py=pyOut-1;py<=pyOut+1;py++)
184 for (pz=pzOut-1;pz<=pzOut+1;pz++)
186 if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
188 glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0);
189 if ( (glOut<min) && (glOut!=0) )
207 lstPathXOut.push_back( pxOut );
208 lstPathYOut.push_back( pyOut );
209 lstPathZOut.push_back( pzOut );
216 bbSetOutputOut( imageoutput );
217 bbSetOutputFinalPoint( lstPointOut );
218 bbSetOutputLength( length );
219 bbSetOutputLstPathXOut( lstPathXOut );
220 bbSetOutputLstPathYOut( lstPathYOut );
221 bbSetOutputLstPathZOut( lstPathZOut );
223 printf("EED Warnning! DistanceMap::Process In or Point1 is EMPTY\n");
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)
230 void DistanceMap::bbUserSetDefaultValues()
233 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
234 // Here we initialize the input 'In' to 0
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)
243 void DistanceMap::bbUserInitializeProcessing()
246 // THE INITIALIZATION METHOD BODY :
248 // but this is where you should allocate the internal/output pointers
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)
256 void DistanceMap::bbUserFinalizeProcessing()
259 // THE FINALIZATION METHOD BODY :
261 // but this is where you should desallocate the internal/output pointers
266 // EO namespace bbcreaVtk