18 #ifndef itkImageIOBase_h
19 #define itkImageIOBase_h
20 #include "ITKIOImageBaseExport.h"
22 #include "itkIOConfigure.h"
34 #include "vnl/vnl_vector.h"
35 #include "vcl_compiler.h"
43 template <
typename TValue>
class VariableLengthVector;
88 itkSetStringMacro(FileName);
89 itkGetStringMacro(FileName);
106 typedef enum { UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
108 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, MATRIX } IOPixelType;
118 typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
119 ULONG, LONG,
ULONGLONG, LONGLONG, FLOAT, DOUBLE } IOComponentType;
124 void SetNumberOfDimensions(
unsigned int);
126 itkGetConstMacro(NumberOfDimensions,
unsigned int);
131 virtual void SetDimensions(
unsigned int i,
SizeValueType dim);
135 {
return m_Dimensions[i]; }
139 virtual void SetOrigin(
unsigned int i,
double origin);
148 virtual void SetSpacing(
unsigned int i,
double spacing);
157 virtual void SetDirection(
unsigned int i,
const std::vector< double > & direction);
159 virtual void SetDirection(
unsigned int i,
const vnl_vector< double > & direction);
163 return m_Direction[i];
168 virtual std::vector< double > GetDefaultDirection(
unsigned int i)
const;
185 itkSetEnumMacro(PixelType, IOPixelType);
186 itkGetEnumMacro(PixelType, IOPixelType);
191 itkSetEnumMacro(ComponentType, IOComponentType);
192 itkGetEnumMacro(ComponentType, IOComponentType);
199 virtual const std::type_info & GetComponentTypeInfo()
const;
205 itkSetMacro(NumberOfComponents,
unsigned int);
206 itkGetConstReferenceMacro(NumberOfComponents,
unsigned int);
210 itkSetMacro(UseCompression,
bool);
211 itkGetConstMacro(UseCompression,
bool);
212 itkBooleanMacro(UseCompression);
216 itkSetMacro(UseStreamedReading,
bool);
217 itkGetConstMacro(UseStreamedReading,
bool);
218 itkBooleanMacro(UseStreamedReading);
222 itkSetMacro(UseStreamedWriting,
bool);
223 itkGetConstMacro(UseStreamedWriting,
bool);
224 itkBooleanMacro(UseStreamedWriting);
231 itkSetMacro(ExpandRGBPalette,
bool);
232 itkGetConstMacro(ExpandRGBPalette,
bool);
233 itkBooleanMacro(ExpandRGBPalette);
240 itkGetConstMacro(IsReadAsScalarPlusPalette,
bool);
244 static std::string GetComponentTypeAsString(IOComponentType);
247 static IOComponentType GetComponentTypeFromString(
const std::string &typeString);
251 static std::string GetPixelTypeAsString(IOPixelType);
254 static IOPixelType GetPixelTypeFromString(
const std::string &pixelString);
258 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
262 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
266 itkSetEnumMacro(FileType, FileType);
267 itkGetEnumMacro(FileType, FileType);
270 this->SetFileType(ASCII);
276 this->SetFileType(Binary);
290 itkSetEnumMacro(ByteOrder, ByteOrder);
291 itkGetEnumMacro(ByteOrder, ByteOrder);
294 this->SetByteOrder(BigEndian);
300 this->SetByteOrder(LittleEndian);
305 std::string GetFileTypeAsString(FileType)
const;
309 std::string GetByteOrderAsString(ByteOrder)
const;
324 virtual SizeType GetPixelStride()
const;
327 SizeType GetImageSizeInPixels()
const;
330 SizeType GetImageSizeInBytes()
const;
334 SizeType GetImageSizeInComponents()
const;
340 virtual unsigned int GetComponentSize()
const;
346 virtual bool CanReadFile(
const char *) = 0;
359 virtual void ReadImageInformation() = 0;
362 virtual void Read(
void *buffer) = 0;
368 virtual bool CanWriteFile(
const char *) = 0;
383 virtual void WriteImageInformation() = 0;
388 virtual void Write(
const void *buffer) = 0;
414 GenerateStreamableReadRegionFromRequestedRegion(
const ImageIORegion & requested)
const;
430 virtual unsigned int GetActualNumberOfSplitsForWriting(
unsigned int numberOfRequestedSplits,
440 virtual ImageIORegion GetSplitRegionForWriting(
unsigned int ithPiece,
441 unsigned int numberOfActualSplits,
460 template <
typename TPixel>
461 void SetTypeInfo(
const TPixel *);
464 template <
typename TPixel>
468 UNKNOWNCOMPONENTTYPE;
470 template <
typename TPixel>
473 this->SetNumberOfComponents(1);
474 this->SetPixelType(SCALAR);
477 template <
typename TPixel>
480 this->SetNumberOfComponents(3);
481 this->SetPixelType(RGB);
484 template <
typename TPixel>
487 this->SetNumberOfComponents(4);
488 this->SetPixelType(RGBA);
491 template <
typename TPixel,
unsigned VLength>
494 this->SetNumberOfComponents(VLength);
495 this->SetPixelType(VECTOR);
498 template <
typename TPixel>
501 this->SetNumberOfComponents(1);
502 this->SetPixelType(VECTOR);
505 template <
typename TPixel,
unsigned VLength>
508 this->SetNumberOfComponents(VLength);
509 this->SetPixelType(COVARIANTVECTOR);
512 template <
typename TPixel,
unsigned VLength>
515 this->SetNumberOfComponents(VLength);
516 this->SetPixelType(COVARIANTVECTOR);
521 template <
typename TPixel,
unsigned VLength>
524 this->SetNumberOfComponents(VLength * (VLength + 1) / 2 );
525 this->SetPixelType(SYMMETRICSECONDRANKTENSOR);
529 template <
typename TPixel>
532 this->SetNumberOfComponents(6);
533 this->SetPixelType(DIFFUSIONTENSOR3D);
537 template <
typename TPixel,
unsigned VLength>
540 this->SetNumberOfComponents(VLength * VLength);
541 this->SetPixelType(MATRIX);
545 template <
typename TPixel>
548 this->SetNumberOfComponents(2);
549 this->SetPixelType(COMPLEX);
553 template <
unsigned VLength>
556 this->SetNumberOfComponents(VLength);
564 void PrintSelf(std::ostream & os,
Indent indent)
const override;
572 virtual bool HasSupportedReadExtension(
const char * fileName,
bool ignoreCase =
true );
573 virtual bool HasSupportedWriteExtension(
const char * fileName,
bool ignoreCase =
true );
599 unsigned int m_NumberOfDimensions{0};
639 virtual void Reset(
const bool freeDynamic =
true);
642 void Resize(
const unsigned int numDimensions,
643 const unsigned int *dimensions);
647 virtual unsigned int GetPixelSize()
const;
655 void ComputeStrides();
659 SizeType GetComponentStride()
const;
680 virtual void OpenFileForReading(std::ifstream & inputStream,
const std::string & filename,
698 virtual void OpenFileForWriting(std::ofstream & outputStream,
const std::string & filename,
699 bool truncate =
true,
bool ascii =
false);
702 virtual void WriteBufferAsASCII(std::ostream & os,
const void *buffer,
707 virtual void ReadBufferAsASCII(std::istream & os,
void *buffer,
712 bool ReadBufferAsBinary(std::istream & os,
void *buffer,
SizeType numberOfBytesToBeRead);
715 void AddSupportedReadExtension(
const char *extension);
718 void AddSupportedWriteExtension(
const char *extension);
722 virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(
unsigned int numberOfRequestedSplits,
727 virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(
unsigned int ithPiece,
728 unsigned int numberOfActualSplits,
739 #define IMAGEIOBASE_TYPEMAP(type,ctype) \
740 template <> struct ImageIOBase::MapPixelType<type> \
742 static constexpr IOComponentType CType = ctype; \
747 IMAGEIOBASE_TYPEMAP(
char, std::numeric_limits<char>::is_signed ? IOComponentType::CHAR : IOComponentType::UCHAR);
759 #undef IMAGIOBASE_TYPEMAP
763 #endif // itkImageIOBase_h
void SetPixelTypeInfo(const Offset< VLength > *)
A templated class holding a M x N size Matrix.
unsigned int m_NumberOfComponents
Light weight base class for most itk classes.
virtual bool SupportsDimension(unsigned long dim)
void SetPixelTypeInfo(const DiffusionTensor3D< TPixel > *)
An ImageIORegion represents a structured region of data.
virtual SizeValueType GetDimensions(unsigned int i) const
void SetByteOrderToLittleEndian()
Abstract superclass defines image IO interface.
Represent Red, Green, Blue and Alpha components for color images.
Represent a symmetric tensor of second rank.
unsigned long SizeValueType
void SetPixelTypeInfo(const Matrix< TPixel, VLength, VLength > *)
std::vector< double > m_Origin
void SetPixelTypeInfo(const VariableLengthVector< TPixel > *)
std::vector< double > m_Spacing
::itk::OffsetValueType BufferSizeType
virtual double GetSpacing(unsigned int i) const
virtual std::vector< double > GetDirection(unsigned int i) const
IMAGEIOBASE_TYPEMAP(signed char, IOComponentType::CHAR)
ArrayOfExtensionsType m_SupportedReadExtensions
void SetFileTypeToBinary()
Simulate a standard C array with copy semnatics.
bool m_UseStreamedWriting
bool m_UseStreamedReading
void SetPixelTypeInfo(const Vector< TPixel, VLength > *)
::itk::IndexValueType IndexValueType
void SetPixelTypeInfo(const TPixel *)
::itk::SizeValueType SizeValueType
virtual double GetOrigin(unsigned int i) const
Represents an array whose length can be defined at run-time.
A templated class holding a n-Dimensional vector.
std::vector< std::vector< double > > m_Direction
signed long IndexValueType
Divide an image region into several pieces.
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image...
void SetPixelTypeInfo(const SymmetricSecondRankTensor< TPixel, VLength > *)
void SetPixelTypeInfo(const std::complex< TPixel > *)
virtual bool CanStreamRead()
void SetPixelTypeInfo(const CovariantVector< TPixel, VLength > *)
void SetPixelTypeInfo(const RGBPixel< TPixel > *)
std::vector< SizeType > m_Strides
ArrayOfExtensionsType m_SupportedWriteExtensions
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
void SetFileTypeToASCII()
std::vector< std::string > ArrayOfExtensionsType
void SetByteOrderToBigEndian()
Base class for most ITK classes.
Represent a diffusion tensor as used in DTI images.
A templated class holding a n-Dimensional covariant vector.
signed long OffsetValueType
bool m_IsReadAsScalarPlusPalette
void SetPixelTypeInfo(const RGBAPixel< TPixel > *)
std::vector< SizeValueType > m_Dimensions
void SetPixelTypeInfo(const FixedArray< TPixel, VLength > *)
virtual bool CanStreamWrite()