1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2009/04/30 14:31:33 $
6 Version: $Revision: 1.23 $
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"
63 #include "vtkObjectFactory.h"
69 //====================================================================
70 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
71 bbtk::AtomicBlackBox);
72 //====================================================================
73 //====================================================================
74 // BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(Relay,
75 // bbtk::AtomicBlackBox);
76 //====================================================================
79 using namespace bbstd;
83 typedef vtkImageData::Pointer vtkImageDataPointer;
84 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(vtkImageDataPointer,
85 "vtkImageDataPointer");
92 //====================================================================
93 // Add the specialized adaptors to the package
94 typedef vtkImagePlaneWidget* I;
95 typedef vtkInteractorObserver* O;
97 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
99 BBTK_DEFINE_RELAY_BLACK_BOX(vtkImageDataPointer,vtk,vtkImageDataPointerRelay);
100 BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageDataPointerRelay,bbtk::AtomicBlackBox);
102 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,vtkImageDataPointerRelay);
103 // BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(vtk,Relay,vtkImageDataPointer);
111 //================================================================
112 class ImagePlanes::VtkCallbackType : public vtkCommand
115 static VtkCallbackType *New()
117 return new VtkCallbackType;
119 //vtkTypeRevisionMacro(VtkCallbackType,vtkCommand);
121 virtual void Execute(vtkObject *caller, unsigned long, void*)
123 mBlackBox->Process();
124 mBlackBox->bbSignalOutputModification();
126 void SetBlackBox(ImagePlanes *BB) { mBlackBox = BB;};
127 // void SetVtkPlaneWidget( vtkImagePlaneWidget *planeWidget );
128 VtkCallbackType() {};
131 // vtkPlaneWidget *planeWidget;
132 ImagePlanes *mBlackBox;
134 //================================================================
136 //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.23 $");
138 //================================================================
140 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
141 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
143 void ImagePlanes::bbUserConstructor()
145 bbSetOutputPlaneX(0);
146 bbSetOutputPlaneY(0);
147 bbSetOutputPlaneZ(0);
148 bbSetOutputImageX(0);
149 bbSetOutputImageY(0);
150 bbSetOutputImageZ(0);
152 std::vector<double> vect;
155 bbSetInputWindowLevel (vect);
159 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
161 bbSetOutputPlaneX(0);
162 bbSetOutputPlaneY(0);
163 bbSetOutputPlaneZ(0);
164 bbSetOutputImageX(0);
165 bbSetOutputImageY(0);
166 bbSetOutputImageZ(0);
170 void ImagePlanes::Init()
173 /// CREATION DES WIDGETS
174 if (bbGetOutputPlaneX() != 0) return;
176 // The shared picker enables us to use 3 planes at one time
177 // and gets the picking order right
178 vtkCellPicker* picker = vtkCellPicker::New();
179 picker->SetTolerance(0.005);
181 // The 3 image plane widgets
182 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
183 planeWidgetX->DisplayTextOn();
184 planeWidgetX->SetPicker(picker);
185 planeWidgetX->SetKeyPressActivationValue('x');
186 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
187 prop1->SetColor(1, 0, 0);
189 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
190 planeWidgetY->DisplayTextOn();
191 planeWidgetY->SetPicker(picker);
192 planeWidgetY->SetKeyPressActivationValue('y');
193 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
194 prop2->SetColor(1, 1, 0);
195 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
197 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
198 planeWidgetZ->DisplayTextOn();
199 planeWidgetZ->SetPicker(picker);
200 planeWidgetZ->SetKeyPressActivationValue('z');
201 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
202 prop3->SetColor(0, 0, 1);
203 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
205 bbSetOutputPlaneX(planeWidgetX);
206 bbSetOutputPlaneY(planeWidgetY);
207 bbSetOutputPlaneZ(planeWidgetZ);
208 bbSetOutputImageX(planeWidgetX->GetResliceOutput());
209 bbSetOutputImageY(planeWidgetY->GetResliceOutput());
210 bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
212 picker->UnRegister(NULL);
214 mVtkCallback = VtkCallbackType::New();
215 mVtkCallback->SetBlackBox(this);
216 planeWidgetX->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);
217 planeWidgetY->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);
218 planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);
221 //---------------------------------------------------------------------
222 void ImagePlanes::bbUserDestructor()
224 if (bbGetOutputPlaneX())
226 bbGetOutputPlaneX()->SetInput(NULL);
227 // if (mVtkCallback) bbGetOutputPlaneX()->RemoveObserver(mVtkCallback);
228 bbGetOutputPlaneX()->Delete();
230 if (bbGetOutputPlaneY())
232 bbGetOutputPlaneY()->SetInput(NULL);
233 // if (mVtkCallback) bbGetOutputPlaneY()->RemoveObserver(mVtkCallback);
234 bbGetOutputPlaneY()->Delete();
236 if (bbGetOutputPlaneZ())
238 bbGetOutputPlaneZ()->SetInput(NULL);
239 // if (mVtkCallback) bbGetOutputPlaneZ()->RemoveObserver(mVtkCallback);
240 bbGetOutputPlaneZ()->Delete();
244 // mVtkCallback->Delete();
248 //---------------------------------------------------------------------
249 void ImagePlanes::Process()
251 if (bbGetInputIn()!=0)
253 // Create the widgets if not already done
256 if ( bbGetInputStatus("In") != bbtk::UPTODATE )
258 // Input image has changed : reinitialize planes
259 image = bbGetInputIn();
261 int xMin, xMax, yMin, yMax, zMin, zMax;
262 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
264 // Initial values : center of the volume (in real world, not in pixels!)
265 double xSpacing, ySpacing, zSpacing;
266 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
268 bbGetOutputPlaneX()->SetInput(bbGetInputIn());
269 bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
270 bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
272 bbGetOutputPlaneY()->SetInput(bbGetInputIn());
273 bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
274 bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
276 bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
277 bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
278 bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
280 if (bbGetInputWindowLevel()[0]!=0)
282 bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
283 bbGetInputWindowLevel()[1]);
287 double *range = image->GetScalarRange();
288 bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
289 0.5*(range[1]+range[0]));
293 // UPDATE DES SORTIES
294 bbGetOutputPlaneX()->GetResliceOutput()->Update();
295 bbGetOutputPlaneY()->GetResliceOutput()->Update();
296 bbGetOutputPlaneZ()->GetResliceOutput()->Update();