1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkVideoIOBase_h 19 #define itkVideoIOBase_h 20 21 #include "itkImageIOBase.h" 22 #include "itkExceptionObject.h" 23 #include "ITKVideoIOExport.h" 24 #include "vnl/vnl_vector.h" 25 26 #include <string> 27 28 namespace itk 29 { 30 /** \class VideoIOBase 31 * \brief Abstract superclass defines video IO interface. 32 * 33 * VideoIOBase is a class that reads and/or writes video data 34 * using a particular external technique or external library (OpenCV, vxl). The 35 * VideoIOBase encapsulates both the reading and writing of data. The 36 * VideoIOBase is used by the VideoFileReader class (to read data) 37 * and the VideoFileWriter (to write data). Normally the user does not directly 38 * manipulate this class directly. 39 * 40 * A Pluggable factory pattern is used. This allows different kinds of 41 * readers to be registered (even at run time) without having to 42 * modify the code in this class. 43 * 44 * \sa VideoFileWriter 45 * \sa VideoFileReader 46 * 47 * \ingroup ITKVideoIO 48 */ 49 class ITKVideoIO_EXPORT VideoIOBase : public ImageIOBase 50 { 51 public: 52 ITK_DISALLOW_COPY_AND_ASSIGN(VideoIOBase); 53 54 /** Standard class type aliases. */ 55 using Self = VideoIOBase; 56 using Superclass = ImageIOBase; 57 using Pointer = SmartPointer< Self >; 58 using SizeValueType = ::itk::SizeValueType; 59 60 /** Frame offset type alias */ 61 using TemporalOffsetType = double; 62 using FrameOffsetType = SizeValueType; 63 using TemporalRatioType = double; 64 65 /** Video-specific type alias */ 66 using CameraIDType = SizeValueType; 67 68 /** Run-time type information (and related methods). */ 69 itkTypeMacro(VideoIOBase, Superclass); 70 71 /** Close the reader and writer and reset members */ 72 virtual void FinishReadingOrWriting() = 0; 73 74 /*-------- This part of the interface deals with reading data. ------ */ 75 76 /** Enum used to define weather to read from a file or a camera */ 77 typedef enum {ReadFromFile, ReadFromCamera} ReadType; 78 79 /** Set to reading from file */ 80 virtual void SetReadFromFile() = 0; 81 82 /** Set to reading from a camera */ 83 virtual void SetReadFromCamera() = 0; 84 85 /** Get the current read type */ GetReadType()86 ReadType GetReadType() { 87 return this->m_ReadType; 88 } 89 90 /** Return whether or not the VideoIO can read from a camera. The cameraID 91 * can be a camera number for OpenCV or a guid for VXL */ 92 virtual bool CanReadCamera( CameraIDType cameraID ) const = 0; 93 94 /** Set the next frame that should be read. Return true if you operation 95 * successful */ 96 virtual bool SetNextFrameToRead( FrameOffsetType frameNumber ) = 0; 97 98 /** Virtual accessor functions to be implemented in each derived class */ 99 virtual TemporalOffsetType GetPositionInMSec() const = 0; 100 virtual TemporalRatioType GetRatio() const = 0; 101 virtual FrameOffsetType GetFrameTotal() const = 0; 102 virtual TemporalRatioType GetFramesPerSecond() const = 0; 103 virtual FrameOffsetType GetCurrentFrame() const = 0; 104 virtual FrameOffsetType GetLastIFrame() const = 0; 105 106 /*-------- This part of the interfaces deals with writing data. ----- */ 107 108 /** Set Writer Parameters */ 109 virtual void SetWriterParameters( TemporalRatioType framesPerSecond, 110 const std::vector<SizeValueType>& dim, 111 const char* fourCC, 112 unsigned int nChannels, 113 IOComponentType componentType) = 0; 114 115 protected: 116 117 VideoIOBase(); 118 ~VideoIOBase() override; 119 120 void PrintSelf(std::ostream & os, Indent indent) const override; 121 122 /** Member Variables */ 123 ReadType m_ReadType{ReadFromFile}; 124 TemporalRatioType m_FramesPerSecond{0.0}; 125 FrameOffsetType m_FrameTotal; 126 FrameOffsetType m_CurrentFrame; 127 FrameOffsetType m_IFrameInterval; 128 FrameOffsetType m_LastIFrame; 129 TemporalRatioType m_Ratio{0.0}; 130 TemporalOffsetType m_PositionInMSec{0.0}; 131 bool m_WriterOpen{false}; 132 bool m_ReaderOpen{false}; 133 }; 134 135 } // end namespace itk 136 137 #endif // itkVideoIOBase_h 138