From 8a545acd568e25e30b6255191f69320265fae99d Mon Sep 17 00:00:00 2001 From: Juan Prieto Date: Tue, 23 Jun 2009 15:58:56 +0000 Subject: [PATCH] vtkPlanes with different way of calculating the plane of the image --- packages/vtk/src/bbvtkImagePlanes.cxx | 276 ++++++++++++++++++++------ packages/vtk/src/bbvtkImagePlanes.h | 25 ++- 2 files changed, 240 insertions(+), 61 deletions(-) diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index e838e03..fca5f6a 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: 2009/06/09 08:41:53 $ - Version: $Revision: 1.26 $ + Date: $Date: 2009/06/23 15:58:56 $ + Version: $Revision: 1.27 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -58,6 +58,8 @@ #include "vtkPlaneWidget.h" +#include + #include "bbstdRelay.h" #include "vtkObjectFactory.h" @@ -133,7 +135,7 @@ namespace bbvtk }; //================================================================ - //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.26 $"); + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.27 $"); //================================================================ @@ -156,6 +158,18 @@ namespace bbvtk vect.push_back(0); bbSetInputWindowLevel (vect); mVtkCallback = 0; + + + std::vector vectpoints; + + bbSetOutputPlane3Pts(0); + bbSetOutputImage3Pts(0); + bbSetInputPointsX(vectpoints); + bbSetInputPointsY(vectpoints); + bbSetInputPointsZ(vectpoints); + + _imageReslicer = NULL; + image=NULL; } @@ -195,12 +209,23 @@ namespace bbvtk prop3->SetColor(0, 0, 1); planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable()); + vtkImagePlaneWidget* planeWidget3Pts = vtkImagePlaneWidget::New(); + //vtkPlaneWidget* planeWidget3Pts = vtkPlaneWidget::New(); + planeWidget3Pts->DisplayTextOn(); + planeWidget3Pts->SetPicker(picker); + planeWidget3Pts->SetKeyPressActivationValue('3'); + vtkProperty* prop3Pts = planeWidget3Pts->GetPlaneProperty(); + prop3Pts->SetColor(0, 1, 1); + planeWidget3Pts->SetLookupTable(planeWidgetX->GetLookupTable()); + bbSetOutputPlaneX(planeWidgetX); bbSetOutputPlaneY(planeWidgetY); bbSetOutputPlaneZ(planeWidgetZ); + bbSetOutputPlane3Pts(planeWidget3Pts); bbSetOutputImageX(planeWidgetX->GetResliceOutput()); bbSetOutputImageY(planeWidgetY->GetResliceOutput()); bbSetOutputImageZ(planeWidgetZ->GetResliceOutput()); + //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); picker->UnRegister(NULL); @@ -239,60 +264,134 @@ namespace bbvtk } //--------------------------------------------------------------------- - void ImagePlanes::Process() - { - if (bbGetInputIn()!=0) - { - - if ( bbGetInputStatus("In") != bbtk::UPTODATE ) - { - // Input image has changed : reinitialize planes - image = bbGetInputIn(); - - int xMin, xMax, yMin, yMax, zMin, zMax; - bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax); - - // Initial values : center of the volume (in real world, not in pixels!) - double xSpacing, ySpacing, zSpacing; - bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing); - - bbGetOutputPlaneX()->SetInput(bbGetInputIn()); - 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); - - bbGetOutputPlaneZ()->SetInput(bbGetInputIn()); - bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes(); - bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing); - - if (bbGetInputWindowLevel()[0]!=0) - { - bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0], - bbGetInputWindowLevel()[1]); - } - else - { - double *range = image->GetScalarRange(); - bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0], - 0.5*(range[1]+range[0])); - } - } - - // UPDATE DES SORTIES - bbGetOutputPlaneX()->GetResliceOutput()->Update(); - bbGetOutputPlaneY()->GetResliceOutput()->Update(); - bbGetOutputPlaneZ()->GetResliceOutput()->Update(); - } - } +void ImagePlanes::Process() +{ + if (bbGetInputIn()!=0) + { + + if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){ + // Input image has changed : reinitialize planes + image = bbGetInputIn(); + + int xMin, xMax, yMin, yMax, zMin, zMax; + bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax); + + // Initial values : center of the volume (in real world, not in pixels!) + double xSpacing, ySpacing, zSpacing; + bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing); + + bbGetOutputPlaneX()->SetInput(bbGetInputIn()); + 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); + + bbGetOutputPlaneZ()->SetInput(bbGetInputIn()); + bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes(); + bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing); + + if (bbGetInputWindowLevel()[0]!=0) + { + bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0], + bbGetInputWindowLevel()[1]); + } + else + { + double *range = image->GetScalarRange(); + bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0], + 0.5*(range[1]+range[0])); + } + + } + // UPDATE DES SORTIES + bbGetOutputPlaneX()->GetResliceOutput()->Update(); + bbGetOutputPlaneY()->GetResliceOutput()->Update(); + bbGetOutputPlaneZ()->GetResliceOutput()->Update(); + + std::vector pointsx = bbGetInputPointsX(); + std::vector pointsy = bbGetInputPointsY(); + std::vector pointsz = bbGetInputPointsZ(); + + std::cout<=3){ + vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts(); + //vtkPlaneWidget* plane3pts = (vtkPlaneWidget*)bbGetOutputPlane3Pts(); + + plane3pts->SetInput(bbGetInputIn()); + + //xSpacing = ySpacing = zSpacing = 1; + double xSpacing, ySpacing, zSpacing; + bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing); + + plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing); + plane3pts->SetPoint1(pointsx[1]*xSpacing,pointsy[1]*ySpacing,pointsz[1]*zSpacing); + //plane3pts->SetPoint1((pointsx[1]-pointsx[0])*xSpacing,(pointsy[1]-pointsy[0])*ySpacing,(pointsz[1]-pointsz[0])*zSpacing); + plane3pts->SetPoint2(pointsx[2]*xSpacing,pointsy[2]*ySpacing,pointsz[2]*zSpacing); + //plane3pts->SetPoint2((pointsx[2]-pointsx[0])*xSpacing,(pointsy[2]-pointsy[0])*ySpacing,(pointsz[2]-pointsz[0])*zSpacing); + plane3pts->GetResliceOutput()->Update(); + + + + if (_imageReslicer==NULL){ + _imageReslicer = vtkImageReslice::New(); + _imageReslicer->SetOutputDimensionality(2); + _imageReslicer->SetInterpolationModeToLinear(); + } + + _imageReslicer->SetInput( bbGetInputIn() ); + _imageReslicer->SetInformationInput(bbGetInputIn()); + + double origin[3]; + 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]; + double point2[3]; + point2[0]= pointsx[2]; + point2[1]= pointsy[2]; + point2[2]= pointsz[2]; + + double* vect1= getNormal(makeVector(origin, point1)); + double* vect2= getNormal(makeVector(origin, point2)); + double* crossp = getCrossProduct(vect1, vect2); + + /*std::cout<<"origin "<SetResliceAxesDirectionCosines(vect1[0],vect1[1],vect1[2], + vect2[0],vect2[1],vect2[2], + crossp[0],crossp[1],crossp[2]); + //_imageReslicer->SetResliceAxesOrigin(0,0,0); + _imageReslicer->SetResliceAxesOrigin(origin[0],origin[1],origin[2]); + + _imageReslicer->GetOutput()->Update; + _imageReslicer->GetOutput()->UpdateInformation(); + + bbSetOutputImage3Pts(_imageReslicer->GetOutput()); + + + } + + } +} //----------------------------------------------------------------- @@ -311,8 +410,71 @@ namespace bbvtk } + +double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ + double* vectCross; + vectCross = new double[3]; + vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]); + vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0])); + 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 mag; + + mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2)); + + std::cout<<"mag "< winLevel; @@ -65,11 +68,14 @@ namespace bbvtk // BBTK_DECLARE_INPUT(Contour,int); BBTK_DECLARE_INPUT(In, vtkImageData *); BBTK_DECLARE_INPUT(WindowLevel, winLevel); + BBTK_DECLARE_INPUT(PointsX, std::vector); + BBTK_DECLARE_INPUT(PointsY, std::vector); + BBTK_DECLARE_INPUT(PointsZ, std::vector); BBTK_DECLARE_OUTPUT(PlaneX,vtkImagePlaneWidget*); BBTK_DECLARE_OUTPUT(PlaneY,vtkImagePlaneWidget*); BBTK_DECLARE_OUTPUT(PlaneZ,vtkImagePlaneWidget*); - BBTK_DECLARE_OUTPUT(Plane3Pts,vtkImagePlaneWidget*); + BBTK_DECLARE_OUTPUT(Plane3Pts,vtkInteractorObserver *); BBTK_DECLARE_OUTPUT(ImageX,vtkImageData*); BBTK_DECLARE_OUTPUT(ImageY,vtkImageData*); BBTK_DECLARE_OUTPUT(ImageZ,vtkImageData*); @@ -83,6 +89,14 @@ namespace bbvtk class VtkCallbackType; VtkCallbackType* mVtkCallback; vtkImageData* image; + vtkImageReslice* _imageReslicer; + + + double* getCrossProduct(double* vect0,double* vect1); + double getPodoubleProduct(double* vect0,double* vect1); + double* getNormal(double* vect); + double getMagnitud(double* vect); + double* makeVector(double podouble0[3], double podouble1[3]); }; //================================================================= @@ -94,11 +108,14 @@ namespace bbvtk BBTK_CATEGORY("3D object creator"); BBTK_INPUT(ImagePlanes, In , "Input Image" , vtkImageData * , ""); BBTK_INPUT(ImagePlanes, WindowLevel , "Widdow Level" , winLevel , ""); + BBTK_INPUT(ImagePlanes, PointsX, "Points in X" , std::vector, ""); + BBTK_INPUT(ImagePlanes, PointsY, "Points in Y" , std::vector, ""); + BBTK_INPUT(ImagePlanes, PointsZ, "Points in Z" , std::vector, ""); BBTK_OUTPUT(ImagePlanes,PlaneX,"The image plane in X direction",vtkImagePlaneWidget*,""); BBTK_OUTPUT(ImagePlanes,PlaneY,"The image plane in Y direction",vtkImagePlaneWidget*,""); BBTK_OUTPUT(ImagePlanes,PlaneZ,"The image plane in Z direction",vtkImagePlaneWidget*,""); - BBTK_OUTPUT(ImagePlanes,Plane3Pts,"The image plane (3 points definition) ",vtkImagePlaneWidget*,""); + BBTK_OUTPUT(ImagePlanes,Plane3Pts,"The image plane (3 points definition) ",vtkInteractorObserver *,""); BBTK_OUTPUT(ImagePlanes,ImageX,"The image in X direction", vtkImageData*, ""); BBTK_OUTPUT(ImagePlanes,ImageY,"The image in Y direction", vtkImageData*, ""); BBTK_OUTPUT(ImagePlanes,ImageZ,"The image in Z direction", vtkImageData*, ""); -- 2.45.1