]> Creatis software - bbtk.git/blob - packages/std/src/bbstdMathOperation.cxx
#2924 BBTK Feature New Normal - DropFiles box package wx #2804 BBTK Featur...
[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 }
89 //===== 
90 // 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)
91 //===== 
92 void MathOperation::bbUserSetDefaultValues()
93 {
94
95 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
96 //    Here we initialize the input 'In' to 0
97    bbSetInputIn1(0);
98    bbSetInputIn2(0);
99    bbSetInputType(0);
100
101    firsttime=true;
102    acum=0;
103 }
104
105 //===== 
106 // 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)
107 //===== 
108 void MathOperation::bbUserInitializeProcessing()
109 {
110
111 //  THE INITIALIZATION METHOD BODY :
112 //    Here does nothing 
113 //    but this is where you should allocate the internal/output pointers 
114 //    if any 
115 }
116
117 //===== 
118 // 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)
119 //===== 
120 void MathOperation::bbUserFinalizeProcessing()
121 {
122 //  THE FINALIZATION METHOD BODY :
123 //    Here does nothing 
124 //    but this is where you should desallocate the internal/output pointers 
125 //    if any  
126 }
127
128 }// EO namespace bbstd
129
130