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 printf("EED VectorFilterDouble::Process bbGetInputType()=%d\n", bbGetInputType() );
33 std::vector< std::vector<double> * > pLstVec;
34 std::vector< std::vector<double> * > pLstVecOut;
35 std::vector<double> In0 = bbGetInputIn0();
36 std::vector<double> In1 = bbGetInputIn1();
37 std::vector<double> In2 = bbGetInputIn2();
38 std::vector<double> In3 = bbGetInputIn3();
39 std::vector<double> In4 = bbGetInputIn4();
40 std::vector<double> In5 = bbGetInputIn5();
41 std::vector<double> In6 = bbGetInputIn6();
42 std::vector<double> In7 = bbGetInputIn7();
43 std::vector<double> In8 = bbGetInputIn8();
44 std::vector<double> In9 = bbGetInputIn9();
46 if (bbGetInputIn0().size()!=0) { pLstVec.push_back( &In0 ); }
47 if (bbGetInputIn1().size()!=0) { pLstVec.push_back( &In1 ); }
48 if (bbGetInputIn2().size()!=0) { pLstVec.push_back( &In2 ); }
49 if (bbGetInputIn3().size()!=0) { pLstVec.push_back( &In3 ); }
50 if (bbGetInputIn4().size()!=0) { pLstVec.push_back( &In4 ); }
51 if (bbGetInputIn5().size()!=0) { pLstVec.push_back( &In5 ); }
52 if (bbGetInputIn6().size()!=0) { pLstVec.push_back( &In6 ); }
53 if (bbGetInputIn7().size()!=0) { pLstVec.push_back( &In7 ); }
54 if (bbGetInputIn8().size()!=0) { pLstVec.push_back( &In8 ); }
55 if (bbGetInputIn9().size()!=0) { pLstVec.push_back( &In9 ); }
57 std::vector<double> Out0;
58 std::vector<double> Out1;
59 std::vector<double> Out2;
60 std::vector<double> Out3;
61 std::vector<double> Out4;
62 std::vector<double> Out5;
63 std::vector<double> Out6;
64 std::vector<double> Out7;
65 std::vector<double> Out8;
66 std::vector<double> Out9;
68 pLstVecOut.push_back( &Out0 );
69 pLstVecOut.push_back( &Out1 );
70 pLstVecOut.push_back( &Out2 );
71 pLstVecOut.push_back( &Out3 );
72 pLstVecOut.push_back( &Out4 );
73 pLstVecOut.push_back( &Out5 );
74 pLstVecOut.push_back( &Out6 );
75 pLstVecOut.push_back( &Out7 );
76 pLstVecOut.push_back( &Out8 );
77 pLstVecOut.push_back( &Out9 );
80 if (bbGetInputType()==0) // Erase duplicate lines
82 if (bbGetInputIn0().size()!=0) // At least one element
86 for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
88 if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() ) { okSizeVec=false; }
90 if ( okSizeVec==false)
92 printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
97 for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ )
100 for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
102 if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] ) { okLine=true; }
105 if ( (okLine==true) || (iLine==0) )
107 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
109 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
114 } // bbGetInputIn0() size
118 if (bbGetInputType()==1) // Resize vector
122 int sizeLines = (*pLstVec[0]).size();
123 double step = (double)sizeLines/((double)bbGetInputk1()-1);
124 for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
126 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
128 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)iLine] );
132 // adding the lastone
133 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
135 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)(sizeLines-1)] );
140 if (bbGetInputType()==2) // Insert intermediate points
146 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
148 size=(*pLstVec[ipLstvec]).size();
151 for (i=0;i<size-1;i++)
153 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[i] ); // First item
154 result=((*pLstVec[ipLstvec])[i] + (*pLstVec[ipLstvec])[i+1] ) / 2;
155 (*pLstVecOut[ipLstvec]).push_back( result );
157 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[size-1] ); // Last item
163 if (bbGetInputType()==3) // Addition k1
169 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
171 size=(*pLstVec[ipLstvec]).size();
174 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
175 (*pLstVecOut[ipLstvec]).push_back( result );
180 if (bbGetInputType()==4) // Substraction k1
186 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
188 size=(*pLstVec[ipLstvec]).size();
191 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
192 (*pLstVecOut[ipLstvec]).push_back( result );
197 if (bbGetInputType()==5) // Multiplication k1
203 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
205 size=(*pLstVec[ipLstvec]).size();
208 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
209 (*pLstVecOut[ipLstvec]).push_back( result );
214 if (bbGetInputType()==6) // Division k1ng gadget (node check, owner GtkCheckButton)
222 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
224 size=(*pLstVec[ipLstvec]).size();
227 if (bbGetInputk1()!=0)
229 result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
230 (*pLstVecOut[ipLstvec]).push_back( result );
232 printf("EED VectorFilterDouble::Process Warning!! Div by 0 in Type 6 \n");
233 (*pLstVecOut[ipLstvec]).push_back( -1 );
241 if (bbGetInputType()==7)
244 for (j=0;j<In4.size(); j++)
246 Out0.push_back( In4[j] );
247 Out1.push_back( In5[j] );
248 Out2.push_back( In6[j] );
252 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
253 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
254 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
257 int sizeJ = In7[ 0 ];
259 double dist2,dist2Min,dx,dy,dz;
262 for (j=jGeneral;j<sizeJ;j++)
265 for (i=iGeneral;i<sizeI;i++)
270 dist2 = dx*dx + dy*dy + dz*dz;
287 if (bbGetInputType()==8) // order all vectors using as base the vector In0
291 sizeII=pLstVec.size();
295 for (i=0;i<size; i++)
297 for (ii=0;ii<sizeII;ii++)
299 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
306 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] )
309 for (ii=0;ii<sizeII;ii++)
311 tmp = (*pLstVecOut[ii])[i];
312 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j];
313 (*pLstVecOut[ii])[j] = tmp;
321 if (bbGetInputType()==9) // Invert vectors
325 sizeII=pLstVec.size();
329 for (i=0;i<size; i++)
331 for (ii=0;ii<sizeII;ii++)
333 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] );
337 for (i=0;i<size2;i++)
339 for (ii=0;ii<sizeII;ii++)
342 tmp = (*pLstVecOut[ii])[i];
343 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ];
344 (*pLstVecOut[ii])[j] = tmp;
350 if (bbGetInputType()==10) // Invert vectors
352 int sizeLstX = In0.size(); // lstX
353 int sizeLstY = In1.size(); // lstY
354 int sizeLstZ = In2.size(); // lstZ
355 printf("EED Warnning VectorFilterDouble::Process() %d %d %d %d\n", sizeLstX,sizeLstY,sizeLstZ,In3.size() );
356 if ( (sizeLstX==sizeLstY) && (sizeLstY==sizeLstZ) && (sizeLstX>0) && (In3.size()==3) )
359 double x1 = In3[0]; // pointX of pointXYZ
360 double y1 = In3[1]; // pointY of pointXYZ
361 double z1 = In3[2]; // pointZ of pointXYZ
362 double distMin = 100000;
367 Out0.push_back( -1 );
368 Out1.push_back( -999 );
369 Out1.push_back( -999 );
370 Out1.push_back( -999 );
371 for (i=0;i<sizeLstX; i++)
376 dist = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
387 printf("EED Warnning VectorFilterDouble::Process() For Type 10 the size of the vectors are not coherent.\n");
393 bbSetOutputOut0( Out0 );
394 bbSetOutputOut1( Out1 );
395 bbSetOutputOut2( Out2 );
396 bbSetOutputOut3( Out3 );
397 bbSetOutputOut4( Out4 );
398 bbSetOutputOut5( Out5 );
399 bbSetOutputOut6( Out6 );
400 bbSetOutputOut7( Out7 );
401 bbSetOutputOut8( Out8 );
402 bbSetOutputOut9( Out9 );
405 // 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)
407 void VectorFilterDouble::bbUserSetDefaultValues()
410 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
411 // Here we initialize the input 'In' to 0
417 // 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)
419 void VectorFilterDouble::bbUserInitializeProcessing()
422 // THE INITIALIZATION METHOD BODY :
424 // but this is where you should allocate the internal/output pointers
430 // 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)
432 void VectorFilterDouble::bbUserFinalizeProcessing()
435 // THE FINALIZATION METHOD BODY :
437 // but this is where you should desallocate the internal/output pointers
442 // EO namespace bbstd