]> Creatis software - creaVtk.git/commitdiff
#3529 clean VTKTurnImage box
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 14 Oct 2024 10:29:00 +0000 (12:29 +0200)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 14 Oct 2024 10:29:00 +0000 (12:29 +0200)
bbtk_creaVtk_PKG/.DS_Store
bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx

index 8fd3482ce295b13412c4a47a718c628794e1ca1a..afa815535c7de6d6e2d9472d3384e822300392fe 100644 (file)
Binary files a/bbtk_creaVtk_PKG/.DS_Store and b/bbtk_creaVtk_PKG/.DS_Store differ
index d64a3c7dc3fb8953b886cb95a29e5f0fe7cbfe3f..581df5025607846e9e374fc2bea53a09a82c8309 100644 (file)
 
 #include "creaVtk_MACROS.h"
 
+#include <vtkImageReslice.h>
+#include <vtkImageChangeInformation.h>
+
 namespace bbcreaVtk
 {
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,TurnImage)
 BBTK_BLACK_BOX_IMPLEMENTATION(TurnImage,bbtk::AtomicBlackBox);
-//===== 
+//=====
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
-//===== 
+//=====
 void TurnImage::Process()
 {
-
-// THE MAIN PROCESSING METHOD BODY
-//   Here we simply set the input 'In' value to the output 'Out'
-//   And print out the output value
-// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
-//    void bbSet{Input|Output}NAME(const TYPE&)
-//    const TYPE& bbGet{Input|Output}NAME() const 
-//    Where :
-//    * NAME is the name of the input/output
-//      (the one provided in the attribute 'name' of the tag 'input')
-//    * TYPE is the C++ type of the input/output
-//      (the one provided in the attribute 'type' of the tag 'input')
-//    bbSetOutputOut( bbGetInputIn() );
-//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
-
-  
-       if (bbGetInputIn()!=NULL)
-       {
-               int dim[3];
-               int ext[6];
-               bbGetInputIn()->GetExtent(ext);
-               dim[0]  = ext[1]-ext[0]+1;
-               dim[1]  = ext[3]-ext[2]+1;
-               dim[2]  = ext[5]-ext[4]+1;
-               double spc[3];
-               bbGetInputIn()->GetSpacing(spc);
-
-               vtkImageData *newImage = vtkImageData::New();
-               newImage->Initialize();
-               if (bbGetInputDir()==1)
-               {
-                       newImage->SetSpacing( spc[1],spc[2],spc[0] );
-                       newImage->SetDimensions(  dim[1],dim[2], dim[0] );
-               } else if (bbGetInputDir()==2)
-               {
-                       newImage->SetSpacing( spc[0],spc[2],spc[1] );
-                       newImage->SetDimensions(  dim[0],dim[2], dim[1] );
-               } else {
-                       newImage->SetSpacing( spc[0],spc[1],spc[2] );
-                       newImage->SetDimensions(  dim[0],dim[1], dim[2] );
-               }// if Dir
-
-//EED 2017-01-01 Migration VTK7
-#if (VTK_MAJOR_VERSION <= 5) 
-               newImage->SetScalarType( bbGetInputIn()->GetScalarType() );
-               newImage->SetNumberOfScalarComponents(1);
-               newImage->AllocateScalars();
-#endif
-#if (VTK_MAJOR_VERSION >= 6) 
-               newImage->AllocateScalars( bbGetInputIn()->GetScalarType(),1 );
-#endif
-
-               DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())                                    
-               DEF_POINTER_IMAGE_VTK_CREA(vNI,ssNI,pNI,stNI,newImage)                                          
-
-               long int index=0;
-               int i,j,k;
-               double value;
-               for (k=0;k<dim[2];k++)
-               {
-                       for (j=0;j<dim[1];j++)
-                       {
-                               for (i=0;i<dim[0];i++)
-                               {
-                                       GETVALUE2_VTK_CREA(vIn,pIn,stIn,index) 
-//                                     value = bbGetInputIn()->GetScalarComponentAsDouble (i,j,k,0);
-                                       if (bbGetInputDir()==1)
-                                       {
-                                               SETVALUE2_VTK_CREA(vIn,pNI,stNI, j + (dim[2]-k-1)*dim[1] + i*dim[1]*dim[2] )            
-//                                             newImage->SetScalarComponentFromDouble(j,dim[2]-k-1,i,0,value);
-                                       } else if (bbGetInputDir()==2)
-                                       {
-                                               SETVALUE2_VTK_CREA(vIn,pNI,stNI, i + (dim[2]-k-1)*dim[0] + j*dim[0]*dim[2] )            
-//                                             newImage->SetScalarComponentFromDouble(i,dim[2]-k-1,j,0,value);
-                                       } else {
-                                               SETVALUE2_VTK_CREA(vIn,pNI,stNI,index)          
-//                                             newImage->SetScalarComponentFromDouble(i,j,k,0,value);
-                                       }// if Dir
-                                       index++;
-                               } // for i
-                       } // for j
-               } // for k
-               bbSetOutputOut(newImage);
-       } else {
-               bbSetOutputOut(NULL);
-       }// if In!=NULL
+    
+    // THE MAIN PROCESSING METHOD BODY
+    //   Here we simply set the input 'In' value to the output 'Out'
+    //   And print out the output value
+    // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+    //    void bbSet{Input|Output}NAME(const TYPE&)
+    //    const TYPE& bbGet{Input|Output}NAME() const
+    //    Where :
+    //    * NAME is the name of the input/output
+    //      (the one provided in the attribute 'name' of the tag 'input')
+    //    * TYPE is the C++ type of the input/output
+    //      (the one provided in the attribute 'type' of the tag 'input')
+    //    bbSetOutputOut( bbGetInputIn() );
+    //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+    
+    
+    if (bbGetInputIn()!=NULL)
+    {
+        /*
+         int dim[3];
+         int ext[6];
+         bbGetInputIn()->GetExtent(ext);
+         dim[0]        = ext[1]-ext[0]+1;
+         dim[1]        = ext[3]-ext[2]+1;
+         dim[2]        = ext[5]-ext[4]+1;
+         double spc[3];
+         bbGetInputIn()->GetSpacing(spc);
+         
+         vtkImageData *newImage = vtkImageData::New();
+         newImage->Initialize();
+         if (bbGetInputDir()==1)
+         {
+         newImage->SetSpacing( spc[1],spc[2],spc[0] );
+         newImage->SetDimensions(  dim[1],dim[2], dim[0] );
+         } else if (bbGetInputDir()==2)
+         {
+         newImage->SetSpacing( spc[0],spc[2],spc[1] );
+         newImage->SetDimensions(  dim[0],dim[2], dim[1] );
+         } else {
+         newImage->SetSpacing( spc[0],spc[1],spc[2] );
+         newImage->SetDimensions(  dim[0],dim[1], dim[2] );
+         }// if Dir
+         
+         //EED 2017-01-01 Migration VTK7
+         #if (VTK_MAJOR_VERSION <= 5)
+         newImage->SetScalarType( bbGetInputIn()->GetScalarType() );
+         newImage->SetNumberOfScalarComponents(1);
+         newImage->AllocateScalars();
+         #endif
+         #if (VTK_MAJOR_VERSION >= 6)
+         newImage->AllocateScalars( bbGetInputIn()->GetScalarType(),1 );
+         #endif
+         
+         DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())
+         DEF_POINTER_IMAGE_VTK_CREA(vNI,ssNI,pNI,stNI,newImage)
+         
+         
+         long int index=0;
+         int i,j,k;
+         double value;
+         for (k=0;k<dim[2];k++)
+         {
+         for (j=0;j<dim[1];j++)
+         {
+         
+         for (i=0;i<dim[0];i++)
+         {
+         
+         GETVALUE2_VTK_CREA(vIn,pIn,stIn,index)
+         //old                                 value = bbGetInputIn()->GetScalarComponentAsDouble (i,j,k,0);
+         if (bbGetInputDir()==1)
+         {
+         SETVALUE2_VTK_CREA(vIn,pNI,stNI, j + (dim[2]-k-1)*dim[1] + i*dim[1]*dim[2] )
+         //old                                         newImage->SetScalarComponentFromDouble(j,dim[2]-k-1,i,0,value);
+         } else if (bbGetInputDir()==2)
+         {
+         SETVALUE2_VTK_CREA(vIn,pNI,stNI, i + (dim[2]-k-1)*dim[0] + j*dim[0]*dim[2] )
+         //old                                         newImage->SetScalarComponentFromDouble(i,dim[2]-k-1,j,0,value);
+         } else {
+         SETVALUE2_VTK_CREA(vIn,pNI,stNI,index)
+         //old                                         newImage->SetScalarComponentFromDouble(i,j,k,0,value);
+         }// if Dir
+         //                    index++;
+         } // for i
+         
+         } // for j
+         } // for k
+         bbSetOutputOut(newImage);
+         */
+        
+        /*
+         vtkImagePermute *permute = vtkImagePermute::New();
+         permute->SetInputData( bbGetInputIn() );
+         permute->SetFilteredAxes (0,2,1);
+         permute->Update();
+         bbSetOutputOut( permute->GetOutput() );
+         */
+        
+        // Rotate about the center
+        //         vtkTransform *transform;
+        //         transform->Translate(center[0], center[1], center[2]);
+        //         transform->RotateWXYZ(angle, 0, 0, 1);
+        //         transform->Translate(-center[0], -center[1], -center[2]);
+        
+        // Reslice does all of the work.
+        vtkImageReslice *reslice = vtkImageReslice::New();
+        static double axes[3][3] = { { 1, 0, 0 }, { 0, 0, -1 }, { 0, 1, 0 } };
+        reslice->SetResliceAxesDirectionCosines(axes[0], axes[1], axes[2]);
+        //         reslice->SetOutputOrigin(0,0,0);
+        reslice->SetInputData( bbGetInputIn() );
+        reslice->SetResliceAxesOrigin( 0,0,0 );
+        reslice->SetInterpolationModeToNearestNeighbor();
+        reslice->Update();
+        
+        vtkImageChangeInformation *mchange = vtkImageChangeInformation::New();
+        mchange->SetInputData( reslice->GetOutput() );
+        mchange->SetOutputOrigin( 0,0,0 );
+        mchange->Update();
+        bbSetOutputOut( mchange->GetOutput() );
+    } else {
+        bbSetOutputOut(NULL);
+    }// if In!=NULL
 }
