]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
dc4e0afc299a4effc6e758f5149a2087a4f67482
[bbtk.git] / packages / vtk / src / bbvtkRescaleSlopeIntercept.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 //=====
29 // Don't edit this file. This file is generated from xml description.. 
30 //===== 
31 #include "bbvtkRescaleSlopeIntercept.h"
32 #include "bbvtkPackage.h"
33
34
35 namespace bbvtk
36 {
37
38 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,RescaleSlopeIntercept)
39 BBTK_BLACK_BOX_IMPLEMENTATION(RescaleSlopeIntercept,bbtk::AtomicBlackBox);
40 //===== 
41 // Don't edit this file. This file is generated from xml description.. 
42 //===== 
43 void RescaleSlopeIntercept::Process()
44 {
45
46 // THE MAIN PROCESSING METHOD BODY
47 //   Here we simply set the input 'In' value to the output 'Out'
48 //   And print out the output value
49 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
50 //    void bbSet{Input|Output}NAME(const TYPE&)
51 //    const TYPE& bbGet{Input|Output}NAME() const 
52 //    Where :
53 //    * NAME is the name of the input/output
54 //      (the one provided in the attribute 'name' of the tag 'input')
55 //    * TYPE is the C++ type of the input/output
56 //      (the one provided in the attribute 'type' of the tag 'input')
57 //    bbSetOutputOut( bbGetInputIn() );
58 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
59   
60         double range[2];
61         double spc[3];
62         int ext[6];
63         double A=bbGetInputA();
64         double B=bbGetInputB();
65         
66         if (bbGetInputIn()!=0)
67         {
68                 if (bbGetInputOutputFormat()=="SAME")                                   outputformat = bbGetInputIn()->GetScalarType();
69                 else if (bbGetInputOutputFormat()=="VTK_BIT")                   outputformat = VTK_BIT;            // 1
70                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                  outputformat = VTK_CHAR;           // 2
71                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;    // 15
72                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;  // 3
73                 else if (bbGetInputOutputFormat()=="VTK_SHORT")                 outputformat = VTK_SHORT;          // 4
74                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT; // 5
75                 else if (bbGetInputOutputFormat()=="VTK_INT")                   outputformat = VTK_INT;            // 6
76                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;   // 7
77                 else if (bbGetInputOutputFormat()=="VTK_LONG")                  outputformat = VTK_LONG;           // 8  
78                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;  // 9
79                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                 outputformat = VTK_FLOAT;          // 10
80                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                outputformat = VTK_DOUBLE;         // 11 
81                 
82                 
83                 bbGetInputIn()->GetScalarRange(range);
84                 bbGetInputIn()->GetSpacing(spc);
85                 bbGetInputIn()->GetExtent( ext );                               
86                 
87                 double range0plusrange1 = range[0]+range[1];
88                 double difrange                 = range[1]-range[0];
89                 double newdifrange              = B-A;
90                 
91                 double shift;
92                 double scale;
93                 
94                 if (bbGetInputType()==0) // Rescale Slope/Intercept
95                 { 
96                         //                      newValue = value*A+B;
97                         scale = A;
98                         shift = B;
99                 } // if type 0
100                 
101                 if (bbGetInputType()==1) // Invert
102                 { 
103                         //                      newValue = value*(-1) + (range0plusrange1);
104                         scale=-1;
105                         shift=range0plusrange1;
106                 } // if type 1
107                 
108                 if (bbGetInputType()==2) // Redimension
109                 { 
110                         //                      newValue = ((value-range[0])/difrange)*newdifrange + A;
111                         scale=newdifrange/difrange;
112                         shift= A - (range[0]*newdifrange/difrange);
113                 } // if type 2
114                 
115                 if (bbGetInputType()==3) // Invert redimension
116                 { 
117                         //                      newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
118                         scale=-newdifrange/difrange;
119                         shift= A + (range[1]*newdifrange/difrange);
120                 } // if type 3
121                 
122                 filter1->SetInput( bbGetInputIn() );
123                 filter1->SetOutputScalarType( VTK_DOUBLE );
124                 filter1->SetShift( 0 );
125                 filter1->SetScale( scale );
126                 
127                 filter2->SetInput( filter1->GetOutput() );
128                 filter2->SetOutputScalarType( outputformat );
129                 filter2->SetShift( shift );
130                 filter2->SetScale( 1 );
131                 
132                 mchange->SetInput( filter2->GetOutput() );
133                 mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
134                 mchange->SetOutputSpacing (spc);
135                 mchange->Update();    //important
136                 bbSetOutputOut( mchange->GetOutput() );
137                 
138         } else  {
139                 bbSetOutputOut( NULL );
140         }               // if bbGetInputIn      
141 }
142         
143         
144 //===== 
145 // Don't edit this file. This file is generated from xml description.. 
146 //===== 
147 void RescaleSlopeIntercept::bbUserSetDefaultValues()
148 {
149
150 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
151 //    Here we initialize the input 'In' to 0
152         bbSetInputIn(NULL);
153         bbSetInputType(0);
154         bbSetInputA(1);
155         bbSetInputB(0);
156         bbSetInputOutputFormat("SAME");
157
158         filter1 = NULL;
159         filter2 = NULL;
160         mchange = NULL;
161 }
162 //===== 
163 // Don't edit this file. This file is generated from xml description.. 
164 //===== 
165 void RescaleSlopeIntercept::bbUserInitializeProcessing()
166 {
167
168 //  THE INITIALIZATION METHOD BODY :
169 //    Here does nothing 
170 //    but this is where you should allocate the internal/output pointers 
171 //    if any 
172
173         filter1 = vtkImageShiftScale::New();
174         filter2 = vtkImageShiftScale::New();
175         mchange = vtkImageChangeInformation::New();
176
177   
178 }
179 //===== 
180 // Don't edit this file. This file is generated from xml description.. 
181 //===== 
182 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
183 {
184
185 //  THE FINALIZATION METHOD BODY :
186 //    Here does nothing 
187 //    but this is where you should desallocate the internal/output pointers 
188 //    if any
189         mchange->Delete();              
190         filter1->Delete();
191         filter2->Delete();
192 }
193         
194 }
195 // EO namespace bbvtk
196
197