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