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()
19 // THE MAIN PROCESSING METHOD BODY
20 // Here we simply set the input 'In' value to the output 'Out'
21 // And print out the output value
22 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
23 // void bbSet{Input|Output}NAME(const TYPE&)
24 // const TYPE& bbGet{Input|Output}NAME() const
26 // * NAME is the name of the input/output
27 // (the one provided in the attribute 'name' of the tag 'input')
28 // * TYPE is the C++ type of the input/output
29 // (the one provided in the attribute 'type' of the tag 'input')
31 std::vector< std::vector<double> * > pLstVec;
32 std::vector< std::vector<double> * > pLstVecOut;
33 std::vector<double> In0 = bbGetInputIn0();
34 std::vector<double> In1 = bbGetInputIn1();
35 std::vector<double> In2 = bbGetInputIn2();
36 std::vector<double> In3 = bbGetInputIn3();
37 std::vector<double> In4 = bbGetInputIn4();
38 std::vector<double> In5 = bbGetInputIn5();
39 std::vector<double> In6 = bbGetInputIn6();
40 std::vector<double> In7 = bbGetInputIn7();
41 std::vector<double> In8 = bbGetInputIn8();
42 std::vector<double> In9 = bbGetInputIn9();
44 if (bbGetInputIn0().size()!=0) { pLstVec.push_back( &In0 ); }
45 if (bbGetInputIn1().size()!=0) { pLstVec.push_back( &In1 ); }
46 if (bbGetInputIn2().size()!=0) { pLstVec.push_back( &In2 ); }
47 if (bbGetInputIn3().size()!=0) { pLstVec.push_back( &In3 ); }
48 if (bbGetInputIn4().size()!=0) { pLstVec.push_back( &In4 ); }
49 if (bbGetInputIn5().size()!=0) { pLstVec.push_back( &In5 ); }
50 if (bbGetInputIn6().size()!=0) { pLstVec.push_back( &In6 ); }
51 if (bbGetInputIn7().size()!=0) { pLstVec.push_back( &In7 ); }
52 if (bbGetInputIn8().size()!=0) { pLstVec.push_back( &In8 ); }
53 if (bbGetInputIn9().size()!=0) { pLstVec.push_back( &In9 ); }
55 std::vector<double> Out0;
56 std::vector<double> Out1;
57 std::vector<double> Out2;
58 std::vector<double> Out3;
59 std::vector<double> Out4;
60 std::vector<double> Out5;
61 std::vector<double> Out6;
62 std::vector<double> Out7;
63 std::vector<double> Out8;
64 std::vector<double> Out9;
66 pLstVecOut.push_back( &Out0 );
67 pLstVecOut.push_back( &Out1 );
68 pLstVecOut.push_back( &Out2 );
69 pLstVecOut.push_back( &Out3 );
70 pLstVecOut.push_back( &Out4 );
71 pLstVecOut.push_back( &Out5 );
72 pLstVecOut.push_back( &Out6 );
73 pLstVecOut.push_back( &Out7 );
74 pLstVecOut.push_back( &Out8 );
75 pLstVecOut.push_back( &Out9 );
78 if (bbGetInputType()==0) // Erase duplicate lines
80 if (bbGetInputIn0().size()!=0) // At least one element
84 for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
86 if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() ) { okSizeVec=false; }
88 if ( okSizeVec==false)
90 printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
95 for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ )
98 for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
100 if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] ) { okLine=true; }
103 if ( (okLine==true) || (iLine==0) )
105 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
107 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
112 } // bbGetInputIn0() size
116 if (bbGetInputType()==1) // Resize vector
120 int sizeLines = (*pLstVec[0]).size();
121 double step = (double)sizeLines/((double)bbGetInputk1()[0]-1);
122 for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
124 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
126 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)iLine] );
130 // adding the lastone
131 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
133 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)(sizeLines-1)] );
138 if (bbGetInputType()==2) // Insert intermediate points
144 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
146 size=(*pLstVec[ipLstvec]).size();
149 for (i=0;i<size-1;i++)
151 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[i] ); // First item
152 result=((*pLstVec[ipLstvec])[i] + (*pLstVec[ipLstvec])[i+1] ) / 2;
153 (*pLstVecOut[ipLstvec]).push_back( result );
155 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[size-1] ); // Last item
161 if (bbGetInputType()==3) // Addition k1[0]
167 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
169 size=(*pLstVec[ipLstvec]).size();
172 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1()[0] ;
173 (*pLstVecOut[ipLstvec]).push_back( result );
178 if (bbGetInputType()==4) // Substraction k1[0]
184 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
186 size=(*pLstVec[ipLstvec]).size();
189 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1()[0] ;
190 (*pLstVecOut[ipLstvec]).push_back( result );
195 if (bbGetInputType()==5) // Multiplication k1[0]
201 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
203 size=(*pLstVec[ipLstvec]).size();
206 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1()[0] ;
207 (*pLstVecOut[ipLstvec]).push_back( result );
212 if (bbGetInputType()==6) // Division k1
218 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
220 size=(*pLstVec[ipLstvec]).size();
223 if (bbGetInputk1()[0]!=0)
225 result= (*pLstVec[ipLstvec])[i] / bbGetInputk1()[0] ;
226 (*pLstVecOut[ipLstvec]).push_back( result );
228 printf("EED VectorFilterDouble::Process Warning!! Div by 0 in Type 6 \n");
229 (*pLstVecOut[ipLstvec]).push_back( -1 );
237 if (bbGetInputType()==7)
240 for (j=0;j<In4.size(); j++)
242 Out0.push_back( In4[j] );
243 Out1.push_back( In5[j] );
244 Out2.push_back( In6[j] );
248 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
249 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
250 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
253 int sizeJ = In7[ 0 ];
255 double dist2,dist2Min,dx,dy,dz;
258 for (j=jGeneral;j<sizeJ;j++)
261 for (i=iGeneral;i<sizeI;i++)
266 dist2 = dx*dx + dy*dy + dz*dz;
283 if (bbGetInputType()==8) // order all vectors using as base the vector In0
287 sizeII=pLstVec.size();
291 for (i=0;i<size; i++)
293 for (ii=0;ii<sizeII;ii++)
295 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
302 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] )
305 for (ii=0;ii<sizeII;ii++)
307 tmp = (*pLstVecOut[ii])[i];
308 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j];
309 (*pLstVecOut[ii])[j] = tmp;
317 if (bbGetInputType()==9) // Invert vectors
321 sizeII=pLstVec.size();
325 for (i=0;i<size; i++)
327 for (ii=0;ii<sizeII;ii++)
329 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
333 for (i=0;i<size2;i++)
335 for (ii=0;ii<sizeII;ii++)
338 tmp = (*pLstVecOut[ii])[i];
339 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ];
340 (*pLstVecOut[ii])[j] = tmp;
346 if (bbGetInputType()==10) // Nearest point in vector
348 int sizeLstX = In0.size(); // lstX
349 int sizeLstY = In1.size(); // lstY
350 int sizeLstZ = In2.size(); // lstZ
351 if ( (sizeLstX==sizeLstY) && (sizeLstY==sizeLstZ) && (sizeLstX>0) && (In3.size()==3) )
354 double x1 = In3[0]; // pointX of pointXYZ
355 double y1 = In3[1]; // pointY of pointXYZ
356 double z1 = In3[2]; // pointZ of pointXYZ
357 double distMin = 100000;
362 Out0.push_back( -1 );
363 Out1.push_back( -999 );
364 Out1.push_back( -999 );
365 Out1.push_back( -999 );
366 for (i=0;i<sizeLstX; i++)
371 dist = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
382 printf("EED Warnning VectorFilterDouble::Process() For Type 10 the size of the vectors are not coherent.\n");
387 if (bbGetInputType()==11) // Nearest point in vector
390 int sizeLstX = In0.size(); // lstX
391 int sizeLstY = In1.size(); // lstY
392 int sizeLstZ = In2.size(); // lstZ
393 std::vector<double> spc = bbGetInputk1();
396 for (i=0;i<sizeLstX; i++)
398 Out0.push_back( In0[i]*spc[0] );
401 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
406 for (i=0;i<sizeLstY; i++)
408 Out1.push_back( In1[i]*spc[1] );
411 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
416 for (i=0;i<sizeLstZ; i++)
418 Out2.push_back( In2[i]*spc[2] );
421 printf("EED Warnning VectorFilterDouble::Process() For Type 11 the K1 vector (spacing) is not coherent.\n");
427 if (bbGetInputType()==12) // Nearest point in vector
430 int sizeLstX = In0.size(); // lstX
431 int sizeLstY = In1.size(); // lstY
432 int sizeLstZ = In2.size(); // lstZ
433 std::vector<double> spc = bbGetInputk1();
438 for (i=0;i<sizeLstX; i++)
440 Out0.push_back( In0[i]/spc[0] );
444 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
451 for (i=0;i<sizeLstY; i++)
453 Out1.push_back( In1[i]/spc[1] );
457 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
464 for (i=0;i<sizeLstZ; i++)
466 Out2.push_back( In2[i]/spc[2] );
470 printf("EED Warnning VectorFilterDouble::Process() For Type 12 the K1 vector (spacing) is not coherent.\n");
477 bbSetOutputOut0( Out0 );
478 bbSetOutputOut1( Out1 );
479 bbSetOutputOut2( Out2 );
480 bbSetOutputOut3( Out3 );
481 bbSetOutputOut4( Out4 );
482 bbSetOutputOut5( Out5 );
483 bbSetOutputOut6( Out6 );
484 bbSetOutputOut7( Out7 );
485 bbSetOutputOut8( Out8 );
486 bbSetOutputOut9( Out9 );
489 // 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)
491 void VectorFilterDouble::bbUserSetDefaultValues()
494 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
495 // Here we initialize the input 'In' to 0
497 std::vector<double> k1;
502 // 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)
504 void VectorFilterDouble::bbUserInitializeProcessing()
507 // THE INITIALIZATION METHOD BODY :
509 // but this is where you should allocate the internal/output pointers
515 // 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)
517 void VectorFilterDouble::bbUserFinalizeProcessing()
520 // THE FINALIZATION METHOD BODY :
522 // but this is where you should desallocate the internal/output pointers
527 // EO namespace bbstd