18 #ifndef itkMeshIOBase_h
19 #define itkMeshIOBase_h
20 #include "ITKIOMeshBaseExport.h"
99 itkSetStringMacro(FileName);
100 itkGetStringMacro(FileName);
106 typedef enum {UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
108 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, ARRAY,
MATRIX,
109 VARIABLELENGTHVECTOR, VARIABLESIZEMATRIX} IOPixelType;
114 typedef enum {UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
115 ULONG, LONG, LONGLONG,
ULONGLONG, FLOAT, DOUBLE, LDOUBLE} IOComponentType;
119 typedef enum {ASCII, BINARY, TYPENOTAPPLICABLE} FileType;
123 typedef enum {BigEndian, LittleEndian, OrderNotApplicable} ByteOrder;
126 typedef enum {VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
129 LAST_ITK_CELL, MAX_ITK_CELLS = 255} CellGeometryType;
136 itkSetEnumMacro(PointPixelType, IOPixelType);
137 itkGetEnumMacro(PointPixelType, IOPixelType);
138 itkSetEnumMacro(CellPixelType, IOPixelType);
139 itkGetEnumMacro(CellPixelType, IOPixelType);
144 itkSetEnumMacro(PointComponentType, IOComponentType);
145 itkGetEnumMacro(PointComponentType, IOComponentType);
146 itkSetEnumMacro(CellComponentType, IOComponentType);
147 itkGetEnumMacro(CellComponentType, IOComponentType);
148 itkSetEnumMacro(PointPixelComponentType, IOComponentType);
149 itkGetEnumMacro(PointPixelComponentType, IOComponentType);
150 itkSetEnumMacro(CellPixelComponentType, IOComponentType);
151 itkGetEnumMacro(CellPixelComponentType, IOComponentType);
154 template<
typename T >
159 template<
typename T >
160 void SetPixelType(
const T & itkNotUsed(dummy),
bool UsePointPixel =
true)
164 SetNumberOfPointPixelComponents(1);
166 SetPointPixelType(SCALAR);
170 SetNumberOfCellPixelComponents(1);
172 SetCellPixelType(SCALAR);
176 template<
typename T >
181 SetNumberOfPointPixelComponents(3);
183 SetPointPixelType(RGB);
187 SetNumberOfCellPixelComponents(3);
189 SetCellPixelType(RGB);
193 template<
typename T >
198 SetNumberOfPointPixelComponents(4);
200 SetPointPixelType(RGBA);
204 SetNumberOfCellPixelComponents(4);
206 SetCellPixelType(RGBA);
210 template<
typename T,
unsigned int VLength >
215 SetNumberOfPointPixelComponents(VLength);
217 SetPointPixelType(VECTOR);
221 SetNumberOfCellPixelComponents(VLength);
223 SetCellPixelType(VECTOR);
227 template<
typename T,
unsigned int VLength >
232 SetNumberOfPointPixelComponents(VLength);
234 SetPointPixelType(COVARIANTVECTOR);
238 SetNumberOfCellPixelComponents(VLength);
240 SetCellPixelType(COVARIANTVECTOR);
244 template<
typename T,
unsigned int VLength >
249 SetNumberOfPointPixelComponents(VLength);
251 SetPointPixelType(FIXEDARRAY);
255 SetNumberOfCellPixelComponents(VLength);
257 SetCellPixelType(FIXEDARRAY);
261 template<
typename T,
unsigned int VLength >
266 SetNumberOfPointPixelComponents(VLength * ( VLength + 1 ) / 2);
268 SetPointPixelType(SYMMETRICSECONDRANKTENSOR);
272 SetNumberOfCellPixelComponents(VLength * ( VLength + 1 ) / 2);
274 SetCellPixelType(SYMMETRICSECONDRANKTENSOR);
278 template<
typename T >
283 SetNumberOfPointPixelComponents(6);
285 SetPointPixelType(DIFFUSIONTENSOR3D);
289 SetNumberOfCellPixelComponents(6);
291 SetCellPixelType(DIFFUSIONTENSOR3D);
295 template<
typename T,
unsigned int NR,
unsigned int NC >
300 SetNumberOfPointPixelComponents(NR * NC);
302 SetPointPixelType(MATRIX);
306 SetNumberOfCellPixelComponents(NR * NC);
308 SetCellPixelType(MATRIX);
312 template<
typename T >
313 void SetPixelType(
const std::complex< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
317 SetNumberOfPointPixelComponents(2);
319 SetPointPixelType(COMPLEX);
323 SetNumberOfCellPixelComponents(2);
325 SetCellPixelType(COMPLEX);
329 template<
typename T >
334 SetNumberOfPointPixelComponents( array.
Size() );
336 SetPointPixelType(ARRAY);
340 SetNumberOfCellPixelComponents( array.
Size() );
342 SetCellPixelType(ARRAY);
346 template<
typename T >
351 SetNumberOfPointPixelComponents( vector.
Size() );
353 SetPointPixelType(VARIABLELENGTHVECTOR);
357 SetNumberOfCellPixelComponents( vector.
Size() );
359 SetCellPixelType(VARIABLELENGTHVECTOR);
363 template<
typename T >
368 SetNumberOfPointPixelComponents( matrix.
Rows() * matrix.
Cols() );
370 SetPointPixelType(VARIABLESIZEMATRIX);
374 SetNumberOfCellPixelComponents( matrix.
Rows() * matrix.
Cols() );
376 SetCellPixelType(VARIABLESIZEMATRIX);
384 itkSetMacro(NumberOfPointPixelComponents,
unsigned int);
385 itkGetConstMacro(NumberOfPointPixelComponents,
unsigned int);
386 itkSetMacro(NumberOfCellPixelComponents,
unsigned int);
387 itkGetConstMacro(NumberOfCellPixelComponents,
unsigned int);
388 itkSetMacro(PointDimension,
unsigned int);
389 itkGetConstMacro(PointDimension,
unsigned int);
400 itkSetMacro(UpdatePoints,
bool);
401 itkGetConstMacro(UpdatePoints,
bool);
402 itkSetMacro(UpdateCells,
bool);
403 itkGetConstMacro(UpdateCells,
bool);
404 itkSetMacro(UpdatePointData,
bool);
405 itkGetConstMacro(UpdatePointData,
bool);
406 itkSetMacro(UpdateCellData,
bool);
407 itkGetConstMacro(UpdateCellData,
bool);
410 unsigned int GetComponentSize(IOComponentType componentType)
const;
414 std::string GetComponentTypeAsString(IOComponentType)
const;
418 std::string GetPixelTypeAsString(IOPixelType)
const;
422 itkSetEnumMacro(FileType, FileType);
423 itkGetEnumMacro(FileType, FileType);
428 this->SetFileType(ASCII);
433 this->SetFileType(BINARY);
447 itkSetEnumMacro(ByteOrder, ByteOrder);
448 itkGetEnumMacro(ByteOrder, ByteOrder);
453 this->SetByteOrder(BigEndian);
458 this->SetByteOrder(LittleEndian);
462 itkSetMacro(UseCompression,
bool);
463 itkGetConstMacro(UseCompression,
bool);
464 itkBooleanMacro(UseCompression);
469 std::string GetFileTypeAsString(FileType)
const;
473 std::string GetByteOrderAsString(ByteOrder)
const;
478 virtual bool CanReadFile(
const char *) = 0;
482 virtual void ReadMeshInformation() = 0;
485 virtual void ReadPoints(
void *buffer) = 0;
487 virtual void ReadCells(
void *buffer) = 0;
489 virtual void ReadPointData(
void *buffer) = 0;
491 virtual void ReadCellData(
void *buffer) = 0;
497 virtual bool CanWriteFile(
const char *) = 0;
499 virtual void WriteMeshInformation() = 0;
501 virtual void WritePoints(
void *buffer) = 0;
503 virtual void WriteCells(
void *buffer) = 0;
505 virtual void WritePointData(
void *buffer) = 0;
507 virtual void WriteCellData(
void *buffer) = 0;
509 virtual void Write() = 0;
515 const ArrayOfExtensionsType & GetSupportedReadExtensions()
const;
521 const ArrayOfExtensionsType & GetSupportedWriteExtensions()
const;
527 void PrintSelf(std::ostream & os,
Indent indent)
const override;
530 void AddSupportedReadExtension(
const char *extension);
533 void AddSupportedWriteExtension(
const char *extension);
536 template<
typename T >
541 inputFile >> buffer[i];
547 template<
typename T >
550 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
552 if ( m_ByteOrder == BigEndian )
559 else if ( m_ByteOrder == LittleEndian )
569 template<
typename T >
577 outputFile << convert(buffer[ii * numberOfComponents + jj]) <<
" ";
585 template<
typename TOutput,
typename TInput >
588 if (
typeid( TInput ) ==
typeid( TOutput ) )
600 outputFile.write(reinterpret_cast< char * >( buffer ), numberOfComponents);
604 auto * data =
new TOutput[numberOfComponents];
607 data[ii] =
static_cast< TOutput
>( buffer[ii] );
619 outputFile.write(reinterpret_cast< char * >( data ), numberOfComponents);
627 template<
typename TInput,
typename TOutput >
630 if ( input && output )
637 auto numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
638 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
640 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
650 template<
typename TInput,
typename TOutput >
653 if ( input && output )
655 SizeValueType inputIndex = itk::NumericTraits< SizeValueType >::ZeroValue();
656 SizeValueType outputIndex = itk::NumericTraits< SizeValueType >::ZeroValue();
662 auto nn =
static_cast< unsigned int >( input[inputIndex++] );
663 if ( cellType == type )
665 output[outputIndex++] = nn;
666 for (
unsigned int jj = 0; jj < nn; jj++ )
668 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
681 template<
typename TInput,
typename TOutput >
684 if ( input && output )
690 output[outputIndex++] =
static_cast< TOutput
>( cellType );
691 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
692 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
694 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
703 template<
typename TInput,
typename TOutput >
706 if ( input && output )
712 auto numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
713 output[outputIndex++] =
static_cast< TOutput
>( cellType );
714 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
715 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
717 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
733 bool m_UseCompression{
false};
747 unsigned int m_NumberOfPointPixelComponents{0};
748 unsigned int m_NumberOfCellPixelComponents{0};
764 bool m_UpdatePoints{
false};
765 bool m_UpdateCells{
false};
766 bool m_UpdatePointData{
false};
767 bool m_UpdateCellData{
false};
773 #define MESHIOBASE_TYPEMAP(type, ctype) \
775 struct MeshIOBase:: MapComponentType< type > \
777 static constexpr IOComponentType CType = ctype; \
793 #undef MESHIOBASE_TYPEMAP
Array class with size defined at construction time.
void SetByteOrderToLittleEndian()
SizeValueType m_NumberOfCells
ArrayOfExtensionsType m_SupportedReadExtensions
A templated class holding a M x N size Matrix.
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)
IdentifierType SizeValueType
Define numeric traits for std::vector.
Represent Red, Green, Blue and Alpha components for color images.
Represent a symmetric tensor of second rank.
unsigned long SizeValueType
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)
void SetPixelType(const DiffusionTensor3D< T > &, bool UsePointPixel=true)
void WriteBufferAsAscii(T *buffer, std::ofstream &outputFile, SizeValueType numberOfLines, SizeValueType numberOfComponents)
unsigned int Cols() const
std::vector< std::string > ArrayOfExtensionsType
void SetFileTypeToASCII()
void SetPixelType(const Matrix< T, NR, NC > &, bool UsePointPixel=true)
SizeValueType m_NumberOfCellPixels
void SetPixelType(const RGBPixel< T > &, bool UsePointPixel=true)
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)
std::streamoff StreamOffsetType
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.
SizeValueType IdentifierType
void SetPixelType(const VariableSizeMatrix< T > &matrix, bool UsePointPixel=true)
SizeValueType Size() const
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
unsigned int Size() const
MESHIOBASE_TYPEMAP(unsigned char, UCHAR)
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)
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
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)
void ReadBufferAsBinary(T *buffer, std::ifstream &inputFile, SizeValueType numberOfComponents)
void SetByteOrderToBigEndian()
Base class for most ITK classes.
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)