ITK  6.0.0
Insight Toolkit
Public Types | Public Member Functions | Protected Member Functions | List of all members
itk::StreamingImageIOBase Class Referenceabstract

#include <itkStreamingImageIOBase.h>

Detailed Description

A base class for specific ImageIO file formats which support streaming.

This class overloads the methods needed to enable streaming. These methods are utilized by the ImageFileReader and ImageFileWriter. The implementation supports streaming of an arbitrary sized region as well as pasting to new or existing file ( of the same name, size, and pixel type ).

See also
CanStreamWrite CanStreamRead GenerateStreamableReadRegionFromRequestedRegion GetActualNumberOfSplitsForWriting

Additionally low level IO methods are provided to read and write an IORegion from a file.

See also
StreamReadBufferAsBinary StreamWriteBufferAsBinary

This implementation was taken from the Insight Journal: https://doi.org/10.54294/olkmog9

See also
itk::ImageFileReader itk::ImageFileWriter

Definition at line 52 of file itkStreamingImageIOBase.h.

+ Inheritance diagram for itk::StreamingImageIOBase:
+ Collaboration diagram for itk::StreamingImageIOBase:

Public Types

using Pointer = SmartPointer< Self >
 
using Self = StreamingImageIOBase
 
using Superclass = ImageIOBase
 
- Public Types inherited from itk::ImageIOBase
using ArrayOfExtensionsType = std::vector< std::string >
 
using BufferSizeType = itk::OffsetValueType
 
using ConstPointer = SmartPointer< const Self >
 
using IndexValueType = itk::IndexValueType
 
using IOByteOrderEnum = itk::IOByteOrderEnum
 
using IOComponentEnum = itk::IOComponentEnum
 
using IOFileEnum = itk::IOFileEnum
 
using Pointer = SmartPointer< Self >
 
using Self = ImageIOBase
 
using SizeType = itk::intmax_t
 
using SizeValueType = itk::SizeValueType
 
using Superclass = LightProcessObject
 
- Public Types inherited from itk::LightProcessObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightProcessObject
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

bool CanStreamRead () override
 
bool CanStreamWrite () override
 
ImageIORegion GenerateStreamableReadRegionFromRequestedRegion (const ImageIORegion &requestedRegion) const override
 
unsigned int GetActualNumberOfSplitsForWriting (unsigned int numberOfRequestedSplits, const ImageIORegion &pasteRegion, const ImageIORegion &largestPossibleRegion) override
 
const char * GetNameOfClass () const override
 
- Public Member Functions inherited from itk::ImageIOBase
virtual bool CanReadFile (const char *)=0
 
virtual bool CanStreamRead ()
 
virtual bool CanStreamWrite ()
 
virtual bool CanWriteFile (const char *)=0
 
virtual ImageIORegion GenerateStreamableReadRegionFromRequestedRegion (const ImageIORegion &requested) const
 
virtual unsigned int GetActualNumberOfSplitsForWriting (unsigned int numberOfRequestedSplits, const ImageIORegion &pasteRegion, const ImageIORegion &largestPossibleRegion)
 
std::string GetByteOrderAsString (IOByteOrderEnum) const
 
virtual unsigned int GetComponentSize () const
 
virtual IOComponentEnum GetComponentType () const
 
virtual const std::type_info & GetComponentTypeInfo () const
 
virtual int GetCompressionLevel () const
 
virtual const std::string & GetCompressor () const
 
virtual std::vector< double > GetDefaultDirection (unsigned int k) const
 
virtual SizeValueType GetDimensions (unsigned int i) const
 
virtual std::vector< double > GetDirection (unsigned int i) const
 
std::string GetFileTypeAsString (IOFileEnum) const
 
SizeType GetImageSizeInBytes () const
 
SizeType GetImageSizeInComponents () const
 
SizeType GetImageSizeInPixels () const
 
virtual bool GetIsReadAsScalarPlusPalette () const
 
const char * GetNameOfClass () const override
 
virtual unsigned int GetNumberOfDimensions () const
 
virtual double GetOrigin (unsigned int i) const
 
