]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdMathOperation.cxx
#3120 BBTK Bug New Normal - merge branch changestoITK3and4 FROM master
[bbtk.git] / packages / std / src / bbstdMathOperation.cxx
diff --git a/packages/std/src/bbstdMathOperation.cxx b/packages/std/src/bbstdMathOperation.cxx
new file mode 100644 (file)
index 0000000..fdedc10
--- /dev/null
@@ -0,0 +1,130 @@
+//===== 
+// 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)
+//===== 
+#include "bbstdMathOperation.h"
+#include "bbstdPackage.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <time.h>
+
+namespace bbstd
+{
+
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MathOperation)
+BBTK_BLACK_BOX_IMPLEMENTATION(MathOperation,bbtk::AtomicBlackBox);
+//===== 
+// 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)
+//===== 
+void MathOperation::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+//   Here we simply set the input 'In' value to the output 'Out'
+//   And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+//    void bbSet{Input|Output}NAME(const TYPE&)
+//    const TYPE& bbGet{Input|Output}NAME() const 
+//    Where :
+//    * NAME is the name of the input/output
+//      (the one provided in the attribute 'name' of the tag 'input')
+//    * TYPE is the C++ type of the input/output
+//      (the one provided in the attribute 'type' of the tag 'input')
+
+        if (firsttime==true)
+        {
+               firsttime=false;
+      /* initialize random seed: */ 
+             srand (time(NULL));
+               if (bbGetInputType()==7) acum=bbGetInputIn1();
+        }
+
+    if (bbGetInputType()==0) 
+       { 
+               bbSetOutputOut( bbGetInputIn1() +  bbGetInputIn2() ); 
+       }
+    if (bbGetInputType()==1) bbSetOutputOut( bbGetInputIn1() -  bbGetInputIn2() );
+    if (bbGetInputType()==2) bbSetOutputOut( bbGetInputIn1() *  bbGetInputIn2() );
+
+    if (bbGetInputType()==3)
+    {
+                       if (bbGetInputIn2()!=0)  bbSetOutputOut( bbGetInputIn1() /  bbGetInputIn2() );
+              else  bbSetOutputOut( 99999999 );
+    }
+
+    if (bbGetInputType()==4) bbSetOutputOut( sqrt( bbGetInputIn1() ) );
+
+    if (bbGetInputType()==5)
+        {
+               if (bbGetInputIn1()>0)  bbSetOutputOut( log( bbGetInputIn1() ) );
+              else  bbSetOutputOut( -99999999 );
+        }
+
+    if (bbGetInputType()==6) bbSetOutputOut( exp( bbGetInputIn1() ) );
+    if (bbGetInputType()==7)
+        {
+               if ( back_acum_In1!=bbGetInputIn1() ) acum=bbGetInputIn1();
+               if (acum<bbGetInputIn1()) acum=bbGetInputIn1();
+               bbSetOutputOut( acum );
+               acum++;
+               if (acum>bbGetInputIn2()) acum=bbGetInputIn1();
+               back_acum_In1=bbGetInputIn1();
+        }
+    if (bbGetInputType()==8 ) bbSetOutputOut( rand() %  (int) (bbGetInputIn2()-bbGetInputIn1()) +  bbGetInputIn1() );
+    if (bbGetInputType()==9 ) bbSetOutputOut( sin( bbGetInputIn1() ) );
+    if (bbGetInputType()==10) bbSetOutputOut( cos( bbGetInputIn1() ) );
+    if (bbGetInputType()==11) bbSetOutputOut( tan( bbGetInputIn1() ) );
+    if (bbGetInputType()==12) bbSetOutputOut( asin( bbGetInputIn1() ) );
+    if (bbGetInputType()==13) bbSetOutputOut( acos( bbGetInputIn1() ) );
+    if (bbGetInputType()==14) bbSetOutputOut( atan( bbGetInputIn1() ) );
+    if (bbGetInputType()==15) bbSetOutputOut( atan2( bbGetInputIn1(),bbGetInputIn2() ) );
+    if (bbGetInputType()==16) bbSetOutputOut( std::min( bbGetInputIn1(),bbGetInputIn2() )  );
+    if (bbGetInputType()==17) bbSetOutputOut( std::max( bbGetInputIn1(),bbGetInputIn2() )  );
+    if (bbGetInputType()==18) bbSetOutputOut( fabs( bbGetInputIn1() ) );
+    if (bbGetInputType()==19) bbSetOutputOut(  (int)bbGetInputIn1() % (int)bbGetInputIn2() );
+}
+//===== 
+// 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)
+//===== 
+void MathOperation::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+   bbSetInputIn1(0);
+   bbSetInputIn2(0);
+   bbSetInputType(0);
+
+   firsttime=true;
+   acum=0;
+}
+
+//===== 
+// 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)
+//===== 
+void MathOperation::bbUserInitializeProcessing()
+{
+
+//  THE INITIALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should allocate the internal/output pointers 
+//    if any 
+}
+
+//===== 
+// 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)
+//===== 
+void MathOperation::bbUserFinalizeProcessing()
+{
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any  
+}
+
+}// EO namespace bbstd
+
+