VTK  9.1.0
vtkVideoSource.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVideoSource.h
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 =========================================================================*/
32 #ifndef vtkVideoSource_h
33 #define vtkVideoSource_h
34 
35 #include "vtkIOVideoModule.h" // For export macro
36 #include "vtkImageAlgorithm.h"
37 
38 #include <mutex> // for std::mutex
39 
40 class vtkTimerLog;
41 class vtkMultiThreader;
42 class vtkScalarsToColors;
43 
44 class VTKIOVIDEO_EXPORT vtkVideoSource : public vtkImageAlgorithm
45 {
46 public:
47  static vtkVideoSource* New();
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
55  virtual void Record();
56 
61  virtual void Play();
62 
66  virtual void Stop();
67 
73  virtual void Rewind();
74 
79  virtual void FastForward();
80 
85  virtual void Seek(int n);
86 
90  virtual void Grab();
91 
93 
97  vtkGetMacro(Recording, int);
99 
101 
105  vtkGetMacro(Playing, int);
107 
109 
117  virtual void SetFrameSize(int x, int y, int z);
118  virtual void SetFrameSize(int dim[3]) { this->SetFrameSize(dim[0], dim[1], dim[2]); }
119  vtkGetVector3Macro(FrameSize, int);
121 
123 
126  virtual void SetFrameRate(float rate);
127  vtkGetMacro(FrameRate, float);
129 
131 
135  virtual void SetOutputFormat(int format);
136  void SetOutputFormatToLuminance() { this->SetOutputFormat(VTK_LUMINANCE); }
137  void SetOutputFormatToRGB() { this->SetOutputFormat(VTK_RGB); }
138  void SetOutputFormatToRGBA() { this->SetOutputFormat(VTK_RGBA); }
139  vtkGetMacro(OutputFormat, int);
141 
143 
147  virtual void SetFrameBufferSize(int FrameBufferSize);
148  vtkGetMacro(FrameBufferSize, int);
150 
152 
158  vtkSetMacro(NumberOfOutputFrames, int);
159  vtkGetMacro(NumberOfOutputFrames, int);
161 
163 
167  vtkBooleanMacro(AutoAdvance, vtkTypeBool);
168  vtkSetMacro(AutoAdvance, vtkTypeBool);
169  vtkGetMacro(AutoAdvance, vtkTypeBool);
171 
173 
179  virtual void SetClipRegion(int r[6]) { this->SetClipRegion(r[0], r[1], r[2], r[3], r[4], r[5]); }
180  virtual void SetClipRegion(int x0, int x1, int y0, int y1, int z0, int z1);
181  vtkGetVector6Macro(ClipRegion, int);
183 
185 
194  vtkSetVector6Macro(OutputWholeExtent, int);
195  vtkGetVector6Macro(OutputWholeExtent, int);
197 
199 
203  vtkSetVector3Macro(DataSpacing, double);
204  vtkGetVector3Macro(DataSpacing, double);
206 
208 
212  vtkSetVector3Macro(DataOrigin, double);
213  vtkGetVector3Macro(DataOrigin, double);
215 
217 
222  vtkSetMacro(Opacity, float);
223  vtkGetMacro(Opacity, float);
225 
227 
231  vtkGetMacro(FrameCount, int);
232  vtkSetMacro(FrameCount, int);
234 
236 
240  vtkGetMacro(FrameIndex, int);
242 
249  virtual double GetFrameTimeStamp(int frame);
250 
256  double GetFrameTimeStamp() { return this->FrameTimeStamp; }
257 
259 
263  virtual void Initialize();
264  virtual int GetInitialized() { return this->Initialized; }
266 
272  virtual void ReleaseSystemResources();
273 
279  virtual void InternalGrab();
280 
282 
286  void SetStartTimeStamp(double t) { this->StartTimeStamp = t; }
287  double GetStartTimeStamp() { return this->StartTimeStamp; }
289 
290 protected:
292  ~vtkVideoSource() override;
294 
296 
297  int FrameSize[3];
298  int ClipRegion[6];
299  int OutputWholeExtent[6];
300  double DataSpacing[3];
301  double DataOrigin[3];
303  // set according to the OutputFormat
305  // The FrameOutputExtent is the WholeExtent for a single output frame.
306  // It is initialized in ExecuteInformation.
307  int FrameOutputExtent[6];
308 
309  // save this information from the output so that we can see if the
310  // output scalars have changed
312  int LastOutputExtent[6];
313 
315  int Playing;
316  float FrameRate;
318 
321 
324 
325  float Opacity;
326 
327  // true if Execute() must apply a vertical flip to each frame
329 
330  // set if output needs to be cleared to be cleared before being written
332 
333  // An example of asynchrony
336 
337  // A mutex for the frame buffer: must be applied when any of the
338  // below data is modified.
339  std::mutex FrameBufferMutex;
340 
341  // set according to the needs of the hardware:
342  // number of bits per framebuffer pixel
344  // byte alignment of each row in the framebuffer
346  // FrameBufferExtent is the extent of frame after it has been clipped
347  // with ClipRegion. It is initialized in CheckBuffer().
348  int FrameBufferExtent[6];
349 
351 
352  // where the current frame is, note this decreases in time
353  // increasing values are older frames
355 
356  // number of frames from the beginning sort of,
357  // it does wrap, sometimes
359 
360  void** FrameBuffer;
362 
364 
367  virtual void UpdateFrameBuffer();
368  virtual void AdvanceFrameBuffer(int n);
370  // if some component conversion is required, it is done here:
371  virtual void UnpackRasterLine(char* outPtr, char* rowPtr, int start, int count);
373 
374 private:
375  vtkVideoSource(const vtkVideoSource&) = delete;
376  void operator=(const vtkVideoSource&) = delete;
377 };
378 
379 #endif
vtkVideoSource::StartTimeStamp
double StartTimeStamp
Definition: vtkVideoSource.h:319
vtkVideoSource::Play
virtual void Play()
Play through the 'tape' sequentially at the specified frame rate.
vtkVideoSource::Opacity
float Opacity
Definition: vtkVideoSource.h:325
vtkVideoSource::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
These methods can be overridden in subclasses.
vtkVideoSource::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVideoSource::FrameCount
int FrameCount
Definition: vtkVideoSource.h:317
vtkVideoSource::FrameTimeStamp
double FrameTimeStamp
Definition: vtkVideoSource.h:320
vtkVideoSource::PlayerThreader
vtkMultiThreader * PlayerThreader
Definition: vtkVideoSource.h:334
vtkVideoSource::SetStartTimeStamp
void SetStartTimeStamp(double t)
And internal variable which marks the beginning of a Record session.
Definition: vtkVideoSource.h:286
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:145
vtkVideoSource::Rewind
virtual void Rewind()
Rewind to the frame with the earliest timestamp.
vtkVideoSource::InternalGrab
virtual void InternalGrab()
The internal function which actually does the grab.
vtkImageAlgorithm.h
vtkVideoSource::GetStartTimeStamp
double GetStartTimeStamp()
And internal variable which marks the beginning of a Record session.
Definition: vtkVideoSource.h:287
vtkVideoSource::FrameIndex
int FrameIndex
Definition: vtkVideoSource.h:358
vtkImageAlgorithm
Generic algorithm superclass for image algs.
Definition: vtkImageAlgorithm.h:57
vtkVideoSource::UnpackRasterLine
virtual void UnpackRasterLine(char *outPtr, char *rowPtr, int start, int count)
These methods can be overridden in subclasses.
vtkVideoSource::Stop
virtual void Stop()
Stop recording or playing.
VTK_LUMINANCE
#define VTK_LUMINANCE
Definition: vtkSystemIncludes.h:84
vtkVideoSource::FrameBufferIndex
int FrameBufferIndex
Definition: vtkVideoSource.h:354
vtkMultiThreader
A class for performing multithreaded execution.
Definition: vtkMultiThreader.h:77
vtkVideoSource::Initialized
int Initialized
Definition: vtkVideoSource.h:295
vtkVideoSource::SetFrameBufferSize
virtual void SetFrameBufferSize(int FrameBufferSize)
Set size of the frame buffer, i.e.
vtkVideoSource::FrameBufferSize
int FrameBufferSize
Definition: vtkVideoSource.h:350
vtkVideoSource::PlayerThreadId
int PlayerThreadId
Definition: vtkVideoSource.h:335
vtkVideoSource::FrameBuffer
void ** FrameBuffer
Definition: vtkVideoSource.h:360
VTK_RGB
#define VTK_RGB
Definition: vtkSystemIncludes.h:86
vtkVideoSource::ReleaseSystemResources
virtual void ReleaseSystemResources()
Release the video driver.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkVideoSource::RequestInformation
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
vtkVideoSource::Playing
int Playing
Definition: vtkVideoSource.h:315
vtkVideoSource::New
static vtkVideoSource * New()
vtkVideoSource::SetOutputFormat
virtual void SetOutputFormat(int format)
Set the output format.
vtkVideoSource::NumberOfScalarComponents
int NumberOfScalarComponents
Definition: vtkVideoSource.h:304
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:109
vtkVideoSource::Grab
virtual void Grab()
Grab a single video frame.
vtkVideoSource::GetFrameTimeStamp
double GetFrameTimeStamp()
Get a time stamp in seconds (resolution of milliseconds) for the Output.
Definition: vtkVideoSource.h:256
vtkVideoSource::AutoAdvance
vtkTypeBool AutoAdvance
Definition: vtkVideoSource.h:322
vtkVideoSource::NumberOfOutputFrames
int NumberOfOutputFrames
Definition: vtkVideoSource.h:323
vtkVideoSource::FrameBufferBitsPerPixel
int FrameBufferBitsPerPixel
Definition: vtkVideoSource.h:343
vtkVideoSource::SetOutputFormatToLuminance
void SetOutputFormatToLuminance()
Set the output format.
Definition: vtkVideoSource.h:136
vtkVideoSource::AdvanceFrameBuffer
virtual void AdvanceFrameBuffer(int n)
These methods can be overridden in subclasses.
vtkVideoSource::SetOutputFormatToRGBA
void SetOutputFormatToRGBA()
Set the output format.
Definition: vtkVideoSource.h:138
vtkVideoSource::OutputNeedsInitialization
int OutputNeedsInitialization
Definition: vtkVideoSource.h:331
vtkVideoSource::Seek
virtual void Seek(int n)
Seek forwards or backwards by the specified number of frames (positive is forward,...
vtkVideoSource::SetClipRegion
virtual void SetClipRegion(int x0, int x1, int y0, int y1, int z0, int z1)
Set the clip rectangle for the frames.
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:183
vtkVideoSource::OutputFormat
int OutputFormat
Definition: vtkVideoSource.h:302
vtkTimerLog
Timer support and logging.
Definition: vtkTimerLog.h:199
vtkVideoSource::FastForward
virtual void FastForward()
FastForward to the last frame that was recorded (i.e.
vtkVideoSource::SetFrameRate
virtual void SetFrameRate(float rate)
Request a particular frame rate (default 30 frames per second).
vtkVideoSource::vtkVideoSource
vtkVideoSource()
vtkVideoSource::SetFrameSize
virtual void SetFrameSize(int x, int y, int z)
Set the full-frame size.
vtkVideoSource::FrameBufferMutex
std::mutex FrameBufferMutex
Definition: vtkVideoSource.h:339
vtkVideoSource::Record
virtual void Record()
Record incoming video at the specified FrameRate.
VTK_RGBA
#define VTK_RGBA
Definition: vtkSystemIncludes.h:87
vtkVideoSource::GetInitialized
virtual int GetInitialized()
Initialize the hardware.
Definition: vtkVideoSource.h:264
vtkVideoSource::FrameBufferRowAlignment
int FrameBufferRowAlignment
Definition: vtkVideoSource.h:345
vtkVideoSource::FlipFrames
int FlipFrames
Definition: vtkVideoSource.h:328
vtkVideoSource::LastNumberOfScalarComponents
int LastNumberOfScalarComponents
Definition: vtkVideoSource.h:311
vtkVideoSource::FrameBufferTimeStamps
double * FrameBufferTimeStamps
Definition: vtkVideoSource.h:361
vtkVideoSource::~vtkVideoSource
~vtkVideoSource() override
vtkVideoSource::SetFrameSize
virtual void SetFrameSize(int dim[3])
Set the full-frame size.
Definition: vtkVideoSource.h:118
vtkVideoSource::GetFrameTimeStamp
virtual double GetFrameTimeStamp(int frame)
Get a time stamp in seconds (resolution of milliseconds) for a video frame.
vtkVideoSource::Recording
int Recording
Definition: vtkVideoSource.h:314
vtkVideoSource::Initialize
virtual void Initialize()
Initialize the hardware.
vtkVideoSource::FrameRate
float FrameRate
Definition: vtkVideoSource.h:316
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkVideoSource::SetClipRegion
virtual void SetClipRegion(int r[6])
Set the clip rectangle for the frames.
Definition: vtkVideoSource.h:179
vtkVideoSource::UpdateFrameBuffer
virtual void UpdateFrameBuffer()
These methods can be overridden in subclasses.
vtkVideoSource::SetOutputFormatToRGB
void SetOutputFormatToRGB()
Set the output format.
Definition: vtkVideoSource.h:137
vtkVideoSource
Superclass of video input devices for VTK.
Definition: vtkVideoSource.h:45