forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkWindowToImageFilter.h
202 lines (173 loc) · 6.46 KB
/
vtkWindowToImageFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWindowToImageFilter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkWindowToImageFilter
* @brief Use a vtkWindow as input to image pipeline
*
* vtkWindowToImageFilter provides methods needed to read the data in
* a vtkWindow and use it as input to the imaging pipeline. This is
* useful for saving an image to a file for example. The window can
* be read as either RGB or RGBA pixels; in addition, the depth buffer
* can also be read. RGB and RGBA pixels are of type unsigned char,
* while Z-Buffer data is returned as floats. Use this filter
* to convert RenderWindows or ImageWindows to an image format.
*
* @warning
* A vtkWindow doesn't behave like other parts of the VTK pipeline: its
* modification time doesn't get updated when an image is rendered. As a
* result, naive use of vtkWindowToImageFilter will produce an image of
* the first image that the window rendered, but which is never updated
* on subsequent window updates. This behavior is unexpected and in
* general undesirable.
*
* @warning
* To force an update of the output image, call vtkWindowToImageFilter's
* Modified method after rendering to the window.
*
* @warning
* In VTK versions 4 and later, this filter is part of the canonical
* way to output an image of a window to a file (replacing the
* obsolete SaveImageAsPPM method for vtkRenderWindows that existed in
* 3.2 and earlier). Connect this filter to the output of the window,
* and filter's output to a writer such as vtkPNGWriter.
*
* @warning
* Reading back alpha planes is dependent on the correct operation of
* the render window's GetRGBACharPixelData method, which in turn is
* dependent on the configuration of the window's alpha planes. As of
* VTK 4.4+, machine-independent behavior is not automatically
* assured because of these dependencies.
*
* @sa
* vtkRendererSource vtkRendererPointCloudSource vtkWindow
* vtkRenderLargeImage
*/
#ifndef vtkWindowToImageFilter_h
#define vtkWindowToImageFilter_h
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkAlgorithm.h"
#include "vtkImageData.h" // makes things a bit easier
// VTK_RGB and VTK_RGBA are defined in system includes
#define VTK_ZBUFFER 5
class vtkWindow;
class vtkWTI2DHelperClass;
class VTKRENDERINGCORE_EXPORT vtkWindowToImageFilter : public vtkAlgorithm
{
public:
static vtkWindowToImageFilter *New();
vtkTypeMacro(vtkWindowToImageFilter,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
/**
* Indicates what renderer to get the pixel data from. Initial value is 0.
*/
void SetInput(vtkWindow *input);
//@{
/**
* Returns which renderer is being used as the source for the pixel data.
* Initial value is 0.
*/
vtkGetObjectMacro(Input,vtkWindow);
//@}
//@{
/**
* The magnification of the current render window. Initial value is 1.
*/
vtkSetClampMacro(Magnification,int,1,2048);
vtkGetMacro(Magnification,int);
//@}
//@{
/**
* When this->Magnification > 1, this class render the full image in tiles.
* Sometimes that results in artificial artifacts at internal tile seams.
* To overcome this issue, set this flag to true.
*/
vtkSetMacro(FixBoundary, bool);
vtkGetMacro(FixBoundary, bool);
vtkBooleanMacro(FixBoundary, bool);
//@}
//@{
/**
* Set/Get the flag that determines which buffer to read from.
* The default is to read from the front buffer.
*/
vtkBooleanMacro(ReadFrontBuffer, int);
vtkGetMacro(ReadFrontBuffer, int);
vtkSetMacro(ReadFrontBuffer, int);
//@}
//@{
/**
* Set/get whether to re-render the input window. Initial value is true.
* (This option makes no difference if Magnification > 1.)
*/
vtkBooleanMacro(ShouldRerender, int);
vtkSetMacro(ShouldRerender, int);
vtkGetMacro(ShouldRerender, int);
//@}
//@{
/**
* Set/get the extents to be used to generate the image. Initial value is
* {0,0,1,1} (This option does not work if Magnification > 1.)
*/
void SetViewport(double, double, double, double);
void SetViewport(double*);
vtkGetVectorMacro(Viewport,double,4);
//@}
//@{
/**
* Set/get the window buffer from which data will be read. Choices
* include VTK_RGB (read the color image from the window), VTK_RGBA
* (same, but include the alpha channel), and VTK_ZBUFFER (depth
* buffer, returned as a float array). Initial value is VTK_RGB.
*/
vtkSetMacro(InputBufferType, int);
vtkGetMacro(InputBufferType, int);
void SetInputBufferTypeToRGB() {this->SetInputBufferType(VTK_RGB);};
void SetInputBufferTypeToRGBA() {this->SetInputBufferType(VTK_RGBA);};
void SetInputBufferTypeToZBuffer() {this->SetInputBufferType(VTK_ZBUFFER);};
//@}
/**
* Get the output data object for a port on this algorithm.
*/
vtkImageData* GetOutput();
/**
* see vtkAlgorithm for details
*/
virtual int ProcessRequest(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
protected:
vtkWindowToImageFilter();
~vtkWindowToImageFilter();
// vtkWindow is not a vtkDataObject, so we need our own ivar.
vtkWindow *Input;
int Magnification;
int ReadFrontBuffer;
int ShouldRerender;
double Viewport[4];
int InputBufferType;
bool FixBoundary;
void RequestData(vtkInformation *,
vtkInformationVector **, vtkInformationVector *);
virtual void RequestInformation (vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
// see algorithm for more info
virtual int FillOutputPortInformation(int port, vtkInformation* info);
// The following was extracted from vtkRenderLargeImage, and patch to handle viewports
void Rescale2DActors();
void Shift2DActors(int x, int y);
void Restore2DActors();
vtkWTI2DHelperClass *StoredData;
private:
vtkWindowToImageFilter(const vtkWindowToImageFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkWindowToImageFilter&) VTK_DELETE_FUNCTION;
};
#endif