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 "bbstdMathOperationVector.h"
5 #include "bbstdPackage.h"
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MathOperationVector)
14 BBTK_BLACK_BOX_IMPLEMENTATION(MathOperationVector,bbtk::AtomicBlackBox);
16 double MathOperationVector::g(std::vector<double>*v,unsigned int i,double defValue )
18 double result=defValue;
26 void MathOperationVector::SumVector(std::vector<double> *v,std::vector<double> *vr)
30 unsigned int sizeVec=v->size();
33 for (i=0;i<sizeVec;i++)
35 tmpResult = (*v)[i] + tmpResult;
37 vr->push_back( tmpResult );
42 void MathOperationVector::MinVector(std::vector<double> *v,std::vector<double> *vr)
46 unsigned int sizeVec=v->size();
50 for (i=1;i<sizeVec;i++)
52 tmpResult = std::min ( (*v)[i] , tmpResult ) ;
54 vr->push_back( tmpResult );
59 void MathOperationVector::MaxVector(std::vector<double> *v,std::vector<double> *vr)
63 unsigned int sizeVec=v->size();
67 for (i=1;i<sizeVec;i++)
69 tmpResult = std::max ( (*v)[i] , tmpResult ) ;
71 vr->push_back( tmpResult );
76 // 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)
78 void MathOperationVector::Process()
80 // THE MAIN PROCESSING METHOD BODY
81 // Here we simply set the input 'In' value to the output 'Out'
82 // And print out the output value
83 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
84 // void bbSet{Input|Output}NAME(const TYPE&)
85 // const TYPE& bbGet{Input|Output}NAME() const
87 // * NAME is the name of the input/output
88 // (the one provided in the attribute 'name' of the tag 'input')
89 // * TYPE is the C++ type of the input/output
90 // (the one provided in the attribute 'type' of the tag 'input')
94 unsigned int sizeVec = bbGetInputIn0().size();
96 std::vector<double> resultVec;
97 std::vector<double> _v0=bbGetInputIn0();
98 std::vector<double> _v1=bbGetInputIn1();
99 std::vector<double> _v2=bbGetInputIn2();
100 std::vector<double> _v3=bbGetInputIn3();
101 std::vector<double> _v4=bbGetInputIn4();
102 std::vector<double> _v5=bbGetInputIn5();
103 std::vector<double> _v6=bbGetInputIn6();
104 std::vector<double> _v7=bbGetInputIn7();
105 std::vector<double> _v8=bbGetInputIn8();
106 std::vector<double> _v9=bbGetInputIn9();
108 std::vector<double> *v0 = &_v0;
109 std::vector<double> *v1 = &_v1;
110 std::vector<double> *v2 = &_v2;
111 std::vector<double> *v3 = &_v3;
112 std::vector<double> *v4 = &_v4;
113 std::vector<double> *v5 = &_v5;
114 std::vector<double> *v6 = &_v6;
115 std::vector<double> *v7 = &_v7;
116 std::vector<double> *v8 = &_v8;
117 std::vector<double> *v9 = &_v9;
125 /* initialize random seed: */
127 if (bbGetInputType()==7)
129 for (i=0;i<sizeVec;i++)
131 acum.push_back(bbGetInputIn0()[i]);
137 if (bbGetInputType()==0)
139 for (i=0;i<sizeVec;i++)
141 tmpResult = g(v0,i,0) + g(v1,i,0) + g(v2,i,0) + g(v3,i,0) +
142 g(v4,i,0) + g(v5,i,0) + g(v6,i,0) +
143 g(v7,i,0) + g(v8,i,0) + g(v9,i,0) ;
144 resultVec.push_back( tmpResult );
146 bbSetOutputOut( resultVec );
149 if (bbGetInputType()==-99)
151 SumVector(v0,&resultVec);
152 SumVector(v1,&resultVec);
153 SumVector(v2,&resultVec);
154 SumVector(v3,&resultVec);
155 SumVector(v4,&resultVec);
156 SumVector(v5,&resultVec);
157 SumVector(v6,&resultVec);
158 SumVector(v7,&resultVec);
159 SumVector(v8,&resultVec);
160 SumVector(v9,&resultVec);
162 bbSetOutputOut( resultVec );
167 if (bbGetInputType()==1)
169 for (i=0;i<sizeVec;i++)
171 tmpResult = g(v0,i,0) - g(v1,i,0) - g(v2,i,0) - g(v3,i,0) -
172 g(v4,i,0) - g(v5,i,0) - g(v6,i,0) -
173 g(v7,i,0) - g(v8,i,0) - g(v9,i,0) ;
174 resultVec.push_back( tmpResult );
176 bbSetOutputOut( resultVec );
180 if (bbGetInputType()==2)
182 for (i=0;i<sizeVec;i++)
184 tmpResult = g(v0,i,0) * g(v1,i,1) * g(v2,i,1) * g(v3,i,1) *
185 g(v4,i,1) * g(v5,i,1) * g(v6,i,1) *
186 g(v7,i,1) * g(v8,i,1) * g(v9,i,1) ;
187 resultVec.push_back( tmpResult );
189 bbSetOutputOut( resultVec );
194 if (bbGetInputType()==3)
197 for (i=0;i<sizeVec;i++)
199 if (g(v1,i,1)!=0) tmpResult = g(v0,i,0) / g(v1,i,1); else error=true;
200 if (g(v2,i,1)!=0) tmpResult = tmpResult / g(v2,i,1); else error=true;
201 if (g(v3,i,1)!=0) tmpResult = tmpResult / g(v3,i,1); else error=true;
202 if (g(v4,i,1)!=0) tmpResult = tmpResult / g(v4,i,1); else error=true;
203 if (g(v5,i,1)!=0) tmpResult = tmpResult / g(v5,i,1); else error=true;
204 if (g(v6,i,1)!=0) tmpResult = tmpResult / g(v6,i,1); else error=true;
205 if (g(v7,i,1)!=0) tmpResult = tmpResult / g(v7,i,1); else error=true;
206 if (g(v8,i,1)!=0) tmpResult = tmpResult / g(v8,i,1); else error=true;
207 if (g(v9,i,1)!=0) tmpResult = tmpResult / g(v9,i,1); else error=true;
208 if (error==true) tmpResult = 99999;
209 resultVec.push_back( tmpResult );
211 bbSetOutputOut( resultVec );
215 if (bbGetInputType()==4)
217 for (i=0;i<sizeVec;i++)
219 if (bbGetInputIn0()[i]>=0) tmpResult = sqrt( bbGetInputIn0()[i] ) ;
221 resultVec.push_back( tmpResult );
223 bbSetOutputOut( resultVec );
227 if (bbGetInputType()==5)
229 for (i=0;i<sizeVec;i++)
231 if (bbGetInputIn0()[i]>0) tmpResult = log( bbGetInputIn0()[i] ) ;
232 else tmpResult = -99999 ;
233 resultVec.push_back( tmpResult );
235 bbSetOutputOut( resultVec );
240 if (bbGetInputType()==6)
242 for (i=0;i<sizeVec;i++)
244 resultVec.push_back( exp( bbGetInputIn0()[i] ) );
246 bbSetOutputOut( resultVec );
250 if (bbGetInputType()==7)
252 bbSetOutputOut( acum );
253 for (i=0;i<sizeVec;i++)
256 if (acum[i]>g(v1,i,0)) acum[i]=g(v0,i,0);
260 if (bbGetInputType()==8 )
262 for (i=0;i<sizeVec;i++)
264 resultVec.push_back( rand() % (int)( g(v1,i,0)-g(v0,i,0) ) + g(v0,i,0) );
266 bbSetOutputOut( resultVec );
269 if (bbGetInputType()==9)
271 for (i=0;i<sizeVec;i++)
273 resultVec.push_back( sin( bbGetInputIn0()[i] ) );
275 bbSetOutputOut( resultVec );
278 if (bbGetInputType()==10)
280 for (i=0;i<sizeVec;i++)
282 resultVec.push_back( cos( bbGetInputIn0()[i] ) );
284 bbSetOutputOut( resultVec );
287 if (bbGetInputType()==11)
289 for (i=0;i<sizeVec;i++)
291 resultVec.push_back( tan( bbGetInputIn0()[i] ) );
293 bbSetOutputOut( resultVec );
296 if (bbGetInputType()==12)
298 for (i=0;i<sizeVec;i++)
300 resultVec.push_back( asin( bbGetInputIn0()[i] ) );
302 bbSetOutputOut( resultVec );
305 if (bbGetInputType()==13)
307 for (i=0;i<sizeVec;i++)
309 resultVec.push_back( acos( bbGetInputIn0()[i] ) );
311 bbSetOutputOut( resultVec );
314 if (bbGetInputType()==14)
316 for (i=0;i<sizeVec;i++)
318 resultVec.push_back( atan( bbGetInputIn0()[i] ) );
320 bbSetOutputOut( resultVec );
323 if (bbGetInputType()==15)
325 for (i=0;i<sizeVec;i++)
327 resultVec.push_back( atan2( g(v0,i,0) , g(v1,i,0) ) );
329 bbSetOutputOut( resultVec );
333 if (bbGetInputType()==16)
335 for (i=0;i<sizeVec;i++)
337 minTmp = std::min( g(v0,i,999999) , g(v1,i,999999) );
338 minTmp = std::min( g(v2,i,999999) , minTmp );
339 minTmp = std::min( g(v3,i,999999) , minTmp );
340 minTmp = std::min( g(v4,i,999999) , minTmp );
341 minTmp = std::min( g(v5,i,999999) , minTmp );
342 minTmp = std::min( g(v6,i,999999) , minTmp );
343 minTmp = std::min( g(v7,i,999999) , minTmp );
344 minTmp = std::min( g(v8,i,999999) , minTmp );
345 minTmp = std::min( g(v9,i,999999) , minTmp );
346 resultVec.push_back( minTmp );
348 bbSetOutputOut( resultVec );
351 if (bbGetInputType()==-16)
353 MinVector(v0,&resultVec);
354 MinVector(v1,&resultVec);
355 MinVector(v2,&resultVec);
356 MinVector(v3,&resultVec);
357 MinVector(v4,&resultVec);
358 MinVector(v5,&resultVec);
359 MinVector(v6,&resultVec);
360 MinVector(v7,&resultVec);
361 MinVector(v8,&resultVec);
362 MinVector(v9,&resultVec);
364 bbSetOutputOut( resultVec );
367 if (bbGetInputType()==17)
369 for (i=0;i<sizeVec;i++)
371 maxTmp = std::max( g(v0,i,-999999) , g(v1,i,-999999) );
372 maxTmp = std::max( g(v2,i,-999999) , maxTmp );
373 maxTmp = std::max( g(v3,i,-999999) , maxTmp );
374 maxTmp = std::max( g(v4,i,-999999) , maxTmp );
375 maxTmp = std::max( g(v5,i,-999999) , maxTmp );
376 maxTmp = std::max( g(v6,i,-999999) , maxTmp );
377 maxTmp = std::max( g(v7,i,-999999) , maxTmp );
378 maxTmp = std::max( g(v8,i,-999999) , maxTmp );
379 maxTmp = std::max( g(v9,i,-999999) , maxTmp );
380 resultVec.push_back( maxTmp );
382 bbSetOutputOut( resultVec );
386 if (bbGetInputType()==-17)
388 MaxVector(v0,&resultVec);
389 MaxVector(v1,&resultVec);
390 MaxVector(v2,&resultVec);
391 MaxVector(v3,&resultVec);
392 MaxVector(v4,&resultVec);
393 MaxVector(v5,&resultVec);
394 MaxVector(v6,&resultVec);
395 MaxVector(v7,&resultVec);
396 MaxVector(v8,&resultVec);
397 MaxVector(v9,&resultVec);
398 bbSetOutputOut( resultVec );
402 if (bbGetInputType()==18)
404 for (i=0;i<sizeVec;i++)
406 resultVec.push_back( fabs( bbGetInputIn0()[i] ) );
408 bbSetOutputOut( resultVec );
411 if (bbGetInputType()==19)
413 for (i=0;i<sizeVec;i++)
415 resultVec.push_back( (int)bbGetInputIn0()[i] % (int)bbGetInputIn1()[i] );
417 bbSetOutputOut( resultVec );
420 if (bbGetInputType()==20)
422 for (i=0;i<sizeVec;i++)
424 if (bbGetInputIn0()[i] < bbGetInputIn1()[i])
426 resultVec.push_back( 1 );
428 resultVec.push_back( 0 );
431 bbSetOutputOut( resultVec );
434 if (bbGetInputType()==21)
436 for (i=0;i<sizeVec;i++)
438 if (bbGetInputIn0()[i] > bbGetInputIn1()[i])
440 resultVec.push_back( 1 );
442 resultVec.push_back( 0 );
445 bbSetOutputOut( resultVec );
449 if (bbGetInputType()==22)
454 double resultMassTotal=0;
455 for (i=0;i<sizeVec;i++)
457 resultX = resultX + g(v0,i,0)*g(v3,i,1);
458 resultY = resultY + g(v1,i,0)*g(v3,i,1);
459 resultZ = resultZ + g(v2,i,0)*g(v3,i,1);
460 resultMassTotal = resultMassTotal + g(v3,i,1);
462 if (resultMassTotal!=0)
464 resultVec.push_back( resultX / resultMassTotal );
465 resultVec.push_back( resultY / resultMassTotal );
466 resultVec.push_back( resultZ / resultMassTotal );
467 } // if resultMassTotal
468 bbSetOutputOut( resultVec );
472 if (bbGetInputType()==23)
474 for (i=0;i<sizeVec;i++)
476 resultVec.push_back( round( bbGetInputIn0()[i] ) );
478 bbSetOutputOut( resultVec );
481 if (bbGetInputType()==24)
483 for (i=0;i<sizeVec;i++)
485 resultVec.push_back( rint( bbGetInputIn0()[i] ) );
487 bbSetOutputOut( resultVec );
490 if (bbGetInputType()==25)
492 for (i=0;i<sizeVec;i++)
494 resultVec.push_back( floor( bbGetInputIn0()[i] ) );
496 bbSetOutputOut( resultVec );
499 if (bbGetInputType()==26)
501 for (i=0;i<sizeVec;i++)
503 resultVec.push_back( ceil( bbGetInputIn0()[i] ) );
505 bbSetOutputOut( resultVec );
508 if (bbGetInputType()==27)
510 for (i=0;i<sizeVec;i++)
512 resultVec.push_back( trunc( bbGetInputIn0()[i] ) );
514 bbSetOutputOut( resultVec );
520 // 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)
522 void MathOperationVector::bbUserSetDefaultValues()
525 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
526 // Here we initialize the input 'In' to 0
534 // 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)
536 void MathOperationVector::bbUserInitializeProcessing()
539 // THE INITIALIZATION METHOD BODY :
541 // but this is where you should allocate the internal/output pointers
547 // 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)
549 void MathOperationVector::bbUserFinalizeProcessing()
552 // THE FINALIZATION METHOD BODY :
554 // but this is where you should desallocate the internal/output pointers
559 // EO namespace bbstd