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()-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
167 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
169 size=(*pLstVec[ipLstvec]).size();
172 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
173 (*pLstVecOut[ipLstvec]).push_back( result );
178 if (bbGetInputType()==4) // Substraction k1
184 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
186 size=(*pLstVec[ipLstvec]).size();
189 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
190 (*pLstVecOut[ipLstvec]).push_back( result );
195 if (bbGetInputType()==5) // Multiplication k1
201 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
203 size=(*pLstVec[ipLstvec]).size();
206 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
207 (*pLstVecOut[ipLstvec]).push_back( result );
212 if (bbGetInputType()==6) // Division k1ng gadget (node check, owner GtkCheckButton)
220 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
222 size=(*pLstVec[ipLstvec]).size();
225 if (bbGetInputk1()!=0)
227 result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
228 (*pLstVecOut[ipLstvec]).push_back( result );
230 printf("EED VectorFilterDouble::Process Warning!! Div by 0 in Type 6 \n");
231 (*pLstVecOut[ipLstvec]).push_back( -1 );
239 if (bbGetInputType()==7)
242 for (j=0;j<In4.size(); j++)
244 Out0.push_back( In4[j] );
245 Out1.push_back( In5[j] );
246 Out2.push_back( In6[j] );
250 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
251 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
252 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
255 int sizeJ = In7[ 0 ];
257 double dist2,dist2Min,dx,dy,dz;
260 for (j=jGeneral;j<sizeJ;j++)
263 for (i=iGeneral;i<sizeI;i++)
268 dist2 = dx*dx + dy*dy + dz*dz;
285 if (bbGetInputType()==8) // order all vectors using as base the vector In0
289 sizeII=pLstVec.size();
293 for (i=0;i<size; i++)
295 for (ii=0;ii<sizeII;ii++)
297 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
304 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] )
307 for (ii=0;ii<sizeII;ii++)
309 tmp = (*pLstVecOut[ii])[i];
310 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j];
311 (*pLstVecOut[ii])[j] = tmp;
319 if (bbGetInputType()==9) // Invert vectors
323 sizeII=pLstVec.size();
327 for (i=0;i<size; i++)
329 for (ii=0;ii<sizeII;ii++)
331 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
335 for (i=0;i<size2;i++)
337 for (ii=0;ii<sizeII;ii++)
340 tmp = (*pLstVecOut[ii])[i];
341 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ];
342 (*pLstVecOut[ii])[j] = tmp;
348 if (bbGetInputType()==10) // Nearest point in vector
350 int sizeLstX = In0.size(); // lstX
351 int sizeLstY = In1.size(); // lstY
352 int sizeLstZ = In2.size(); // lstZ
353 if ( (sizeLstX==sizeLstY) && (sizeLstY==sizeLstZ) && (sizeLstX>0) && (In3.size()==3) )
356 double x1 = In3[0]; // pointX of pointXYZ
357 double y1 = In3[1]; // pointY of pointXYZ
358 double z1 = In3[2]; // pointZ of pointXYZ
359 double distMin = 100000;
364 Out0.push_back( -1 );
365 Out1.push_back( -999 );
366 Out1.push_back( -999 );
367 Out1.push_back( -999 );
368 for (i=0;i<sizeLstX; i++)
373 dist = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
384 printf("EED Warnning VectorFilterDouble::Process() For Type 10 the size of the vectors are not coherent.\n");
390 bbSetOutputOut0( Out0 );
391 bbSetOutputOut1( Out1 );
392 bbSetOutputOut2( Out2 );
393 bbSetOutputOut3( Out3 );
394 bbSetOutputOut4( Out4 );
395 bbSetOutputOut5( Out5 );
396 bbSetOutputOut6( Out6 );
397 bbSetOutputOut7( Out7 );
398 bbSetOutputOut8( Out8 );
399 bbSetOutputOut9( Out9 );
402 // 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)
404 void VectorFilterDouble::bbUserSetDefaultValues()
407 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
408 // Here we initialize the input 'In' to 0
414 // 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)
416 void VectorFilterDouble::bbUserInitializeProcessing()
419 // THE INITIALIZATION METHOD BODY :
421 // but this is where you should allocate the internal/output pointers
427 // 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)
429 void VectorFilterDouble::bbUserFinalizeProcessing()
432 // THE FINALIZATION METHOD BODY :
434 // but this is where you should desallocate the internal/output pointers
439 // EO namespace bbstd