1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2008/11/26 16:19:44 $
6 Version: $Revision: 1.11 $
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 "bbstdCast.h"
45 //====================================================================
46 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
47 bbtk::AtomicBlackBox);
48 //====================================================================
51 using namespace bbstd;
54 //====================================================================
55 // Add the specialized adaptors to the package
56 typedef vtkImagePlaneWidget* I;
57 typedef vtkInteractorObserver* O;
59 BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
67 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
68 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
70 void ImagePlanes::bbUserConstructor()
72 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
74 std::vector<double> vect;
77 bbSetInputWindowLevel (vect);
80 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
82 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
85 void ImagePlanes::Init()
87 if (planeWidgetX != 0) return;
88 // The shared picker enables us to use 3 planes at one time
89 // and gets the picking order right
90 vtkCellPicker* picker = vtkCellPicker::New();
91 picker->SetTolerance(0.005);
93 // The 3 image plane widgets
94 planeWidgetX = vtkImagePlaneWidget::New();
95 planeWidgetX->DisplayTextOn();
96 planeWidgetX->SetPicker(picker);
97 planeWidgetX->SetKeyPressActivationValue('x');
98 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
99 prop1->SetColor(1, 0, 0);
101 planeWidgetY = vtkImagePlaneWidget::New();
102 planeWidgetY->DisplayTextOn();
103 planeWidgetY->SetPicker(picker);
104 planeWidgetY->SetKeyPressActivationValue('y');
105 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
106 prop2->SetColor(1, 1, 0);
107 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
109 planeWidgetZ = vtkImagePlaneWidget::New();
110 planeWidgetZ->DisplayTextOn();
111 planeWidgetZ->SetPicker(picker);
112 planeWidgetZ->SetKeyPressActivationValue('z');
113 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
114 prop3->SetColor(0, 0, 1);
115 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
117 bbSetOutputPlaneX(planeWidgetX);
118 bbSetOutputPlaneY(planeWidgetY);
119 bbSetOutputPlaneZ(planeWidgetZ);
121 picker->UnRegister(NULL);
124 //---------------------------------------------------------------------
125 void ImagePlanes::bbUserDestructor()
128 if (planeWidgetX) planeWidgetX->UnRegister(NULL);
129 if (planeWidgetY) planeWidgetY->UnRegister(NULL);
130 if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
134 //---------------------------------------------------------------------
135 void ImagePlanes::Process()
137 if (bbGetInputIn()!=0)
141 int xMin, xMax, yMin, yMax, zMin, zMax;
142 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
144 // Initial values : center of the volume (in real world, not in pixels!)
145 double xSpacing, ySpacing, zSpacing;
146 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
148 planeWidgetX->SetInput(bbGetInputIn());
149 planeWidgetX->SetPlaneOrientationToXAxes();
150 planeWidgetX->SetSlicePosition((xMax+xMin)/2.*xSpacing);
152 planeWidgetY->SetInput(bbGetInputIn());
153 planeWidgetY->SetPlaneOrientationToYAxes();
154 planeWidgetY->SetSlicePosition((yMax+yMin)/2.*ySpacing);
156 planeWidgetZ->SetInput(bbGetInputIn());
157 planeWidgetZ->SetPlaneOrientationToZAxes();
158 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.*zSpacing);
160 // planeWidgetZ->SetWindowLevel(512,256);
162 planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);