]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
Feature #1774
[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;
70                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                  outputformat = VTK_CHAR;
71                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")   outputformat = VTK_SIGNED_CHAR;
72                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR;
73                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT;
74                 else if (bbGetInputOutputFormat()=="VTK_INT")                   outputformat = VTK_INT;
75                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")  outputformat = VTK_UNSIGNED_INT;
76                 else if (bbGetInputOutputFormat()=="VTK_LONG")                  outputformat = VTK_LONG;
77                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG;
78                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                 outputformat = VTK_FLOAT;
79                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                outputformat = VTK_DOUBLE;
80                 
81                 
82                 bbGetInputIn()->GetScalarRange(range);
83                 bbGetInputIn()->GetSpacing(spc);
84                 bbGetInputIn()->GetExtent( ext );                               
85                 
86                 double range0plusrange1 = range[0]+range[1];
87                 double difrange                 = range[1]-range[0];
88                 double newdifrange              = B-A;
89                 
90                 double shift;
91                 double scale;
92                 
93                 if (bbGetInputType()==0) // Rescale Slope/Intercept
94                 { 
95                         //                      newValue = value*A+B;
96                         scale = A;
97                         shift = B;
98                 } // if type 0
99                 
100                 if (bbGetInputType()==1) // Invert
101                 { 
102                         //                      newValue = value*(-1) + (range0plusrange1);
103                         scale=-1;
104                         shift=range0plusrange1;
105                 } // if type 1
106                 
107                 if (bbGetInputType()==2) // Redimension
108                 { 
109                         //                      newValue = ((value-range[0])/difrange)*newdifrange + A;
110                         scale=newdifrange/difrange;
111                         shift= A - (range[0]*newdifrange/difrange);
112                 } // if type 2
113                 
114                 if (bbGetInputType()==3) // Invert redimension
115                 { 
116                         //                      newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
117                         scale=-newdifrange/difrange;
118                         shift= A + (range[1]*newdifrange/difrange);
119                 } // if type 3
120                 
121                 filter1->SetInput( bbGetInputIn() );
122                 filter1->SetOutputScalarType( VTK_DOUBLE );
123                 filter1->SetShift( 0 );
124                 filter1->SetScale( scale );
125                 
126                 filter2->SetInput( filter1->GetOutput() );
127                 filter2->SetOutputScalarType( outputformat );
128                 filter2->SetShift( shift );
129                 filter2->SetScale( 1 );
130                 
131                 mchange->SetInput( filter2->GetOutput() );
132                 mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
133                 mchange->SetOutputSpacing (spc);
134                 mchange->Update();    //important
135                 bbSetOutputOut( mchange->GetOutput() );
136                 
137         } else  {
138                 bbSetOutputOut( NULL );
139         }               // if bbGetInputIn      
140 }
141         
142         
143 //===== 
144 // Don't edit this file. This file is generated from xml description.. 
145 //===== 
146 void RescaleSlopeIntercept::bbUserSetDefaultValues()
147 {
148
149 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
150 //    Here we initialize the input 'In' to 0
151         bbSetInputIn(NULL);
152         bbSetInputType(0);
153         bbSetInputA(1);
154         bbSetInputB(0);
155         bbSetInputOutputFormat("SAME");
156
157         filter1 = NULL;
158         filter2 = NULL;
159         mchange = NULL;
160 }
161 //===== 
162 // Don't edit this file. This file is generated from xml description.. 
163 //===== 
164 void RescaleSlopeIntercept::bbUserInitializeProcessing()
165 {
166
167 //  THE INITIALIZATION METHOD BODY :
168 //    Here does nothing 
169 //    but this is where you should allocate the internal/output pointers 
170 //    if any 
171
172         filter1 = vtkImageShiftScale::New();
173         filter2 = vtkImageShiftScale::New();
174         mchange = vtkImageChangeInformation::New();
175
176   
177 }
178 //===== 
179 // Don't edit this file. This file is generated from xml description.. 
180 //===== 
181 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
182 {
183
184 //  THE FINALIZATION METHOD BODY :
185 //    Here does nothing 
186 //    but this is where you should desallocate the internal/output pointers 
187 //    if any
188         mchange->Delete();              
189         filter1->Delete();
190         filter2->Delete();
191 }
192         
193 }
194 // EO namespace bbvtk
195
196