//=====
#include "bbvtkRescaleSlopeIntercept.h"
#include "bbvtkPackage.h"
+
+
namespace bbvtk
{
double range[2];
- double spc[6];
- int dim[3];
+ double spc[3];
int ext[6];
- double value;
- double newValue;
double A=bbGetInputA();
double B=bbGetInputB();
else if (bbGetInputOutputFormat()=="VTK_FLOAT") outputformat = VTK_FLOAT;
else if (bbGetInputOutputFormat()=="VTK_DOUBLE") outputformat = VTK_DOUBLE;
- imageoutput->Initialize();
- imageoutput->SetScalarType( outputformat );
+
bbGetInputIn()->GetScalarRange(range);
bbGetInputIn()->GetSpacing(spc);
- imageoutput->SetSpacing( spc );
- bbGetInputIn()->GetWholeExtent(ext);
- dim[0]=ext[1]-ext[0]+1;
- dim[1]=ext[3]-ext[2]+1;
- dim[2]=ext[5]-ext[4]+1;
- imageoutput->SetDimensions( dim[0] , dim[1], dim[2] );
- imageoutput->AllocateScalars();
-
+ bbGetInputIn()->GetExtent( ext );
+
double range0plusrange1 = range[0]+range[1];
- double difrange = range[1]-range[0];
- double newdifrange = B-A;
+ double difrange = range[1]-range[0];
+ double newdifrange = B-A;
- int i,j,k;
- for (i=0; i<dim[0]; i++)
- {
- for (j=0; j<dim[1]; j++)
- {
- for (k=0; k<dim[2]; k++)
- {
- value = bbGetInputIn()->GetScalarComponentAsDouble(i,j,k,0);
-
- if (bbGetInputType()==0) // Rescale Slope/Intercept
- {
- newValue = value*A+B;
- } // if type 0
-
- if (bbGetInputType()==1) // Invert
- {
- newValue = value*(-1) + (range0plusrange1);
- } // if type 1
-
- if (bbGetInputType()==2) // Redimension
- {
- newValue = ((value-range[0])/difrange)*newdifrange + A;
- } // if type 2
-
- if (bbGetInputType()==3) // Invert redimension
- {
- newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
- } // if type 3
-
- imageoutput->SetScalarComponentFromDouble (i,j,k, 0, newValue);
- } // for k
- } // for j
- } // for i
-
- bbSetOutputOut(imageoutput);
+ double shift;
+ double scale;
+
+ if (bbGetInputType()==0) // Rescale Slope/Intercept
+ {
+ // newValue = value*A+B;
+ scale = A;
+ shift = B;
+ } // if type 0
+
+ if (bbGetInputType()==1) // Invert
+ {
+ // newValue = value*(-1) + (range0plusrange1);
+ scale=-1;
+ shift=range0plusrange1;
+ } // if type 1
+
+ if (bbGetInputType()==2) // Redimension
+ {
+ // newValue = ((value-range[0])/difrange)*newdifrange + A;
+ scale=newdifrange/difrange;
+ shift= A - (range[0]*newdifrange/difrange);
+ } // if type 2
+
+ if (bbGetInputType()==3) // Invert redimension
+ {
+ // newValue = ((value*(-1)+range[1])/difrange)*newdifrange + A;
+ scale=-newdifrange/difrange;
+ shift= A + (range[1]*newdifrange/difrange);
+ } // if type 3
+
+ filter->SetInput( bbGetInputIn() );
+ filter->SetOutputScalarType( outputformat );
+ filter->SetScale( scale );
+ filter->SetShift( shift );
+
+ mchange->SetInput( filter->GetOutput() );
+ mchange->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
+ mchange->SetOutputSpacing (spc);
+ mchange->Update(); //important
+
+ bbSetOutputOut( mchange->GetOutput() );
+
} // if
}
bbSetInputA(1);
bbSetInputB(0);
bbSetInputOutputFormat("SAME");
- imageoutput=NULL;
+
+ filter = NULL;
+ mchange = NULL;
}
//=====
// Don't edit this file. This file is generated from xml description..
// but this is where you should allocate the internal/output pointers
// if any
- imageoutput = vtkImageData::New();
+ filter = vtkImageShiftScale::New();
+ mchange = vtkImageChangeInformation::New();
+
}
//=====
// Here does nothing
// but this is where you should desallocate the internal/output pointers
// if any
- imageoutput->Delete();
+ mchange->Delete();
+ filter->Delete();
}
+
}
// EO namespace bbvtk