]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImagePlanes.cxx
Now middle slice position is properly computed when spacing is not isotrop
[bbtk.git] / packages / vtk / src / bbvtkImagePlanes.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkImagePlanes.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/27 14:57:38 $
6   Version:   $Revision: 1.12 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36 #ifdef _USE_VTK_
37 #include "bbvtkImagePlanes.h"
38 #include "bbvtkPackage.h"
39 #include "vtkCellPicker.h"
40 #include "vtkProperty.h"
41
42 #include "bbstdCast.h"
43 namespace bbstd
44 {
45   //====================================================================
46   BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
47                                           bbtk::AtomicBlackBox);
48   //====================================================================
49
50 }
51 using namespace bbstd;
52 namespace bbvtk
53 {
54   //====================================================================
55   // Add the specialized adaptors to the package
56   typedef vtkImagePlaneWidget* I;
57   typedef vtkInteractorObserver* O;
58
59   BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
60
61 }
62
63 namespace bbvtk
64 {
65
66    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
67    BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
68
69    void ImagePlanes::bbUserConstructor() 
70    { 
71      planeWidgetX = planeWidgetY = planeWidgetZ = 0;
72      imageX       = imageY       = imageZ       = 0;
73      bbSetInputIn(0);
74      std::vector<double> vect;
75      vect.push_back(512);
76      vect.push_back(256);
77      bbSetInputWindowLevel (vect);
78    }
79    
80    void ImagePlanes::bbUserCopyConstructor(bbtk::BlackBox::Pointer) 
81    { 
82      planeWidgetX = planeWidgetY = planeWidgetZ = 0;
83      imageX       = imageY       = imageZ       = 0;
84    }
85
86    void ImagePlanes::Init() 
87    {
88    
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);
94   
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);
102
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());
110
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());
118
119      bbSetOutputPlaneX(planeWidgetX);
120      bbSetOutputPlaneY(planeWidgetY);
121      bbSetOutputPlaneZ(planeWidgetZ);
122
123      picker->UnRegister(NULL);
124    }
125
126 //---------------------------------------------------------------------
127   void ImagePlanes::bbUserDestructor()
128   {
129
130     if (planeWidgetX) planeWidgetX->UnRegister(NULL);
131     if (planeWidgetY) planeWidgetY->UnRegister(NULL);
132     if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
133
134   }
135   
136 //---------------------------------------------------------------------  
137    void ImagePlanes::Process()
138    {
139      if (bbGetInputIn()!=0)
140        {
141          Init();
142
143          int xMin, xMax, yMin, yMax, zMin, zMax;
144          bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
145
146          // Initial values : center of the volume (in real world, not in pixels!)
147          double xSpacing, ySpacing, zSpacing;
148          bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
149          
150          planeWidgetX->SetInput(bbGetInputIn());
151          planeWidgetX->SetPlaneOrientationToXAxes();
152          planeWidgetX->SetSlicePosition((xMax+xMin)/2.*xSpacing);
153          bbSetOutput("ImageX", planeWidgetX->GetResliceOutput());
154
155          planeWidgetY->SetInput(bbGetInputIn());
156          planeWidgetY->SetPlaneOrientationToYAxes();
157          planeWidgetY->SetSlicePosition((yMax+yMin)/2.*ySpacing); 
158          bbSetOutput("ImageY", planeWidgetY->GetResliceOutput());
159          
160          planeWidgetZ->SetInput(bbGetInputIn());
161          planeWidgetZ->SetPlaneOrientationToZAxes();
162          planeWidgetZ->SetSlicePosition((zMax+zMin)/2.*zSpacing); 
163          bbSetOutput("ImageZ", planeWidgetZ->GetResliceOutput());
164          
165         // planeWidgetZ->SetWindowLevel(512,256);
166
167          planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);
168        }
169    }
170 }//namespace bbtk
171
172 #endif // _USE_VTK_
173