-//===== 
+
+//=====
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
-//===== 
+//=====
 void TurnImage::bbUserSetDefaultValues()
 {
-
-//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
-//    Here we initialize the input 'In' to 0
-   bbSetInputIn(NULL);
-   bbSetInputDir(0);
-  
+    //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+    //    Here we initialize the input 'In' to 0
+    bbSetInputIn(NULL);
+    bbSetInputDir(0);
 }
-//===== 
+
+//=====
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
-//===== 
+//=====
 void TurnImage::bbUserInitializeProcessing()
 {
-
-//  THE INITIALIZATION METHOD BODY :
-//    Here does nothing 
-//    but this is where you should allocate the internal/output pointers 
-//    if any 
-
-  
+    //  THE INITIALIZATION METHOD BODY :
+    //    Here does nothing
+    //    but this is where you should allocate the internal/output pointers
+    //    if any
 }
-//===== 
+
+//=====
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
-//===== 
+//=====
 void TurnImage::bbUserFinalizeProcessing()
 {
-
-//  THE FINALIZATION METHOD BODY :
-//    Here does nothing 
-//    but this is where you should desallocate the internal/output pointers 
-//    if any
-  
-}
+    //  THE FINALIZATION METHOD BODY :
+    //    Here does nothing
+    //    but this is where you should desallocate the internal/output pointers
+    //    if any
 }
-// EO namespace bbcreaVtk
+
+}// EO namespace bbcreaVtk