virtual SizeType GetPixelStride () const
 
virtual double GetSpacing (unsigned int i) const
 
virtual ImageIORegion GetSplitRegionForWriting (unsigned int ithPiece, unsigned int numberOfActualSplits, const ImageIORegion &pasteRegion, const ImageIORegion &largestPossibleRegion)
 
const ArrayOfExtensionsTypeGetSupportedReadExtensions () const
 
const ArrayOfExtensionsTypeGetSupportedWriteExtensions () const
 
virtual void Read (void *buffer)=0
 
virtual void ReadImageInformation ()=0
 
void SetByteOrderToLittleEndian ()
 
virtual void SetComponentType (const IOComponentEnum _arg)
 
virtual void SetCompressionLevel (int _arg)
 
virtual void SetCompressor (std::string _c)
 
virtual void SetDirection (unsigned int i, const std::vector< double > &direction)
 
virtual void SetDirection (unsigned int i, const vnl_vector< double > &direction)
 
void SetFileTypeToBinary ()
 
void SetNumberOfDimensions (unsigned int)
 
virtual void SetOrigin (unsigned int i, double origin)
 
virtual void SetSpacing (unsigned int i, double spacing)
 
template<typename TPixel >
void SetTypeInfo (const TPixel *)
 
virtual bool SupportsDimension (unsigned long dim)
 
virtual void Write (const void *buffer)=0
 
virtual void WriteImageInformation ()=0
 
virtual void SetFileName (const char *_arg)
 
virtual const char * GetFileName () const
 
virtual void SetDimensions (unsigned int i, SizeValueType dim)
 
virtual void SetIORegion (ImageIORegion _arg)
 
virtual const ImageIORegionGetIORegion () const
 
virtual void SetPixelType (const itk::CommonEnums::IOPixel _arg)
 
virtual itk::CommonEnums::IOPixel GetPixelType () const
 
virtual void SetNumberOfComponents (unsigned int _arg)
 
virtual const unsigned int & GetNumberOfComponents () const
 
virtual void SetUseCompression (bool _arg)
 
virtual bool GetUseCompression () const
 
virtual void UseCompressionOn ()
 
virtual void SetUseStreamedReading (bool _arg)
 
virtual bool GetUseStreamedReading () const
 
virtual void UseStreamedReadingOn ()
 
virtual void SetUseStreamedWriting (bool _arg)
 
virtual bool GetUseStreamedWriting () const
 
virtual void UseStreamedWritingOn ()
 
virtual void SetExpandRGBPalette (bool _arg)
 
virtual bool GetExpandRGBPalette () const
 
virtual void ExpandRGBPaletteOn ()
 
virtual void SetWritePalette (bool _arg)
 
virtual bool GetWritePalette () const
 
virtual void WritePaletteOn ()
 
virtual void SetFileType (const IOFileEnum _arg)
 
virtual IOFileEnum GetFileType () const
 
void SetFileTypeToASCII ()
 
virtual void SetByteOrder (const IOByteOrderEnum _arg)
 
virtual IOByteOrderEnum GetByteOrder () const
 
void SetByteOrderToBigEndian ()
 
template<typename TPixel >
void SetPixelTypeInfo (const TPixel *)
 
template<typename TPixel >
void SetPixelTypeInfo (const RGBPixel< TPixel > *)
 
template<typename TPixel >
void SetPixelTypeInfo (const RGBAPixel< TPixel > *)
 
template<unsigned int VLength>
void SetPixelTypeInfo (const Offset< VLength > *)
 
template<typename TPixel , unsigned int VLength>
void SetPixelTypeInfo (const Vector< TPixel, VLength > *)
 
template<typename TCoordRep , unsigned int VPointDimension>
void SetPixelTypeInfo (const Point< TCoordRep, VPointDimension > *)
 
template<typename TPixel , unsigned int VLength>
void SetPixelTypeInfo (const CovariantVector< TPixel, VLength > *)
 
template<typename TPixel , unsigned int VLength>
void SetPixelTypeInfo (const SymmetricSecondRankTensor< TPixel, VLength > *)
 
