]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImagePlanes.cxx
=== MAJOR RELEASE ====
[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/04/18 12:59:52 $
7   Version:   $Revision: 1.2 $
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
24
25 #ifdef _USE_VTK_
26 #include "bbvtkImagePlanes.h"
27 #include "bbvtkPackage.h"
28 #include "vtkCellPicker.h"
29 #include "vtkProperty.h"
30
31 #include "bbstdCast.h"
32 namespace bbstd
33 {
34   //====================================================================
35   BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
36                                           bbtk::AtomicBlackBox);
37   //====================================================================
38
39 }
40 using namespace bbstd;
41 namespace bbvtk
42 {
43   //====================================================================
44   // Add the specialized adaptors to the package
45   typedef vtkImagePlaneWidget* I;
46   typedef vtkInteractorObserver* O;
47
48   BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
49
50 }
51
52
53
54 namespace bbvtk
55 {
56
57
58    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
59    BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
60
61
62
63
64
65    void ImagePlanes::bbUserConstructor() 
66    { 
67      Init();
68      bbSetInputIn(0);
69    }
70    void ImagePlanes::bbUserCopyConstructor() 
71    { 
72      Init();
73    }
74
75    void ImagePlanes::Init() 
76    { 
77      
78      // The shared picker enables us to use 3 planes at one time
79      // and gets the picking order right
80      vtkCellPicker* picker = vtkCellPicker::New();
81      picker->SetTolerance(0.005);
82   
83      // The 3 image plane widgets are used to probe the dataset.
84      planeWidgetX = vtkImagePlaneWidget::New();
85      planeWidgetX->DisplayTextOn();
86      planeWidgetX->SetPicker(picker);
87      planeWidgetX->SetKeyPressActivationValue('x');
88      vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
89      prop1->SetColor(1, 0, 0);
90
91      planeWidgetY = vtkImagePlaneWidget::New();
92      planeWidgetY->DisplayTextOn();
93      planeWidgetY->SetPicker(picker);
94      planeWidgetY->SetKeyPressActivationValue('y');
95      vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
96      prop2->SetColor(1, 1, 0);
97      planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
98
99      // for the z-slice, turn off texture interpolation:
100      // interpolation is now nearest neighbour, to demonstrate
101      // cross-hair cursor snapping to pixel centers
102      planeWidgetZ = vtkImagePlaneWidget::New();
103      planeWidgetZ->DisplayTextOn();
104      planeWidgetZ->SetPicker(picker);
105      planeWidgetZ->SetKeyPressActivationValue('z');
106      vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
107      prop3->SetColor(0, 0, 1);
108      planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
109
110      bbSetOutputPlaneX(planeWidgetX);
111      bbSetOutputPlaneY(planeWidgetY);
112      bbSetOutputPlaneZ(planeWidgetZ);
113    }
114
115 //---------------------------------------------------------------------
116
117    void ImagePlanes::Process()
118    {
119      if (bbGetInputIn()!=0)
120        {
121          int xMin, xMax, yMin, yMax, zMin, zMax;
122          bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
123
124          planeWidgetX->SetInput(bbGetInputIn());
125          planeWidgetX->SetPlaneOrientationToXAxes();
126          planeWidgetX->SetSlicePosition((xMax+xMin)/2.); 
127
128          planeWidgetY->SetInput(bbGetInputIn());
129          planeWidgetY->SetPlaneOrientationToYAxes();
130          planeWidgetY->SetSlicePosition((yMax+yMin)/2.); 
131
132          planeWidgetZ->SetInput(bbGetInputIn());
133          planeWidgetZ->SetPlaneOrientationToZAxes();
134          planeWidgetZ->SetSlicePosition((zMax+zMin)/2.); 
135
136          planeWidgetZ->SetWindowLevel(512,256);
137        }
138    }
139 }//namespace bbtk
140
141 #endif // _USE_VTK_
142