]> Creatis software - bbtk.git/commitdiff
no message
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 19 Apr 2011 10:39:35 +0000 (10:39 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 19 Apr 2011 10:39:35 +0000 (10:39 +0000)
packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx
packages/vtk/src/bbvtkRescaleSlopeIntercept.h

index 8e9ea4c06768d31278b6dc695611f917bb9c7e4d..911d6626c66cbce1b5d25077fb9b6f961ddfa889 100644 (file)
@@ -3,6 +3,8 @@
 //===== 
 #include "bbvtkRescaleSlopeIntercept.h"
 #include "bbvtkPackage.h"
+
+
 namespace bbvtk
 {
 
@@ -30,11 +32,8 @@ void RescaleSlopeIntercept::Process()
   
 
        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();
        
@@ -53,57 +52,58 @@ void RescaleSlopeIntercept::Process()
                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
 }
        
@@ -120,7 +120,9 @@ void RescaleSlopeIntercept::bbUserSetDefaultValues()
        bbSetInputA(1);
        bbSetInputB(0);
        bbSetInputOutputFormat("SAME");
-       imageoutput=NULL;
+
+       filter  = NULL;
+       mchange = NULL;
 }
 //===== 
 // Don't edit this file. This file is generated from xml description.. 
@@ -133,7 +135,9 @@ void RescaleSlopeIntercept::bbUserInitializeProcessing()
 //    but this is where you should allocate the internal/output pointers 
 //    if any 
 
-       imageoutput = vtkImageData::New();
+       filter  = vtkImageShiftScale::New();
+       mchange = vtkImageChangeInformation::New();
+
   
 }
 //===== 
@@ -146,8 +150,10 @@ void RescaleSlopeIntercept::bbUserFinalizeProcessing()
 //    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
 
index e78296372a5cdf8275c60b9723cab578ae1ac4b0..140a0cf3a36f0d334446882ab401e96c99236018 100644 (file)
@@ -8,6 +8,9 @@
 #include "iostream"
 
 #include "vtkImageData.h"
+#include <vtkImageShiftScale.h>
+#include <vtkImageChangeInformation.h>
+
 
 
 namespace bbvtk
@@ -30,9 +33,10 @@ class bbvtk_EXPORT RescaleSlopeIntercept
   BBTK_PROCESS(Process);
   void Process();
        
-       int outputformat;
-       vtkImageData* imageoutput;
-       
+       int                                                     outputformat;
+       vtkImageShiftScale                      *filter;
+       vtkImageChangeInformation       *mchange;
+
 //===== 
 // Don't edit this file. This file is generated from xml description.. 
 //=====