]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
Clean comments
[bbtk.git] / packages / vtk / src / bbvtkRescaleSlopeIntercept.cxx
1 //===== 
2 // Don't edit this file. This file is generated from xml description.. 
3 //===== 
4 #include "bbvtkRescaleSlopeIntercept.h"
5 #include "bbvtkPackage.h"
6
7
8 namespace bbvtk
9 {
10
11 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,RescaleSlopeIntercept)
12 BBTK_BLACK_BOX_IMPLEMENTATION(RescaleSlopeIntercept,bbtk::AtomicBlackBox);
13 //===== 
14 // Don't edit this file. This file is generated from xml description.. 
15 //===== 
16 void RescaleSlopeIntercept::Process()
17 {
18
19 // THE MAIN PROCESSING METHOD BODY
20 //   Here we simply set the input 'In' value to the output 'Out'
21 //   And print out the output value
22 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
23 //    void bbSet{Input|Output}NAME(const TYPE&)
24 //    const TYPE& bbGet{Input|Output}NAME() const 
25 //    Where :
26 //    * NAME is the name of the input/output
27 //      (the one provided in the attribute 'name' of the tag 'input')
28 //    * TYPE is the C++ type of the input/output
29 //      (the one provided in the attribute 'type' of the tag 'input')
30 //    bbSetOutputOut( bbGetInputIn() );
31 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
32   
33         
34         printf("EED  RescaleSlopeIntercept::Process start\n");          
35         
36
37         double range[2];
38         double spc[3];
39         int ext[6];
40         double A=bbGetInputA();
41         double B=bbGetInputB();
42         
43         if (bbGetInputIn()!=0)
44         {
45                 if (bbGetInputOutputFormat()=="SAME")                                   outputformat = bbGetInputIn()->GetScalarType();
46                 else if (bbGetInputOutputFormat()=="VTK_BIT")                   outputformat = VTK_BIT;
47                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                  outputformat = VTK_CHAR;
48                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")   outputformat = VTK_SIGNED_CHAR;
49                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR;
50                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT;
51                 else if (bbGetInputOutputFormat()=="VTK_INT")                   outputformat = VTK_INT;
52                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")  outputformat = VTK_UNSIGNED_INT;
53                 else if (bbGetInputOutputFormat()=="VTK_LONG")                  outputformat = VTK_LONG;
54                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG;
55                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                 outputformat = VTK_FLOAT;
56                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                outputformat = VTK_DOUBLE;
57                 
58                 
59                 bbGetInputIn()->GetScalarRange(range);
60                 bbGetInputIn()->GetSpacing(spc);
61                 bbGetInputIn()->GetExtent( ext );                               
62                 
63                 double range0plusrange1 = range[0]+range[1];
64                 double difrange                 = range[1]-range[0];
65                 double newdifrange              = B-A;
66                 
67                 double shift;
68                 double scale;
69                 
70                 if (bbGetInputType()==0) // Rescale Slope/Intercept
71                 { 
72                         //                      newValue = value*A+B;
73                         scale = A;
74                         shift = B;
75                 } // if type 0
76                 
77                 if (bbGetInputType()==1) // Invert
78                 { 
79                         //                      newValue = value*(-1) + (range0plusrange1);
80                         scale=-1;
81                         shift=range0plusrange1;
82                 } // if type 1
83                 
84                 if (bbGetInputType()==2) // Redimension
85                 { 
86                         //                      newValue = ((value-range[0])/difrange)*newdifrange + A;
87                         scale=newdifrange/difrange;
88                         shift= A - (range[0]*newdifrange/difrange);
89                 } // if type 2
90                 
91                 if (bbGetInputType()==3) // Invert redimension
92                 { 
93                         //                      newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
94                         scale=-newdifrange/difrange;
95                         shift= A + (range[1]*newdifrange/difrange);
96                 } // if type 3
97                 
98                 filter1->SetInput( bbGetInputIn() );
99                 filter1->SetOutputScalarType( VTK_DOUBLE );
100                 filter1->SetShift( 0 );
101                 filter1->SetScale( scale );
102                 
103                 filter2->SetInput( filter1->GetOutput() );
104                 filter2->SetOutputScalarType( outputformat );
105                 filter2->SetShift( shift );
106                 filter2->SetScale( 1 );
107                 
108                 mchange->SetInput( filter2->GetOutput() );
109                 mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
110                 mchange->SetOutputSpacing (spc);
111                 mchange->Update();    //important
112                 bbSetOutputOut( mchange->GetOutput() );
113                 
114         } else  {
115                 bbSetOutputOut( NULL );
116         }               // if bbGetInputIn
117         
118         printf("EED  RescaleSlopeIntercept::Process end\n");            
119         
120 }
121         
122 //===== 
123 // Don't edit this file. This file is generated from xml description.. 
124 //===== 
125 void RescaleSlopeIntercept::bbUserSetDefaultValues()
126 {
127
128 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
129 //    Here we initialize the input 'In' to 0
130         bbSetInputIn(NULL);
131         bbSetInputType(0);
132         bbSetInputA(1);
133         bbSetInputB(0);
134         bbSetInputOutputFormat("SAME");
135
136         filter1 = NULL;
137         filter2 = NULL;
138         mchange = NULL;
139 }
140 //===== 
141 // Don't edit this file. This file is generated from xml description.. 
142 //===== 
143 void RescaleSlopeIntercept::bbUserInitializeProcessing()
144 {
145
146 //  THE INITIALIZATION METHOD BODY :
147 //    Here does nothing 
148 //    but this is where you should allocate the internal/output pointers 
149 //    if any 
150
151         filter1 = vtkImageShiftScale::New();
152         filter2 = vtkImageShiftScale::New();
153         mchange = vtkImageChangeInformation::New();
154
155   
156 }
157 //===== 
158 // Don't edit this file. This file is generated from xml description.. 
159 //===== 
160 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
161 {
162
163 //  THE FINALIZATION METHOD BODY :
164 //    Here does nothing 
165 //    but this is where you should desallocate the internal/output pointers 
166 //    if any
167         mchange->Delete();              
168         filter1->Delete();
169         filter2->Delete();
170 }
171         
172 }
173 // EO namespace bbvtk
174
175