]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorFilterDouble.cxx
85dee1f9d0d11e21a6c1b8291c6d108fd90b549c
[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();
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         } // Type==1
125
126         if (bbGetInputType()==2) // Insert intermediate points
127         {
128                 int             ipLstvec;
129                 int     i;
130                 int     size;
131                 double  result;
132                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
133                 {
134                         size=(*pLstVec[ipLstvec]).size();
135                         if (size>=2)
136                         {
137                                 for (i=0;i<size-1;i++)
138                                 {
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 );                            
142                                 }// for size
143                                 (*pLstVecOut[ipLstvec]).push_back( (*pLstVec[ipLstvec])[size-1] );      // Last item            
144                         } // if size>=2
145                 } // for pLstVec                
146         } // Type==2
147
148
149         if (bbGetInputType()==3) // Addition  k1
150         {
151                 int             ipLstvec;
152                 int     i;
153                 int     size;
154                 double  result;
155                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
156                 {
157                         size=(*pLstVec[ipLstvec]).size();
158                         for (i=0;i<size;i++)
159                         {
160                                 result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
161                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
162                         }// for size
163                 } // for pLstVec                
164         } // Type==3
165
166         if (bbGetInputType()==4) // Substraction  k1
167         {
168                 int             ipLstvec;
169                 int     i;
170                 int     size;
171                 double  result;
172                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
173                 {
174                         size=(*pLstVec[ipLstvec]).size();
175                         for (i=0;i<size;i++)
176                         {
177                                 result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
178                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
179                         }// for size
180                 } // for pLstVec                
181         } // Type==4
182
183         if (bbGetInputType()==5) // Multiplication  k1
184         {
185                 int     ipLstvec;
186                 int     i;
187                 int     size;
188                 double  result;
189                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
190                 {
191                         size=(*pLstVec[ipLstvec]).size();
192                         for (i=0;i<size;i++)
193                         {
194                                 result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
195                                 (*pLstVecOut[ipLstvec]).push_back( result );                            
196                         }// for size
197                 } // for pLstVec                
198         } // Type==5
199
200         if (bbGetInputType()==6) // Division  k1ng gadget (node check, owner GtkCheckButton)
201
202
203         {
204                 int     ipLstvec;
205                 int     i;
206                 int     size;
207                 double  result;
208                 for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
209                 {
210                         size=(*pLstVec[ipLstvec]).size();
211                         for (i=0;i<size;i++)
212                         {
213                                 if (bbGetInputk1()!=0)
214                                 {
215                                         result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
216                                         (*pLstVecOut[ipLstvec]).push_back( result );                            
217                                 } else {
218                                         printf("EED VectorFilterDouble::Process  Warning!! Div by 0 in Type 6 \n");
219                                         (*pLstVecOut[ipLstvec]).push_back( -1 );                                
220                                 }
221                         }// for size
222                 } // for pLstVec                
223         } // Type==6
224
225
226
227         if (bbGetInputType()==7) 
228         {
229                 int i,j;
230                 for (j=0;j<In4.size(); j++)
231                 {
232                         Out0.push_back( In4[j] );
233                         Out1.push_back( In5[j] );
234                         Out2.push_back( In6[j] );
235                 } //
236
237
238                 int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
239                 for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
240                 sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
241
242                 int jGeneral = 0;
243                 int sizeJ        = In7[ 0 ];
244
245                 double dist2,dist2Min,dx,dy,dz;
246                 int iBack;
247
248                 for (j=jGeneral;j<sizeJ;j++) 
249                 {
250                         dist2Min=1000000;
251                         for (i=iGeneral;i<sizeI;i++) 
252                         {       
253                                 dx              = In0[i]-In4[j];
254                                 dy              = In1[i]-In5[j];
255                                 dz              = In2[i]-In6[j];
256                                 dist2           = dx*dx + dy*dy + dz*dz;
257                                 if (dist2<dist2Min) 
258                                 {
259                                                 dist2Min=dist2;
260                                                 iBack=i;
261                                 } // if
262                         } // for j
263                         Out0[j]=In0[iBack]; 
264                         Out1[j]=In1[iBack]; 
265                         Out2[j]=In2[iBack]; 
266                 } // for i
267
268
269         }       // Type 7
270
271
272
273         if (bbGetInputType()==8)   // order all vectors using as base the vector In0
274         {
275 printf("EED VectorFilterDouble::Process Type 8 Start\n");
276                 double tmp;
277                 int i,j,ii,sizeII;
278                 sizeII=pLstVec.size();
279
280
281                 int size=In0.size();
282                 for (i=0;i<size; i++)
283                 {
284                         for (ii=0;ii<sizeII;ii++)
285                         {
286                                  (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] ); 
287                         } // for ii
288                 } // i
289                 for (i=0;i<size;i++)
290                 {
291                         for (j=i;j<size;j++)
292                         {
293                                 if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] ) 
294                                 {       
295                                         
296                                         for (ii=0;ii<sizeII;ii++)
297                                         {
298                                                 tmp = (*pLstVecOut[ii])[i]; 
299                                                 (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j]; 
300                                                 (*pLstVecOut[ii])[j] = tmp; 
301 //                                              tmp=Out0[i]; Out0[i]=Out0[j]; Out0[j]=tmp; 
302                                         }
303                                 }
304                         } // for j
305                 } // for i
306 printf("EED VectorFilterDouble::Process Type 8 End\n");
307
308         } // Type 8
309
310
311
312
313         bbSetOutputOut0( Out0 );
314         bbSetOutputOut1( Out1 );
315         bbSetOutputOut2( Out2 );
316         bbSetOutputOut3( Out3 );
317         bbSetOutputOut4( Out4 );
318         bbSetOutputOut5( Out5 );
319         bbSetOutputOut6( Out6 );
320         bbSetOutputOut7( Out7 );
321         bbSetOutputOut8( Out8 );
322         bbSetOutputOut9( Out9 );
323 }
324 //===== 
325 // 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)
326 //===== 
327 void VectorFilterDouble::bbUserSetDefaultValues()
328 {
329
330 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
331 //    Here we initialize the input 'In' to 0
332    bbSetInputType(0);
333    bbSetInputk1(0);
334   
335 }
336 //===== 
337 // 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)
338 //===== 
339 void VectorFilterDouble::bbUserInitializeProcessing()
340 {
341
342 //  THE INITIALIZATION METHOD BODY :
343 //    Here does nothing 
344 //    but this is where you should allocate the internal/output pointers 
345 //    if any 
346
347   
348 }
349 //===== 
350 // 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)
351 //===== 
352 void VectorFilterDouble::bbUserFinalizeProcessing()
353 {
354
355 //  THE FINALIZATION METHOD BODY :
356 //    Here does nothing 
357 //    but this is where you should desallocate the internal/output pointers 
358 //    if any
359   
360 }
361 }
362 // EO namespace bbstd
363
364