18 #ifndef itkImageIOBase_h
19 #define itkImageIOBase_h
20 #include "ITKIOImageBaseExport.h"
22 #include "itkIOConfigure.h"
35 #include "vnl/vnl_vector.h"
36 #include "vcl_compiler.h"
83 itkSetStringMacro(FileName);
84 itkGetStringMacro(FileName);
101 typedef enum { UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
103 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, MATRIX } IOPixelType;
109 typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
110 ULONG, LONG, FLOAT, DOUBLE } IOComponentType;
115 void SetNumberOfDimensions(
unsigned int);
117 itkGetConstMacro(NumberOfDimensions,
unsigned int);
122 virtual void SetDimensions(
unsigned int i,
unsigned int dim);
126 {
return m_Dimensions[i]; }
130 virtual void SetOrigin(
unsigned int i,
double origin);
139 virtual void SetSpacing(
unsigned int i,
double spacing);
148 virtual void SetDirection(
unsigned int i,
const std::vector< double > & direction);
150 virtual void SetDirection(
unsigned int i,
const vnl_vector< double > & direction);
154 return m_Direction[i];
159 virtual std::vector< double > GetDefaultDirection(
unsigned int i)
const;
176 itkSetEnumMacro(PixelType, IOPixelType);
177 itkGetEnumMacro(PixelType, IOPixelType);
182 itkSetEnumMacro(ComponentType, IOComponentType);
183 itkGetEnumMacro(ComponentType, IOComponentType);
190 virtual const std::type_info & GetComponentTypeInfo()
const;
196 itkSetMacro(NumberOfComponents,
unsigned int);
197 itkGetConstReferenceMacro(NumberOfComponents,
unsigned int);
201 itkSetMacro(UseCompression,
bool);
202 itkGetConstMacro(UseCompression,
bool);
203 itkBooleanMacro(UseCompression);
207 itkSetMacro(UseStreamedReading,
bool);
208 itkGetConstMacro(UseStreamedReading,
bool);
209 itkBooleanMacro(UseStreamedReading);
213 itkSetMacro(UseStreamedWriting,
bool);
214 itkGetConstMacro(UseStreamedWriting,
bool);
215 itkBooleanMacro(UseStreamedWriting);
220 static std::string GetComponentTypeAsString(IOComponentType);
223 static IOComponentType GetComponentTypeFromString(
const std::string &typeString);
227 static std::string GetPixelTypeAsString(IOPixelType);
230 static IOPixelType GetPixelTypeFromString(
const std::string &pixelString);
234 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
238 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
242 itkSetEnumMacro(FileType, FileType);
243 itkGetEnumMacro(FileType, FileType);
246 this->SetFileType(ASCII);
252 this->SetFileType(Binary);
266 itkSetEnumMacro(ByteOrder, ByteOrder);
267 itkGetEnumMacro(ByteOrder, ByteOrder);
270 this->SetByteOrder(BigEndian);
276 this->SetByteOrder(LittleEndian);
281 std::string GetFileTypeAsString(FileType)
const;
285 std::string GetByteOrderAsString(ByteOrder)
const;
300 virtual SizeType GetPixelStride()
const;
303 SizeType GetImageSizeInPixels()
const;
306 SizeType GetImageSizeInBytes()
const;
310 SizeType GetImageSizeInComponents()
const;
316 virtual unsigned int GetComponentSize()
const;
322 virtual bool CanReadFile(
const char *) = 0;
335 virtual void ReadImageInformation() = 0;
338 virtual void Read(
void *buffer) = 0;
344 virtual bool CanWriteFile(
const char *) = 0;
359 virtual void WriteImageInformation() = 0;
364 virtual void Write(
const void *buffer) = 0;
390 GenerateStreamableReadRegionFromRequestedRegion(
const ImageIORegion & requested)
const;
406 virtual unsigned int GetActualNumberOfSplitsForWriting(
unsigned int numberOfRequestedSplits,
416 virtual ImageIORegion GetSplitRegionForWriting(
unsigned int ithPiece,
417 unsigned int numberOfActualSplits,
436 template <
typename TPixel>
437 void SetTypeInfo(
const TPixel *);
440 template <
typename TPixel>
444 UNKNOWNCOMPONENTTYPE;
446 template <
typename TPixel>
449 this->SetNumberOfComponents(1);
450 this->SetPixelType(SCALAR);
453 template <
typename TPixel>
456 this->SetNumberOfComponents(3);
457 this->SetPixelType(RGB);
460 template <
typename TPixel>
463 this->SetNumberOfComponents(4);
464 this->SetPixelType(RGBA);
467 template <
typename TPixel,
unsigned VLength>
470 this->SetNumberOfComponents(VLength);
471 this->SetPixelType(VECTOR);
474 template <
typename TPixel>
477 this->SetNumberOfComponents(1);
478 this->SetPixelType(VECTOR);
481 template <
typename TPixel,
unsigned VLength>
484 this->SetNumberOfComponents(VLength);
485 this->SetPixelType(COVARIANTVECTOR);
488 template <
typename TPixel,
unsigned VLength>
491 this->SetNumberOfComponents(VLength);
492 this->SetPixelType(COVARIANTVECTOR);
497 template <
typename TPixel,
unsigned VLength>
500 this->SetNumberOfComponents(VLength * (VLength + 1) / 2 );
501 this->SetPixelType(SYMMETRICSECONDRANKTENSOR);
505 template <
typename TPixel>
508 this->SetNumberOfComponents(6);
509 this->SetPixelType(DIFFUSIONTENSOR3D);
513 template <
typename TPixel,
unsigned VLength>
516 this->SetNumberOfComponents(VLength * VLength);
517 this->SetPixelType(MATRIX);
521 template <
typename TPixel>
524 this->SetNumberOfComponents(2);
525 this->SetPixelType(COMPLEX);
529 template <
unsigned VLength>
532 this->SetNumberOfComponents(VLength);
540 virtual void PrintSelf(std::ostream & os,
Indent indent)
const ITK_OVERRIDE;
600 virtual void Reset(
const bool freeDynamic =
true);
603 void Resize(
const unsigned int numDimensions,
604 const unsigned int *dimensions);
608 virtual unsigned int GetPixelSize()
const;
616 void ComputeStrides();
620 SizeType GetComponentStride()
const;
641 virtual void OpenFileForReading(std::ifstream & inputStream,
const std::string & filename,
659 virtual void OpenFileForWriting(std::ofstream & outputStream,
const std::string & filename,
660 bool truncate =
true,
bool ascii =
false);
663 virtual void WriteBufferAsASCII(std::ostream & os,
const void *buffer,
668 virtual void ReadBufferAsASCII(std::istream & os,
void *buffer,
673 bool ReadBufferAsBinary(std::istream & os,
void *buffer,
SizeType numberOfBytesToBeRead);
676 void AddSupportedReadExtension(
const char *extension);
679 void AddSupportedWriteExtension(
const char *extension);
683 virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(
unsigned int numberOfRequestedSplits,
688 virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(
unsigned int ithPiece,
689 unsigned int numberOfActualSplits,
694 void operator=(
const Self &);
700 #define IMAGEIOBASE_TYPEMAP(type,ctype) \
701 template <> struct ImageIOBase::MapPixelType<type> \
703 static const IOComponentType CType = ctype; \
707 #if VCL_CHAR_IS_SIGNED
709 #endif // VCL_CHAR_IS_SIGNED
720 #undef IMAGIOBASE_TYPEMAP
725 #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 itk::SizeValueType GetDimensions(unsigned int i) const
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.
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 > *)
std::vector< double > m_Origin
void SetPixelTypeInfo(const VariableLengthVector< TPixel > *)
std::vector< double > m_Spacing
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
ArrayOfExtensionsType m_SupportedReadExtensions
void SetFileTypeToBinary()
unsigned int m_NumberOfDimensions
Simulate a standard C array with copy semnatics.
bool m_UseStreamedWriting
bool m_UseStreamedReading
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.
std::vector< std::vector< double > > m_Direction
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
IOComponentType m_ComponentType
void SetPixelTypeInfo(const CovariantVector< TPixel, VLength > *)
::itk::OffsetValueType BufferSizeType
void SetPixelTypeInfo(const RGBPixel< TPixel > *)
::itk::IndexValueType IndexValueType
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()
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 > *)
std::vector< SizeValueType > m_Dimensions
void SetPixelTypeInfo(const FixedArray< TPixel, VLength > *)
virtual bool CanStreamWrite()