]> Creatis software - bbtk.git/blob - packages/wxvtk/src/wxvtkImageViewer2.h
67208328af2ed093f7bb9f3b2f06d54b6c90179a
[bbtk.git] / packages / wxvtk / src / wxvtkImageViewer2.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: wxvtkImageViewer2.h,v $
5
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13
14 =========================================================================*/
15 // .NAME wxvtkImageViewer2 - Display a 2D image.
16 // .SECTION Description
17 // wxvtkImageViewer2 is a convenience class for displaying a 2D image.  It
18 // packages up the functionality found in vtkRenderWindow, vtkRenderer,
19 // vtkImageActor and vtkImageMapToWindowLevelColors into a single easy to use
20 // class.  This class also creates an image interactor style
21 // (vtkInteractorStyleImage) that allows zooming and panning of images, and
22 // supports interactive window/level operations on the image. Note that
23 // wxvtkImageViewer2 is simply a wrapper around these classes.
24 //
25 // wxvtkImageViewer2 uses the 3D rendering and texture mapping engine
26 // to draw an image on a plane.  This allows for rapid rendering,
27 // zooming, and panning. The image is placed in the 3D scene at a
28 // depth based on the z-coordinate of the particular image slice. Each
29 // call to SetSlice() changes the image data (slice) displayed AND
30 // changes the depth of the displayed slice in the 3D scene. This can
31 // be controlled by the AutoAdjustCameraClippingRange ivar of the
32 // InteractorStyle member.
33 //
34 // It is possible to mix images and geometry, using the methods:
35 //
36 // viewer->SetInput( myImage );
37 // viewer->GetRenderer()->AddActor( myActor );
38 //
39 // This can be used to annotate an image with a PolyData of "edges" or
40 // or highlight sections of an image or display a 3D isosurface
41 // with a slice from the volume, etc. Any portions of your geometry
42 // that are in front of the displayed slice will be visible; any
43 // portions of your geometry that are behind the displayed slice will
44 // be obscured. A more general framework (with respect to viewing
45 // direction) for achieving this effect is provided by the
46 // vtkImagePlaneWidget .
47 //
48 // Note that pressing 'r' will reset the window/level and pressing
49 // shift+'r' or control+'r' will reset the camera.
50 //
51 // .SECTION See Also
52 // vtkRenderWindow vtkRenderer vtkImageActor vtkImageMapToWindowLevelColors
53
54 #ifndef __wxvtkImageViewer2_h
55 #define __wxvtkImageViewer2_h
56
57 #include "vtkObject.h"
58
59 class vtkAlgorithmOutput;
60 class vtkImageActor;
61 class vtkImageData;
62 class vtkImageMapToWindowLevelColors;
63 class vtkInteractorStyleImage;
64 class vtkRenderWindow;
65 class vtkRenderer;
66 class vtkRenderWindowInteractor;
67
68 class /*VTK_RENDERING_EXPORT*/ wxvtkImageViewer2 : public vtkObject 
69 {
70 public:
71   static wxvtkImageViewer2 *New();
72   vtkTypeRevisionMacro(wxvtkImageViewer2,vtkObject);
73   void PrintSelf(ostream& os, vtkIndent indent);
74
75   // Description:
76   // Get the name of rendering window.
77   virtual const char *GetWindowName();
78
79   // Description:
80   // Render the resulting image.
81   virtual void Render(void);
82   
83   // Description:
84   // Set/Get the input image to the viewer.
85   virtual void SetInput(vtkImageData *in);
86   virtual vtkImageData *GetInput();
87   virtual void SetInputConnection(vtkAlgorithmOutput* input);
88   
89   // Description:
90   // Set/get the slice orientation
91   //BTX
92   enum
93   {
94     SLICE_ORIENTATION_YZ = 0,
95     SLICE_ORIENTATION_XZ = 1,
96     SLICE_ORIENTATION_XY = 2
97   };
98   //ETX
99   vtkGetMacro(SliceOrientation, int);
100   virtual void SetSliceOrientation(int orientation);
101   virtual void SetSliceOrientationToXY()
102     { this->SetSliceOrientation(wxvtkImageViewer2::SLICE_ORIENTATION_XY); };
103   virtual void SetSliceOrientationToYZ()
104     { this->SetSliceOrientation(wxvtkImageViewer2::SLICE_ORIENTATION_YZ); };
105   virtual void SetSliceOrientationToXZ()
106     { this->SetSliceOrientation(wxvtkImageViewer2::SLICE_ORIENTATION_XZ); };
107
108   // Description:
109   // Set/Get the current slice to display (depending on the orientation
110   // this can be in X, Y or Z).
111   vtkGetMacro(Slice, int);
112   virtual void SetSlice(int s);
113
114   // Description:
115   // Update the display extent manually so that the proper slice for the
116   // given orientation is displayed. It will also try to set a
117   // reasonable camera clipping range.
118   // This method is called automatically when the Input is changed, but
119   // most of the time the input of this class is likely to remain the same,
120   // i.e. connected to the output of a filter, or an image reader. When the
121   // input of this filter or reader itself is changed, an error message might
122   // be displayed since the current display extent is probably outside
123   // the new whole extent. Calling this method will ensure that the display
124   // extent is reset properly.
125   virtual void UpdateDisplayExtent();
126   
127   // Description:
128   // Return the minimum and maximum slice values (depending on the orientation
129   // this can be in X, Y or Z).
130   virtual int GetSliceMin();
131   virtual int GetSliceMax();
132   virtual void GetSliceRange(int range[2])
133     { this->GetSliceRange(range[0], range[1]); }
134   virtual void GetSliceRange(int &min, int &max);
135   virtual int* GetSliceRange();
136   
137   // Description:
138   // Set window and level for mapping pixels to colors.
139   virtual double GetColorWindow();
140   virtual double GetColorLevel();
141   virtual void SetColorWindow(double s);
142   virtual void SetColorLevel(double s);
143
144   // Description:
145   // These are here when using a Tk window.
146   virtual void SetDisplayId(void *a);
147   virtual void SetWindowId(void *a);
148   virtual void SetParentId(void *a);
149   
150   // Description:
151   // Set/Get the position in screen coordinates of the rendering window.
152   virtual int* GetPosition();
153   virtual void SetPosition(int a,int b);
154   virtual void SetPosition(int a[2]) { this->SetPosition(a[0],a[1]); }
155   
156   // Description:
157   // Set/Get the size of the window in screen coordinates in pixels.
158   virtual int* GetSize();
159   virtual void SetSize(int a, int b);
160   virtual void SetSize(int a[2]) { this->SetSize(a[0],a[1]); }
161   
162   // Description:
163   // Get the internal render window, renderer, image actor, and
164   // image map instances.
165   vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
166   vtkGetObjectMacro(Renderer, vtkRenderer);
167   vtkGetObjectMacro(ImageActor,vtkImageActor);
168   vtkGetObjectMacro(WindowLevel,vtkImageMapToWindowLevelColors);
169   vtkGetObjectMacro(InteractorStyle,vtkInteractorStyleImage);
170   
171   // Description:
172   // Set your own renderwindow and renderer
173   virtual void SetRenderWindow(vtkRenderWindow *arg);
174   virtual void SetRenderer(vtkRenderer *arg);
175
176   // Description:
177   // Attach an interactor for the internal render window.
178   virtual void SetupInteractor(vtkRenderWindowInteractor*);
179   
180   // Description:  
181   // Create a window in memory instead of on the screen. This may not
182   // be supported for every type of window and on some windows you may
183   // need to invoke this prior to the first render.
184   virtual void SetOffScreenRendering(int);
185   virtual int GetOffScreenRendering();
186   vtkBooleanMacro(OffScreenRendering,int);
187
188   // Description:
189   // @deprecated Replaced by wxvtkImageViewer2::GetSliceMin() as of VTK 5.0.
190   VTK_LEGACY(int GetWholeZMin());
191
192   // Description:
193   // @deprecated Replaced by wxvtkImageViewer2::GetSliceMax() as of VTK 5.0.
194   VTK_LEGACY(int GetWholeZMax());
195
196   // Description:
197   // @deprecated Replaced by wxvtkImageViewer2::GetSlice() as of VTK 5.0.
198   VTK_LEGACY(int GetZSlice());
199
200   // Description:
201   // @deprecated Replaced by wxvtkImageViewer2::SetSlice() as of VTK 5.0.
202   VTK_LEGACY(void SetZSlice(int));
203
204 protected:
205   wxvtkImageViewer2();
206   ~wxvtkImageViewer2();
207
208   virtual void InstallPipeline();
209   virtual void UnInstallPipeline();
210
211   vtkImageMapToWindowLevelColors  *WindowLevel;
212   vtkRenderWindow                 *RenderWindow;
213   vtkRenderer                     *Renderer;
214   vtkImageActor                   *ImageActor;
215   vtkRenderWindowInteractor       *Interactor;
216   vtkInteractorStyleImage         *InteractorStyle;
217
218   int SliceOrientation;
219   int FirstRender;
220   int Slice;
221
222   virtual void UpdateOrientation();
223
224 private:
225   wxvtkImageViewer2(const wxvtkImageViewer2&);  // Not implemented.
226   void operator=(const wxvtkImageViewer2&);  // Not implemented.
227 };
228
229 #endif
230
231