18 #ifndef __itkMeshIOBase_h
19 #define __itkMeshIOBase_h
95 itkSetStringMacro(FileName);
96 itkGetStringMacro(FileName);
102 typedef enum {UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
104 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, ARRAY,
MATRIX,
105 VARIABLELENGTHVECTOR, VARIABLESIZEMATRIX} IOPixelType;
110 typedef enum {UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
111 ULONG, LONG, LONGLONG,
ULONGLONG, FLOAT, DOUBLE, LDOUBLE} IOComponentType;
115 typedef enum {ASCII, BINARY, TYPENOTAPPLICABLE} FileType;
119 typedef enum {BigEndian, LittleEndian, OrderNotApplicable} ByteOrder;
122 typedef enum {VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
125 LAST_ITK_CELL, MAX_ITK_CELLS = 255} CellGeometryType;
132 itkSetEnumMacro(PointPixelType, IOPixelType);
133 itkGetEnumMacro(PointPixelType, IOPixelType);
134 itkSetEnumMacro(CellPixelType, IOPixelType);
135 itkGetEnumMacro(CellPixelType, IOPixelType);
140 itkSetEnumMacro(PointComponentType, IOComponentType);
141 itkGetEnumMacro(PointComponentType, IOComponentType);
142 itkSetEnumMacro(CellComponentType, IOComponentType);
143 itkGetEnumMacro(CellComponentType, IOComponentType);
144 itkSetEnumMacro(PointPixelComponentType, IOComponentType);
145 itkGetEnumMacro(PointPixelComponentType, IOComponentType);
146 itkSetEnumMacro(CellPixelComponentType, IOComponentType);
147 itkGetEnumMacro(CellPixelComponentType, IOComponentType);
150 template<
typename T >
155 template<
typename T >
156 void SetPixelType(
const T & itkNotUsed(dummy),
bool UsePointPixel =
true)
160 SetNumberOfPointPixelComponents(1);
162 SetPointPixelType(SCALAR);
166 SetNumberOfCellPixelComponents(1);
168 SetCellPixelType(SCALAR);
172 template<
typename T >
173 void SetPixelType(
const RGBPixel< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
177 SetNumberOfPointPixelComponents(3);
179 SetPointPixelType(RGB);
183 SetNumberOfCellPixelComponents(3);
185 SetCellPixelType(RGB);
189 template<
typename T >
190 void SetPixelType(
const RGBAPixel< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
194 SetNumberOfPointPixelComponents(4);
196 SetPointPixelType(RGBA);
200 SetNumberOfCellPixelComponents(4);
202 SetCellPixelType(RGBA);
206 template<
typename T,
unsigned int VLength >
211 SetNumberOfPointPixelComponents(VLength);
213 SetPointPixelType(VECTOR);
217 SetNumberOfCellPixelComponents(VLength);
219 SetCellPixelType(VECTOR);
223 template<
typename T,
unsigned int VLength >
228 SetNumberOfPointPixelComponents(VLength);
230 SetPointPixelType(COVARIANTVECTOR);
234 SetNumberOfCellPixelComponents(VLength);
236 SetCellPixelType(COVARIANTVECTOR);
240 template<
typename T,
unsigned int VLength >
245 SetNumberOfPointPixelComponents(VLength);
247 SetPointPixelType(FIXEDARRAY);
251 SetNumberOfCellPixelComponents(VLength);
253 SetCellPixelType(FIXEDARRAY);
257 template<
typename T,
unsigned int VLength >
262 SetNumberOfPointPixelComponents(VLength * ( VLength + 1 ) / 2);
264 SetPointPixelType(SYMMETRICSECONDRANKTENSOR);
268 SetNumberOfCellPixelComponents(VLength * ( VLength + 1 ) / 2);
270 SetCellPixelType(SYMMETRICSECONDRANKTENSOR);
274 template<
typename T >
279 SetNumberOfPointPixelComponents(6);
281 SetPointPixelType(DIFFUSIONTENSOR3D);
285 SetNumberOfCellPixelComponents(6);
287 SetCellPixelType(DIFFUSIONTENSOR3D);
291 template<
typename T,
unsigned int NR,
unsigned int NC >
296 SetNumberOfPointPixelComponents(
NR * NC);
298 SetPointPixelType(MATRIX);
302 SetNumberOfCellPixelComponents(
NR * NC);
304 SetCellPixelType(MATRIX);
308 template<
typename T >
309 void SetPixelType(
const std::complex< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
313 SetNumberOfPointPixelComponents(2);
315 SetPointPixelType(COMPLEX);
319 SetNumberOfCellPixelComponents(2);
321 SetCellPixelType(COMPLEX);
325 template<
typename T >
326 void SetPixelType(
const Array< T > & array,
bool UsePointPixel =
true)
330 SetNumberOfPointPixelComponents( array.
Size() );
332 SetPointPixelType(ARRAY);
336 SetNumberOfCellPixelComponents( array.
Size() );
338 SetCellPixelType(ARRAY);
342 template<
typename T >
347 SetNumberOfPointPixelComponents( vector.
Size() );
349 SetPointPixelType(VARIABLELENGTHVECTOR);
353 SetNumberOfCellPixelComponents( vector.
Size() );
355 SetCellPixelType(VARIABLELENGTHVECTOR);
359 template<
typename T >
364 SetNumberOfPointPixelComponents( matrix.
Rows() * matrix.
Cols() );
366 SetPointPixelType(VARIABLESIZEMATRIX);
370 SetNumberOfCellPixelComponents( matrix.
Rows() * matrix.
Cols() );
372 SetCellPixelType(VARIABLESIZEMATRIX);
380 itkSetMacro(NumberOfPointPixelComponents,
unsigned int);
381 itkGetConstMacro(NumberOfPointPixelComponents,
unsigned int);
382 itkSetMacro(NumberOfCellPixelComponents,
unsigned int);
383 itkGetConstMacro(NumberOfCellPixelComponents,
unsigned int);
384 itkSetMacro(PointDimension,
unsigned int);
385 itkGetConstMacro(PointDimension,
unsigned int);
396 itkSetMacro(UpdatePoints,
bool);
397 itkGetConstMacro(UpdatePoints,
bool);
398 itkSetMacro(UpdateCells,
bool);
399 itkGetConstMacro(UpdateCells,
bool);
400 itkSetMacro(UpdatePointData,
bool);
401 itkGetConstMacro(UpdatePointData,
bool);
402 itkSetMacro(UpdateCellData,
bool);
403 itkGetConstMacro(UpdateCellData,
bool);
406 unsigned int GetComponentSize(IOComponentType componentType)
const;
410 std::string GetComponentTypeAsString(IOComponentType)
const;
414 std::string GetPixelTypeAsString(IOPixelType)
const;
418 itkSetEnumMacro(FileType, FileType);
419 itkGetEnumMacro(FileType, FileType);
422 void SetFileTypeToASCII()
424 this->SetFileType(ASCII);
427 void SetFileTypeToBinary()
429 this->SetFileType(BINARY);
443 itkSetEnumMacro(ByteOrder, ByteOrder);
444 itkGetEnumMacro(ByteOrder, ByteOrder);
447 void SetByteOrderToBigEndian()
449 this->SetByteOrder(BigEndian);
452 void SetByteOrderToLittleEndian()
454 this->SetByteOrder(LittleEndian);
458 itkSetMacro(UseCompression,
bool);
459 itkGetConstMacro(UseCompression,
bool);
460 itkBooleanMacro(UseCompression);
465 std::string GetFileTypeAsString(FileType)
const;
469 std::string GetByteOrderAsString(ByteOrder)
const;
474 virtual bool CanReadFile(
const char *) = 0;
478 virtual void ReadMeshInformation() = 0;
481 virtual void ReadPoints(
void *buffer) = 0;
483 virtual void ReadCells(
void *buffer) = 0;
485 virtual void ReadPointData(
void *buffer) = 0;
487 virtual void ReadCellData(
void *buffer) = 0;
493 virtual bool CanWriteFile(
const char *) = 0;
495 virtual void WriteMeshInformation() = 0;
497 virtual void WritePoints(
void *buffer) = 0;
499 virtual void WriteCells(
void *buffer) = 0;
501 virtual void WritePointData(
void *buffer) = 0;
503 virtual void WriteCellData(
void *buffer) = 0;
505 virtual void Write() = 0;
511 const ArrayOfExtensionsType & GetSupportedReadExtensions()
const;
517 const ArrayOfExtensionsType & GetSupportedWriteExtensions()
const;
523 void PrintSelf(std::ostream & os,
Indent indent)
const;
526 void AddSupportedReadExtension(
const char *extension);
529 void AddSupportedWriteExtension(
const char *extension);
533 void ReadBufferAsAscii(T *buffer, std::ifstream & inputFile,
SizeValueType numberOfComponents)
537 inputFile >> buffer[i];
544 void ReadBufferAsBinary(T *buffer, std::ifstream & inputFile,
SizeValueType numberOfComponents)
546 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
548 if ( m_ByteOrder == BigEndian )
555 else if ( m_ByteOrder == LittleEndian )
572 outputFile << buffer[ii * numberOfComponents + jj] <<
" ";
580 template<
class TOutput,
class TInput >
581 void WriteBufferAsBinary(TInput *buffer, std::ofstream & outputFile,
SizeValueType numberOfComponents)
583 if (
typeid( TInput ) ==
typeid( TOutput ) )
595 outputFile.write(reinterpret_cast< char * >( buffer ), numberOfComponents);
599 TOutput *data =
new TOutput[numberOfComponents];
602 data[ii] =
static_cast< TOutput
>( buffer[ii] );
614 outputFile.write(reinterpret_cast< char * >( data ), numberOfComponents);
621 template<
class TInput,
class TOutput >
622 void ReadCellsBuffer(TInput *input, TOutput *output)
624 if ( input && output )
631 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
632 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
634 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
644 template<
class TInput,
class TOutput >
647 if ( input && output )
656 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
657 if ( cellType == type )
659 output[outputIndex++] = nn;
660 for (
unsigned int jj = 0; jj < nn; jj++ )
662 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
675 template<
class TInput,
class TOutput >
678 if ( input && output )
684 output[outputIndex++] =
static_cast< TOutput
>( cellType );
685 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
686 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
688 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
697 template<
class TInput,
class TOutput >
700 if ( input && output )
706 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
707 output[outputIndex++] =
static_cast< TOutput
>( cellType );
708 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
709 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
711 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
765 void operator=(
const Self &);
770 #define MESHIOBASE_TYPEMAP(type, ctype) \
772 struct MeshIOBase:: MapComponentType< type > \
774 static const IOComponentType CType = ctype; \
790 #undef MESHIOBASE_TYPEMAP