]> Creatis software - bbtk.git/blob - packages/std/src/bbstdMathOperation.cxx
#3460 MathOperation equal option
[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) 
45         { 
46                 bbSetOutputOut( bbGetInputIn1() +  bbGetInputIn2() ); 
47         }
48     if (bbGetInputType()==1) bbSetOutputOut( bbGetInputIn1() -  bbGetInputIn2() );
49     if (bbGetInputType()==2) bbSetOutputOut( bbGetInputIn1() *  bbGetInputIn2() );
50
51     if (bbGetInputType()==3)
52     {
53                         if (bbGetInputIn2()!=0)  bbSetOutputOut( bbGetInputIn1() /  bbGetInputIn2() );
54               else  bbSetOutputOut( 99999999 );
55     }
56
57     if (bbGetInputType()==4) bbSetOutputOut( sqrt( bbGetInputIn1() ) );
58
59     if (bbGetInputType()==5)
60          {
61                 if (bbGetInputIn1()>0)  bbSetOutputOut( log( bbGetInputIn1() ) );
62               else  bbSetOutputOut( -99999999 );
63          }
64
65     if (bbGetInputType()==6) bbSetOutputOut( exp( bbGetInputIn1() ) );
66  
67     if (bbGetInputType()==7)
68          {
69                 if ( back_acum_In1!=bbGetInputIn1() ) acum=bbGetInputIn1();
70                 if (acum<bbGetInputIn1()) acum=bbGetInputIn1();
71                 bbSetOutputOut( acum );
72                 acum++;
73                 if (acum>bbGetInputIn2()) acum=bbGetInputIn1();
74                 back_acum_In1=bbGetInputIn1();
75          }
76     if (bbGetInputType()==8 ) bbSetOutputOut( rand() %  (int) (bbGetInputIn2()-bbGetInputIn1()) +  bbGetInputIn1() );
77     if (bbGetInputType()==9 ) bbSetOutputOut( sin( bbGetInputIn1() ) );
78     if (bbGetInputType()==10) bbSetOutputOut( cos( bbGetInputIn1() ) );
79     if (bbGetInputType()==11) bbSetOutputOut( tan( bbGetInputIn1() ) );
80     if (bbGetInputType()==12) bbSetOutputOut( asin( bbGetInputIn1() ) );
81     if (bbGetInputType()==13) bbSetOutputOut( acos( bbGetInputIn1() ) );
82     if (bbGetInputType()==14) bbSetOutputOut( atan( bbGetInputIn1() ) );
83     if (bbGetInputType()==15) bbSetOutputOut( atan2( bbGetInputIn1(),bbGetInputIn2() ) );
84     if (bbGetInputType()==16) bbSetOutputOut( std::min( bbGetInputIn1(),bbGetInputIn2() )  );
85     if (bbGetInputType()==17) bbSetOutputOut( std::max( bbGetInputIn1(),bbGetInputIn2() )  );
86     if (bbGetInputType()==18) bbSetOutputOut( fabs( bbGetInputIn1() ) );
87     if (bbGetInputType()==19) bbSetOutputOut(  (int)bbGetInputIn1() % (int)bbGetInputIn2() );
88     if (bbGetInputType()==20) if (bbGetInputIn1()<(int)bbGetInputIn2()) { bbSetOutputOut(1); } else { bbSetOutputOut(0); } ;
89     if (bbGetInputType()==21) if (bbGetInputIn1()>(int)bbGetInputIn2()) { bbSetOutputOut(1); } else { bbSetOutputOut(0); } ;
90     if (bbGetInputType()==22) bbSetOutputOut( round( bbGetInputIn1() ) );
91     if (bbGetInputType()==23) bbSetOutputOut( rint( bbGetInputIn1() ) );
92     if (bbGetInputType()==24) bbSetOutputOut( floor( bbGetInputIn1() ) );
93     if (bbGetInputType()==25) bbSetOutputOut( ceil( bbGetInputIn1() ) );
94     if (bbGetInputType()==26) bbSetOutputOut( trunc( bbGetInputIn1() ) );
95     if (bbGetInputType()==30) if (bbGetInputIn1()==(int)bbGetInputIn2()) { bbSetOutputOut(1); } else { bbSetOutputOut(0); } ;
96 }
97 //===== 
98 // 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)
99 //===== 
100 void MathOperation::bbUserSetDefaultValues()
101 {
102
103 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
104 //    Here we initialize the input 'In' to 0
105    bbSetInputIn1(0);
106    bbSetInputIn2(0);
107    bbSetInputType(0);
108
109    firsttime=true;
110    acum=0;
111 }
112
113 //===== 
114 // 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)
115 //===== 
116 void MathOperation::bbUserInitializeProcessing()
117 {
118
119 //  THE INITIALIZATION METHOD BODY :
120 //    Here does nothing 
121 //    but this is where you should allocate the internal/output pointers 
122 //    if any 
123 }
124
125 //===== 
126 // 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)
127 //===== 
128 void MathOperation::bbUserFinalizeProcessing()
129 {
130 //  THE FINALIZATION METHOD BODY :
131 //    Here does nothing 
132 //    but this is where you should desallocate the internal/output pointers 
133 //    if any  
134 }
135
136 }// EO namespace bbstd
137
138