OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkVideoSource.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkVideoSource.h,v $
5   Language:  C++
6   Date:      $Date: 2002/09/11 17:46:32 $
7   Version:   $Revision: 1.25 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
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.
16
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.
26 // .SECTION Caveats
27 // You must call the ReleaseSystemResources() method before the application
28 // exits.  Otherwise the application might hang while trying to exit.
29 // .SECTION See Also
30 // vtkWin32VideoSource vtkMILVideoSource
31
32 #ifndef __vtkVideoSource_h
33 #define __vtkVideoSource_h
34
35 #include "vtkImageSource.h"
36
37 class vtkTimerLog;
38 class vtkCriticalSection;
39 class vtkMultiThreader;
40 class vtkScalarsToColors;
41
42 class VTK_HYBRID_EXPORT vtkVideoSource : public vtkImageSource
43 {
44 public:
45   static vtkVideoSource *New();
46   vtkTypeRevisionMacro(vtkVideoSource,vtkImageSource);
47   void PrintSelf(ostream& os, vtkIndent indent);   
48
49   // Description:
50   // Record incoming video at the specified FrameRate.  The recording
51   // continues indefinitely until Stop() is called. 
52   virtual void Record();
53
54   // Description:
55   // Play through the 'tape' sequentially at the specified frame rate.
56   // If you have just finished Recoding, you should call Rewind() first.
57   virtual void Play();
58
59   // Description:
60   // Stop recording or playing.
61   virtual void Stop();
62
63   // Description:
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();
68
69   // Description:
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();
73
74   // Description:
75   // Seek forwards or backwards by the specified number of frames
76   // (positive is forward, negative is backward).
77   virtual void Seek(int n); 
78
79   // Description:
80   // Grab a single video frame.
81   virtual void Grab();
82
83   // Description:
84   // Are we in record mode? (record mode and play mode are mutually
85   // exclusive).
86   vtkGetMacro(Recording,int);
87
88   // Description:
89   // Are we in play mode? (record mode and play mode are mutually
90   // exclusive).
91   vtkGetMacro(Playing,int);
92
93   // Description:
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);
104
105   // Description:
106   // Request a particular frame rate (default 30 frames per second).
107   virtual void SetFrameRate(float rate);
108   vtkGetMacro(FrameRate,float);
109
110   // Description:
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);
118
119   // Description:
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);
124
125   // Description:
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.
129   // Default: 1
130   vtkSetMacro(NumberOfOutputFrames,int);
131   vtkGetMacro(NumberOfOutputFrames,int);
132
133   // Description:
134   // Set whether to automatically advance the buffer before each grab. 
135   // Default: on
136   vtkBooleanMacro(AutoAdvance,int);
137   vtkSetMacro(AutoAdvance,int)
138   vtkGetMacro(AutoAdvance,int);
139
140   // Description:
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);
149
150   // Description:
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);
160   
161   // Description:
162   // Set/Get the pixel spacing. 
163   // Default: (1.0,1.0,1.0)
164   vtkSetVector3Macro(DataSpacing,float);
165   vtkGetVector3Macro(DataSpacing,float);
166   
167   // Description:
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);
172
173   // Description:
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);  
179
180   // Description:
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);
185
186   // Description:
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);
190
191   // Description:
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);
197
198   // Description:
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; };
203
204   // Description:
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; };
209
210   // Description:
211   // Release the video driver.  This method must be called before
212   // application exit, or else the application might hang during
213   // exit.  
214   virtual void ReleaseSystemResources();
215
216   // Description:
217   // The internal function which actually does the grab.  You will
218   // definitely want to override this if you develop a vtkVideoSource
219   // subclass. 
220   virtual void InternalGrab();
221
222   // Description:
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; };
227
228 protected:
229   vtkVideoSource();
230   ~vtkVideoSource();
231   void ExecuteInformation();
232
233   int Initialized;
234
235   int FrameSize[3];
236   int ClipRegion[6];
237   int OutputWholeExtent[6];
238   float DataSpacing[3];
239   float DataOrigin[3];
240   int OutputFormat;
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];
246
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];
251
252   int Recording;
253   int Playing;
254   float FrameRate;
255   int FrameCount;
256   int FrameIndex;
257   double StartTimeStamp;
258   double FrameTimeStamp;
259
260   int AutoAdvance;
261   int NumberOfOutputFrames;
262
263   float Opacity;
264
265   // true if Execute() must apply a vertical flip to each frame
266   int FlipFrames;
267
268   // set if output needs to be cleared to be cleared before being written
269   int OutputNeedsInitialization;
270
271   // An example of asynchrony
272   vtkMultiThreader *PlayerThreader;
273   int PlayerThreadId;
274
275   // A mutex for the frame buffer: must be applied when any of the
276   // below data is modified.
277   vtkCriticalSection *FrameBufferMutex;
278
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];
287
288   int FrameBufferSize;
289   int FrameBufferIndex;
290   void **FrameBuffer;
291   double *FrameBufferTimeStamps;
292
293   // Description:
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);
301
302 private:
303   vtkVideoSource(const vtkVideoSource&);  // Not implemented.
304   void operator=(const vtkVideoSource&);  // Not implemented.
305 };
306
307 #endif
308
309
310
311
312