X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkImagePlanes.cxx;h=9f61f6ea0efc81d02221ef80ab3d25cd10549369;hb=2e1f522c4615a3a0f71575ece9e053860883eeec;hp=ccfba10fce9c18e1d5ba4b385553b680267808b4;hpb=f20c3308a0d420bbc81089fad47108fa4f25aa17;p=bbtk.git diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index ccfba10..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/02/27 11:20:26 $ - Version: $Revision: 1.20 $ + 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" @@ -58,8 +60,11 @@ #include "vtkPlaneWidget.h" +#include + #include "bbstdRelay.h" +#include "vtkObjectFactory.h" namespace bbstd @@ -108,13 +113,15 @@ namespace bbvtk { //================================================================ - class ImagePlanes::VtkCallbackType : public vtkCommand + class ImagePlanes::VtkCallbackType : public vtkCommand { public: static VtkCallbackType *New() - { - return new VtkCallbackType; - } + { + return new VtkCallbackType; + } + //vtkTypeRevisionMacro(VtkCallbackType,vtkCommand); + virtual void Execute(vtkObject *caller, unsigned long, void*) { mBlackBox->Process(); @@ -130,14 +137,16 @@ namespace bbvtk }; //================================================================ - + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.30 $"); //================================================================ BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes) BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox); - void ImagePlanes::bbUserConstructor() + + + void ImagePlanes::bbUserSetDefaultValues() { bbSetOutputPlaneX(0); bbSetOutputPlaneY(0); @@ -150,19 +159,26 @@ namespace bbvtk vect.push_back(0); 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; + _transform =NULL; + _matrix =NULL; } - void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer) - { - bbSetOutputPlaneX(0); - bbSetOutputPlaneY(0); - bbSetOutputPlaneZ(0); - bbSetOutputImageX(0); - bbSetOutputImageY(0); - bbSetOutputImageZ(0); - } - void ImagePlanes::Init() + + void ImagePlanes::bbUserInitializeProcessing() { /// CREATION DES WIDGETS @@ -197,12 +213,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); @@ -214,83 +241,268 @@ namespace bbvtk } //--------------------------------------------------------------------- - void ImagePlanes::bbUserDestructor() + void ImagePlanes::bbUserFinalizeProcessing() { - + if (bbGetOutputPlaneX()) { - bbGetOutputPlaneX()->SetInput(NULL); - bbGetOutputPlaneX()->UnRegister(NULL); - } - if (bbGetOutputPlaneY()) - { - bbGetOutputPlaneY()->SetInput(NULL); - bbGetOutputPlaneY()->UnRegister(NULL); - } - if (bbGetOutputPlaneZ()) - { - bbGetOutputPlaneZ()->SetInput(NULL); - bbGetOutputPlaneZ()->UnRegister(NULL); + + /* + + bbGetOutputPlaneX()->RemoveObserver(mVtkCallback); + bbGetOutputPlaneY()->RemoveObserver(mVtkCallback); + bbGetOutputPlaneZ()->RemoveObserver(mVtkCallback); + + + bbGetOutputPlaneX()->Delete(); + bbGetOutputPlaneY()->Delete(); + bbGetOutputPlaneZ()->Delete(); + mVtkCallback->Delete(); + */ + //bbGetOutputPlaneX()->SetInput(NULL); + //bbGetOutputPlaneY()->SetInput(NULL); + //bbGetOutputPlaneZ()->SetInput(NULL); + } - mVtkCallback->Delete(); + } //--------------------------------------------------------------------- - void ImagePlanes::Process() - { - if (bbGetInputIn()!=0) - { - // Create the widgets if not already done - Init(); - - 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); - - 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])); - } +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(); + + + // 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(); - - - } - } + // 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){ + + + //Get the corresponding three points out of the vectors + 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]; + + //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 *newx = getCrossProduct(vect2, crossp); + + int ext[6],factor=0; + bbGetInputIn()->GetExtent(ext); + + factor = ext[0]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); + + + + } + } +} + + + //----------------------------------------------------------------- + void vtkImageDataPointerRelay::bbUserSetDefaultValues() + { + } + + //----------------------------------------------------------------- + void vtkImageDataPointerRelay::bbUserInitializeProcessing() + { + } + + //----------------------------------------------------------------- + void vtkImageDataPointerRelay::bbUserFinalizeProcessing() + { + } + + + +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 "<