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 "bbstdVectorFilterDouble.h"
5 #include "bbstdPackage.h"
11 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,VectorFilterDouble)
12 BBTK_BLACK_BOX_IMPLEMENTATION(VectorFilterDouble,bbtk::AtomicBlackBox);
14 // 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)
16 void VectorFilterDouble::Process()
18 // THE MAIN PROCESSING METHOD BODY
19 // Here we simply set the input 'In' value to the output 'Out'
20 // And print out the output value
21 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
22 // void bbSet{Input|Output}NAME(const TYPE&)
23 // const TYPE& bbGet{Input|Output}NAME() const
25 // * NAME is the name of the input/output
26 // (the one provided in the attribute 'name' of the tag 'input')
27 // * TYPE is the C++ type of the input/output
28 // (the one provided in the attribute 'type' of the tag 'input')
29 std::vector< std::vector<double> * > pLstVec;
30 std::vector< std::vector<double> * > pLstVecOut;
31 std::vector<double> In0 = bbGetInputIn0();
32 std::vector<double> In1 = bbGetInputIn1();
33 std::vector<double> In2 = bbGetInputIn2();
34 std::vector<double> In3 = bbGetInputIn3();
35 std::vector<double> In4 = bbGetInputIn4();
36 std::vector<double> In5 = bbGetInputIn5();
37 std::vector<double> In6 = bbGetInputIn6();
38 std::vector<double> In7 = bbGetInputIn7();
39 std::vector<double> In8 = bbGetInputIn8();
40 std::vector<double> In9 = bbGetInputIn9();
41 if (bbGetInputIn0().size()!=0) { pLstVec.push_back( &In0 ); }
42 if (bbGetInputIn1().size()!=0) { pLstVec.push_back( &In1 ); }
43 if (bbGetInputIn2().size()!=0) { pLstVec.push_back( &In2 ); }
44 if (bbGetInputIn3().size()!=0) { pLstVec.push_back( &In3 ); }
45 if (bbGetInputIn4().size()!=0) { pLstVec.push_back( &In4 ); }
46 if (bbGetInputIn5().size()!=0) { pLstVec.push_back( &In5 ); }
47 if (bbGetInputIn6().size()!=0) { pLstVec.push_back( &In6 ); }
48 if (bbGetInputIn7().size()!=0) { pLstVec.push_back( &In7 ); }
49 if (bbGetInputIn8().size()!=0) { pLstVec.push_back( &In8 ); }
50 if (bbGetInputIn9().size()!=0) { pLstVec.push_back( &In9 ); }
51 std::vector<double> Out0;
52 std::vector<double> Out1;
53 std::vector<double> Out2;
54 std::vector<double> Out3;
55 std::vector<double> Out4;
56 std::vector<double> Out5;
57 std::vector<double> Out6;
58 std::vector<double> Out7;
59 std::vector<double> Out8;
60 std::vector<double> Out9;
61 pLstVecOut.push_back( &Out0 );
62 pLstVecOut.push_back( &Out1 );
63 pLstVecOut.push_back( &Out2 );
64 pLstVecOut.push_back( &Out3 );
65 pLstVecOut.push_back( &Out4 );
66 pLstVecOut.push_back( &Out5 );
67 pLstVecOut.push_back( &Out6 );
68 pLstVecOut.push_back( &Out7 );
69 pLstVecOut.push_back( &Out8 );
70 pLstVecOut.push_back( &Out9 );
71 if (bbGetInputType()==0) // Erase duplicate lines
73 if (bbGetInputIn0().size()!=0) // At least one element
77 for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
79 if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() ) { okSizeVec=false; }
81 if ( okSizeVec==false)
83 printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
88 for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ )
91 for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
93 if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] ) { okLine=true; }
96 if ( (okLine==true) || (iLine==0) )
98 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
100 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
105 } // bbGetInputIn0() size
107 if (bbGetInputType()==1) // Resize vector
111 int sizeLines = (*pLstVec[0]).size();
112 double step = (double)sizeLines/((double)bbGetInputk1()[0]-1);
113 for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
115 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
117 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)iLine] );
120 // adding the lastone
121 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
123 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)(sizeLines-1)] );
126 if (bbGetInputType()==2) // Insert intermediate points
132 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
134 size=(*pLstVec[ipLstvec]).size();
137 for (i=0;i<size-1;i++)
139 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[i] ); // First item
140 result=((*pLstVec[ipLstvec])[i] + (*pLstVec[ipLstvec])[i+1] ) / 2;
141 (*pLstVecOut[ipLstvec]).push_back( result );
143 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[size-1] ); // Last item
147 if (bbGetInputType()==3) // Addition k1[0]
153 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
155 size=(*pLstVec[ipLstvec]).size();
158 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1()[0] ;
159 (*pLstVecOut[ipLstvec]).push_back( result );
163 if (bbGetInputType()==4) // Substraction k1[0]
169 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
171 size=(*pLstVec[ipLstvec]).size();
174 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1()[0] ;
175 (*pLstVecOut[ipLstvec]).push_back( result );
179 if (bbGetInputType()==5) // Multiplication k1[0]
185 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
187 size=(*pLstVec[ipLstvec]).size();
190 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1()[0] ;
191 (*pLstVecOut[ipLstvec]).push_back( result );
195 if (bbGetInputType()==6) // Division k1
201 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
203 size=(*pLstVec[ipLstvec]).size();
206 if (bbGetInputk1()[0]!=0)
208 result= (*pLstVec[ipLstvec])[i] / bbGetInputk1()[0] ;
209 (*pLstVecOut[ipLstvec]).push_back( result );
211 printf("EED VectorFilterDouble::Process Warning!! Div by 0 in Type 6 \n");
212 (*pLstVecOut[ipLstvec]).push_back( -1 );
217 if (bbGetInputType()==7)
220 for (j=0;j<In4.size(); j++)
222 Out0.push_back( In4[j] );
223 Out1.push_back( In5[j] );
224 Out2.push_back( In6[j] );
226 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
227 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
228 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
230 int sizeJ = In7[ 0 ];
231 double dist2,dist2Min,dx,dy,dz;
233 for (j=jGeneral;j<sizeJ;j++)
236 for (i=iGeneral;i<sizeI;i++)
241 dist2 = dx*dx + dy*dy + dz*dz;
253 if (bbGetInputType()==8) // order all vectors using as base the vector In0
257 sizeII=pLstVec.size();
259 for (i=0;i<size; i++)
261 for (ii=0;ii<sizeII;ii++)
263 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
270 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] )
272 for (ii=0;ii<sizeII;ii++)
274 tmp = (*pLstVecOut[ii])[i];
275 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j];
276 (*pLstVecOut[ii])[j] = tmp;
282 if (bbGetInputType()==9) // Invert vectors
286 sizeII=pLstVec.size();
289 for (i=0;i<size; i++)
291 for (ii=0;ii<sizeII;ii++)
293 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
296 for (i=0;i<size2;i++)
298 for (ii=0;ii<sizeII;ii++)
301 tmp = (*pLstVecOut[ii])[i];
302 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ];
303 (*pLstVecOut[ii])[j] = tmp;
307 if (bbGetInputType()==10) // Nearest point in vector
309 int sizeLstX = In0.size(); // lstX
310 int sizeLstY = In1.size(); // lstY
311 int sizeLstZ = In2.size(); // lstZ
312 if ( (sizeLstX==sizeLstY) && (sizeLstY==sizeLstZ) && (sizeLstX>0) && (In3.size()==3) )
315 double x1 = In3[0]; // pointX of pointXYZ
316 double y1 = In3[1]; // pointY of pointXYZ
317 double z1 = In3[2]; // pointZ of pointXYZ
318 double distMin = 100000;
323 Out0.push_back( -1 );
324 Out1.push_back( -999 );
325 Out1.push_back( -999 );
326 Out1.push_back( -999 );
327 for (i=0;i<sizeLstX; i++)
332 dist = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
343 printf("EED Warnning VectorFilterDouble::Process() For Type 10 the size of the vectors are not coherent.\n");
346 if (bbGetInputType()==11) // Nearest point in vector
349 int sizeLstX = In0.size(); // lstX
350 int sizeLstY = In1.size(); // lstY
351 int sizeLstZ = In2.size(); // lstZ
352 std::vector<double> spc = bbGetInputk1();
355 for (i=0;i<sizeLstX; i++)
357 Out0.push_back( In0[i]*spc[0] );
360 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
364 for (i=0;i<sizeLstY; i++)
366 Out1.push_back( In1[i]*spc[1] );
369 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
373 for (i=0;i<sizeLstZ; i++)
375 Out2.push_back( In2[i]*spc[2] );
378 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
381 if (bbGetInputType()==12) // Nearest point in vector
384 int sizeLstX = In0.size(); // lstX
385 int sizeLstY = In1.size(); // lstY
386 int sizeLstZ = In2.size(); // lstZ
387 std::vector<double> spc = bbGetInputk1();
392 for (i=0;i<sizeLstX; i++)
394 Out0.push_back( In0[i]/spc[0] );
398 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
404 for (i=0;i<sizeLstY; i++)
406 Out1.push_back( In1[i]/spc[1] );
410 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
416 for (i=0;i<sizeLstZ; i++)
418 Out2.push_back( In2[i]/spc[2] );
422 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
425 if (bbGetInputType()==13) // Distance point 3D between In0 and In1
427 if ( In0.size()==3 and In1.size()==3)
429 double x = In0[0] - In1[0];
430 double y = In0[1] - In1[1];
431 double z = In0[2] - In1[2];
432 Out0.push_back( sqrt( x*x +y*y +z*z ) );
435 bbSetOutputOut0( Out0 );
436 bbSetOutputOut1( Out1 );
437 bbSetOutputOut2( Out2 );
438 bbSetOutputOut3( Out3 );
439 bbSetOutputOut4( Out4 );
440 bbSetOutputOut5( Out5 );
441 bbSetOutputOut6( Out6 );
442 bbSetOutputOut7( Out7 );
443 bbSetOutputOut8( Out8 );
444 bbSetOutputOut9( Out9 );
448 // 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)
450 void VectorFilterDouble::bbUserSetDefaultValues()
452 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
453 // Here we initialize the input 'In' to 0
455 std::vector<double> k1;
461 // 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)
463 void VectorFilterDouble::bbUserInitializeProcessing()
465 // THE INITIALIZATION METHOD BODY :
467 // but this is where you should allocate the internal/output pointers
472 // 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)
474 void VectorFilterDouble::bbUserFinalizeProcessing()
476 // THE FINALIZATION METHOD BODY :
478 // but this is where you should desallocate the internal/output pointers
482 }// EO namespace bbstd