2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
29 // Don't edit this file. This file is generated from xml description..
31 #include "bbvtkRescaleSlopeIntercept.h"
32 #include "bbvtkPackage.h"
38 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,RescaleSlopeIntercept)
39 BBTK_BLACK_BOX_IMPLEMENTATION(RescaleSlopeIntercept,bbtk::AtomicBlackBox);
41 // Don't edit this file. This file is generated from xml description..
43 void RescaleSlopeIntercept::Process()
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
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;
63 double A=bbGetInputA();
64 double B=bbGetInputB();
66 if (bbGetInputIn()!=0)
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;
82 bbGetInputIn()->GetScalarRange(range);
83 bbGetInputIn()->GetSpacing(spc);
84 bbGetInputIn()->GetExtent( ext );
86 double range0plusrange1 = range[0]+range[1];
87 double difrange = range[1]-range[0];
88 double newdifrange = B-A;
93 if (bbGetInputType()==0) // Rescale Slope/Intercept
95 // newValue = value*A+B;
100 if (bbGetInputType()==1) // Invert
102 // newValue = value*(-1) + (range0plusrange1);
104 shift=range0plusrange1;
107 if (bbGetInputType()==2) // Redimension
109 // newValue = ((value-range[0])/difrange)*newdifrange + A;
110 scale=newdifrange/difrange;
111 shift= A - (range[0]*newdifrange/difrange);
114 if (bbGetInputType()==3) // Invert redimension
116 // newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
117 scale=-newdifrange/difrange;
118 shift= A + (range[1]*newdifrange/difrange);
121 filter1->SetInput( bbGetInputIn() );
122 filter1->SetOutputScalarType( VTK_DOUBLE );
123 filter1->SetShift( 0 );
124 filter1->SetScale( scale );
126 filter2->SetInput( filter1->GetOutput() );
127 filter2->SetOutputScalarType( outputformat );
128 filter2->SetShift( shift );
129 filter2->SetScale( 1 );
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() );
138 bbSetOutputOut( NULL );
144 // Don't edit this file. This file is generated from xml description..
146 void RescaleSlopeIntercept::bbUserSetDefaultValues()
149 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
150 // Here we initialize the input 'In' to 0
155 bbSetInputOutputFormat("SAME");
162 // Don't edit this file. This file is generated from xml description..
164 void RescaleSlopeIntercept::bbUserInitializeProcessing()
167 // THE INITIALIZATION METHOD BODY :
169 // but this is where you should allocate the internal/output pointers
172 filter1 = vtkImageShiftScale::New();
173 filter2 = vtkImageShiftScale::New();
174 mchange = vtkImageChangeInformation::New();
179 // Don't edit this file. This file is generated from xml description..
181 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
184 // THE FINALIZATION METHOD BODY :
186 // but this is where you should desallocate the internal/output pointers
194 // EO namespace bbvtk