1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: wxvtkImageViewer2.h,v $
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
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.
34 // It is possible to mix images and geometry, using the methods:
36 // viewer->SetInput( myImage );
37 // viewer->GetRenderer()->AddActor( myActor );
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 .
48 // Note that pressing 'r' will reset the window/level and pressing
49 // shift+'r' or control+'r' will reset the camera.
52 // vtkRenderWindow vtkRenderer vtkImageActor vtkImageMapToWindowLevelColors
54 #ifndef __wxvtkImageViewer2_h
55 #define __wxvtkImageViewer2_h
57 #include "vtkObject.h"
59 class vtkAlgorithmOutput;
62 class vtkImageMapToWindowLevelColors;
63 class vtkInteractorStyleImage;
64 class vtkRenderWindow;
66 class vtkRenderWindowInteractor;
68 class /*VTK_RENDERING_EXPORT*/ wxvtkImageViewer2 : public vtkObject
71 static wxvtkImageViewer2 *New();
72 vtkTypeRevisionMacro(wxvtkImageViewer2,vtkObject);
73 void PrintSelf(ostream& os, vtkIndent indent);
76 // Get the name of rendering window.
77 virtual const char *GetWindowName();
80 // Render the resulting image.
81 virtual void Render(void);
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);
90 // Set/get the slice orientation
94 SLICE_ORIENTATION_YZ = 0,
95 SLICE_ORIENTATION_XZ = 1,
96 SLICE_ORIENTATION_XY = 2
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); };
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);
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();
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();
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);
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);
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]); }
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]); }
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);
172 // Set your own renderwindow and renderer
173 virtual void SetRenderWindow(vtkRenderWindow *arg);
174 virtual void SetRenderer(vtkRenderer *arg);
177 // Attach an interactor for the internal render window.
178 virtual void SetupInteractor(vtkRenderWindowInteractor*);
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);
189 // @deprecated Replaced by wxvtkImageViewer2::GetSliceMin() as of VTK 5.0.
190 VTK_LEGACY(int GetWholeZMin());
193 // @deprecated Replaced by wxvtkImageViewer2::GetSliceMax() as of VTK 5.0.
194 VTK_LEGACY(int GetWholeZMax());
197 // @deprecated Replaced by wxvtkImageViewer2::GetSlice() as of VTK 5.0.
198 VTK_LEGACY(int GetZSlice());
201 // @deprecated Replaced by wxvtkImageViewer2::SetSlice() as of VTK 5.0.
202 VTK_LEGACY(void SetZSlice(int));
206 ~wxvtkImageViewer2();
208 virtual void InstallPipeline();
209 virtual void UnInstallPipeline();
211 vtkImageMapToWindowLevelColors *WindowLevel;
212 vtkRenderWindow *RenderWindow;
213 vtkRenderer *Renderer;
214 vtkImageActor *ImageActor;
215 vtkRenderWindowInteractor *Interactor;
216 vtkInteractorStyleImage *InteractorStyle;
218 int SliceOrientation;
222 virtual void UpdateOrientation();
225 wxvtkImageViewer2(const wxvtkImageViewer2&); // Not implemented.
226 void operator=(const wxvtkImageViewer2&); // Not implemented.