1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2008/12/09 12:54:05 $
6 Version: $Revision: 1.16 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
37 #include "bbvtkImagePlanes.h"
38 #include "bbvtkPackage.h"
39 #include "vtkCellPicker.h"
40 #include "vtkProperty.h"
42 #include "vtkMetaImageWriter.h"
43 #include "vtkPNGWriter.h"
45 #include "bbstdCast.h"
46 #include <vtkCommand.h>
48 #include "vtkImageData.h"
49 //#include "vtkOutlineFilter.h"
50 //#include "vtkPolyDataMapper.h"
51 //#include "vtkActor.h"
52 #include "vtkImagePlaneWidget.h"
53 #include "vtkCellPicker.h"
54 //#include "vtkProperty.h"
56 //#include "vtkRenderer.h"
57 //#include "vtkCamera.h"
59 #include "vtkPlaneWidget.h"
65 //====================================================================
66 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
67 bbtk::AtomicBlackBox);
68 //====================================================================
71 using namespace bbstd;
76 //====================================================================
77 // Add the specialized adaptors to the package
78 typedef vtkImagePlaneWidget* I;
79 typedef vtkInteractorObserver* O;
81 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
88 //================================================================
89 class myCallbackPlane : public vtkCommand
92 static myCallbackPlane *New()
94 return new myCallbackPlane;
96 virtual void Execute(vtkObject *caller, unsigned long, void*)
98 currentBlackBox->Process();
99 currentBlackBox->bbSignalOutputModification();
101 void SetCurrentBlackBox(ImagePlanes *cBB) {currentBlackBox = cBB;};
102 void SetVtkPlaneWidget( vtkImagePlaneWidget *planeWidget );
103 myCallbackPlane() {};
106 vtkPlaneWidget *planeWidget;
107 ImagePlanes *currentBlackBox;
109 //================================================================
113 //================================================================
115 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
116 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
118 void ImagePlanes::bbUserConstructor()
120 bbSetOutputPlaneX(0);
121 bbSetOutputPlaneY(0);
122 bbSetOutputPlaneZ(0);
123 bbSetOutputImageX(0);
124 bbSetOutputImageY(0);
125 bbSetOutputImageZ(0);
127 std::vector<double> vect;
130 bbSetInputWindowLevel (vect);
133 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
135 bbSetOutputPlaneX(0);
136 bbSetOutputPlaneY(0);
137 bbSetOutputPlaneZ(0);
138 bbSetOutputImageX(0);
139 bbSetOutputImageY(0);
140 bbSetOutputImageZ(0);
143 void ImagePlanes::Init()
146 /// CREATION DES WIDGETS
147 if (bbGetOutputPlaneX() != 0) return;
149 // The shared picker enables us to use 3 planes at one time
150 // and gets the picking order right
151 vtkCellPicker* picker = vtkCellPicker::New();
152 picker->SetTolerance(0.005);
154 // The 3 image plane widgets
155 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
156 planeWidgetX->DisplayTextOn();
157 planeWidgetX->SetPicker(picker);
158 planeWidgetX->SetKeyPressActivationValue('x');
159 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
160 prop1->SetColor(1, 0, 0);
162 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
163 planeWidgetY->DisplayTextOn();
164 planeWidgetY->SetPicker(picker);
165 planeWidgetY->SetKeyPressActivationValue('y');
166 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
167 prop2->SetColor(1, 1, 0);
168 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
170 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
171 planeWidgetZ->DisplayTextOn();
172 planeWidgetZ->SetPicker(picker);
173 planeWidgetZ->SetKeyPressActivationValue('z');
174 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
175 prop3->SetColor(0, 0, 1);
176 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
178 bbSetOutputPlaneX(planeWidgetX);
179 bbSetOutputPlaneY(planeWidgetY);
180 bbSetOutputPlaneZ(planeWidgetZ);
181 bbSetOutputImageX(planeWidgetX->GetResliceOutput());
182 bbSetOutputImageY(planeWidgetY->GetResliceOutput());
183 bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
185 picker->UnRegister(NULL);
187 myCallbackPlane *_myCallback = myCallbackPlane::New();
188 _myCallback->SetCurrentBlackBox(this);
189 planeWidgetX->AddObserver(vtkCommand::InteractionEvent,_myCallback);
190 planeWidgetY->AddObserver(vtkCommand::InteractionEvent,_myCallback);
191 planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,_myCallback);
194 //---------------------------------------------------------------------
195 void ImagePlanes::bbUserDestructor()
198 if (bbGetOutputPlaneX()) bbGetOutputPlaneX()->UnRegister(NULL);
199 if (bbGetOutputPlaneY()) bbGetOutputPlaneY()->UnRegister(NULL);
200 if (bbGetOutputPlaneZ()) bbGetOutputPlaneZ()->UnRegister(NULL);
203 //---------------------------------------------------------------------
204 void ImagePlanes::Process()
206 if (bbGetInputIn()!=0)
208 // Create the widgets if not already done
211 if ( bbGetInputStatus("In") != bbtk::UPTODATE )
213 // Input image has changed : reinitialize planes
214 image = bbGetInputIn();
216 int xMin, xMax, yMin, yMax, zMin, zMax;
217 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
219 // Initial values : center of the volume (in real world, not in pixels!)
220 double xSpacing, ySpacing, zSpacing;
221 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
223 bbGetOutputPlaneX()->SetInput(bbGetInputIn());
224 bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
225 bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
227 bbGetOutputPlaneY()->SetInput(bbGetInputIn());
228 bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
229 bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
231 bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
232 bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
233 bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
235 if (bbGetInputWindowLevel()[0]!=0)
237 bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
238 bbGetInputWindowLevel()[1]);
242 double *range = image->GetScalarRange();
243 bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
244 0.5*(range[1]+range[0]));
249 // UPDATE DES SORTIES
250 bbGetOutputPlaneX()->GetResliceOutput()->Update();
251 bbGetOutputPlaneY()->GetResliceOutput()->Update();
252 bbGetOutputPlaneZ()->GetResliceOutput()->Update();