X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkImagePlanes.cxx;h=9f61f6ea0efc81d02221ef80ab3d25cd10549369;hb=01fb8df604fbbe40e30ffd608ad40bca4433f32b;hp=fca5f6a3c9f8531ad744d8a583f658c69a871f73;hpb=8a545acd568e25e30b6255191f69320265fae99d;p=bbtk.git diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index fca5f6a..9f61f6e 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/23 15:58:56 $ - Version: $Revision: 1.27 $ + Date: $Date: 2009/09/01 13:59:48 $ + Version: $Revision: 1.30 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -38,6 +38,8 @@ #include "bbvtkPackage.h" #include "vtkCellPicker.h" #include "vtkProperty.h" +#include "vtkPolyData.h" + #include "vtkMetaImageWriter.h" #include "vtkPNGWriter.h" @@ -135,7 +137,7 @@ namespace bbvtk }; //================================================================ - //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.27 $"); + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.30 $"); //================================================================ @@ -170,6 +172,8 @@ namespace bbvtk _imageReslicer = NULL; image=NULL; + _transform =NULL; + _matrix =NULL; } @@ -269,12 +273,13 @@ void ImagePlanes::Process() if (bbGetInputIn()!=0) { + int xMin, xMax, yMin, yMax, zMin, zMax; + bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax); + 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); + image = bbGetInputIn(); + // Initial values : center of the volume (in real world, not in pixels!) double xSpacing, ySpacing, zSpacing; @@ -323,33 +328,9 @@ void ImagePlanes::Process() 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()); + //Get the corresponding three points out of the vectors double origin[3]; origin[0] = pointsx[0]; origin[1] = pointsy[0]; @@ -362,34 +343,81 @@ void ImagePlanes::Process() double point2[3]; point2[0]= pointsx[2]; point2[1]= pointsy[2]; - point2[2]= pointsz[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); - /*std::cout<<"origin "<GetExtent(ext); - _imageReslicer->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]); + factor = ext[0]GetOutput()->Update; + //for the plane widgets + vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts(); + plane3pts->SetInput(bbGetInputIn()); + double xSpacing, ySpacing, zSpacing; + bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing); + plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing); + plane3pts->SetPoint1((origin[0]+newx[0]*factor)*xSpacing, + (origin[1]+newx[1]*factor)*ySpacing, + (origin[2]+newx[2]*factor)*zSpacing); + plane3pts->SetPoint2((origin[0]+vect2[0]*factor)*xSpacing, + (origin[1]+vect2[1]*factor)*ySpacing, + (origin[2]+vect2[2]*factor)*zSpacing); + plane3pts->GetResliceOutput()->Update(); +//To get the slice of image out of the selected volume + if (_imageReslicer==NULL){ + _imageReslicer = vtkImageReslice::New(); + _imageReslicer->SetOutputDimensionality(2); + _imageReslicer->SetInterpolationModeToLinear(); + _transform = vtkTransform::New(); + _matrix = vtkMatrix4x4::New(); + } + _imageReslicer->SetInput( bbGetInputIn() ); + _imageReslicer->SetInformationInput(bbGetInputIn()); + //fill out the information with the created vectors and using the spacing of the image + _imageReslicer->SetResliceAxesDirectionCosines(newx[0]*xSpacing,newx[1]*xSpacing,newx[2]*xSpacing, + vect2[0]*ySpacing,vect2[1]*ySpacing,vect2[2]*ySpacing, + crossp[0]*zSpacing,crossp[1]*zSpacing,crossp[2]*zSpacing); + _imageReslicer->SetResliceAxesOrigin(origin[0]*xSpacing,origin[1]*ySpacing,origin[2]*zSpacing); + _imageReslicer->GetOutput()->Update(); _imageReslicer->GetOutput()->UpdateInformation(); + bbSetOutputImage3Pts(_imageReslicer->GetOutput()); + + + _matrix->Identity(); + + _matrix->SetElement(0,0,newx[0]*xSpacing); + _matrix->SetElement(1,0,newx[1]*xSpacing); + _matrix->SetElement(2,0,newx[2]*xSpacing); + _matrix->SetElement(0,1,vect2[0]*ySpacing); + _matrix->SetElement(1,1,vect2[1]*ySpacing); + _matrix->SetElement(2,1,vect2[2]*ySpacing); + _matrix->SetElement(0,2,crossp[0]*zSpacing); + _matrix->SetElement(1,2,crossp[1]*zSpacing); + _matrix->SetElement(2,2,crossp[2]*zSpacing); + _matrix->SetElement(0,3,origin[0]*xSpacing); + _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); + + + + } } } @@ -465,9 +493,9 @@ double* ImagePlanes::makeVector(double podouble0[3], double podouble1[3]){ double *vect; vect = new double[3]; - vect[0]= podouble0[0]-podouble1[0]; - vect[1]= podouble0[1]-podouble1[1]; - vect[2]= podouble0[2]-podouble1[2]; + vect[0]= podouble1[0]-podouble0[0]; + vect[1]= podouble1[1]-podouble0[1]; + vect[2]= podouble1[2]-podouble0[2]; return vect;