X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkImagePlanes.cxx;h=d3cd9d4040fca938bd84fa6ed9446927fb706c20;hb=2ab6bff6c5478054c4fdc9d37304b28151251acb;hp=92daa652fad7dca3429fe42ab4b561694f1e2eb4;hpb=b3225bf9915c36f8e79d9a328b525cde6eed9247;p=bbtk.git diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index 92daa65..d3cd9d4 100644 --- a/packages/vtk/src/bbvtkImagePlanes.cxx +++ b/packages/vtk/src/bbvtkImagePlanes.cxx @@ -1,33 +1,38 @@ -/*========================================================================= +/* + # --------------------------------------------------------------------- + # + # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image + # pour la SantÈ) + # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton + # Previous Authors : Laurent Guigues, Jean-Pierre Roux + # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil + # + # This software is governed by the CeCILL-B license under French law and + # abiding by the rules of distribution of free software. You can use, + # modify and/ or redistribute the software under the terms of the CeCILL-B + # license as circulated by CEA, CNRS and INRIA at the following URL + # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + # or in the file LICENSE.txt. + # + # As a counterpart to the access to the source code and rights to copy, + # modify and redistribute granted by the license, users are provided only + # with a limited warranty and the software's author, the holder of the + # economic rights, and the successive licensors have only limited + # liability. + # + # The fact that you are presently reading this means that you have had + # knowledge of the CeCILL-B license and that you accept its terms. + # ------------------------------------------------------------------------ */ + + +/*========================================================================= Program: bbtk Module: $RCSfile: bbvtkImagePlanes.cxx,v $ Language: C++ - Date: $Date: 2010/03/07 13:18:41 $ - Version: $Revision: 1.32 $ + Date: $Date: 2012/11/16 08:51:58 $ + Version: $Revision: 1.38 $ =========================================================================*/ -/* --------------------------------------------------------------------- - -* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) -* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux -* -* This software is governed by the CeCILL-B license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL-B -* license as circulated by CEA, CNRS and INRIA at the following URL -* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -* or in the file LICENSE.txt. -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited -* liability. -* -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL-B license and that you accept its terms. -* ------------------------------------------------------------------------ */ - /** * \file * \brief @@ -65,7 +70,10 @@ #include "bbstdRelay.h" #include "vtkObjectFactory.h" +#include "vtkImageFlip.h" +#include "vtkImageReslice.h" +#include "vtkImageChangeInformation.h" namespace bbstd { @@ -92,7 +100,6 @@ namespace bbtk namespace bbvtk { - //==================================================================== // Add the specialized adaptors to the package typedef vtkImagePlaneWidget* I; @@ -137,50 +144,47 @@ namespace bbvtk }; //================================================================ - //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.32 $"); + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.38 $"); //================================================================ BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes) BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox); - - void ImagePlanes::bbUserSetDefaultValues() { - bbSetOutputPlaneX(0); - bbSetOutputPlaneY(0); - bbSetOutputPlaneZ(0); - bbSetOutputImageX(0); - bbSetOutputImageY(0); - bbSetOutputImageZ(0); - bbSetInputIn(0); + bbSetOutputPlaneX(NULL); + bbSetOutputPlaneY(NULL); + bbSetOutputPlaneZ(NULL); + bbSetOutputImageX(NULL); + bbSetOutputImageY(NULL); + bbSetOutputImageZ(NULL); + bbSetInputIn(NULL); std::vector vect; vect.push_back(0); vect.push_back(0); bbSetInputWindowLevel (vect); mVtkCallback = 0; - - std::vector vectpoints; + std::vector vectpoints; bbSetOutputPlane3Pts(0); - bbSetOutputImage3Pts(0); - bbSetInputPointsX(vectpoints); - bbSetInputPointsY(vectpoints); - bbSetInputPointsZ(vectpoints); - - _imageReslicer = NULL; - image=NULL; - _transform =NULL; - _matrix =NULL; + bbSetOutputImage3Pts(0); + bbSetInputPointsX(vectpoints); + bbSetInputPointsY(vectpoints); + bbSetInputPointsZ(vectpoints); + + _imageReslicer = NULL; + image = NULL; + _transform = NULL; + _matrix = NULL; + + bbSetInputInterpolation(1); } - void ImagePlanes::bbUserInitializeProcessing() { - /// CREATION DES WIDGETS if (bbGetOutputPlaneX() != 0) return; @@ -191,48 +195,77 @@ namespace bbvtk // The 3 image plane widgets vtkImagePlaneWidget* planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker); - vtkImagePlaneWidget* planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker); + vtkImagePlaneWidget* planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker); planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable()); vtkImagePlaneWidget* planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker); planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable()); - vtkImagePlaneWidget* planeWidget3Pts = GetPlaneWidget('3', 0, 1, 1, picker); + 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()); + bbSetOutputPlane3Pts(planeWidget3Pts); + bbSetOutputImageX( flipYFilter->GetOutput() ); // EED MPR view orientation correction.. + bbSetOutputImageY( imageResult->GetOutput() ); // EED MPR view orientation correction.. bbSetOutputImageZ(planeWidgetZ->GetResliceOutput()); - bbSetInputInteractor(0); - //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); + bbSetInputInteractor(0); + //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); + + if(picker != 0) + { + picker->UnRegister(NULL); + } - picker->UnRegister(NULL); - mVtkCallback = VtkCallbackType::New(); mVtkCallback->SetBlackBox(this); planeWidgetX->AddObserver(vtkCommand::InteractionEvent,mVtkCallback); planeWidgetY->AddObserver(vtkCommand::InteractionEvent,mVtkCallback); - planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,mVtkCallback); + planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,mVtkCallback); + } //--------------------------------------------------------------------- void ImagePlanes::bbUserFinalizeProcessing() { - + if (bbGetOutputPlaneX()) { /* - bbGetOutputPlaneX()->RemoveObserver(mVtkCallback); bbGetOutputPlaneY()->RemoveObserver(mVtkCallback); bbGetOutputPlaneZ()->RemoveObserver(mVtkCallback); - - + bbGetOutputPlaneX()->Delete(); bbGetOutputPlaneY()->Delete(); bbGetOutputPlaneZ()->Delete(); @@ -241,26 +274,35 @@ namespace bbvtk //bbGetOutputPlaneX()->SetInput(NULL); //bbGetOutputPlaneY()->SetInput(NULL); //bbGetOutputPlaneZ()->SetInput(NULL); - + } - } //--------------------------------------------------------------------- -void ImagePlanes::Process() -{ + 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); @@ -268,12 +310,10 @@ void ImagePlanes::Process() bbGetOutputPlaneX()->SetPlaneOrientationToXAxes(); bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing); - // bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing ); // bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing); // bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing); - bbGetOutputPlaneY()->SetInput(bbGetInputIn()); bbGetOutputPlaneY()->SetPlaneOrientationToYAxes(); bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing); @@ -286,54 +326,65 @@ void ImagePlanes::Process() { bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0], bbGetInputWindowLevel()[1]); - } - else - { + } else { double *range = image->GetScalarRange(); - bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0], - 0.5*(range[1]+range[0])); - } - + 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(); //std::cout<=3){ - + if (pointsx.size()==pointsy.size() && pointsx.size()==pointsz.size()&&pointsx.size()>=3) + { //Get the corresponding three points out of the vectors double origin[3]; - origin[0] = pointsx[0]; - origin[1] = pointsy[0]; - origin[2] = pointsz[0]; + origin[0] = pointsx[0]; + origin[1] = pointsy[0]; + origin[2] = pointsz[0]; double point1[3]; - point1[0] = pointsx[1]; - point1[1] = pointsy[1]; - point1[2] = pointsz[1]; + point1[0] = pointsx[1]; + point1[1] = pointsy[1]; + point1[2] = pointsz[1]; double point2[3]; - point2[0]= pointsx[2]; - point2[1]= pointsy[2]; - point2[2]= pointsz[2]; + point2[0] = pointsx[2]; + point2[1] = pointsy[2]; + point2[2] = pointsz[2]; //With the three points we create the corresponding X, Y and Z vectors all orthogonal to each other - double* vect1= getNormal(makeVector(origin, point1)); - double* vect2= getNormal(makeVector(origin, point2)); - double* crossp = getCrossProduct(vect1, vect2); + double* vect1 = getNormal(makeVector(origin, point1)); + double* vect2 = getNormal(makeVector(origin, point2)); + double* crossp = getCrossProduct(vect1, vect2); - double *newx = getCrossProduct(vect2, crossp); - - int ext[6],factor=0; + double *newx = getCrossProduct(vect2, crossp); + + int ext[6],factor = 0; bbGetInputIn()->GetExtent(ext); factor = ext[0]GetResliceOutput()->Update(); //To get the slice of image out of the selected volume - if (_imageReslicer==NULL){ + if (_imageReslicer==NULL) + { _imageReslicer = vtkImageReslice::New(); _imageReslicer->SetOutputDimensionality(2); - _imageReslicer->SetInterpolationModeToLinear(); _transform = vtkTransform::New(); _matrix = vtkMatrix4x4::New(); - } + } // if + _imageReslicer->SetInterpolationMode( bbGetInputInterpolation() ); _imageReslicer->SetInput( bbGetInputIn() ); _imageReslicer->SetInformationInput(bbGetInputIn()); //fill out the information with the created vectors and using the spacing of the image @@ -370,11 +422,8 @@ void ImagePlanes::Process() _imageReslicer->GetOutput()->Update(); _imageReslicer->GetOutput()->UpdateInformation(); - bbSetOutputImage3Pts(_imageReslicer->GetOutput()); - - _matrix->Identity(); _matrix->SetElement(0,0,newx[0]*xSpacing); @@ -390,51 +439,48 @@ void ImagePlanes::Process() _matrix->SetElement(1,3,origin[1]*ySpacing); _matrix->SetElement(2,3,origin[2]*zSpacing); - _transform->SetMatrix(_matrix); //set the transformation out to be used by other bbBoxes - bbSetOutputTransform3Pts((vtkLinearTransform*)_transform); - - - - } - } -} + bbSetOutputTransform3Pts((vtkLinearTransform*)_transform); + } // pointsx pointsy pointsz + } // bbGetInputIn + } -void ImagePlanes::updateInteractor(){ - - vtkRenderWindowInteractor* interactor = bbGetInputInteractor(); - - if(interactor){ - bbGetOutputPlaneX()->SetInteractor(interactor); - bbGetOutputPlaneX()->EnabledOn(); - bbGetOutputPlaneY()->SetInteractor(interactor); - bbGetOutputPlaneY()->EnabledOn(); - bbGetOutputPlaneZ()->SetInteractor(interactor); - bbGetOutputPlaneZ()->EnabledOn(); - bbGetOutputPlane3Pts()->SetInteractor(interactor); - bbGetOutputPlane3Pts()->EnabledOn(); - } -} + void ImagePlanes::updateInteractor() + { + vtkRenderWindowInteractor* interactor = bbGetInputInteractor(); + if(interactor) + { + bbGetOutputPlaneX()->SetInteractor(interactor); + bbGetOutputPlaneX()->EnabledOn(); + bbGetOutputPlaneY()->SetInteractor(interactor); + bbGetOutputPlaneY()->EnabledOn(); + bbGetOutputPlaneZ()->SetInteractor(interactor); + bbGetOutputPlaneZ()->EnabledOn(); + bbGetOutputPlane3Pts()->SetInteractor(interactor); + bbGetOutputPlane3Pts()->EnabledOn(); + } // if + } + //----------------------------------------------------------------- - void vtkImageDataPointerRelay::bbUserSetDefaultValues() + void vtkImageDataPointerRelay::bbUserSetDefaultValues() { } //----------------------------------------------------------------- - void vtkImageDataPointerRelay::bbUserInitializeProcessing() + void vtkImageDataPointerRelay::bbUserInitializeProcessing() { } //----------------------------------------------------------------- - void vtkImageDataPointerRelay::bbUserFinalizeProcessing() + void vtkImageDataPointerRelay::bbUserFinalizeProcessing() { } - vtkImagePlaneWidget* ImagePlanes::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker) - { + vtkImagePlaneWidget* ImagePlanes::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker) + { vtkProperty* prop1 = 0; vtkImagePlaneWidget* planeWidget = 0; @@ -446,9 +492,9 @@ void ImagePlanes::updateInteractor(){ prop1->SetColor(r, g, b); return planeWidget; - } + } -double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ + double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ double* vectCross; vectCross = new double[3]; vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]); @@ -456,32 +502,27 @@ double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]); return vectCross; -} + } /** ** Returns the magnitud of the given vector **/ -double ImagePlanes::getMagnitud(double* vect){ + double ImagePlanes::getMagnitud(double* vect){ double mag; - mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2)); - - std::cout<<"mag "<