From 2825c6ab65c1333b6236d54bb157b315097e6fb5 Mon Sep 17 00:00:00 2001 From: Eduardo Davila Date: Mon, 9 Jul 2012 13:02:42 +0000 Subject: [PATCH] 1493 Bug Image Planes: view orientation --- packages/vtk/src/bbvtkImagePlanes.cxx | 79 ++++++++++++++++++++++----- packages/vtk/src/bbvtkImagePlanes.h | 8 ++- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index 746492a..426189b 100644 --- a/packages/vtk/src/bbvtkImagePlanes.cxx +++ b/packages/vtk/src/bbvtkImagePlanes.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbvtkImagePlanes.cxx,v $ Language: C++ - Date: $Date: 2012/07/04 08:38:21 $ - Version: $Revision: 1.36 $ + Date: $Date: 2012/07/09 13:02:42 $ + Version: $Revision: 1.37 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -65,7 +65,10 @@ #include "bbstdRelay.h" #include "vtkObjectFactory.h" +#include "vtkImageFlip.h" +#include "vtkImageReslice.h" +#include "vtkImageChangeInformation.h" namespace bbstd { @@ -136,7 +139,7 @@ namespace bbvtk }; //================================================================ - //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.36 $"); + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.37 $"); //================================================================ @@ -196,12 +199,39 @@ namespace bbvtk vtkImagePlaneWidget* planeWidget3Pts = GetPlaneWidget('3', 0, 1, 1, picker); planeWidget3Pts->SetLookupTable(planeWidgetX->GetLookupTable()); + // EED MPR view orientation correction.. + vtkImageFlip *flipYFilter = vtkImageFlip::New(); + flipYFilter->SetFilteredAxis(1); // flip y axis + flipYFilter->SetInput( planeWidgetX->GetResliceOutput() ); + flipYFilter->Update(); + + vtkImageChangeInformation *image = vtkImageChangeInformation::New(); + image->SetInput( planeWidgetY->GetResliceOutput() ); + image->SetOutputSpacing( 1,1,1 ); + image->CenterImageOn(); + image->Update(); + _imageTransform = vtkTransform::New(); + vtkImageReslice *slicer =vtkImageReslice::New(); + slicer->SetInput( image->GetOutput() ); + slicer->SetInformationInput( image->GetOutput() ); + slicer->SetResliceTransform( _imageTransform ); + slicer->SetOutputOrigin(0 , 0 , 0 ); + slicer->SetInterpolationModeToNearestNeighbor(); + slicer->Update(); + vtkImageChangeInformation *imageResult = vtkImageChangeInformation::New(); + imageResult->SetInput( slicer->GetOutput() ); + double spc[3]; + planeWidgetY->GetResliceOutput()->GetSpacing(spc); + imageResult->SetOutputSpacing( spc[1], spc[0], spc[2] ); + imageResult->SetOutputOrigin( 0,0,0 ); + + bbSetOutputPlaneX(planeWidgetX); bbSetOutputPlaneY(planeWidgetY); bbSetOutputPlaneZ(planeWidgetZ); bbSetOutputPlane3Pts(planeWidget3Pts); - bbSetOutputImageX(planeWidgetX->GetResliceOutput()); - bbSetOutputImageY(planeWidgetY->GetResliceOutput()); + bbSetOutputImageX( flipYFilter->GetOutput() ); // EED MPR view orientation correction.. + bbSetOutputImageY( imageResult->GetOutput() ); // EED MPR view orientation correction.. bbSetOutputImageZ(planeWidgetZ->GetResliceOutput()); bbSetInputInteractor(0); //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); @@ -244,16 +274,28 @@ namespace bbvtk //--------------------------------------------------------------------- void ImagePlanes::Process() { + if (bbGetInputIn()!=0) { - int xMin, xMax, yMin, yMax, zMin, zMax; - bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax); - + int dim[3]; + int ext[6]; + bbGetOutputPlaneX()->GetResliceOutput()->GetWholeExtent(ext); + dim[0] = ext[1]-ext[0]+1; + dim[1] = ext[3]-ext[2]+1; + dim[2] = ext[5]-ext[4]+1; + _imageTransform->Identity(); + _imageTransform->PostMultiply(); + _imageTransform->Translate( (int)(-(dim[0]/2)) , (int)(-(dim[1]/2)) ,0); + _imageTransform->RotateZ(90); + + if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){ // Input image has changed : reinitialize planes image = bbGetInputIn(); // Initial values : center of the volume (in real world, not in pixels!) + int xMin, xMax, yMin, yMax, zMin, zMax; + bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax); double xSpacing, ySpacing, zSpacing; bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing); @@ -277,24 +319,33 @@ namespace bbvtk { bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0], bbGetInputWindowLevel()[1]); - } - else - { + } else { double *range = image->GetScalarRange(); bbGetOutputPlaneZ()->SetWindowLevel(range[1]-range[0], 0.5*(range[1]+range[0])); - } + } // windowlevel updateInteractor(); - } + + dim[0] = xMax-xMin+1; + dim[1] = yMax-yMin+1; + dim[2] = zMax-zMin+1; + _imageTransform->Identity(); + _imageTransform->PostMultiply(); + _imageTransform->Translate( (int)(-(dim[0]/2)*(1/xSpacing)) , (int)(-(dim[2]/2)*(1/zSpacing)) ,0); + _imageTransform->RotateZ(90); + + } // image + // UPDATE DES SORTIES bbGetOutputPlaneX()->SetResliceInterpolate( bbGetInputInterpolation() ); bbGetOutputPlaneY()->SetResliceInterpolate( bbGetInputInterpolation() ); bbGetOutputPlaneZ()->SetResliceInterpolate( bbGetInputInterpolation() ); + bbGetOutputPlaneX()->GetResliceOutput()->Update(); bbGetOutputPlaneY()->GetResliceOutput()->Update(); bbGetOutputPlaneZ()->GetResliceOutput()->Update(); - + std::vector pointsx = bbGetInputPointsX(); std::vector pointsy = bbGetInputPointsY(); std::vector pointsz = bbGetInputPointsZ(); diff --git a/packages/vtk/src/bbvtkImagePlanes.h b/packages/vtk/src/bbvtkImagePlanes.h index 3f0c3a8..778748d 100644 --- a/packages/vtk/src/bbvtkImagePlanes.h +++ b/packages/vtk/src/bbvtkImagePlanes.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbvtkImagePlanes.h,v $ Language: C++ - Date: $Date: 2012/07/04 08:38:21 $ - Version: $Revision: 1.23 $ + Date: $Date: 2012/07/09 13:02:45 $ + Version: $Revision: 1.24 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -89,6 +89,10 @@ namespace bbvtk BBTK_PROCESS(Process); void Process(); + + vtkTransform *_imageTransform; + + protected: private: -- 2.45.0