18 #ifndef __itkImageIOBase_h
19 #define __itkImageIOBase_h
21 #include "itkIOConfigure.h"
34 #include "vnl/vnl_vector.h"
80 itkSetStringMacro(FileName);
81 itkGetStringMacro(FileName);
98 typedef enum { UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
100 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, MATRIX } IOPixelType;
106 typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
107 ULONG, LONG, FLOAT, DOUBLE } IOComponentType;
112 void SetNumberOfDimensions(
unsigned int);
114 itkGetConstMacro(NumberOfDimensions,
unsigned int);
119 virtual void SetDimensions(
unsigned int i,
unsigned int dim);
123 {
return m_Dimensions[i]; }
127 virtual void SetOrigin(
unsigned int i,
double origin);
129 virtual double GetOrigin(
unsigned int i)
const
136 virtual void SetSpacing(
unsigned int i,
double spacing);
138 virtual double GetSpacing(
unsigned int i)
const
145 virtual void SetDirection(
unsigned int i, std::vector< double > & direction);
147 virtual void SetDirection(
unsigned int i, vnl_vector< double > & direction);
149 virtual std::vector< double > GetDirection(
unsigned int i)
const
151 return m_Direction[i];
156 virtual std::vector< double > GetDefaultDirection(
unsigned int i)
const;
173 itkSetEnumMacro(PixelType, IOPixelType);
174 itkGetEnumMacro(PixelType, IOPixelType);
179 itkSetEnumMacro(ComponentType, IOComponentType);
180 itkGetEnumMacro(ComponentType, IOComponentType);
187 virtual const std::type_info & GetComponentTypeInfo()
const;
193 itkSetMacro(NumberOfComponents,
unsigned int);
194 itkGetConstReferenceMacro(NumberOfComponents,
unsigned int);
198 itkSetMacro(UseCompression,
bool);
199 itkGetConstMacro(UseCompression,
bool);
200 itkBooleanMacro(UseCompression);
204 itkSetMacro(UseStreamedReading,
bool);
205 itkGetConstMacro(UseStreamedReading,
bool);
206 itkBooleanMacro(UseStreamedReading);
210 itkSetMacro(UseStreamedWriting,
bool);
211 itkGetConstMacro(UseStreamedWriting,
bool);
212 itkBooleanMacro(UseStreamedWriting);
217 static std::string GetComponentTypeAsString(IOComponentType);
220 static IOComponentType GetComponentTypeFromString(
const std::string &typeString);
224 static std::string GetPixelTypeAsString(IOPixelType);
227 static IOPixelType GetPixelTypeFromString(
const std::string &pixelString);
231 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
235 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
239 itkSetEnumMacro(FileType, FileType);
240 itkGetEnumMacro(FileType, FileType);
241 void SetFileTypeToASCII()
243 this->SetFileType(ASCII);
247 void SetFileTypeToBinary()
249 this->SetFileType(Binary);
263 itkSetEnumMacro(ByteOrder, ByteOrder);
264 itkGetEnumMacro(ByteOrder, ByteOrder);
265 void SetByteOrderToBigEndian()
267 this->SetByteOrder(BigEndian);
271 void SetByteOrderToLittleEndian()
273 this->SetByteOrder(LittleEndian);
278 std::string GetFileTypeAsString(FileType)
const;
282 std::string GetByteOrderAsString(ByteOrder)
const;
297 virtual SizeType GetPixelStride()
const;
300 SizeType GetImageSizeInPixels()
const;
303 SizeType GetImageSizeInBytes()
const;
307 SizeType GetImageSizeInComponents()
const;
313 virtual unsigned int GetComponentSize()
const;
319 virtual bool CanReadFile(
const char *) = 0;
325 virtual bool CanStreamRead()
332 virtual void ReadImageInformation() = 0;
335 virtual void Read(
void *buffer) = 0;
341 virtual bool CanWriteFile(
const char *) = 0;
349 virtual bool CanStreamWrite()
356 virtual void WriteImageInformation() = 0;
361 virtual void Write(
const void *buffer) = 0;
370 virtual bool SupportsDimension(
unsigned long dim)
387 GenerateStreamableReadRegionFromRequestedRegion(
const ImageIORegion & requested)
const;
403 virtual unsigned int GetActualNumberOfSplitsForWriting(
unsigned int numberOfRequestedSplits,
413 virtual ImageIORegion GetSplitRegionForWriting(
unsigned int ithPiece,
414 unsigned int numberOfActualSplits,
433 template <
typename TPixel>
434 void SetTypeInfo(
const TPixel *);
437 template <
typename TPixel>
441 UNKNOWNCOMPONENTTYPE;
443 template <
typename TPixel>
444 void SetPixelTypeInfo(
const TPixel *)
446 this->SetNumberOfComponents(1);
447 this->SetPixelType(SCALAR);
450 template <
typename TPixel>
453 this->SetNumberOfComponents(3);
454 this->SetPixelType(RGB);
457 template <
typename TPixel>
460 this->SetNumberOfComponents(4);
461 this->SetPixelType(RGBA);
464 template <
typename TPixel,
unsigned VLength>
467 this->SetNumberOfComponents(VLength);
468 this->SetPixelType(VECTOR);
471 template <
typename TPixel>
474 this->SetNumberOfComponents(1);
475 this->SetPixelType(VECTOR);
478 template <
typename TPixel,
unsigned VLength>
481 this->SetNumberOfComponents(VLength);
482 this->SetPixelType(COVARIANTVECTOR);
485 template <
typename TPixel,
unsigned VLength>
488 this->SetNumberOfComponents(VLength);
489 this->SetPixelType(COVARIANTVECTOR);
494 template <
class TPixel,
unsigned VLength>
497 this->SetNumberOfComponents(VLength * (VLength + 1) / 2 );
498 this->SetPixelType(SYMMETRICSECONDRANKTENSOR);
502 template <
typename TPixel>
505 this->SetNumberOfComponents(6);
506 this->SetPixelType(DIFFUSIONTENSOR3D);
510 template <
typename TPixel,
unsigned VLength>
513 this->SetNumberOfComponents(VLength * VLength);
514 this->SetPixelType(MATRIX);
518 template <
typename TPixel>
519 void SetPixelTypeInfo(
const std::complex< TPixel > *)
521 this->SetNumberOfComponents(2);
522 this->SetPixelType(COMPLEX);
526 template <
unsigned VLength>
529 this->SetNumberOfComponents(VLength);
537 void PrintSelf(std::ostream & os,
Indent indent)
const;
597 virtual void Reset(
const bool freeDynamic =
true);
600 void Resize(
const unsigned int numDimensions,
601 const unsigned int *dimensions);
605 virtual unsigned int GetPixelSize()
const;
613 void ComputeStrides();
617 SizeType GetComponentStride()
const;
628 virtual void WriteBufferAsASCII(std::ostream & os,
const void *buffer,
633 virtual void ReadBufferAsASCII(std::istream & os,
void *buffer,
638 bool ReadBufferAsBinary(std::istream & os,
void *buffer,
SizeType numberOfBytesToBeRead);
641 void AddSupportedReadExtension(
const char *extension);
644 void AddSupportedWriteExtension(
const char *extension);
648 virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(
unsigned int numberOfRequestedSplits,
653 virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(
unsigned int ithPiece,
654 unsigned int numberOfActualSplits,
659 void operator=(
const Self &);
665 #define IMAGEIOBASE_TYPEMAP(type,ctype) \
666 template <> struct ImageIOBase::MapPixelType<type> \
668 static const IOComponentType CType = ctype; \
681 #undef IMAGIOBASE_TYPEMAP
686 #endif // __itkImageIOBase_h