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
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkWindowToImageFilter.h,v $
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.
=========================================================================*/
// .NAME vtkWindowToImageFilter - Use a vtkWindow as input to image pipeline
// .SECTION Description
// 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.
//
// .SECTION Caveats
// 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.
//
// To force an update of the output image, call vtkWindowToImageFilter's
// Modified method after rendering to the window.
//
// 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.
//
// 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.
// .SECTION see also
// vtkWindow
#ifndef __vtkWindowToImageFilter_h
#define __vtkWindowToImageFilter_h
#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 VTK_RENDERING_EXPORT vtkWindowToImageFilter : public vtkAlgorithm
{
public:
static vtkWindowToImageFilter *New();
vtkTypeRevisionMacro(vtkWindowToImageFilter,vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Indicates what renderer to get the pixel data from.
void SetInput(vtkWindow *input);
// Description:
// Returns which renderer is being used as the source for the pixel data.
vtkGetObjectMacro(Input,vtkWindow);
// Description:
// The magnification of the current render window
vtkSetClampMacro(Magnification,int,1,2048);
vtkGetMacro(Magnification,int);
// Description:
// 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);
// Description:
// Set/get whether to re-render the input window. (This option makes no
// difference if Magnification > 1.)
vtkBooleanMacro(ShouldRerender, int);
vtkSetMacro(ShouldRerender, int);
vtkGetMacro(ShouldRerender, int);
//Description:
//Set/get the extents to be used to generate the image. (This option
//does not work if Magnification > 1.)
vtkSetVector4Macro(Viewport,double);
vtkGetVectorMacro(Viewport,double,4);
//Description:
//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).
vtkSetMacro(InputBufferType, int);
vtkGetMacro(InputBufferType, int);
void SetInputBufferTypeToRGB() {this->SetInputBufferType(VTK_RGB);};
void SetInputBufferTypeToRGBA() {this->SetInputBufferType(VTK_RGBA);};
void SetInputBufferTypeToZBuffer() {this->SetInputBufferType(VTK_ZBUFFER);};
// Description:
// Get the output data object for a port on this algorithm.
vtkImageData* GetOutput();
// Description:
// 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;
void RequestData(vtkInformation *,
vtkInformationVector **, vtkInformationVector *);
virtual void RequestInformation (vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
// see algorithm for more info
virtual int FillOutputPortInformation(int port, vtkInformation* info);
private:
vtkWindowToImageFilter(const vtkWindowToImageFilter&); // Not implemented.
void operator=(const vtkWindowToImageFilter&); // Not implemented.
};
#endif
|