]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImagePlanes.cxx
0f5e34b66c4ab462c9fb74165f0ba7d7908936c3
[bbtk.git] / packages / vtk / src / bbvtkImagePlanes.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkImagePlanes.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:30 $
6   Version:   $Revision: 1.9 $
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
67    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
68    BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
69
70    void ImagePlanes::bbUserConstructor() 
71    { 
72      planeWidgetX = planeWidgetY = planeWidgetZ = 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() 
81    { 
82      planeWidgetX = planeWidgetY = planeWidgetZ = 0;
83    }
84
85    void ImagePlanes::Init() 
86    { 
87      if (planeWidgetX != 0) return;
88      // The shared picker enables us to use 3 planes at one time
89      // and gets the picking order right
90      vtkCellPicker* picker = vtkCellPicker::New();
91      picker->SetTolerance(0.005);
92   
93      // The 3 image plane widgets 
94      planeWidgetX = vtkImagePlaneWidget::New();
95      planeWidgetX->DisplayTextOn();
96      planeWidgetX->SetPicker(picker);
97      planeWidgetX->SetKeyPressActivationValue('x');
98      vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
99      prop1->SetColor(1, 0, 0);
100
101      planeWidgetY = vtkImagePlaneWidget::New();
102      planeWidgetY->DisplayTextOn();
103      planeWidgetY->SetPicker(picker);
104      planeWidgetY->SetKeyPressActivationValue('y');
105      vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
106      prop2->SetColor(1, 1, 0);
107      planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
108
109      planeWidgetZ = vtkImagePlaneWidget::New();
110      planeWidgetZ->DisplayTextOn();
111      planeWidgetZ->SetPicker(picker);
112      planeWidgetZ->SetKeyPressActivationValue('z');
113      vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
114      prop3->SetColor(0, 0, 1);
115      planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
116
117      bbSetOutputPlaneX(planeWidgetX);
118      bbSetOutputPlaneY(planeWidgetY);
119      bbSetOutputPlaneZ(planeWidgetZ);
120
121      picker->UnRegister(NULL);
122    }
123
124 //---------------------------------------------------------------------
125   void ImagePlanes::bbUserDestructor()
126   {
127
128     if (planeWidgetX) planeWidgetX->UnRegister(NULL);
129     if (planeWidgetY) planeWidgetY->UnRegister(NULL);
130     if (planeWidgetZ) planeWidgetZ->UnRegister(NULL);
131
132   }
133   
134 //---------------------------------------------------------------------  
135    void ImagePlanes::Process()
136    {
137      if (bbGetInputIn()!=0)
138        {
139          Init();
140
141          int xMin, xMax, yMin, yMax, zMin, zMax;
142          bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
143
144          planeWidgetX->SetInput(bbGetInputIn());
145          planeWidgetX->SetPlaneOrientationToXAxes();
146          planeWidgetX->SetSlicePosition((xMax+xMin)/2.); 
147
148          planeWidgetY->SetInput(bbGetInputIn());
149          planeWidgetY->SetPlaneOrientationToYAxes();
150          planeWidgetY->SetSlicePosition((yMax+yMin)/2.); 
151
152          planeWidgetZ->SetInput(bbGetInputIn());
153          planeWidgetZ->SetPlaneOrientationToZAxes();
154          planeWidgetZ->SetSlicePosition((zMax+zMin)/2.); 
155
156         // planeWidgetZ->SetWindowLevel(512,256);
157
158          planeWidgetZ->SetWindowLevel(bbGetInputWindowLevel()[0],bbGetInputWindowLevel()[1]);
159        }
160    }
161 }//namespace bbtk
162
163 #endif // _USE_VTK_
164