]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorRescaleSlope.cxx
no message
[bbtk.git] / packages / std / src / bbstdVectorRescaleSlope.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 "bbstdVectorRescaleSlope.h"
5 #include "bbstdPackage.h"
6 namespace bbstd
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,VectorRescaleSlope)
10 BBTK_BLACK_BOX_IMPLEMENTATION(VectorRescaleSlope,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void VectorRescaleSlope::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28         
29         unsigned int i;
30         std::vector<double> result;
31         double range[2];
32
33         double A=bbGetInputA();
34         double B=bbGetInputB();
35         
36         
37         // -------------------------------------------------
38         
39         if (bbGetInputIn().size()>=1)   
40         {
41                 range[0]=bbGetInputIn()[0];
42                 range[1]=bbGetInputIn()[0];
43         } else {
44                 range[0]=999999;
45                 range[1]=-999999;
46         }
47         for (i=0; i<bbGetInputIn().size();i++)
48         {
49                 if (range[0]>bbGetInputIn()[i])
50                 {
51                         range[0]=bbGetInputIn()[i];
52                 }
53                 if (range[1]<bbGetInputIn()[i])
54                 {
55                         range[1]=bbGetInputIn()[i];
56                 }
57         }
58         
59         
60         // -------------------------------------------------
61         
62         
63         double range0plusrange1 = range[0]+range[1];
64         double difrange                 = range[1]-range[0];
65         double newdifrange              = B-A;
66         double shift;
67         double scale;
68         
69         if (bbGetInputType()==0) // Rescale Slope/Intercept
70         { 
71                 //                      newValue = value*A+B;
72                 scale = A;
73                 shift = B;
74         } // if type 0
75         
76         if (bbGetInputType()==1) // Invert
77         { 
78                 //                      newValue = value*(-1) + (range0plusrange1);
79                 scale=-1;
80                 shift=range0plusrange1;
81         } // if type 1
82         
83         if (bbGetInputType()==2) // Redimension
84         { 
85                 //                      newValue = ((value-range[0])/difrange)*newdifrange + A;
86                 scale=newdifrange/difrange;
87                 shift= A - (range[0]*newdifrange/difrange);
88         } // if type 2
89         
90         if (bbGetInputType()==3) // Invert redimension
91         { 
92                 //                      newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
93                 scale=-newdifrange/difrange;
94                 shift= A + (range[1]*newdifrange/difrange);
95         } // if type 3
96         
97                 
98         for (i=0; i<bbGetInputIn().size();i++)
99         {
100                 result.push_back( bbGetInputIn()[i]*scale+shift );
101         }
102         
103         bbSetOutputOut(result);
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 VectorRescaleSlope::bbUserSetDefaultValues()
110 {
111
112 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
113 //    Here we initialize the input 'In' to 0
114         bbSetInputA(1);
115         bbSetInputB(0);
116         bbSetInputType(0);
117         
118 }
119 //===== 
120 // 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)
121 //===== 
122 void VectorRescaleSlope::bbUserInitializeProcessing()
123 {
124
125 //  THE INITIALIZATION METHOD BODY :
126 //    Here does nothing 
127 //    but this is where you should allocate the internal/output pointers 
128 //    if any 
129
130   
131 }
132 //===== 
133 // 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)
134 //===== 
135 void VectorRescaleSlope::bbUserFinalizeProcessing()
136 {
137
138 //  THE FINALIZATION METHOD BODY :
139 //    Here does nothing 
140 //    but this is where you should desallocate the internal/output pointers 
141 //    if any
142   
143 }
144 }
145 // EO namespace bbstd
146
147