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