template<typename TPixel >
void SetPixelTypeInfo (const DiffusionTensor3D< TPixel > *)
 
template<typename TPixel >
void SetPixelTypeInfo (const std::complex< TPixel > *)
 
template<typename TPixel , unsigned int VLength>
void SetPixelTypeInfo (const FixedArray< TPixel, VLength > *)
 
template<typename TPixel >
void SetPixelTypeInfo (const VariableLengthVector< TPixel > *)
 
template<typename TValue >
void SetPixelTypeInfo (const Array< TValue > *)
 
template<typename TPixel , unsigned int VLength>
void SetPixelTypeInfo (const Matrix< TPixel, VLength, VLength > *)
 
template<typename TValue >
void SetPixelTypeInfo (const VariableSizeMatrix< TValue > *)
 
- Public Member Functions inherited from itk::LightProcessObject
virtual void AbortGenerateDataOn ()
 
virtual const bool & GetAbortGenerateData () const
 
const char * GetNameOfClass () const override
 
virtual void SetAbortGenerateData (bool _arg)
 
virtual void UpdateOutputData ()
 
void UpdateProgress (float amount)
 
virtual void SetProgress (float _arg)
 
virtual const float & GetProgress () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *cmd) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
const char * GetNameOfClass () const override
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag) const
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual Pointer CreateAnother () const
 
virtual void Delete ()
 
virtual const char * GetNameOfClass () const
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 
virtual void Register () const
 
virtual void SetReferenceCount (int)
 
virtual void UnRegister () const noexcept
 

Protected Member Functions

virtual SizeType GetDataPosition () const
 
virtual SizeType GetHeaderSize () const =0
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual bool ReadBufferAsBinary (std::istream &is, void *buffer, SizeType num)
 
virtual bool RequestedToStream () const
 
 StreamingImageIOBase ()
 
virtual bool StreamReadBufferAsBinary (std::istream &file, void *_buffer)
 
virtual bool StreamWriteBufferAsBinary (std::ostream &file, const void *_buffer)
 
virtual bool WriteBufferAsBinary (std::ostream &os, const void *buffer, SizeType num)
 
- Protected Member Functions inherited from itk::ImageIOBase
void AddSupportedReadExtension (const char *extension)
 
void AddSupportedWriteExtension (const char *extension)
 
void ComputeStrides ()
 
virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite (unsigned int numberOfRequestedSplits, const ImageIORegion &pasteRegion) const
 
SizeType GetComponentStride () const
 
virtual const ImageRegionSplitterBaseGetImageRegionSplitter () const
 
virtual unsigned int GetPixelSize () const
 
SizeType GetRowStride () const
 
SizeType GetSliceStride () const
 
virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite (unsigned int ithPiece, unsigned int numberOfActualSplits, const ImageIORegion &pasteRegion) const
 
 ImageIOBase ()
 
virtual void InternalSetCompressor (const std::string &_compressor)
 
virtual void OpenFileForReading (std::ifstream &inputStream, const std::string &filename, bool ascii=false)
 
virtual void OpenFileForWriting (std::ofstream &outputStream, const std::string &filename, bool truncate=true, bool ascii=false)
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual void ReadBufferAsASCII (std::istream &is, void *buffer, IOComponentEnum ctype, SizeType numComp)
 
bool ReadBufferAsBinary (std::istream &is, void *buffer, SizeType num)
 
virtual void Reset (const bool freeDynamic=true)
 
void Resize (const unsigned int numDimensions, const unsigned int *dimensions)
 
void SetSupportedReadExtensions (const ArrayOfExtensionsType &)
 
void SetSupportedWriteExtensions (const ArrayOfExtensionsType &)
 
virtual void WriteBufferAsASCII (std::ostream &os, const void *buffer, IOComponentEnum ctype, SizeType numComp)
 
 ~ImageIOBase () override
 
virtual bool HasSupportedReadExtension (const char *fileName, bool ignoreCase=true)
 
virtual bool HasSupportedWriteExtension (const char *fileName, bool ignoreCase=true)
 
virtual void SetMaximumCompressionLevel (int)
 
