1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2009/01/08 10:18:37 $
6 Version: $Revision: 1.19 $
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"
61 #include "bbstdRelay.h"
68 //====================================================================
69 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
70 bbtk::AtomicBlackBox);
71 //====================================================================
72 //====================================================================
73 // BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(Relay,
74 // bbtk::AtomicBlackBox);
75 //====================================================================
78 using namespace bbstd;
82 typedef vtkImageData::Pointer vtkImageDataPointer;
83 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(vtkImageDataPointer,
84 "vtkImageDataPointer");
91 //====================================================================
92 // Add the specialized adaptors to the package
93 typedef vtkImagePlaneWidget* I;
94 typedef vtkInteractorObserver* O;
96 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
98 BBTK_DEFINE_RELAY_BLACK_BOX(vtkImageDataPointer,vtk,vtkImageDataPointerRelay);
99 BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageDataPointerRelay,bbtk::AtomicBlackBox);
101 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,vtkImageDataPointerRelay);
102 // BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(vtk,Relay,vtkImageDataPointer);
110 //================================================================
111 class myCallbackPlane : public vtkCommand
114 static myCallbackPlane *New()
116 return new myCallbackPlane;
118 virtual void Execute(vtkObject *caller, unsigned long, void*)
120 currentBlackBox->Process();
121 currentBlackBox->bbSignalOutputModification();
123 void SetCurrentBlackBox(ImagePlanes *cBB) {currentBlackBox = cBB;};
124 void SetVtkPlaneWidget( vtkImagePlaneWidget *planeWidget );
125 myCallbackPlane() {};
128 vtkPlaneWidget *planeWidget;
129 ImagePlanes *currentBlackBox;
131 //================================================================
135 //================================================================
137 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
138 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
140 void ImagePlanes::bbUserConstructor()
142 bbSetOutputPlaneX(0);
143 bbSetOutputPlaneY(0);
144 bbSetOutputPlaneZ(0);
145 bbSetOutputImageX(0);
146 bbSetOutputImageY(0);
147 bbSetOutputImageZ(0);
149 std::vector<double> vect;
152 bbSetInputWindowLevel (vect);
155 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
157 bbSetOutputPlaneX(0);
158 bbSetOutputPlaneY(0);
159 bbSetOutputPlaneZ(0);
160 bbSetOutputImageX(0);
161 bbSetOutputImageY(0);
162 bbSetOutputImageZ(0);
165 void ImagePlanes::Init()
168 /// CREATION DES WIDGETS
169 if (bbGetOutputPlaneX() != 0) return;
171 // The shared picker enables us to use 3 planes at one time
172 // and gets the picking order right
173 vtkCellPicker* picker = vtkCellPicker::New();
174 picker->SetTolerance(0.005);
176 // The 3 image plane widgets
177 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
178 planeWidgetX->DisplayTextOn();
179 planeWidgetX->SetPicker(picker);
180 planeWidgetX->SetKeyPressActivationValue('x');
181 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
182 prop1->SetColor(1, 0, 0);
184 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
185 planeWidgetY->DisplayTextOn();
186 planeWidgetY->SetPicker(picker);
187 planeWidgetY->SetKeyPressActivationValue('y');
188 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
189 prop2->SetColor(1, 1, 0);
190 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
192 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
193 planeWidgetZ->DisplayTextOn();
194 planeWidgetZ->SetPicker(picker);
195 planeWidgetZ->SetKeyPressActivationValue('z');
196 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
197 prop3->SetColor(0, 0, 1);
198 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
200 bbSetOutputPlaneX(planeWidgetX);
201 bbSetOutputPlaneY(planeWidgetY);
202 bbSetOutputPlaneZ(planeWidgetZ);
203 bbSetOutputImageX(planeWidgetX->GetResliceOutput());
204 bbSetOutputImageY(planeWidgetY->GetResliceOutput());
205 bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
207 picker->UnRegister(NULL);
209 myCallbackPlane *_myCallback = myCallbackPlane::New();
210 _myCallback->SetCurrentBlackBox(this);
211 planeWidgetX->AddObserver(vtkCommand::InteractionEvent,_myCallback);
212 planeWidgetY->AddObserver(vtkCommand::InteractionEvent,_myCallback);
213 planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,_myCallback);
216 //---------------------------------------------------------------------
217 void ImagePlanes::bbUserDestructor()
220 if (bbGetOutputPlaneX()) bbGetOutputPlaneX()->UnRegister(NULL);
221 if (bbGetOutputPlaneY()) bbGetOutputPlaneY()->UnRegister(NULL);
222 if (bbGetOutputPlaneZ()) bbGetOutputPlaneZ()->UnRegister(NULL);
225 //---------------------------------------------------------------------
226 void ImagePlanes::Process()
228 if (bbGetInputIn()!=0)
230 // Create the widgets if not already done
233 if ( bbGetInputStatus("In") != bbtk::UPTODATE )
235 // Input image has changed : reinitialize planes
236 image = bbGetInputIn();
238 int xMin, xMax, yMin, yMax, zMin, zMax;
239 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
241 // Initial values : center of the volume (in real world, not in pixels!)
242 double xSpacing, ySpacing, zSpacing;
243 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
246 bbGetOutputPlaneX()->SetInput(bbGetInputIn());
247 bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
248 bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
250 bbGetOutputPlaneY()->SetInput(bbGetInputIn());
251 bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
252 bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
254 bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
255 bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
256 bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
258 if (bbGetInputWindowLevel()[0]!=0)
260 bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
261 bbGetInputWindowLevel()[1]);
265 double *range = image->GetScalarRange();
266 bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
267 0.5*(range[1]+range[0]));
272 // UPDATE DES SORTIES
273 bbGetOutputPlaneX()->GetResliceOutput()->Update();
274 bbGetOutputPlaneY()->GetResliceOutput()->Update();
275 bbGetOutputPlaneZ()->GetResliceOutput()->Update();