]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
cb1a77050240e041c2764afd6d908b74d0d23f95
[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         double range[2];
35         double spc[3];
36         int ext[6];
37         double A=bbGetInputA();
38         double B=bbGetInputB();
39         
40         if (bbGetInputIn()!=0)
41         {
42                 if (bbGetInputOutputFormat()=="SAME")                                   outputformat = bbGetInputIn()->GetScalarType();
43                 else if (bbGetInputOutputFormat()=="VTK_BIT")                   outputformat = VTK_BIT;
44                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                  outputformat = VTK_CHAR;
45                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")   outputformat = VTK_SIGNED_CHAR;
46                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR;
47                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT;
48                 else if (bbGetInputOutputFormat()=="VTK_INT")                   outputformat = VTK_INT;
49                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")  outputformat = VTK_UNSIGNED_INT;
50                 else if (bbGetInputOutputFormat()=="VTK_LONG")                  outputformat = VTK_LONG;
51                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG;
52                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                 outputformat = VTK_FLOAT;
53                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                outputformat = VTK_DOUBLE;
54                 
55                 
56                 bbGetInputIn()->GetScalarRange(range);
57                 bbGetInputIn()->GetSpacing(spc);
58                 bbGetInputIn()->GetExtent( ext );                               
59                 
60                 double range0plusrange1 = range[0]+range[1];
61                 double difrange                 = range[1]-range[0];
62                 double newdifrange              = B-A;
63                 
64                 double shift;
65                 double scale;
66                 
67                 if (bbGetInputType()==0) // Rescale Slope/Intercept
68                 { 
69                         //                      newValue = value*A+B;
70                         scale = A;
71                         shift = B;
72                 } // if type 0
73                 
74                 if (bbGetInputType()==1) // Invert
75                 { 
76                         //                      newValue = value*(-1) + (range0plusrange1);
77                         scale=-1;
78                         shift=range0plusrange1;
79                 } // if type 1
80                 
81                 if (bbGetInputType()==2) // Redimension
82                 { 
83                         //                      newValue = ((value-range[0])/difrange)*newdifrange + A;
84                         scale=newdifrange/difrange;
85                         shift= A - (range[0]*newdifrange/difrange);
86                 } // if type 2
87                 
88                 if (bbGetInputType()==3) // Invert redimension
89                 { 
90                         //                      newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
91                         scale=-newdifrange/difrange;
92                         shift= A + (range[1]*newdifrange/difrange);
93                 } // if type 3
94                 
95                 filter1->SetInput( bbGetInputIn() );
96                 filter1->SetOutputScalarType( VTK_DOUBLE );
97                 filter1->SetShift( 0 );
98                 filter1->SetScale( scale );
99                 
100                 filter2->SetInput( filter1->GetOutput() );
101                 filter2->SetOutputScalarType( outputformat );
102                 filter2->SetShift( shift );
103                 filter2->SetScale( 1 );
104                 
105                 mchange->SetInput( filter2->GetOutput() );
106                 mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
107                 mchange->SetOutputSpacing (spc);
108                 mchange->Update();    //important
109                 
110                 bbSetOutputOut( mchange->GetOutput() );
111                 
112         } // if
113 }
114         
115 //===== 
116 // Don't edit this file. This file is generated from xml description.. 
117 //===== 
118 void RescaleSlopeIntercept::bbUserSetDefaultValues()
119 {
120
121 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
122 //    Here we initialize the input 'In' to 0
123         bbSetInputIn(NULL);
124         bbSetInputType(0);
125         bbSetInputA(1);
126         bbSetInputB(0);
127         bbSetInputOutputFormat("SAME");
128
129         filter1 = NULL;
130         filter2 = NULL;
131         mchange = NULL;
132 }
133 //===== 
134 // Don't edit this file. This file is generated from xml description.. 
135 //===== 
136 void RescaleSlopeIntercept::bbUserInitializeProcessing()
137 {
138
139 //  THE INITIALIZATION METHOD BODY :
140 //    Here does nothing 
141 //    but this is where you should allocate the internal/output pointers 
142 //    if any 
143
144         filter1 = vtkImageShiftScale::New();
145         filter2 = vtkImageShiftScale::New();
146         mchange = vtkImageChangeInformation::New();
147
148   
149 }
150 //===== 
151 // Don't edit this file. This file is generated from xml description.. 
152 //===== 
153 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
154 {
155
156 //  THE FINALIZATION METHOD BODY :
157 //    Here does nothing 
158 //    but this is where you should desallocate the internal/output pointers 
159 //    if any
160         mchange->Delete();              
161         filter1->Delete();
162         filter2->Delete();
163 }
164         
165 }
166 // EO namespace bbvtk
167
168