1 /*=========================================================================
3 Module: $RCSfile: bbvtkImagePlanes.cxx,v $
5 Date: $Date: 2008/12/03 09:34:39 $
6 Version: $Revision: 1.14 $
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"
41 #include "vtkMetaImageWriter.h"
43 #include "bbstdCast.h"
46 //====================================================================
47 BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
48 bbtk::AtomicBlackBox);
49 //====================================================================
52 using namespace bbstd;
55 //====================================================================
56 // Add the specialized adaptors to the package
57 typedef vtkImagePlaneWidget* I;
58 typedef vtkInteractorObserver* O;
60 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;
73 imageX = imageY = imageZ = 0;
75 std::vector<double> vect;
78 bbSetInputWindowLevel (vect);
80 bbSetModifiedStatus();
83 void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
85 planeWidgetX = planeWidgetY = planeWidgetZ = 0;
86 imageX = imageY = imageZ = 0;
89 void ImagePlanes::Init()
91 if (planeWidgetX != 0) return;
93 // The shared picker enables us to use 3 planes at one time
94 // and gets the picking order right
95 vtkCellPicker* picker = vtkCellPicker::New();
96 picker->SetTolerance(0.005);
98 // The 3 image plane widgets
99 planeWidgetX = vtkImagePlaneWidget::New();
100 planeWidgetX->DisplayTextOn();
101 planeWidgetX->SetPicker(picker);
102 planeWidgetX->SetKeyPressActivationValue('x');
103 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
104 prop1->SetColor(1, 0, 0);
106 planeWidgetY = vtkImagePlaneWidget::New();
107 planeWidgetY->DisplayTextOn();
108 planeWidgetY->SetPicker(picker);
109 planeWidgetY->SetKeyPressActivationValue('y');
110 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
111 prop2->SetColor(1, 1, 0);
112 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
114 planeWidgetZ = vtkImagePlaneWidget::New();
115 planeWidgetZ->DisplayTextOn();
116 planeWidgetZ->SetPicker(picker);
117 planeWidgetZ->SetKeyPressActivationValue('z');
118 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
119 prop3->SetColor(0, 0, 1);
120 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
122 bbSetOutputPlaneX(planeWidgetX);
123 bbSetOutputPlaneY(planeWidgetY);
124 bbSetOutputPlaneZ(planeWidgetZ);
126 picker->UnRegister(NULL);
128 myCallbackPlane *_myCallback = myCallbackPlane::New();
129 _myCallback->SetCurrentBlackBox(this);
130 planeWidgetX->AddObserver(vtkCommand::InteractionEvent,_myCallback);
131 planeWidgetY->AddObserver(vtkCommand::InteractionEvent,_myCallback);
132 planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,_myCallback);
135 //---------------------------------------------------------------------
136 void ImagePlanes::bbUserDestructor()
139 if (planeWidgetX) planeWidgetX->UnRegister(NULL);
140 if (planeWidgetY) planeWidgetY->UnRegister(NULL);
141 if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
145 //---------------------------------------------------------------------
146 void ImagePlanes::Process()
148 if (bbGetInputIn()!=0)
152 int xMin, xMax, yMin, yMax, zMin, zMax;
153 bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
155 // Initial values : center of the volume (in real world, not in pixels!)
156 double xSpacing, ySpacing, zSpacing;
157 bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
159 planeWidgetX->SetInput(bbGetInputIn());
160 planeWidgetX->SetPlaneOrientationToXAxes();
161 planeWidgetX->SetSlicePosition((xMax+xMin)/2.*xSpacing);
162 planeWidgetX->GetResliceOutput()->Update();
163 bbSetOutput("ImageX", planeWidgetX->GetResliceOutput());
166 vtkMetaImageWriter *writer = vtkMetaImageWriter::New();
168 std::string newFilenameX("newFilenameX.mhd");
169 writer->SetInput(planeWidgetX->GetResliceOutput());
170 writer->SetFileName(newFilenameX.c_str());
173 //planeWidgetX->GetResliceOutput()->Print(std::cout);
175 planeWidgetY->SetInput(bbGetInputIn());
176 planeWidgetY->SetPlaneOrientationToYAxes();
177 planeWidgetY->SetSlicePosition((yMax+yMin)/2.*ySpacing);
178 planeWidgetY->GetResliceOutput()->Update();
179 bbSetOutput("ImageY", planeWidgetY->GetResliceOutput());
180 //planeWidgetY->GetResliceOutput()->Print(std::cout);
182 std::string newFilenameY("newFilenameY.mhd");
183 writer->SetInput(planeWidgetY->GetResliceOutput());
184 writer->SetFileName(newFilenameY.c_str());
187 planeWidgetZ->SetInput(bbGetInputIn());
188 planeWidgetZ->SetPlaneOrientationToZAxes();
189 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.*zSpacing);
190 planeWidgetZ->GetResliceOutput()->Update();
191 bbSetOutput("ImageZ", planeWidgetZ->GetResliceOutput());
192 // planeWidgetZ->GetResliceOutput()->Print(std::cout);
194 // planeWidgetZ->SetWindowLevel(512,256);
196 std::string newFilenameZ("newFilenameZ.mhd");
197 writer->SetInput(planeWidgetZ->GetResliceOutput());
198 writer->SetFileName(newFilenameZ.c_str());
201 planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);
203 // writer->vtkMetaImageWriter::Delete();