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;
85 itkSetStringMacro(FileName);
86 itkGetStringMacro(FileName);
103 typedef enum { UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
105 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, MATRIX } IOPixelType;
111 typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
112 ULONG, LONG,
ULONGLONG, LONGLONG, FLOAT, DOUBLE } IOComponentType;
117 void SetNumberOfDimensions(
unsigned int);
119 itkGetConstMacro(NumberOfDimensions,
unsigned int);
124 virtual void SetDimensions(
unsigned int i,
SizeValueType dim);
128 {
return m_Dimensions[i]; }
132 virtual void SetOrigin(
unsigned int i,
double origin);
141 virtual void SetSpacing(
unsigned int i,
double spacing);
150 virtual void SetDirection(
unsigned int i,
const std::vector< double > & direction);
152 virtual void SetDirection(
unsigned int i,
const vnl_vector< double > & direction);
156 return m_Direction[i];
161 virtual std::vector< double > GetDefaultDirection(
unsigned int i)
const;
178 itkSetEnumMacro(PixelType, IOPixelType);
179 itkGetEnumMacro(PixelType, IOPixelType);
184 itkSetEnumMacro(ComponentType, IOComponentType);
185 itkGetEnumMacro(ComponentType, IOComponentType);
192 virtual const std::type_info & GetComponentTypeInfo()
const;
198 itkSetMacro(NumberOfComponents,
unsigned int);
199 itkGetConstReferenceMacro(NumberOfComponents,
unsigned int);
203 itkSetMacro(UseCompression,
bool);
204 itkGetConstMacro(UseCompression,
bool);
205 itkBooleanMacro(UseCompression);
209 itkSetMacro(UseStreamedReading,
bool);
210 itkGetConstMacro(UseStreamedReading,
bool);
211 itkBooleanMacro(UseStreamedReading);
215 itkSetMacro(UseStreamedWriting,
bool);
216 itkGetConstMacro(UseStreamedWriting,
bool);
217 itkBooleanMacro(UseStreamedWriting);
224 itkSetMacro(ExpandRGBPalette,
bool);
225 itkGetConstMacro(ExpandRGBPalette,
bool);
226 itkBooleanMacro(ExpandRGBPalette);
233 itkGetConstMacro(IsReadAsScalarPlusPalette,
bool);
237 static std::string GetComponentTypeAsString(IOComponentType);
240 static IOComponentType GetComponentTypeFromString(
const std::string &typeString);
244 static std::string GetPixelTypeAsString(IOPixelType);
247 static IOPixelType GetPixelTypeFromString(
const std::string &pixelString);
251 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
255 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
259 itkSetEnumMacro(FileType, FileType);
260 itkGetEnumMacro(FileType, FileType);
263 this->SetFileType(ASCII);
269 this->SetFileType(Binary);
283 itkSetEnumMacro(ByteOrder, ByteOrder);
284 itkGetEnumMacro(ByteOrder, ByteOrder);
287 this->SetByteOrder(BigEndian);
293 this->SetByteOrder(LittleEndian);
298 std::string GetFileTypeAsString(FileType)
const;
302 std::string GetByteOrderAsString(ByteOrder)
const;
317 virtual SizeType GetPixelStride()
const;
320 SizeType GetImageSizeInPixels()
const;
323 SizeType GetImageSizeInBytes()
const;
327 SizeType GetImageSizeInComponents()
const;
333 virtual unsigned int GetComponentSize()
const;
339 virtual bool CanReadFile(
const char *) = 0;
352 virtual void ReadImageInformation() = 0;
355 virtual void Read(
void *buffer) = 0;
361 virtual bool CanWriteFile(
const char *) = 0;
376 virtual void WriteImageInformation() = 0;
381 virtual void Write(
const void *buffer) = 0;
407 GenerateStreamableReadRegionFromRequestedRegion(
const ImageIORegion & requested)
const;
423 virtual unsigned int GetActualNumberOfSplitsForWriting(
unsigned int numberOfRequestedSplits,
433 virtual ImageIORegion GetSplitRegionForWriting(
unsigned int ithPiece,
434 unsigned int numberOfActualSplits,
453 template <
typename TPixel>
454 void SetTypeInfo(
const TPixel *);
457 template <
typename TPixel>
461 UNKNOWNCOMPONENTTYPE;
463 template <
typename TPixel>
466 this->SetNumberOfComponents(1);
467 this->SetPixelType(SCALAR);
470 template <
typename TPixel>
473 this->SetNumberOfComponents(3);
474 this->SetPixelType(RGB);
477 template <
typename TPixel>
480 this->SetNumberOfComponents(4);
481 this->SetPixelType(RGBA);
484 template <
typename TPixel,
unsigned VLength>
487 this->SetNumberOfComponents(VLength);
488 this->SetPixelType(VECTOR);
491 template <
typename TPixel>
494 this->SetNumberOfComponents(1);
495 this->SetPixelType(VECTOR);
498 template <
typename TPixel,
unsigned VLength>
501 this->SetNumberOfComponents(VLength);
502 this->SetPixelType(COVARIANTVECTOR);
505 template <
typename TPixel,
unsigned VLength>
508 this->SetNumberOfComponents(VLength);
509 this->SetPixelType(COVARIANTVECTOR);
514 template <
typename TPixel,
unsigned VLength>
517 this->SetNumberOfComponents(VLength * (VLength + 1) / 2 );
518 this->SetPixelType(SYMMETRICSECONDRANKTENSOR);
522 template <
typename TPixel>
525 this->SetNumberOfComponents(6);
526 this->SetPixelType(DIFFUSIONTENSOR3D);
530 template <
typename TPixel,
unsigned VLength>
533 this->SetNumberOfComponents(VLength * VLength);
534 this->SetPixelType(MATRIX);
538 template <
typename TPixel>
541 this->SetNumberOfComponents(2);
542 this->SetPixelType(COMPLEX);
546 template <
unsigned VLength>
549 this->SetNumberOfComponents(VLength);
557 virtual
void PrintSelf(std::ostream & os,
Indent indent) const ITK_OVERRIDE;
577 std::
string m_FileName;
581 unsigned int m_NumberOfComponents;
584 unsigned int m_NumberOfDimensions;
587 bool m_UseCompression;
590 bool m_UseStreamedReading;
593 bool m_UseStreamedWriting;
596 bool m_ExpandRGBPalette;
600 bool m_IsReadAsScalarPlusPalette;
611 std::vector<
double > m_Spacing;
614 std::vector<
double > m_Origin;
617 std::vector< std::vector<
double > > m_Direction;
624 virtual
void Reset(const
bool freeDynamic = true);
627 void Resize(const
unsigned int numDimensions,
628 const
unsigned int *dimensions);
632 virtual
unsigned int GetPixelSize() const;
640 void ComputeStrides();
644 SizeType GetComponentStride() const;
665 virtual
void OpenFileForReading(std::ifstream & inputStream, const std::
string & filename,
683 virtual
void OpenFileForWriting(std::ofstream & outputStream, const std::
string & filename,
684 bool truncate = true,
bool ascii = false);
687 virtual
void WriteBufferAsASCII(std::ostream & os, const
void *buffer,
692 virtual
void ReadBufferAsASCII(std::istream & os,
void *buffer,
697 bool ReadBufferAsBinary(std::istream & os,
void *buffer,
SizeType numberOfBytesToBeRead);
700 void AddSupportedReadExtension(const
char *extension);
703 void AddSupportedWriteExtension(const
char *extension);
707 virtual
unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(
unsigned int numberOfRequestedSplits,
712 virtual
ImageIORegion GetSplitRegionForWritingCanStreamWrite(
unsigned int ithPiece,
713 unsigned int numberOfActualSplits,
723 #define IMAGEIOBASE_TYPEMAP(type,ctype) \
724 template <> struct ImageIOBase::MapPixelType<type> \
726 static ITK_CONSTEXPR_VAR IOComponentType CType = ctype; \
730 #if VCL_CHAR_IS_SIGNED
732 #endif // VCL_CHAR_IS_SIGNED
745 #undef IMAGIOBASE_TYPEMAP
750 #endif // itkImageIOBase_h
void SetPixelTypeInfo(const Offset< VLength > *)
A templated class holding a M x N size Matrix.
Represent the offset between two n-dimensional indexes in a n-dimensional image.
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.
signed long OffsetValueType
Represent Red, Green, Blue and Alpha components for color images.
Represent a symmetric tensor of second rank.
signed long IndexValueType
void SetPixelTypeInfo(const Matrix< TPixel, VLength, VLength > *)
void SetPixelTypeInfo(const VariableLengthVector< TPixel > *)
LightProcessObject Superclass
virtual double GetSpacing(unsigned int i) const
std::vector< std::string > ArrayOfExtensionsType
unsigned long SizeValueType
virtual std::vector< double > GetDirection(unsigned int i) const
void SetFileTypeToBinary()
Simulate a standard C array with copy semnatics.
void SetPixelTypeInfo(const Vector< TPixel, VLength > *)
void SetPixelTypeInfo(const TPixel *)
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.
Divide an image region into several pieces.
void SetPixelTypeInfo(const SymmetricSecondRankTensor< TPixel, VLength > *)
void SetPixelTypeInfo(const std::complex< TPixel > *)
virtual bool CanStreamRead()
::itk::SizeValueType SizeValueType
void SetPixelTypeInfo(const CovariantVector< TPixel, VLength > *)
::itk::OffsetValueType BufferSizeType
void SetPixelTypeInfo(const RGBPixel< TPixel > *)
::itk::IndexValueType IndexValueType
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
void SetFileTypeToASCII()
IMAGEIOBASE_TYPEMAP(char, CHAR)
SmartPointer< Self > Pointer
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.
void SetPixelTypeInfo(const RGBAPixel< TPixel > *)
void SetPixelTypeInfo(const FixedArray< TPixel, VLength > *)
virtual bool CanStreamWrite()