X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkImagePlanes.cxx;h=c31a38d2583e85fdc3059f9b9f2a1ab97db0af54;hb=80c01320fbade82fcc5bc972f2ed9f3e65239987;hp=24d9f36a6243a5d205e6dfe44e76beb7cfc963ad;hpb=5566eb4dec92fe8915fd68824a4ce56ea0529f81;p=bbtk.git diff --git a/packages/vtk/src/bbvtkImagePlanes.cxx b/packages/vtk/src/bbvtkImagePlanes.cxx index 24d9f36..c31a38d 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/07/02 07:17:33 $ - Version: $Revision: 1.29 $ + Date: $Date: 2010/08/18 12:36:45 $ + Version: $Revision: 1.35 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -92,7 +92,6 @@ namespace bbtk namespace bbvtk { - //==================================================================== // Add the specialized adaptors to the package typedef vtkImagePlaneWidget* I; @@ -137,15 +136,13 @@ namespace bbvtk }; //================================================================ - //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.29 $"); + //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.35 $"); //================================================================ BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes) BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox); - - void ImagePlanes::bbUserSetDefaultValues() { bbSetOutputPlaneX(0); @@ -161,26 +158,23 @@ namespace bbvtk 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; } - void ImagePlanes::bbUserInitializeProcessing() { - /// CREATION DES WIDGETS if (bbGetOutputPlaneX() != 0) return; @@ -190,70 +184,49 @@ namespace bbvtk picker->SetTolerance(0.005); // The 3 image plane widgets - vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New(); - planeWidgetX->DisplayTextOn(); - planeWidgetX->SetPicker(picker); - planeWidgetX->SetKeyPressActivationValue('x'); - vtkProperty* prop1 = planeWidgetX->GetPlaneProperty(); - prop1->SetColor(1, 0, 0); - - vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New(); - planeWidgetY->DisplayTextOn(); - planeWidgetY->SetPicker(picker); - planeWidgetY->SetKeyPressActivationValue('y'); - vtkProperty* prop2 = planeWidgetY->GetPlaneProperty(); - prop2->SetColor(1, 1, 0); + vtkImagePlaneWidget* planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker); + vtkImagePlaneWidget* planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker); planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable()); - vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New(); - planeWidgetZ->DisplayTextOn(); - planeWidgetZ->SetPicker(picker); - planeWidgetZ->SetKeyPressActivationValue('z'); - vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty(); - prop3->SetColor(0, 0, 1); + vtkImagePlaneWidget* planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker); 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); + vtkImagePlaneWidget* planeWidget3Pts = GetPlaneWidget('3', 0, 1, 1, picker); planeWidget3Pts->SetLookupTable(planeWidgetX->GetLookupTable()); bbSetOutputPlaneX(planeWidgetX); bbSetOutputPlaneY(planeWidgetY); bbSetOutputPlaneZ(planeWidgetZ); - bbSetOutputPlane3Pts(planeWidget3Pts); + bbSetOutputPlane3Pts(planeWidget3Pts); bbSetOutputImageX(planeWidgetX->GetResliceOutput()); bbSetOutputImageY(planeWidgetY->GetResliceOutput()); bbSetOutputImageZ(planeWidgetZ->GetResliceOutput()); - //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); + bbSetInputInteractor(0); + //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput()); - picker->UnRegister(NULL); + if(picker != 0) + 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(); @@ -262,24 +235,21 @@ 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); 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; @@ -289,12 +259,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); @@ -311,10 +279,10 @@ void ImagePlanes::Process() 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])); + } + updateInteractor(); } // UPDATE DES SORTIES bbGetOutputPlaneX()->GetResliceOutput()->Update(); @@ -325,11 +293,12 @@ void ImagePlanes::Process() std::vector pointsy = bbGetInputPointsY(); std::vector pointsz = bbGetInputPointsZ(); - std::cout<=3){ + //std::cout<=3) + { + //Get the corresponding three points out of the vectors double origin[3]; origin[0] = pointsx[0]; origin[1] = pointsy[0]; @@ -344,19 +313,20 @@ void ImagePlanes::Process() 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; @@ -369,7 +339,7 @@ void ImagePlanes::Process() (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); @@ -379,63 +349,86 @@ void ImagePlanes::Process() } _imageReslicer->SetInput( bbGetInputIn() ); _imageReslicer->SetInformationInput(bbGetInputIn()); - _imageReslicer->SetResliceAxesDirectionCosines(newx[0],newx[1],newx[2], - vect2[0],vect2[1],vect2[2], - crossp[0],crossp[1],crossp[2]); + //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]); - _matrix->SetElement(1,0,newx[1]); - _matrix->SetElement(2,0,newx[2]); - _matrix->SetElement(0,1,vect2[0]); - _matrix->SetElement(1,1,vect2[1]); - _matrix->SetElement(2,1,vect2[2]); - _matrix->SetElement(0,2,crossp[0]); - _matrix->SetElement(1,2,crossp[1]); - _matrix->SetElement(2,2,crossp[2]); - _matrix->SetElement(0,3,origin[0]); - _matrix->SetElement(1,3,origin[1]); - _matrix->SetElement(2,3,origin[2]); - - - _transform->SetMatrix(_matrix); - - bbSetOutputTransform3Pts((vtkLinearTransform*)_transform); + _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 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 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) + { + vtkProperty* prop1 = 0; + vtkImagePlaneWidget* planeWidget = 0; -double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ + planeWidget = vtkImagePlaneWidget::New(); + planeWidget->DisplayTextOn(); + planeWidget->SetPicker(picker); + planeWidget->SetKeyPressActivationValue(activationkey); + prop1 = planeWidget->GetPlaneProperty(); + prop1->SetColor(r, g, b); + + return planeWidget; + } + + double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){ double* vectCross; vectCross = new double[3]; vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]); @@ -443,32 +436,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 "<