From 321f4a5d59a4664326da8d5a7e3fbd5352784637 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Thu, 17 Oct 2024 15:57:42 +0200 Subject: [PATCH] #3530 bbcreaVtkTurnImage optimisation --- bbtk_creaVtk_PKG/.DS_Store | Bin 8196 -> 8196 bytes bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx | 104 ++++++++++---------- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/bbtk_creaVtk_PKG/.DS_Store b/bbtk_creaVtk_PKG/.DS_Store index afa815535c7de6d6e2d9472d3384e822300392fe..8fd3482ce295b13412c4a47a718c628794e1ca1a 100644 GIT binary patch delta 14 VcmZp1XmQx^U67G+^AABDJ^(9H1sMPU delta 14 VcmZp1XmQx^U67Gs^AABDJ^(9B1sDJT diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx index 581df50..7afd2e9 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx @@ -75,69 +75,65 @@ void TurnImage::Process() 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;kGetScalarComponentAsDouble (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 (i=0;iGetScalarComponentAsDouble (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 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() ); + */ + if ( (bbGetInputDir()==1) || (bbGetInputDir()==2) ) + { + vtkImageReslice *reslice = vtkImageReslice::New(); + vtkImageChangeInformation *mchange = vtkImageChangeInformation::New(); + // Reslice does all of the work. + if ( bbGetInputDir()==1 ) + { + static double axes[3][3] = { { 0, 1, 0 }, { 0, 0, -1 }, { 1, 0, 0 } }; + reslice->SetResliceAxesDirectionCosines(axes[0], axes[1], axes[2]); + } // dir 1 + if ( bbGetInputDir()==2 ) + { + static double axes[3][3] = { { 1, 0, 0 }, { 0, 0, -1 }, { 0, 1, 0 } }; + reslice->SetResliceAxesDirectionCosines(axes[0], axes[1], axes[2]); + } // dir 2 + // reslice->SetOutputOrigin(0,0,0); + reslice->SetInputData( bbGetInputIn() ); + reslice->SetResliceAxesOrigin( 0,0,0 ); + reslice->SetInterpolationModeToNearestNeighbor(); + reslice->Update(); + mchange->SetInputData( reslice->GetOutput() ); + mchange->SetOutputOrigin( 0,0,0 ); + mchange->Update(); + bbSetOutputOut( mchange->GetOutput() ); + } else { + bbSetOutputOut( bbGetInputIn() ); + }// if Dir 1 or 2 + } else { bbSetOutputOut(NULL); }// if In!=NULL -- 2.47.1