virtual int GetMaximumCompressionLevel () const
 
- Protected Member Functions inherited from itk::LightProcessObject
virtual void GenerateData ()
 
 LightProcessObject ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~LightProcessObject () override
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintSelf (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Additional Inherited Members

- Static Public Member Functions inherited from itk::ImageIOBase
static std::string GetComponentTypeAsString (IOComponentEnum)
 
static IOComponentEnum GetComponentTypeFromString (const std::string &typeString)
 
static std::string GetPixelTypeAsString (IOPixelEnum)
 
static IOPixelEnum GetPixelTypeFromString (const std::string &pixelString)
 
- Static Public Member Functions inherited from itk::LightProcessObject
static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 
- Protected Attributes inherited from itk::ImageIOBase
IOByteOrderEnum m_ByteOrder { IOByteOrderEnum::OrderNotApplicable }
 
IOComponentEnum m_ComponentType { IOComponentEnum::UNKNOWNCOMPONENTTYPE }
 
int m_CompressionLevel { 30 }
 
std::string m_Compressor { "uninitialized" }
 
std::vector< SizeValueTypem_Dimensions {}
 
std::vector< std::vector< double > > m_Direction {}
 
bool m_ExpandRGBPalette {}
 
std::string m_FileName {}
 
IOFileEnum m_FileType { IOFileEnum::TypeNotApplicable }
 
bool m_Initialized {}
 
ImageIORegion m_IORegion {}
 
bool m_IsReadAsScalarPlusPalette {}
 
int m_MaximumCompressionLevel { 100 }
 
unsigned int m_NumberOfComponents {}
 
unsigned int m_NumberOfDimensions { 0 }
 
std::vector< double > m_Origin {}
 
IOPixelEnum m_PixelType { IOPixelEnum::SCALAR }
 
std::vector< double > m_Spacing {}
 
std::vector< SizeTypem_Strides {}
 
bool m_UseCompression { false }
 
bool m_UseStreamedReading {}
 
bool m_UseStreamedWriting {}
 
bool m_WritePalette {}
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Member Typedef Documentation

◆ Pointer

Definition at line 60 of file itkStreamingImageIOBase.h.

◆ Self

Standard class type aliases.

Definition at line 58 of file itkStreamingImageIOBase.h.

◆ Superclass

Definition at line 59 of file itkStreamingImageIOBase.h.

Constructor & Destructor Documentation

◆ StreamingImageIOBase()

itk::StreamingImageIOBase::StreamingImageIOBase ( )
protected

Member Function Documentation

◆ CanStreamRead()

bool itk::StreamingImageIOBase::CanStreamRead ( )
overridevirtual

Determine if the ImageIO can stream reading from the current settings. Default is false. If this is queried after the header of the file has been read then it will indicate if that file can be streamed

Reimplemented from itk::ImageIOBase.

Reimplemented in itk::VTKImageIO.

◆ CanStreamWrite()

bool itk::StreamingImageIOBase::CanStreamWrite ( )
overridevirtual

Determine if the ImageIO can stream write from the current settings.

There are two types of non exclusive streaming: pasting subregions, and iterative

Reimplemented from itk::ImageIOBase.

Reimplemented in itk::JPEG2000ImageIO, and itk::VTKImageIO.

◆ GenerateStreamableReadRegionFromRequestedRegion()

ImageIORegion itk::StreamingImageIOBase::GenerateStreamableReadRegionFromRequestedRegion ( const ImageIORegion requested) const
overridevirtual

Method for supporting streaming. Given a requested region, determine what could be the region that we can read from the file. This is called the streamable region, which will be equal or smaller than the LargestPossibleRegion (unless it was dimensionally clipped) and greater or equal to the RequestedRegion

the resulting IORegion may be a greater dimensions the requested IORegion, if the derived class is unable to read the requested region. For example if the file has a size of [ 10, 10, 10] but the requested region is [10, 10] the return may be 3 dimensions.

Reimplemented from itk::ImageIOBase.

Reimplemented in itk::JPEG2000ImageIO.

◆ GetActualNumberOfSplitsForWriting()

unsigned int itk::StreamingImageIOBase::GetActualNumberOfSplitsForWriting ( unsigned int  numberOfRequestedSplits,
const ImageIORegion pasteRegion,
const ImageIORegion largestPossibleRegion 
)
overridevirtual

Before this method is called all the configuration will be done, that is Streaming/PasteRegion/Compression/Filename etc If pasting is being used the number of requested splits is for that region not the largest. The derived ImageIO class should verify that the file is capable of being written with this configuration. If pasted is enabled and is not support or does not work with the file, then an exception should be thrown.

The default implementation depends on CanStreamWrite. If false then 1 is returned (unless pasting is indicated), so that the whole file will be updated in one region. If true then its assumed that any arbitrary region can be written to any file. So the users request will be respected. If a derived class has more restrictive conditions then they should be checked

Reimplemented from itk::ImageIOBase.

◆ GetDataPosition()

virtual SizeType itk::StreamingImageIOBase::GetDataPosition ( ) const
inlineprotectedvirtual

Returns the byte offset into the file where the data is located.

The default implementation is to return the header size.

Definition at line 167 of file itkStreamingImageIOBase.h.

◆ GetHeaderSize()

virtual SizeType itk::StreamingImageIOBase::GetHeaderSize ( ) const
protectedpure virtual

Returns the size of the header in the file.

Implemented in itk::HDF5ImageIO, itk::JPEG2000ImageIO, itk::MRCImageIO, and itk::VTKImageIO.

◆ GetNameOfClass()

const char * itk::StreamingImageIOBase::GetNameOfClass ( ) const
overridevirtual

◆ PrintSelf()

void itk::StreamingImageIOBase::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from itk::ImageIOBase.

Reimplemented in itk::HDF5ImageIO, itk::JPEG2000ImageIO, itk::MRCImageIO, and itk::VTKImageIO.

◆ ReadBufferAsBinary()

virtual bool itk::StreamingImageIOBase::ReadBufferAsBinary ( std::istream &  is,
void *  buffer,
SizeType  num 
)
protectedvirtual

Reimplemented from superclass to get around 2GB read/write limitation.

Todo:
Move this method to itk::ImageIOBase

◆ RequestedToStream()

virtual bool itk::StreamingImageIOBase::RequestedToStream ( ) const
protectedvirtual

Returns true if GetIORegion() is not the same size as the largest region give by GetNumberOfDimensions().

This compares the IORegion to the size of the image in the file. With out regard to the dimensions of either, if the images represent the same region then false is returned.

◆ StreamReadBufferAsBinary()

virtual bool itk::StreamingImageIOBase::StreamReadBufferAsBinary ( std::istream &  file,
void *  _buffer 
)
protectedvirtual

Reads the set IORegion from os into buffer.

Parameters
fileis an istream presumed to be opened for reading in binary mode
_bufferis pointer to an allocated block of memory suitable to hold the IORegion of the pixel type

This methods relies on GetDataPosition() to determine where the data is located in the file. It uses ImageIOBase::m_IORegion to determine the requested region to read.

The files data is assumed to be unpadded and continuous in the file for the size of the image in the dimensions of the ImageIOBase::m_IORegion. This means that the image file could be broken into slices, but not blocks for this methods to be used.

◆ StreamWriteBufferAsBinary()

virtual bool itk::StreamingImageIOBase::StreamWriteBufferAsBinary ( std::ostream &  file,
const void *  _buffer 
)
protectedvirtual

Writes the set IORegion from buffer into os.

Parameters
fileis an ostream presumed to be opened for writing and reading
_bufferis a pointer to the data in a continuous block for the region

This methods relies on GetDataPosition() to determine where the data is located in the file. It uses ImageIOBase::m_IORegion determine the requested region to written.

◆ WriteBufferAsBinary()

virtual bool itk::StreamingImageIOBase::WriteBufferAsBinary ( std::ostream &  os,
const void *  buffer,
SizeType  num 
)
protectedvirtual

Reimplemented from super class to get around 2GB read/write limitation.

Todo:
Move this methods to itk::ImageIOBase

The documentation for this class was generated from the following file: