18 #ifndef __itkMeshIOBase_h
19 #define __itkMeshIOBase_h
20 #include "ITKIOMeshExport.h"
97 itkSetStringMacro(FileName);
98 itkGetStringMacro(FileName);
104 typedef enum {UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
106 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, ARRAY,
MATRIX,
107 VARIABLELENGTHVECTOR, VARIABLESIZEMATRIX} IOPixelType;
112 typedef enum {UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
113 ULONG, LONG, LONGLONG,
ULONGLONG, FLOAT, DOUBLE, LDOUBLE} IOComponentType;
117 typedef enum {ASCII, BINARY, TYPENOTAPPLICABLE} FileType;
121 typedef enum {BigEndian, LittleEndian, OrderNotApplicable} ByteOrder;
124 typedef enum {VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
127 LAST_ITK_CELL, MAX_ITK_CELLS = 255} CellGeometryType;
134 itkSetEnumMacro(PointPixelType, IOPixelType);
135 itkGetEnumMacro(PointPixelType, IOPixelType);
136 itkSetEnumMacro(CellPixelType, IOPixelType);
137 itkGetEnumMacro(CellPixelType, IOPixelType);
142 itkSetEnumMacro(PointComponentType, IOComponentType);
143 itkGetEnumMacro(PointComponentType, IOComponentType);
144 itkSetEnumMacro(CellComponentType, IOComponentType);
145 itkGetEnumMacro(CellComponentType, IOComponentType);
146 itkSetEnumMacro(PointPixelComponentType, IOComponentType);
147 itkGetEnumMacro(PointPixelComponentType, IOComponentType);
148 itkSetEnumMacro(CellPixelComponentType, IOComponentType);
149 itkGetEnumMacro(CellPixelComponentType, IOComponentType);
152 template<
typename T >
157 template<
typename T >
158 void SetPixelType(
const T & itkNotUsed(dummy),
bool UsePointPixel =
true)
162 SetNumberOfPointPixelComponents(1);
164 SetPointPixelType(SCALAR);
168 SetNumberOfCellPixelComponents(1);
170 SetCellPixelType(SCALAR);
174 template<
typename T >
179 SetNumberOfPointPixelComponents(3);
181 SetPointPixelType(RGB);
185 SetNumberOfCellPixelComponents(3);
187 SetCellPixelType(RGB);
191 template<
typename T >
196 SetNumberOfPointPixelComponents(4);
198 SetPointPixelType(RGBA);
202 SetNumberOfCellPixelComponents(4);
204 SetCellPixelType(RGBA);
208 template<
typename T,
unsigned int VLength >
213 SetNumberOfPointPixelComponents(VLength);
215 SetPointPixelType(VECTOR);
219 SetNumberOfCellPixelComponents(VLength);
221 SetCellPixelType(VECTOR);
225 template<
typename T,
unsigned int VLength >
230 SetNumberOfPointPixelComponents(VLength);
232 SetPointPixelType(COVARIANTVECTOR);
236 SetNumberOfCellPixelComponents(VLength);
238 SetCellPixelType(COVARIANTVECTOR);
242 template<
typename T,
unsigned int VLength >
247 SetNumberOfPointPixelComponents(VLength);
249 SetPointPixelType(FIXEDARRAY);
253 SetNumberOfCellPixelComponents(VLength);
255 SetCellPixelType(FIXEDARRAY);
259 template<
typename T,
unsigned int VLength >
264 SetNumberOfPointPixelComponents(VLength * ( VLength + 1 ) / 2);
266 SetPointPixelType(SYMMETRICSECONDRANKTENSOR);
270 SetNumberOfCellPixelComponents(VLength * ( VLength + 1 ) / 2);
272 SetCellPixelType(SYMMETRICSECONDRANKTENSOR);
276 template<
typename T >
281 SetNumberOfPointPixelComponents(6);
283 SetPointPixelType(DIFFUSIONTENSOR3D);
287 SetNumberOfCellPixelComponents(6);
289 SetCellPixelType(DIFFUSIONTENSOR3D);
293 template<
typename T,
unsigned int NR,
unsigned int NC >
298 SetNumberOfPointPixelComponents(
NR * NC);
300 SetPointPixelType(MATRIX);
304 SetNumberOfCellPixelComponents(
NR * NC);
306 SetCellPixelType(MATRIX);
310 template<
typename T >
311 void SetPixelType(
const std::complex< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
315 SetNumberOfPointPixelComponents(2);
317 SetPointPixelType(COMPLEX);
321 SetNumberOfCellPixelComponents(2);
323 SetCellPixelType(COMPLEX);
327 template<
typename T >
332 SetNumberOfPointPixelComponents( array.
Size() );
334 SetPointPixelType(ARRAY);
338 SetNumberOfCellPixelComponents( array.
Size() );
340 SetCellPixelType(ARRAY);
344 template<
typename T >
349 SetNumberOfPointPixelComponents( vector.
Size() );
351 SetPointPixelType(VARIABLELENGTHVECTOR);
355 SetNumberOfCellPixelComponents( vector.
Size() );
357 SetCellPixelType(VARIABLELENGTHVECTOR);
361 template<
typename T >
366 SetNumberOfPointPixelComponents( matrix.
Rows() * matrix.
Cols() );
368 SetPointPixelType(VARIABLESIZEMATRIX);
372 SetNumberOfCellPixelComponents( matrix.
Rows() * matrix.
Cols() );
374 SetCellPixelType(VARIABLESIZEMATRIX);
382 itkSetMacro(NumberOfPointPixelComponents,
unsigned int);
383 itkGetConstMacro(NumberOfPointPixelComponents,
unsigned int);
384 itkSetMacro(NumberOfCellPixelComponents,
unsigned int);
385 itkGetConstMacro(NumberOfCellPixelComponents,
unsigned int);
386 itkSetMacro(PointDimension,
unsigned int);
387 itkGetConstMacro(PointDimension,
unsigned int);
398 itkSetMacro(UpdatePoints,
bool);
399 itkGetConstMacro(UpdatePoints,
bool);
400 itkSetMacro(UpdateCells,
bool);
401 itkGetConstMacro(UpdateCells,
bool);
402 itkSetMacro(UpdatePointData,
bool);
403 itkGetConstMacro(UpdatePointData,
bool);
404 itkSetMacro(UpdateCellData,
bool);
405 itkGetConstMacro(UpdateCellData,
bool);
408 unsigned int GetComponentSize(IOComponentType componentType)
const;
412 std::string GetComponentTypeAsString(IOComponentType)
const;
416 std::string GetPixelTypeAsString(IOPixelType)
const;
420 itkSetEnumMacro(FileType, FileType);
421 itkGetEnumMacro(FileType, FileType);
426 this->SetFileType(ASCII);
431 this->SetFileType(BINARY);
445 itkSetEnumMacro(ByteOrder, ByteOrder);
446 itkGetEnumMacro(ByteOrder, ByteOrder);
451 this->SetByteOrder(BigEndian);
456 this->SetByteOrder(LittleEndian);
460 itkSetMacro(UseCompression,
bool);
461 itkGetConstMacro(UseCompression,
bool);
462 itkBooleanMacro(UseCompression);
467 std::string GetFileTypeAsString(FileType)
const;
471 std::string GetByteOrderAsString(ByteOrder)
const;
476 virtual bool CanReadFile(
const char *) = 0;
480 virtual void ReadMeshInformation() = 0;
483 virtual void ReadPoints(
void *buffer) = 0;
485 virtual void ReadCells(
void *buffer) = 0;
487 virtual void ReadPointData(
void *buffer) = 0;
489 virtual void ReadCellData(
void *buffer) = 0;
495 virtual bool CanWriteFile(
const char *) = 0;
497 virtual void WriteMeshInformation() = 0;
499 virtual void WritePoints(
void *buffer) = 0;
501 virtual void WriteCells(
void *buffer) = 0;
503 virtual void WritePointData(
void *buffer) = 0;
505 virtual void WriteCellData(
void *buffer) = 0;
507 virtual void Write() = 0;
513 const ArrayOfExtensionsType & GetSupportedReadExtensions()
const;
519 const ArrayOfExtensionsType & GetSupportedWriteExtensions()
const;
525 virtual void PrintSelf(std::ostream & os,
Indent indent)
const ITK_OVERRIDE;
528 void AddSupportedReadExtension(
const char *extension);
531 void AddSupportedWriteExtension(
const char *extension);
534 template<
typename T >
539 inputFile >> buffer[i];
545 template<
typename T >
548 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
550 if ( m_ByteOrder == BigEndian )
557 else if ( m_ByteOrder == LittleEndian )
567 template<
typename T >
575 outputFile << convert(buffer[ii * numberOfComponents + jj]) <<
" ";
583 template<
typename TOutput,
typename TInput >
586 if (
typeid( TInput ) ==
typeid( TOutput ) )
598 outputFile.write(reinterpret_cast< char * >( buffer ), numberOfComponents);
602 TOutput *data =
new TOutput[numberOfComponents];
605 data[ii] =
static_cast< TOutput
>( buffer[ii] );
617 outputFile.write(reinterpret_cast< char * >( data ), numberOfComponents);
625 template<
typename TInput,
typename TOutput >
628 if ( input && output )
635 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
636 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
638 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
648 template<
typename TInput,
typename TOutput >
651 if ( input && output )
660 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
661 if ( cellType == type )
663 output[outputIndex++] = nn;
664 for (
unsigned int jj = 0; jj < nn; jj++ )
666 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
679 template<
typename TInput,
typename TOutput >
682 if ( input && output )
688 output[outputIndex++] =
static_cast< TOutput
>( cellType );
689 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
690 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
692 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
701 template<
typename TInput,
typename TOutput >
704 if ( input && output )
710 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
711 output[outputIndex++] =
static_cast< TOutput
>( cellType );
712 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
713 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
715 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
769 void operator=(
const Self &);
774 #define MESHIOBASE_TYPEMAP(type, ctype) \
776 struct MeshIOBase:: MapComponentType< type > \
778 static const IOComponentType CType = ctype; \
794 #undef MESHIOBASE_TYPEMAP
Array class with size defined at construction time.
void SetByteOrderToLittleEndian()
SizeValueType m_NumberOfCells
ArrayOfExtensionsType m_SupportedReadExtensions
SmartPointer< const Self > ConstPointer
A templated class holding a M x N size Matrix.
unsigned int m_NumberOfPointPixelComponents
unsigned int Rows() const
Light weight base class for most itk classes.
void ReadCellsBuffer(TInput *input, TOutput *output)
SizeValueType m_NumberOfPoints
SizeValueType m_CellBufferSize
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryType cellType, unsigned int numberOfPoints, SizeValueType numberOfCells)
std::streamoff StreamOffsetType
unsigned int Size(void) const
IOComponentType m_PointComponentType
Represent Red, Green, Blue and Alpha components for color images.
Represent a symmetric tensor of second rank.
unsigned int m_PointDimension
void SetPixelType(const Array< T > &array, bool UsePointPixel=true)
A templated class holding a M x N size Matrix.
void SetPixelType(const RGBAPixel< T > &, bool UsePointPixel=true)
IOComponentType m_CellComponentType
void SetPixelType(const DiffusionTensor3D< T > &, bool UsePointPixel=true)
*brief Mask an image with the negative of a mask **This class is templated over the types of the *input image type
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
IOComponentType m_PointPixelComponentType
unsigned int Cols() const
IdentifierType SizeValueType
void SetFileTypeToASCII()
void SetPixelType(const Matrix< T, NR, NC > &, bool UsePointPixel=true)
SizeValueType m_NumberOfCellPixels
void SetPixelType(const RGBPixel< T > &, bool UsePointPixel=true)
unsigned long SizeValueType
void SetPixelType(const SymmetricSecondRankTensor< T, VLength >, bool UsePointPixel=true)
void ReadBufferAsAscii(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
Simulate a standard C array with copy semnatics.
void SetPixelType(const Vector< T, VLength > &, bool UsePointPixel=true)
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
SizeValueType IdentifierType
void SetPixelType(const FixedArray< T, VLength > &, bool UsePointPixel=true)
Represents an array whose length can be defined at run-time.
Convert floating and fixed point numbers to strings.
A templated class holding a n-Dimensional vector.
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool UsePointPixel=true)
ArrayOfExtensionsType m_SupportedWriteExtensions
void WriteCellsBuffer(TInput *input, TOutput *output, CellGeometryType cellType, SizeValueType numberOfCells)
void SetFileTypeToBinary()
static void SwapRangeFromSystemToLittleEndian(T *p, BufferSizeType num)
SizeValueType m_NumberOfPointPixels
IOPixelType m_CellPixelType
LightProcessObject Superclass
MESHIOBASE_TYPEMAP(unsigned char, UCHAR)
SmartPointer< Self > Pointer
void ReadCellsBuffer(TInput *input, TOutput *output, MeshIOBase::CellGeometryType type)
Represent Red, Green and Blue components for color images.
void SetPixelType(const T &, bool UsePointPixel=true)
IOComponentType m_CellPixelComponentType
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
SizeValueType Size(void) const
IOPixelType m_PointPixelType
void SetPixelType(const CovariantVector< T, VLength > &, bool UsePointPixel=true)
void SetPixelType(const std::complex< T > &, bool UsePointPixel=true)
Abstract superclass defines mesh IO interface.
void WriteBufferAsBinary(TInput *buffer, std::ofstream &outputFile, SizeValueType numberOfComponents)
Define additional traits for native types such as int or float.
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
void SetByteOrderToBigEndian()
Perform machine dependent byte swapping.
Represent a diffusion tensor as used in DTI images.
A templated class holding a n-Dimensional covariant vector.
void SetPixelType(const VariableLengthVector< T > &vector, bool UsePointPixel=true)
std::vector< std::string > ArrayOfExtensionsType
unsigned int m_NumberOfCellPixelComponents