]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
no message
[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 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,RescaleSlopeIntercept)
10 BBTK_BLACK_BOX_IMPLEMENTATION(RescaleSlopeIntercept,bbtk::AtomicBlackBox);
11 //===== 
12 // Don't edit this file. This file is generated from xml description.. 
13 //===== 
14 void RescaleSlopeIntercept::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 //    bbSetOutputOut( bbGetInputIn() );
29 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
30   
31
32         double range[2];
33         double spc[6];
34         int dim[3];
35         int ext[6];
36         double value;
37         double newValue;
38         double A=bbGetInputA();
39         double B=bbGetInputB();
40         
41         if (bbGetInputIn()!=0)
42         {
43                 if (bbGetInputOutputFormat()=="SAME")                                   outputformat = bbGetInputIn()->GetScalarType();
44                 else if (bbGetInputOutputFormat()=="VTK_BIT")                   outputformat = VTK_BIT;
45                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                  outputformat = VTK_CHAR;
46                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")   outputformat = VTK_SIGNED_CHAR;
47                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR;
48                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT;
49                 else if (bbGetInputOutputFormat()=="VTK_INT")                   outputformat = VTK_INT;
50                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")  outputformat = VTK_UNSIGNED_INT;
51                 else if (bbGetInputOutputFormat()=="VTK_LONG")                  outputformat = VTK_LONG;
52                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG;
53                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                 outputformat = VTK_FLOAT;
54                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                outputformat = VTK_DOUBLE;
55                 
56                 imageoutput->Initialize();
57                 imageoutput->SetScalarType( outputformat );     
58                 bbGetInputIn()->GetScalarRange(range);
59                 bbGetInputIn()->GetSpacing(spc);
60                 imageoutput->SetSpacing( spc );
61                 bbGetInputIn()->GetWholeExtent(ext);
62                 dim[0]=ext[1]-ext[0]+1;
63                 dim[1]=ext[3]-ext[2]+1;
64                 dim[2]=ext[5]-ext[4]+1;
65                 imageoutput->SetDimensions( dim[0] , dim[1], dim[2] );
66                 imageoutput->AllocateScalars();
67
68                 double range0plusrange1 = range[0]+range[1];
69                 double difrange = range[1]-range[0];
70                 double newdifrange = B-A;
71                 
72                 int i,j,k;
73                 for (i=0; i<dim[0]; i++)
74                 {
75                         for (j=0; j<dim[1]; j++)
76                         {
77                                 for (k=0; k<dim[2]; k++)
78                                 {
79                                         value = bbGetInputIn()->GetScalarComponentAsDouble(i,j,k,0);
80
81                                         if (bbGetInputType()==0) // Rescale Slope/Intercept
82                                         { 
83                                                 newValue = value*A+B;
84                                         } // if type 0
85
86                                         if (bbGetInputType()==1) // Invert
87                                         { 
88                                                 newValue = value*(-1) + (range0plusrange1);
89                                         } // if type 1
90                                         
91                                         if (bbGetInputType()==2) // Redimension
92                                         { 
93                                                 newValue = ((value-range[0])/difrange)*newdifrange + A;
94                                         } // if type 2
95
96                                         if (bbGetInputType()==3) // Invert redimension
97                                         { 
98                                                 newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
99                                         } // if type 3
100                                         
101                                         imageoutput->SetScalarComponentFromDouble (i,j,k, 0, newValue);
102                                 } // for k
103                         } // for j
104                 } // for i
105                         
106                 bbSetOutputOut(imageoutput);
107         } // if
108 }
109         
110 //===== 
111 // Don't edit this file. This file is generated from xml description.. 
112 //===== 
113 void RescaleSlopeIntercept::bbUserSetDefaultValues()
114 {
115
116 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
117 //    Here we initialize the input 'In' to 0
118         bbSetInputIn(NULL);
119         bbSetInputType(0);
120         bbSetInputA(1);
121         bbSetInputB(0);
122         bbSetInputOutputFormat("SAME");
123         imageoutput=NULL;
124 }
125 //===== 
126 // Don't edit this file. This file is generated from xml description.. 
127 //===== 
128 void RescaleSlopeIntercept::bbUserInitializeProcessing()
129 {
130
131 //  THE INITIALIZATION METHOD BODY :
132 //    Here does nothing 
133 //    but this is where you should allocate the internal/output pointers 
134 //    if any 
135
136         imageoutput = vtkImageData::New();
137   
138 }
139 //===== 
140 // Don't edit this file. This file is generated from xml description.. 
141 //===== 
142 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
143 {
144
145 //  THE FINALIZATION METHOD BODY :
146 //    Here does nothing 
147 //    but this is where you should desallocate the internal/output pointers 
148 //    if any
149   
150 }
151 }
152 // EO namespace bbvtk
153
154