]> Creatis software - bbtk.git/blob - packages/std/src/bbstdMathOperation.cxx
#2812 BBTK Bug New Normal Package std not compiling in windows fmin fmax missing...
[bbtk.git] / packages / std / src / bbstdMathOperation.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 "bbstdMathOperation.h"
5 #include "bbstdPackage.h"
6
7 #include <math.h>
8 #include <stdlib.h>
9 #include <time.h>
10
11 namespace bbstd
12 {
13
14
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MathOperation)
16 BBTK_BLACK_BOX_IMPLEMENTATION(MathOperation,bbtk::AtomicBlackBox);
17 //===== 
18 // 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)
19 //===== 
20 void MathOperation::Process()
21 {
22
23 // THE MAIN PROCESSING METHOD BODY
24 //   Here we simply set the input 'In' value to the output 'Out'
25 //   And print out the output value
26 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
27 //    void bbSet{Input|Output}NAME(const TYPE&)
28 //    const TYPE& bbGet{Input|Output}NAME() const 
29 //    Where :
30 //    * NAME is the name of the input/output
31 //      (the one provided in the attribute 'name' of the tag 'input')
32 //    * TYPE is the C++ type of the input/output
33 //      (the one provided in the attribute 'type' of the tag 'input')
34
35  
36          if (firsttime==true)
37          {
38                 firsttime=false;
39       /* initialize random seed: */ 
40       srand (time(NULL));
41                 if (bbGetInputType()==7) acum=bbGetInputIn1();
42          }
43
44     if (bbGetInputType()==0) bbSetOutputOut( bbGetInputIn1() +  bbGetInputIn2() );
45     if (bbGetInputType()==1) bbSetOutputOut( bbGetInputIn1() -  bbGetInputIn2() );
46     if (bbGetInputType()==2) bbSetOutputOut( bbGetInputIn1() *  bbGetInputIn2() );
47
48     if (bbGetInputType()==3)
49     {
50                         if (bbGetInputIn2()!=0)  bbSetOutputOut( bbGetInputIn1() /  bbGetInputIn2() );
51               else  bbSetOutputOut( 99999999 );
52     }
53
54     if (bbGetInputType()==4) bbSetOutputOut( sqrt( bbGetInputIn1() ) );
55
56     if (bbGetInputType()==5)
57          {
58                 if (bbGetInputIn1()>0)  bbSetOutputOut( log( bbGetInputIn1() ) );
59               else  bbSetOutputOut( -99999999 );
60          }
61
62     if (bbGetInputType()==6) bbSetOutputOut( exp( bbGetInputIn1() ) );
63  
64     if (bbGetInputType()==7)
65          {
66                  bbSetOutputOut( acum );
67                  acum++;
68        if (acum>bbGetInputIn2()) acum=bbGetInputIn1();
69          }
70     if (bbGetInputType()==8 ) bbSetOutputOut( rand() %  (int) (bbGetInputIn2()-bbGetInputIn1()) +  bbGetInputIn1() );
71     if (bbGetInputType()==9 ) bbSetOutputOut( sin( bbGetInputIn1() ) );
72     if (bbGetInputType()==10) bbSetOutputOut( cos( bbGetInputIn1() ) );
73     if (bbGetInputType()==11) bbSetOutputOut( tan( bbGetInputIn1() ) );
74     if (bbGetInputType()==12) bbSetOutputOut( asin( bbGetInputIn1() ) );
75     if (bbGetInputType()==13) bbSetOutputOut( acos( bbGetInputIn1() ) );
76     if (bbGetInputType()==14) bbSetOutputOut( atan( bbGetInputIn1() ) );
77     if (bbGetInputType()==15) bbSetOutputOut( atan2( bbGetInputIn1(),bbGetInputIn2() ) );
78     if (bbGetInputType()==16) bbSetOutputOut( std::min( bbGetInputIn1(),bbGetInputIn2() )  );
79     if (bbGetInputType()==17) bbSetOutputOut( std::max( bbGetInputIn1(),bbGetInputIn2() )  );
80     if (bbGetInputType()==18) bbSetOutputOut( fabs( bbGetInputIn1() ) );
81 }
82 //===== 
83 // 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)
84 //===== 
85 void MathOperation::bbUserSetDefaultValues()
86 {
87
88 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
89 //    Here we initialize the input 'In' to 0
90    bbSetInputIn1(0);
91    bbSetInputIn2(0);
92    bbSetInputType(0);
93
94    firsttime=true;
95    acum=0;
96 }
97
98 //===== 
99 // 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)
100 //===== 
101 void MathOperation::bbUserInitializeProcessing()
102 {
103
104 //  THE INITIALIZATION METHOD BODY :
105 //    Here does nothing 
106 //    but this is where you should allocate the internal/output pointers 
107 //    if any 
108 }
109
110 //===== 
111 // 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)
112 //===== 
113 void MathOperation::bbUserFinalizeProcessing()
114 {
115 //  THE FINALIZATION METHOD BODY :
116 //    Here does nothing 
117 //    but this is where you should desallocate the internal/output pointers 
118 //    if any  
119 }
120
121 }// EO namespace bbstd
122
123