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; // 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
83 bbGetInputIn()->GetScalarRange(range);
84 bbGetInputIn()->GetSpacing(spc);
85 bbGetInputIn()->GetExtent( ext );
87 double range0plusrange1 = range[0]+range[1];
88 double difrange = range[1]-range[0];
89 double newdifrange = B-A;
94 if (bbGetInputType()==0) // Rescale Slope/Intercept
96 // newValue = value*A+B;
101 if (bbGetInputType()==1) // Invert
103 // newValue = value*(-1) + (range0plusrange1);
105 shift=range0plusrange1;
108 if (bbGetInputType()==2) // Redimension
110 // newValue = ((value-range[0])/difrange)*newdifrange + A;
111 scale=newdifrange/difrange;
112 shift= A - (range[0]*newdifrange/difrange);
115 if (bbGetInputType()==3) // Invert redimension
117 // newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
118 scale=-newdifrange/difrange;
119 shift= A + (range[1]*newdifrange/difrange);
122 filter1->SetInput( bbGetInputIn() );
123 filter1->SetOutputScalarType( VTK_DOUBLE );
124 filter1->SetShift( 0 );
125 filter1->SetScale( scale );
127 filter2->SetInput( filter1->GetOutput() );
128 filter2->SetOutputScalarType( outputformat );
129 filter2->SetShift( shift );
130 filter2->SetScale( 1 );
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() );
139 bbSetOutputOut( NULL );
145 // Don't edit this file. This file is generated from xml description..
147 void RescaleSlopeIntercept::bbUserSetDefaultValues()
150 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
151 // Here we initialize the input 'In' to 0
156 bbSetInputOutputFormat("SAME");
163 // Don't edit this file. This file is generated from xml description..
165 void RescaleSlopeIntercept::bbUserInitializeProcessing()
168 // THE INITIALIZATION METHOD BODY :
170 // but this is where you should allocate the internal/output pointers
173 filter1 = vtkImageShiftScale::New();
174 filter2 = vtkImageShiftScale::New();
175 mchange = vtkImageChangeInformation::New();
180 // Don't edit this file. This file is generated from xml description..
182 void RescaleSlopeIntercept::bbUserFinalizeProcessing()
185 // THE FINALIZATION METHOD BODY :
187 // but this is where you should desallocate the internal/output pointers
195 // EO namespace bbvtk