]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorFilterDouble.cxx
ffed94ac2ef729909a3aec9b4459d736abe7cd15
[bbtk.git] / packages / std / src / bbstdVectorFilterDouble.cxx
1 //===== 
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)
3 //===== 
4 #include "bbstdVectorFilterDouble.h"
5 #include "bbstdPackage.h"
6 namespace bbstd
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,VectorFilterDouble)
10 BBTK_BLACK_BOX_IMPLEMENTATION(VectorFilterDouble,bbtk::AtomicBlackBox);
11 //===== 
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)
13 //===== 
14 void VectorFilterDouble::Process()
15 {
16
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 
23 //    Where :
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')
28
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
42         if (bbGetInputIn0().size()!=0) { pLstVec.push_back( &In0 ); }
43         if (bbGetInputIn1().size()!=0) { pLstVec.push_back( &In1 ); }
44         if (bbGetInputIn2().size()!=0) { pLstVec.push_back( &In2 ); }
45         if (bbGetInputIn3().size()!=0) { pLstVec.push_back( &In3 ); }
46         if (bbGetInputIn4().size()!=0) { pLstVec.push_back( &In4 ); }
47         if (bbGetInputIn5().size()!=0) { pLstVec.push_back( &In5 ); }
48         if (bbGetInputIn6().size()!=0) { pLstVec.push_back( &In6 ); }
49         if (bbGetInputIn7().size()!=0) { pLstVec.push_back( &In7 ); }
50         if (bbGetInputIn8().size()!=0) { pLstVec.push_back( &In8 ); }
51         if (bbGetInputIn9().size()!=0) { pLstVec.push_back( &In9 ); }
52
53         std::vector<double> Out0;
54         std::vector<double> Out1;
55         std::vector<double> Out2;
56         std::vector<double> Out3;
57         std::vector<double> Out4;
58         std::vector<double> Out5;
59         std::vector<double> Out6;
60         std::vector<double> Out7;
61         std::vector<double> Out8;
62         std::vector<double> Out9;
63
64         pLstVecOut.push_back( &Out0 );
65         pLstVecOut.push_back( &Out1 );
66         pLstVecOut.push_back( &Out2 );
67         pLstVecOut.push_back( &Out3 );
68         pLstVecOut.push_back( &Out4 );
69         pLstVecOut.push_back( &Out5 );
70         pLstVecOut.push_back( &Out6 );
71         pLstVecOut.push_back( &Out7 );
72         pLstVecOut.push_back( &Out8 );
73         pLstVecOut.push_back( &Out9 );
74
75
76         if (bbGetInputType()==0)  // Erase duplicate lines
77         {
78                 bool okSizeVec=true;
79                 int ipLstvec; 
80                 for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
81                 {
82                         if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() )  { okSizeVec=false; }
83                 }
84                 if ( okSizeVec==false)
85                 {
86                         printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
87                 } else {
88                         int iLine;
89                         int ipLstvec2; 
90                         bool okLine;
91                         for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ ) 
92                         {
93                                 okLine=false;
94                                 for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
95                                 {
96                                         if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] )  { okLine=true; }
97                                 } // for ipLstVec2
98                                                 
99                                 if ( (okLine==true) || (iLine==0) ) 
100                                 {
101                                         for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
102                                         {
103                                                 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
104                                         } // for
105                                 } // if okLine
106                         } // for iLine
107                 } // if okSizeVec
108         } // Type==0
109
110
111         if (bbGetInputType()==1) // Resize vector
112         {
113                 int             ipLstvec2;
114                 double  iLine;
115                 int     sizeLines       = (*pLstVec[0]).size();
116                 double  step            = (double)sizeLines/((double)bbGetInputk1()-1);
117                 for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
118                 {
119                         for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
120                         {
121                                 (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)iLine] );
122                         } // for                        
123                 } // for ipLstVec
124
125                 // adding the lastone
126                 for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
127                 {
128                         (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)(sizeLines-1)] );
129                 } // for                        
130
131         } // Type==1
132
133         if (bbGetInputType()==2) // Insert intermediate points
134         {
135                 int             ipLstvec;
136                 int     i;
137                 int     size;
138                 double  result;
139                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
140                 {
141                         size=(*pLstVec[ipLstvec]).size();
142                         if (size>=2)
143                         {
144                                 for (i=0;i<size-1;i++)
145                                 {
146                                         (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[i] );   // First item                   
147                                         result=((*pLstVec[ipLstvec])[i] + (*pLstVec[ipLstvec])[i+1]  ) / 2;
148                                         (*pLstVecOut[ipLstvec]).push_back( result );                            
149                                 }// for size
150                                 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[size-1] );      // Last item            
151                         } // if size>=2
152                 } // for pLstVec                
153         } // Type==2
154
155
156         if (bbGetInputType()==3) // Addition  k1
157         {
158                 int             ipLstvec;
159                 int     i;
160                 int     size;
161                 double  result;
162                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
163                 {
164                         size=(*pLstVec[ipLstvec]).size();
165                         for (i=0;i<size;i++)
166                         {
167                                 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
168                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
169                         }// for size
170                 } // for pLstVec                
171         } // Type==3
172
173         if (bbGetInputType()==4) // Substraction  k1
174         {
175                 int             ipLstvec;
176                 int     i;
177                 int     size;
178                 double  result;
179                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
180                 {
181                         size=(*pLstVec[ipLstvec]).size();
182                         for (i=0;i<size;i++)
183                         {
184                                 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
185                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
186                         }// for size
187                 } // for pLstVec                
188         } // Type==4
189
190         if (bbGetInputType()==5) // Multiplication  k1
191         {
192                 int     ipLstvec;
193                 int     i;
194                 int     size;
195                 double  result;
196                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
197                 {
198                         size=(*pLstVec[ipLstvec]).size();
199                         for (i=0;i<size;i++)
200                         {
201                                 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
202                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
203                         }// for size
204                 } // for pLstVec                
205         } // Type==5
206
207         if (bbGetInputType()==6) // Division  k1ng gadget (node check, owner GtkCheckButton)
208
209
210         {
211                 int     ipLstvec;
212                 int     i;
213                 int     size;
214                 double  result;
215                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
216                 {
217                         size=(*pLstVec[ipLstvec]).size();
218                         for (i=0;i<size;i++)
219                         {
220                                 if (bbGetInputk1()!=0)
221                                 {
222                                         result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
223                                         (*pLstVecOut[ipLstvec]).push_back( result );                            
224                                 } else {
225                                         printf("EED VectorFilterDouble::Process  Warning!! Div by 0 in Type 6 \n");
226                                         (*pLstVecOut[ipLstvec]).push_back( -1 );                                
227                                 }
228                         }// for size
229                 } // for pLstVec                
230         } // Type==6
231
232
233
234         if (bbGetInputType()==7) 
235         {
236                 int i,j;
237                 for (j=0;j<In4.size(); j++)
238                 {
239                         Out0.push_back( In4[j] );
240                         Out1.push_back( In5[j] );
241                         Out2.push_back( In6[j] );
242                 } //
243
244
245                 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
246                 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
247                 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
248
249                 int jGeneral = 0;
250                 int sizeJ        = In7[ 0 ];
251
252                 double dist2,dist2Min,dx,dy,dz;
253                 int iBack;
254
255                 for (j=jGeneral;j<sizeJ;j++) 
256                 {
257                         dist2Min=1000000;
258                         for (i=iGeneral;i<sizeI;i++) 
259                         {       
260                                 dx              = In0[i]-In4[j];
261                                 dy              = In1[i]-In5[j];
262                                 dz              = In2[i]-In6[j];
263                                 dist2           = dx*dx + dy*dy + dz*dz;
264                                 if (dist2<dist2Min) 
265                                 {
266                                                 dist2Min=dist2;
267                                                 iBack=i;
268                                 } // if
269                         } // for j
270                         Out0[j]=In0[iBack]; 
271                         Out1[j]=In1[iBack]; 
272                         Out2[j]=In2[iBack]; 
273                 } // for i
274
275
276         }       // Type 7
277
278
279
280         if (bbGetInputType()==8)   // order all vectors using as base the vector In0
281         {
282                 double tmp;
283                 int i,j,ii,sizeII;
284                 sizeII=pLstVec.size();
285
286
287                 int size=In0.size();
288                 for (i=0;i<size; i++)
289                 {
290                         for (ii=0;ii<sizeII;ii++)
291                         {
292                                  (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] ); 
293                         } // for ii
294                 } // i
295                 for (i=0;i<size;i++)
296                 {
297                         for (j=i;j<size;j++)
298                         {
299                                 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] ) 
300                                 {       
301                                         
302                                         for (ii=0;ii<sizeII;ii++)
303                                         {
304                                                 tmp = (*pLstVecOut[ii])[i]; 
305                                                 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j]; 
306                                                 (*pLstVecOut[ii])[j] = tmp; 
307                                         } // for ii
308                                 } // if <
309                         } // for j
310                 } // for i
311         } // Type 8
312
313
314         if (bbGetInputType()==9)   // Invert vectors
315         {
316                 double tmp;
317                 int i,j,ii,sizeII;
318                 sizeII=pLstVec.size();
319
320                 int size=In0.size();
321                 int size2=size/2;
322                 for (i=0;i<size; i++)
323                 {
324                         for (ii=0;ii<sizeII;ii++)
325                         {
326                                  (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] ); 
327                         } // for ii
328                 } // i
329
330                 for (i=0;i<size2;i++)
331                 {
332                         for (ii=0;ii<sizeII;ii++)
333                         {
334                                 j=size-1-i;     
335                                 tmp = (*pLstVecOut[ii])[i]; 
336                                 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ]; 
337                                 (*pLstVecOut[ii])[j] = tmp; 
338                         } // for ii
339                 } // for i
340         } // Type 9
341
342         bbSetOutputOut0( Out0 );
343         bbSetOutputOut1( Out1 );
344         bbSetOutputOut2( Out2 );
345         bbSetOutputOut3( Out3 );
346         bbSetOutputOut4( Out4 );
347         bbSetOutputOut5( Out5 );
348         bbSetOutputOut6( Out6 );
349         bbSetOutputOut7( Out7 );
350         bbSetOutputOut8( Out8 );
351         bbSetOutputOut9( Out9 );
352 }
353 //===== 
354 // 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)
355 //===== 
356 void VectorFilterDouble::bbUserSetDefaultValues()
357 {
358
359 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
360 //    Here we initialize the input 'In' to 0
361    bbSetInputType(0);
362    bbSetInputk1(0);
363   
364 }
365 //===== 
366 // 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)
367 //===== 
368 void VectorFilterDouble::bbUserInitializeProcessing()
369 {
370
371 //  THE INITIALIZATION METHOD BODY :
372 //    Here does nothing 
373 //    but this is where you should allocate the internal/output pointers 
374 //    if any 
375
376   
377 }
378 //===== 
379 // 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)
380 //===== 
381 void VectorFilterDouble::bbUserFinalizeProcessing()
382 {
383
384 //  THE FINALIZATION METHOD BODY :
385 //    Here does nothing 
386 //    but this is where you should desallocate the internal/output pointers 
387 //    if any
388   
389 }
390 }
391 // EO namespace bbstd
392
393