1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2008/11/27 16:38:32 $
6 Version: $Revision: 1.13 $
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);
66 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
67 BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
69 void ImagePlanes::bbUserConstructor()
71 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
72 imageX = imageY = imageZ = 0;
74 std::vector<double> vect;
77 bbSetInputWindowLevel (vect);
80 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
82 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
83 imageX = imageY = imageZ = 0;
86 void ImagePlanes::Init()
89 if (planeWidgetX != 0) return;
90 // The shared picker enables us to use 3 planes at one time
91 // and gets the picking order right
92 vtkCellPicker* picker = vtkCellPicker::New();
93 picker->SetTolerance(0.005);
95 // The 3 image plane widgets
96 planeWidgetX = vtkImagePlaneWidget::New();
97 planeWidgetX->DisplayTextOn();
98 planeWidgetX->SetPicker(picker);
99 planeWidgetX->SetKeyPressActivationValue('x');
100 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
101 prop1->SetColor(1, 0, 0);
103 planeWidgetY = vtkImagePlaneWidget::New();
104 planeWidgetY->DisplayTextOn();
105 planeWidgetY->SetPicker(picker);
106 planeWidgetY->SetKeyPressActivationValue('y');
107 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
108 prop2->SetColor(1, 1, 0);
109 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
111 planeWidgetZ = vtkImagePlaneWidget::New();
112 planeWidgetZ->DisplayTextOn();
113 planeWidgetZ->SetPicker(picker);
114 planeWidgetZ->SetKeyPressActivationValue('z');
115 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
116 prop3->SetColor(0, 0, 1);
117 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
119 bbSetOutputPlaneX(planeWidgetX);
120 bbSetOutputPlaneY(planeWidgetY);
121 bbSetOutputPlaneZ(planeWidgetZ);
123 picker->UnRegister(NULL);
126 //---------------------------------------------------------------------
127 void ImagePlanes::bbUserDestructor()
130 if (planeWidgetX) planeWidgetX->UnRegister(NULL);
131 if (planeWidgetY) planeWidgetY->UnRegister(NULL);
132 if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
136 //---------------------------------------------------------------------
137 void ImagePlanes::Process()
139 if (bbGetInputIn()!=0)
143 int xMin, xMax, yMin, yMax, zMin, zMax;
144 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
146 // Initial values : center of the volume (in real world, not in pixels!)
147 double xSpacing, ySpacing, zSpacing;
148 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
150 planeWidgetX->SetInput(bbGetInputIn());
151 planeWidgetX->SetPlaneOrientationToXAxes();
152 planeWidgetX->SetSlicePosition((xMax+xMin)/2.*xSpacing);
153 planeWidgetX->GetResliceOutput()->Update();
154 bbSetOutput("ImageX", planeWidgetX->GetResliceOutput());
155 //planeWidgetX->GetResliceOutput()->Print(std::cout);
157 planeWidgetY->SetInput(bbGetInputIn());
158 planeWidgetY->SetPlaneOrientationToYAxes();
159 planeWidgetY->SetSlicePosition((yMax+yMin)/2.*ySpacing);
160 planeWidgetY->GetResliceOutput()->Update();
161 bbSetOutput("ImageY", planeWidgetY->GetResliceOutput());
162 //planeWidgetY->GetResliceOutput()->Print(std::cout);
164 planeWidgetZ->SetInput(bbGetInputIn());
165 planeWidgetZ->SetPlaneOrientationToZAxes();
166 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.*zSpacing);
167 planeWidgetZ->GetResliceOutput()->Update();
168 bbSetOutput("ImageZ", planeWidgetZ->GetResliceOutput());
169 // planeWidgetZ->GetResliceOutput()->Print(std::cout);
171 // planeWidgetZ->SetWindowLevel(512,256);
173 planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);