1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2008/12/18 11:55:00 $
6 Version: $Revision: 1.18 $
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"
66 //====================================================================
67 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
68 bbtk::AtomicBlackBox);
69 //====================================================================
70 //====================================================================
71 BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(Relay,
72 bbtk::AtomicBlackBox);
73 //====================================================================
76 using namespace bbstd;
83 //====================================================================
84 // Add the specialized adaptors to the package
85 typedef vtkImagePlaneWidget* I;
86 typedef vtkInteractorObserver* O;
88 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
90 BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(vtk,Relay,vtkImageDataPointer);
97 //================================================================
98 class myCallbackPlane : public vtkCommand
101 static myCallbackPlane *New()
103 return new myCallbackPlane;
105 virtual void Execute(vtkObject *caller, unsigned long, void*)
107 currentBlackBox->Process();
108 currentBlackBox->bbSignalOutputModification();
110 void SetCurrentBlackBox(ImagePlanes *cBB) {currentBlackBox = cBB;};
111 void SetVtkPlaneWidget( vtkImagePlaneWidget *planeWidget );
112 myCallbackPlane() {};
115 vtkPlaneWidget *planeWidget;
116 ImagePlanes *currentBlackBox;
118 //================================================================
122 //================================================================
124 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
125 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
127 void ImagePlanes::bbUserConstructor()
129 bbSetOutputPlaneX(0);
130 bbSetOutputPlaneY(0);
131 bbSetOutputPlaneZ(0);
132 bbSetOutputImageX(0);
133 bbSetOutputImageY(0);
134 bbSetOutputImageZ(0);
136 std::vector<double> vect;
139 bbSetInputWindowLevel (vect);
142 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
144 bbSetOutputPlaneX(0);
145 bbSetOutputPlaneY(0);
146 bbSetOutputPlaneZ(0);
147 bbSetOutputImageX(0);
148 bbSetOutputImageY(0);
149 bbSetOutputImageZ(0);
152 void ImagePlanes::Init()
155 /// CREATION DES WIDGETS
156 if (bbGetOutputPlaneX() != 0) return;
158 // The shared picker enables us to use 3 planes at one time
159 // and gets the picking order right
160 vtkCellPicker* picker = vtkCellPicker::New();
161 picker->SetTolerance(0.005);
163 // The 3 image plane widgets
164 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
165 planeWidgetX->DisplayTextOn();
166 planeWidgetX->SetPicker(picker);
167 planeWidgetX->SetKeyPressActivationValue('x');
168 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
169 prop1->SetColor(1, 0, 0);
171 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
172 planeWidgetY->DisplayTextOn();
173 planeWidgetY->SetPicker(picker);
174 planeWidgetY->SetKeyPressActivationValue('y');
175 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
176 prop2->SetColor(1, 1, 0);
177 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
179 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
180 planeWidgetZ->DisplayTextOn();
181 planeWidgetZ->SetPicker(picker);
182 planeWidgetZ->SetKeyPressActivationValue('z');
183 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
184 prop3->SetColor(0, 0, 1);
185 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
187 bbSetOutputPlaneX(planeWidgetX);
188 bbSetOutputPlaneY(planeWidgetY);
189 bbSetOutputPlaneZ(planeWidgetZ);
190 bbSetOutputImageX(planeWidgetX->GetResliceOutput());
191 bbSetOutputImageY(planeWidgetY->GetResliceOutput());
192 bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
194 picker->UnRegister(NULL);
196 myCallbackPlane *_myCallback = myCallbackPlane::New();
197 _myCallback->SetCurrentBlackBox(this);
198 planeWidgetX->AddObserver(vtkCommand::InteractionEvent,_myCallback);
199 planeWidgetY->AddObserver(vtkCommand::InteractionEvent,_myCallback);
200 planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,_myCallback);
203 //---------------------------------------------------------------------
204 void ImagePlanes::bbUserDestructor()
207 if (bbGetOutputPlaneX()) bbGetOutputPlaneX()->UnRegister(NULL);
208 if (bbGetOutputPlaneY()) bbGetOutputPlaneY()->UnRegister(NULL);
209 if (bbGetOutputPlaneZ()) bbGetOutputPlaneZ()->UnRegister(NULL);
212 //---------------------------------------------------------------------
213 void ImagePlanes::Process()
215 if (bbGetInputIn()!=0)
217 // Create the widgets if not already done
220 if ( bbGetInputStatus("In") != bbtk::UPTODATE )
222 // Input image has changed : reinitialize planes
223 image = bbGetInputIn();
225 int xMin, xMax, yMin, yMax, zMin, zMax;
226 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
228 // Initial values : center of the volume (in real world, not in pixels!)
229 double xSpacing, ySpacing, zSpacing;
230 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
233 bbGetOutputPlaneX()->SetInput(bbGetInputIn());
234 bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
235 bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
237 bbGetOutputPlaneY()->SetInput(bbGetInputIn());
238 bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
239 bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
241 bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
242 bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
243 bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
245 if (bbGetInputWindowLevel()[0]!=0)
247 bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
248 bbGetInputWindowLevel()[1]);
252 double *range = image->GetScalarRange();
253 bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
254 0.5*(range[1]+range[0]));
259 // UPDATE DES SORTIES
260 bbGetOutputPlaneX()->GetResliceOutput()->Update();
261 bbGetOutputPlaneY()->GetResliceOutput()->Update();
262 bbGetOutputPlaneZ()->GetResliceOutput()->Update();