1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkVideoSource.h,v $
6 Date: $Date: 2002/09/11 17:46:32 $
7 Version: $Revision: 1.25 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkVideoSource - Superclass of video input devices for VTK
19 // .SECTION Description
20 // vtkVideoSource is a superclass for video input interfaces for VTK.
21 // The goal is to provide an interface which is very similar to the
22 // interface of a VCR, where the 'tape' is an internal frame buffer
23 // capable of holding a preset number of video frames. Specialized
24 // versions of this class record input from various video input sources.
25 // This base class records input from a noise source.
27 // You must call the ReleaseSystemResources() method before the application
28 // exits. Otherwise the application might hang while trying to exit.
30 // vtkWin32VideoSource vtkMILVideoSource
32 #ifndef __vtkVideoSource_h
33 #define __vtkVideoSource_h
35 #include "vtkImageSource.h"
38 class vtkCriticalSection;
39 class vtkMultiThreader;
40 class vtkScalarsToColors;
42 class VTK_HYBRID_EXPORT vtkVideoSource : public vtkImageSource
45 static vtkVideoSource *New();
46 vtkTypeRevisionMacro(vtkVideoSource,vtkImageSource);
47 void PrintSelf(ostream& os, vtkIndent indent);
50 // Record incoming video at the specified FrameRate. The recording
51 // continues indefinitely until Stop() is called.
52 virtual void Record();
55 // Play through the 'tape' sequentially at the specified frame rate.
56 // If you have just finished Recoding, you should call Rewind() first.
60 // Stop recording or playing.
64 // Rewind to the frame with the earliest timestamp. Record operations
65 // will start on the following frame, therefore if you want to re-record
66 // over this frame you must call Seek(-1) before calling Grab() or Record().
67 virtual void Rewind();
70 // FastForward to the last frame that was recorded (i.e. to the frame
71 // that has the most recent timestamp).
72 virtual void FastForward();
75 // Seek forwards or backwards by the specified number of frames
76 // (positive is forward, negative is backward).
77 virtual void Seek(int n);
80 // Grab a single video frame.
84 // Are we in record mode? (record mode and play mode are mutually
86 vtkGetMacro(Recording,int);
89 // Are we in play mode? (record mode and play mode are mutually
91 vtkGetMacro(Playing,int);
94 // Set the full-frame size. This must be an allowed size for the device,
95 // the device may either refuse a request for an illegal frame size or
96 // automatically choose a new frame size.
97 // The default is usually 320x240x1, but can be device specific.
98 // The 'depth' should always be 1 (unless you have a device that
99 // can handle 3D acquisition).
100 virtual void SetFrameSize(int x, int y, int z);
101 virtual void SetFrameSize(int dim[3]) {
102 this->SetFrameSize(dim[0], dim[1], dim[2]); };
103 vtkGetVector3Macro(FrameSize,int);
106 // Request a particular frame rate (default 30 frames per second).
107 virtual void SetFrameRate(float rate);
108 vtkGetMacro(FrameRate,float);
111 // Set the output format. This must be appropriate for device,
112 // usually only VTK_LUMINANCE, VTK_RGB, and VTK_RGBA are supported.
113 virtual void SetOutputFormat(int format);
114 void SetOutputFormatToLuminance() { this->SetOutputFormat(VTK_LUMINANCE); };
115 void SetOutputFormatToRGB() { this->SetOutputFormat(VTK_RGB); };
116 void SetOutputFormatToRGBA() { this->SetOutputFormat(VTK_RGBA); };
117 vtkGetMacro(OutputFormat,int);
120 // Set size of the frame buffer, i.e. the number of frames that
121 // the 'tape' can store.
122 virtual void SetFrameBufferSize(int FrameBufferSize);
123 vtkGetMacro(FrameBufferSize,int);
126 // Set the number of frames to copy to the output on each execute.
127 // The frames will be concatenated along the Z dimension, with the
128 // most recent frame first.
130 vtkSetMacro(NumberOfOutputFrames,int);
131 vtkGetMacro(NumberOfOutputFrames,int);
134 // Set whether to automatically advance the buffer before each grab.
136 vtkBooleanMacro(AutoAdvance,int);
137 vtkSetMacro(AutoAdvance,int)
138 vtkGetMacro(AutoAdvance,int);
141 // Set the clip rectangle for the frames. The video will be clipped
142 // before it is copied into the framebuffer. Changing the ClipRegion
143 // will destroy the current contents of the framebuffer.
144 // The default ClipRegion is (0,VTK_INT_MAX,0,VTK_INT_MAX,0,VTK_INT_MAX).
145 virtual void SetClipRegion(int r[6]) {
146 this->SetClipRegion(r[0],r[1],r[2],r[3],r[4],r[5]); };
147 virtual void SetClipRegion(int x0, int x1, int y0, int y1, int z0, int z1);
148 vtkGetVector6Macro(ClipRegion,int);
151 // Get/Set the WholeExtent of the output. This can be used to either
152 // clip or pad the video frame. This clipping/padding is done when
153 // the frame is copied to the output, and does not change the contents
154 // of the framebuffer. This is useful e.g. for expanding
155 // the output size to a power of two for texture mapping. The
156 // default is (0,-1,0,-1,0,-1) which causes the entire frame to be
157 // copied to the output.
158 vtkSetVector6Macro(OutputWholeExtent,int);
159 vtkGetVector6Macro(OutputWholeExtent,int);
162 // Set/Get the pixel spacing.
163 // Default: (1.0,1.0,1.0)
164 vtkSetVector3Macro(DataSpacing,float);
165 vtkGetVector3Macro(DataSpacing,float);
168 // Set/Get the coordinates of the lower, left corner of the frame.
169 // Default: (0.0,0.0,0.0)
170 vtkSetVector3Macro(DataOrigin,float);
171 vtkGetVector3Macro(DataOrigin,float);
174 // For RGBA output only (4 scalar components), set the opacity. This
175 // will not modify the existing contents of the framebuffer, only
176 // subsequently grabbed frames.
177 vtkSetMacro(Opacity,float);
178 vtkGetMacro(Opacity,float);
181 // This value is incremented each time a frame is grabbed.
182 // reset it to zero (or any other value) at any time.
183 vtkGetMacro(FrameCount, int);
184 vtkSetMacro(FrameCount, int);
187 // Get the frame index relative to the 'beginning of the tape'. This
188 // value wraps back to zero if it increases past the FrameBufferSize.
189 vtkGetMacro(FrameIndex, int);
192 // Get a time stamp in seconds (resolution of milliseconds) for
193 // a video frame. Time began on Jan 1, 1970. You can specify
194 // a number (negative or positive) to specify the position of the
195 // video frame relative to the current frame.
196 virtual double GetFrameTimeStamp(int frame);
199 // Get a time stamp in seconds (resolution of milliseconds) for
200 // the Output. Time began on Jan 1, 1970. This timestamp is only
201 // valid after the Output has been Updated.
202 double GetFrameTimeStamp() { return this->FrameTimeStamp; };
205 // Initialize the hardware. This is called automatically
206 // on the first Update or Grab.
207 virtual void Initialize();
208 virtual int GetInitialized() { return this->Initialized; };
211 // Release the video driver. This method must be called before
212 // application exit, or else the application might hang during
214 virtual void ReleaseSystemResources();
217 // The internal function which actually does the grab. You will
218 // definitely want to override this if you develop a vtkVideoSource
220 virtual void InternalGrab();
223 // And internal variable which marks the beginning of a Record session.
224 // These methods are for internal use only.
225 void SetStartTimeStamp(double t) { this->StartTimeStamp = t; };
226 double GetStartTimeStamp() { return this->StartTimeStamp; };
231 void ExecuteInformation();
237 int OutputWholeExtent[6];
238 float DataSpacing[3];
241 // set according to the OutputFormat
242 int NumberOfScalarComponents;
243 // The FrameOutputExtent is the WholeExtent for a single output frame.
244 // It is initialized in ExecuteInformation.
245 int FrameOutputExtent[6];
247 // save this information from the output so that we can see if the
248 // output scalars have changed
249 int LastNumberOfScalarComponents;
250 int LastOutputExtent[6];
257 double StartTimeStamp;
258 double FrameTimeStamp;
261 int NumberOfOutputFrames;
265 // true if Execute() must apply a vertical flip to each frame
268 // set if output needs to be cleared to be cleared before being written
269 int OutputNeedsInitialization;
271 // An example of asynchrony
272 vtkMultiThreader *PlayerThreader;
275 // A mutex for the frame buffer: must be applied when any of the
276 // below data is modified.
277 vtkCriticalSection *FrameBufferMutex;
279 // set according to the needs of the hardware:
280 // number of bits per framebuffer pixel
281 int FrameBufferBitsPerPixel;
282 // byte alignment of each row in the framebuffer
283 int FrameBufferRowAlignment;
284 // FrameBufferExtent is the extent of frame after it has been clipped
285 // with ClipRegion. It is initialized in CheckBuffer().
286 int FrameBufferExtent[6];
289 int FrameBufferIndex;
291 double *FrameBufferTimeStamps;
294 // These methods can be overridden in subclasses
295 virtual void UpdateFrameBuffer();
296 virtual void AdvanceFrameBuffer(int n);
297 virtual void ExecuteData(vtkDataObject *data);
298 // if some component conversion is required, it is done here:
299 virtual void UnpackRasterLine(char *outPtr, char *rowPtr,
300 int start, int count);
303 vtkVideoSource(const vtkVideoSource&); // Not implemented.
304 void operator=(const vtkVideoSource&); // Not implemented.