ITK  5.3.0
Insight Toolkit
itkVideoStream.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkVideoStream_h
19 #define itkVideoStream_h
20 
21 #include "itkTemporalDataObject.h"
22 #include "itkImage.h"
23 
24 namespace itk
25 {
26 
41 template <typename TFrameType>
42 class ITK_TEMPLATE_EXPORT VideoStream : public TemporalDataObject
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(VideoStream);
46 
48  using Self = VideoStream;
53 
54  using FrameType = TFrameType;
55  using FramePointer = typename FrameType::Pointer;
57  using typename Superclass::BufferType;
58 
60  using IndexType = typename FrameType::IndexType;
61  using PixelType = typename FrameType::PixelType;
62  using PointType = typename FrameType::PointType;
63  using SpacingType = typename FrameType::SpacingType;
64  using SizeType = typename FrameType::SizeType;
66  using NumberOfComponentsPerPixelType = unsigned int;
67 
69  using SpatialRegionMapType = typename std::map<SizeValueType, SpatialRegionType>;
70  using PointMapType = typename std::map<SizeValueType, PointType>;
71  using DirectionMapType = typename std::map<SizeValueType, DirectionType>;
72  using SpacingMapType = typename std::map<SizeValueType, SpacingType>;
73  using NumberOfComponentsPerPixelMapType = typename std::map<SizeValueType, NumberOfComponentsPerPixelType>;
74 
76  static constexpr unsigned int FrameDimension = FrameType::ImageDimension;
77  static unsigned int
79  {
80  return FrameType::ImageDimension;
81  }
82 
83  itkNewMacro(Self);
84 
86  itkTypeMacro(VideoStream, TemporalDataObject);
87 
89  void
90  SetMinimumBufferSize(SizeValueType minimumNumberOfFrames);
91 
98  void
99  InitializeEmptyFrames();
100 
102  BufferType *
104  {
105  return reinterpret_cast<BufferType *>(m_DataObjectBuffer.GetPointer());
106  }
107  const BufferType *
109  {
110  return reinterpret_cast<BufferType *>(m_DataObjectBuffer.GetPointer());
111  }
115  void
116  SetFrameBuffer(BufferType * buffer);
117 
119  const SpatialRegionMapType &
121  {
122  return m_LargestPossibleSpatialRegionCache;
123  }
124  void
126  {
127  m_LargestPossibleSpatialRegionCache = map;
128  }
131  const SpatialRegionMapType &
133  {
134  return m_RequestedSpatialRegionCache;
135  }
136  void
138  {
139  m_RequestedSpatialRegionCache = map;
140  }
141 
142  const SpatialRegionMapType &
144  {
145  return m_BufferedSpatialRegionCache;
146  }
147  void
149  {
150  m_BufferedSpatialRegionCache = map;
151  }
152 
153  const SpacingMapType &
155  {
156  return m_SpacingCache;
157  }
158  void
160  {
161  m_SpacingCache = map;
162  }
163 
164  const PointMapType &
166  {
167  return m_OriginCache;
168  }
169  void
171  {
172  m_OriginCache = map;
173  }
174 
175  const DirectionMapType &
177  {
178  return m_DirectionCache;
179  }
180  void
182  {
183  m_DirectionCache = map;
184  }
185 
186  const NumberOfComponentsPerPixelMapType &
188  {
189  return m_NumberOfComponentsPerPixelCache;
190  }
191  void
193  {
194  m_NumberOfComponentsPerPixelCache = map;
195  }
196 
198  void
199  SetFrame(SizeValueType frameNumber, FramePointer frame);
200 
205  FrameType *
206  GetFrame(SizeValueType frameNumber);
207  const FrameType *
208  GetFrame(SizeValueType frameNumber) const;
212  void
213  SetFrameLargestPossibleSpatialRegion(SizeValueType frameNumber, SpatialRegionType region);
214 
215  const SpatialRegionType &
216  GetFrameLargestPossibleSpatialRegion(SizeValueType frameNumber) const;
217 
219  void
220  SetFrameRequestedSpatialRegion(SizeValueType frameNumber, SpatialRegionType region);
221 
222  const SpatialRegionType &
223  GetFrameRequestedSpatialRegion(SizeValueType frameNumber) const;
224 
226  void
227  SetFrameBufferedSpatialRegion(SizeValueType frameNumber, SpatialRegionType region);
228 
229  const SpatialRegionType &
230  GetFrameBufferedSpatialRegion(SizeValueType frameNumber) const;
231 
233  void
234  SetFrameSpacing(SizeValueType frameNumber, SpacingType spacing);
235 
236  const SpacingType &
237  GetFrameSpacing(SizeValueType frameNumber) const;
238 
240  void
241  SetFrameOrigin(SizeValueType frameNumber, PointType origin);
242 
243  const PointType &
244  GetFrameOrigin(SizeValueType frameNumber) const;
245 
247  void
248  SetFrameDirection(SizeValueType frameNumber, DirectionType direction);
249 
250  const DirectionType &
251  GetFrameDirection(SizeValueType frameNumber) const;
252 
254  void
255  SetFrameNumberOfComponentsPerPixel(SizeValueType frameNumber, unsigned int n);
256 
257  const NumberOfComponentsPerPixelType &
258  GetFrameNumberOfComponentsPerPixel(SizeValueType frameNumber) const;
259 
263  void
264  SetAllLargestPossibleSpatialRegions(SpatialRegionType region);
265 
269  void
270  SetAllRequestedSpatialRegions(SpatialRegionType region);
271 
275  void
276  SetAllBufferedSpatialRegions(SpatialRegionType region);
277 
281  void
282  SetAllFramesSpacing(SpacingType spacing);
283 
287  void
288  SetAllFramesOrigin(PointType origin);
289 
293  void
294  SetAllFramesDirection(DirectionType direction);
295 
299  void
300  SetAllFramesNumberOfComponentsPerPixel(NumberOfComponentsPerPixelType n);
301 
317  // Initialize all frames in the buffered temporal region
318  video->InitializeEmptyFrames();
319 
320  // Set the buffered spatial region for each frame
321  SpatialRegionType bufferedSpatialRegion;
324  size[0] = 50;
325  size[1] = 40;
326  start.Fill( 0 );
327  bufferedSpatialRegion.SetSize( size );
328  bufferedSpatialRegion.SetIndex( start );
329  video->SetAllBufferedSpatialRegions( bufferedSpatialRegion );
330 
331  // Allocate memory for the frames
332  video->Allocate();
333  \endcode
334  */
335  void
336  Allocate();
337 
342  void
343  Graft(const DataObject * data) override;
344 
345 protected:
346  VideoStream() = default;
347  ~VideoStream() override = default;
348 
349  void
350  PrintSelf(std::ostream & os, Indent indent) const override
351  {
352  Superclass::Print(os, indent);
353  }
354 
361 
368 
369 }; // end class VideoStream
370 
371 } // end namespace itk
372 
373 #ifndef ITK_MANUAL_INSTANTIATION
374 # include "itkVideoStream.hxx"
375 #endif
376 
377 #endif
itk::TemporalDataObject
class ITK_FORWARD_EXPORT TemporalDataObject
Definition: itkTemporalProcessObject.h:29
itk::VideoStream::PointType
typename FrameType::PointType PointType
Definition: itkVideoStream.h:62
itk::VideoStream::m_RequestedSpatialRegionCache
SpatialRegionMapType m_RequestedSpatialRegionCache
Definition: itkVideoStream.h:359
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:92
itk::VideoStream::FrameType
TFrameType FrameType
Definition: itkVideoStream.h:54
itk::VideoStream::m_BufferedSpatialRegionCache
SpatialRegionMapType m_BufferedSpatialRegionCache
Definition: itkVideoStream.h:360
itk::VideoStream::SpacingMapType
typename std::map< SizeValueType, SpacingType > SpacingMapType
Definition: itkVideoStream.h:72
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:93
itk::VideoStream::NumberOfComponentsPerPixelType
unsigned int NumberOfComponentsPerPixelType
Definition: itkVideoStream.h:66
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::VideoStream::NumberOfComponentsPerPixelMapType
typename std::map< SizeValueType, NumberOfComponentsPerPixelType > NumberOfComponentsPerPixelMapType
Definition: itkVideoStream.h:73
itk::VideoStream::GetFrameBuffer
BufferType * GetFrameBuffer()
Definition: itkVideoStream.h:103
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::VideoStream::SpatialRegionType
typename FrameType::RegionType SpatialRegionType
Definition: itkVideoStream.h:59
itk::VideoStream::GetRequestedSpatialRegionCache
const SpatialRegionMapType & GetRequestedSpatialRegionCache() const
Definition: itkVideoStream.h:132
itk::VideoStream::PixelType
typename FrameType::PixelType PixelType
Definition: itkVideoStream.h:61
itk::VideoStream::GetSpacingCache
const SpacingMapType & GetSpacingCache() const
Definition: itkVideoStream.h:154
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::VideoStream::m_DirectionCache
DirectionMapType m_DirectionCache
Definition: itkVideoStream.h:365
itkImage.h
itk::VideoStream::SpatialRegionMapType
typename std::map< SizeValueType, SpatialRegionType > SpatialRegionMapType
Definition: itkVideoStream.h:69
itk::VideoStream::m_OriginCache
PointMapType m_OriginCache
Definition: itkVideoStream.h:366
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::VideoStream::GetLargestPossibleSpatialRegionCache
const SpatialRegionMapType & GetLargestPossibleSpatialRegionCache() const
Definition: itkVideoStream.h:120
itk::VideoStream::m_LargestPossibleSpatialRegionCache
SpatialRegionMapType m_LargestPossibleSpatialRegionCache
Definition: itkVideoStream.h:358
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:274
itk::VideoStream::m_NumberOfComponentsPerPixelCache
NumberOfComponentsPerPixelMapType m_NumberOfComponentsPerPixelCache
Definition: itkVideoStream.h:367
itk::VideoStream::IndexType
typename FrameType::IndexType IndexType
Definition: itkVideoStream.h:60
itk::VideoStream::SizeType
typename FrameType::SizeType SizeType
Definition: itkVideoStream.h:64
itk::VideoStream::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkVideoStream.h:350
itk::VideoStream::GetFrameDimension
static unsigned int GetFrameDimension()
Definition: itkVideoStream.h:78
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::VideoStream::DirectionMapType
typename std::map< SizeValueType, DirectionType > DirectionMapType
Definition: itkVideoStream.h:71
itk::VideoStream::PointMapType
typename std::map< SizeValueType, PointType > PointMapType
Definition: itkVideoStream.h:70
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::VideoStream::GetBufferedSpatialRegionCache
const SpatialRegionMapType & GetBufferedSpatialRegionCache() const
Definition: itkVideoStream.h:143
itk::VideoStream::GetNumberOfComponentsPerPixelCache
void GetNumberOfComponentsPerPixelCache(NumberOfComponentsPerPixelMapType map)
Definition: itkVideoStream.h:192
itk::VideoStream::GetOriginCache
const PointMapType & GetOriginCache() const
Definition: itkVideoStream.h:165
itk::VideoStream::SetLargestPossibleSpatialRegionCache
void SetLargestPossibleSpatialRegionCache(SpatialRegionMapType map)
Definition: itkVideoStream.h:125
itk::VideoStream::m_SpacingCache
SpacingMapType m_SpacingCache
Definition: itkVideoStream.h:364
itk::VideoStream::GetDirectionCache
const DirectionMapType & GetDirectionCache() const
Definition: itkVideoStream.h:176
itk::VideoStream::GetFrameBuffer
const BufferType * GetFrameBuffer() const
Definition: itkVideoStream.h:108
itk::VideoStream::SetDirectionCache
void SetDirectionCache(DirectionMapType map)
Definition: itkVideoStream.h:181
itk::WeakPointer
Implements a weak reference to an object.
Definition: itkWeakPointer.h:44
itk::VideoStream::FramePointer
typename FrameType::Pointer FramePointer
Definition: itkVideoStream.h:55
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::VideoStream
A DataObject that holds a buffered portion of a video.
Definition: itkVideoStream.h:42
itkTemporalDataObject.h
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::VideoStream::SpacingType
typename FrameType::SpacingType SpacingType
Definition: itkVideoStream.h:63
itk::VideoStream::SetOriginCache
void SetOriginCache(PointMapType map)
Definition: itkVideoStream.h:170
itk::VideoStream::SetSpacingCache
void SetSpacingCache(SpacingMapType map)
Definition: itkVideoStream.h:159
AddImageFilter
Definition: itkAddImageFilter.h:80
itk::VideoStream::FrameConstPointer
typename FrameType::ConstPointer FrameConstPointer
Definition: itkVideoStream.h:56
itk::VideoStream::SetRequestedSpatialRegionCache
void SetRequestedSpatialRegionCache(SpatialRegionMapType map)
Definition: itkVideoStream.h:137
itk::VideoStream::DirectionType
typename FrameType::DirectionType DirectionType
Definition: itkVideoStream.h:65
itk::VideoStream::GetNumberOfComponentsPerPixelCache
const NumberOfComponentsPerPixelMapType & GetNumberOfComponentsPerPixelCache() const
Definition: itkVideoStream.h:187
itk::VideoStream::SetBufferedSpatialRegionCache
void SetBufferedSpatialRegionCache(SpatialRegionMapType map)
Definition: itkVideoStream.h:148
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::TemporalDataObject
DataObject subclass with knowledge of temporal region.
Definition: itkTemporalDataObject.h:65
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293