18 #ifndef __itkImageIOBase_h
19 #define __itkImageIOBase_h
21 #include "itkIOConfigure.h"
33 #include "vnl/vnl_vector.h"
79 itkSetStringMacro(FileName);
80 itkGetStringMacro(FileName);
97 typedef enum { UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
99 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, MATRIX } IOPixelType;
105 typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
106 ULONG, LONG, FLOAT, DOUBLE } IOComponentType;
111 void SetNumberOfDimensions(
unsigned int);
113 itkGetConstMacro(NumberOfDimensions,
unsigned int);
118 virtual void SetDimensions(
unsigned int i,
unsigned int dim);
121 virtual unsigned int GetDimensions(
unsigned int i)
const
122 {
return m_Dimensions[i]; }
126 virtual void SetOrigin(
unsigned int i,
double origin);
128 virtual double GetOrigin(
unsigned int i)
const
135 virtual void SetSpacing(
unsigned int i,
double spacing);
137 virtual double GetSpacing(
unsigned int i)
const
144 virtual void SetDirection(
unsigned int i, std::vector< double > & direction);
148 virtual std::vector< double > GetDirection(
unsigned int i)
const
150 return m_Direction[i];
155 virtual std::vector< double > GetDefaultDirection(
unsigned int i)
const;
172 itkSetEnumMacro(PixelType, IOPixelType);
173 itkGetEnumMacro(PixelType, IOPixelType);
178 itkSetEnumMacro(ComponentType, IOComponentType);
179 itkGetEnumMacro(ComponentType, IOComponentType);
186 virtual const std::type_info & GetComponentTypeInfo()
const;
192 itkSetMacro(NumberOfComponents,
unsigned int);
193 itkGetConstReferenceMacro(NumberOfComponents,
unsigned int);
197 itkSetMacro(UseCompression,
bool);
198 itkGetConstMacro(UseCompression,
bool);
199 itkBooleanMacro(UseCompression);
203 itkSetMacro(UseStreamedReading,
bool);
204 itkGetConstMacro(UseStreamedReading,
bool);
205 itkBooleanMacro(UseStreamedReading);
209 itkSetMacro(UseStreamedWriting,
bool);
210 itkGetConstMacro(UseStreamedWriting,
bool);
211 itkBooleanMacro(UseStreamedWriting);
216 static std::string GetComponentTypeAsString(IOComponentType);
219 static IOComponentType GetComponentTypeFromString(
const std::string &typeString);
223 static std::string GetPixelTypeAsString(IOPixelType);
226 static IOPixelType GetPixelTypeFromString(
const std::string &pixelString);
230 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
234 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
238 itkSetEnumMacro(FileType, FileType);
239 itkGetEnumMacro(FileType, FileType);
240 void SetFileTypeToASCII()
242 this->SetFileType(ASCII);
246 void SetFileTypeToBinary()
248 this->SetFileType(Binary);
262 itkSetEnumMacro(ByteOrder, ByteOrder);
263 itkGetEnumMacro(ByteOrder, ByteOrder);
264 void SetByteOrderToBigEndian()
266 this->SetByteOrder(BigEndian);
270 void SetByteOrderToLittleEndian()
272 this->SetByteOrder(LittleEndian);
277 std::string GetFileTypeAsString(FileType)
const;
281 std::string GetByteOrderAsString(ByteOrder)
const;
296 virtual SizeType GetPixelStride()
const;
299 SizeType GetImageSizeInPixels()
const;
302 SizeType GetImageSizeInBytes()
const;
306 SizeType GetImageSizeInComponents()
const;
312 virtual unsigned int GetComponentSize()
const;
318 virtual bool CanReadFile(
const char *) = 0;
324 virtual bool CanStreamRead()
331 virtual void ReadImageInformation() = 0;
334 virtual void Read(
void *buffer) = 0;
340 virtual bool CanWriteFile(
const char *) = 0;
348 virtual bool CanStreamWrite()
355 virtual void WriteImageInformation() = 0;
360 virtual void Write(
const void *buffer) = 0;
369 virtual bool SupportsDimension(
unsigned long dim)
386 GenerateStreamableReadRegionFromRequestedRegion(
const ImageIORegion & requested)
const;
402 virtual unsigned int GetActualNumberOfSplitsForWriting(
unsigned int numberOfRequestedSplits,
412 virtual ImageIORegion GetSplitRegionForWriting(
unsigned int ithPiece,
413 unsigned int numberOfActualSplits,
432 template <
typename TPixel>
433 void SetTypeInfo(
const TPixel *);
436 template <
typename TPixel>
440 UNKNOWNCOMPONENTTYPE;
442 template <
typename TPixel>
443 void SetPixelTypeInfo(
const TPixel *)
445 this->SetNumberOfComponents(1);
446 this->SetPixelType(SCALAR);
449 template <
typename TPixel>
452 this->SetNumberOfComponents(3);
453 this->SetPixelType(RGB);
456 template <
typename TPixel>
459 this->SetNumberOfComponents(4);
460 this->SetPixelType(RGBA);
463 template <
typename TPixel,
unsigned VLength>
466 this->SetNumberOfComponents(VLength);
467 this->SetPixelType(VECTOR);
470 template <
typename TPixel>
473 this->SetNumberOfComponents(1);
474 this->SetPixelType(VECTOR);
477 template <
typename TPixel,
unsigned VLength>
480 this->SetNumberOfComponents(VLength);
481 this->SetPixelType(COVARIANTVECTOR);
484 template <
typename TPixel,
unsigned VLength>
487 this->SetNumberOfComponents(VLength);
488 this->SetPixelType(COVARIANTVECTOR);
493 template <
class TPixel,
unsigned VLength>
496 this->SetNumberOfComponents(VLength * (VLength + 1) / 2 );
497 this->SetPixelType(SYMMETRICSECONDRANKTENSOR);
501 template <
typename TPixel>
504 this->SetNumberOfComponents(6);
505 this->SetPixelType(DIFFUSIONTENSOR3D);
509 template <
typename TPixel,
unsigned VLength>
512 this->SetNumberOfComponents(VLength * VLength);
513 this->SetPixelType(MATRIX);
517 template <
typename TPixel>
518 void SetPixelTypeInfo(
const std::complex< TPixel > *)
520 this->SetNumberOfComponents(2);
521 this->SetPixelType(COMPLEX);
525 template <
unsigned VLength>
528 this->SetNumberOfComponents(VLength);
535 void PrintSelf(std::ostream & os,
Indent indent)
const;
593 virtual void Reset(
const bool freeDynamic =
true);
596 void Resize(
const unsigned int numDimensions,
597 const unsigned int *dimensions);
601 virtual unsigned int GetPixelSize()
const;
609 void ComputeStrides();
613 SizeType GetComponentStride()
const;
624 virtual void WriteBufferAsASCII(std::ostream & os,
const void *buffer,
629 virtual void ReadBufferAsASCII(std::istream & os,
void *buffer,
634 bool ReadBufferAsBinary(std::istream & os,
void *buffer,
SizeType numberOfBytesToBeRead);
637 void AddSupportedReadExtension(
const char *extension);
640 void AddSupportedWriteExtension(
const char *extension);
644 virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(
unsigned int numberOfRequestedSplits,
649 virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(
unsigned int ithPiece,
650 unsigned int numberOfActualSplits,
655 void operator=(
const Self &);
661 #define IMAGEIOBASE_TYPEMAP(type,ctype) \
662 template <> struct ImageIOBase::MapPixelType<type> \
664 static const IOComponentType CType = ctype; \
677 #undef IMAGIOBASE_TYPEMAP
682 #endif // __itkImageIOBase_h