1 /*=========================================================================
4 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
6 Date: $Date: 2008/10/14 08:53:14 $
7 Version: $Revision: 1.8 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
24 #include "bbvtkImagePlanes.h"
25 #include "bbvtkPackage.h"
26 #include "vtkCellPicker.h"
27 #include "vtkProperty.h"
29 #include "bbstdCast.h"
32 //====================================================================
33 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
34 bbtk::AtomicBlackBox);
35 //====================================================================
38 using namespace bbstd;
41 //====================================================================
42 // Add the specialized adaptors to the package
43 typedef vtkImagePlaneWidget* I;
44 typedef vtkInteractorObserver* O;
46 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
54 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
55 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
57 void ImagePlanes::bbUserConstructor()
59 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
61 std::vector<double> vect;
64 bbSetInputWindowLevel (vect);
67 void ImagePlanes::bbUserCopyConstructor()
69 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
72 void ImagePlanes::Init()
74 if (planeWidgetX != 0) return;
75 // The shared picker enables us to use 3 planes at one time
76 // and gets the picking order right
77 vtkCellPicker* picker = vtkCellPicker::New();
78 picker->SetTolerance(0.005);
80 // The 3 image plane widgets
81 planeWidgetX = vtkImagePlaneWidget::New();
82 planeWidgetX->DisplayTextOn();
83 planeWidgetX->SetPicker(picker);
84 planeWidgetX->SetKeyPressActivationValue('x');
85 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
86 prop1->SetColor(1, 0, 0);
88 planeWidgetY = vtkImagePlaneWidget::New();
89 planeWidgetY->DisplayTextOn();
90 planeWidgetY->SetPicker(picker);
91 planeWidgetY->SetKeyPressActivationValue('y');
92 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
93 prop2->SetColor(1, 1, 0);
94 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
96 planeWidgetZ = vtkImagePlaneWidget::New();
97 planeWidgetZ->DisplayTextOn();
98 planeWidgetZ->SetPicker(picker);
99 planeWidgetZ->SetKeyPressActivationValue('z');
100 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
101 prop3->SetColor(0, 0, 1);
102 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
104 bbSetOutputPlaneX(planeWidgetX);
105 bbSetOutputPlaneY(planeWidgetY);
106 bbSetOutputPlaneZ(planeWidgetZ);
108 picker->UnRegister(NULL);
111 //---------------------------------------------------------------------
112 void ImagePlanes::bbUserDestructor()
115 if (planeWidgetX) planeWidgetX->UnRegister(NULL);
116 if (planeWidgetY) planeWidgetY->UnRegister(NULL);
117 if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
121 //---------------------------------------------------------------------
122 void ImagePlanes::Process()
124 if (bbGetInputIn()!=0)
128 int xMin, xMax, yMin, yMax, zMin, zMax;
129 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
131 planeWidgetX->SetInput(bbGetInputIn());
132 planeWidgetX->SetPlaneOrientationToXAxes();
133 planeWidgetX->SetSlicePosition((xMax+xMin)/2.);
135 planeWidgetY->SetInput(bbGetInputIn());
136 planeWidgetY->SetPlaneOrientationToYAxes();
137 planeWidgetY->SetSlicePosition((yMax+yMin)/2.);
139 planeWidgetZ->SetInput(bbGetInputIn());
140 planeWidgetZ->SetPlaneOrientationToZAxes();
141 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.);
143 // planeWidgetZ->SetWindowLevel(512,256);
145 planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);