]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImagePlanes.cxx
Add Input : WindowLevel
[bbtk.git] / packages / vtk / src / bbvtkImagePlanes.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbvtkImagePlanes.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/06/25 08:21:31 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22
23 #ifdef _USE_VTK_
24 #include "bbvtkImagePlanes.h"
25 #include "bbvtkPackage.h"
26 #include "vtkCellPicker.h"
27 #include "vtkProperty.h"
28
29 #include "bbstdCast.h"
30 namespace bbstd
31 {
32   //====================================================================
33   BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
34                                           bbtk::AtomicBlackBox);
35   //====================================================================
36
37 }
38 using namespace bbstd;
39 namespace bbvtk
40 {
41   //====================================================================
42   // Add the specialized adaptors to the package
43   typedef vtkImagePlaneWidget* I;
44   typedef vtkInteractorObserver* O;
45
46   BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
47
48 }
49
50 namespace bbvtk
51 {
52
53
54    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
55    BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
56
57    void ImagePlanes::bbUserConstructor() 
58    { 
59      Init();
60      bbSetInputIn(0);
61      std::vector<double> vect;
62      vect.push_back(512);
63      vect.push_back(256);
64      bbSetInputWindowLevel (vect);
65    }
66    
67    void ImagePlanes::bbUserCopyConstructor() 
68    { 
69      Init();
70    }
71
72    void ImagePlanes::Init() 
73    { 
74      
75      // The shared picker enables us to use 3 planes at one time
76      // and gets the picking order right
77      vtkCellPicker* picker = vtkCellPicker::New();
78      picker->SetTolerance(0.005);
79   
80      // The 3 image plane widgets are used to probe the dataset.
81      planeWidgetX = vtkImagePlaneWidget::New();
82      planeWidgetX->DisplayTextOn();
83      planeWidgetX->SetPicker(picker);
84      planeWidgetX->SetKeyPressActivationValue('x');
85      vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
86      prop1->SetColor(1, 0, 0);
87
88      planeWidgetY = vtkImagePlaneWidget::New();
89      planeWidgetY->DisplayTextOn();
90      planeWidgetY->SetPicker(picker);
91      planeWidgetY->SetKeyPressActivationValue('y');
92      vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
93      prop2->SetColor(1, 1, 0);
94      planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
95
96      // for the z-slice, turn off texture interpolation:
97      // interpolation is now nearest neighbour, to demonstrate
98      // cross-hair cursor snapping to pixel centers
99      planeWidgetZ = vtkImagePlaneWidget::New();
100      planeWidgetZ->DisplayTextOn();
101      planeWidgetZ->SetPicker(picker);
102      planeWidgetZ->SetKeyPressActivationValue('z');
103      vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
104      prop3->SetColor(0, 0, 1);
105      planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
106
107      bbSetOutputPlaneX(planeWidgetX);
108      bbSetOutputPlaneY(planeWidgetY);
109      bbSetOutputPlaneZ(planeWidgetZ);
110
111      picker->UnRegister(NULL);
112    }
113
114 //---------------------------------------------------------------------
115   void ImagePlanes::bbUserDestructor()
116   {
117     planeWidgetX->Delete();
118     planeWidgetY->Delete();
119     planeWidgetZ->Delete();
120   }
121   
122 //---------------------------------------------------------------------  
123    void ImagePlanes::Process()
124    {
125      if (bbGetInputIn()!=0)
126        {
127          int xMin, xMax, yMin, yMax, zMin, zMax;
128          bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
129
130          planeWidgetX->SetInput(bbGetInputIn());
131          planeWidgetX->SetPlaneOrientationToXAxes();
132          planeWidgetX->SetSlicePosition((xMax+xMin)/2.); 
133
134          planeWidgetY->SetInput(bbGetInputIn());
135          planeWidgetY->SetPlaneOrientationToYAxes();
136          planeWidgetY->SetSlicePosition((yMax+yMin)/2.); 
137
138          planeWidgetZ->SetInput(bbGetInputIn());
139          planeWidgetZ->SetPlaneOrientationToZAxes();
140          planeWidgetZ->SetSlicePosition((zMax+zMin)/2.); 
141
142         // planeWidgetZ->SetWindowLevel(512,256);
143
144          planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);
145        }
146    }
147 }//namespace bbtk
148
149 #endif // _USE_VTK_
150