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