18 #ifndef __itkMeshIOBase_h
19 #define __itkMeshIOBase_h
96 itkSetStringMacro(FileName);
97 itkGetStringMacro(FileName);
103 typedef enum {UNKNOWNPIXELTYPE, SCALAR, RGB, RGBA, OFFSET,
VECTOR,
105 DIFFUSIONTENSOR3D, COMPLEX, FIXEDARRAY, ARRAY,
MATRIX,
106 VARIABLELENGTHVECTOR, VARIABLESIZEMATRIX} IOPixelType;
111 typedef enum {UNKNOWNCOMPONENTTYPE, UCHAR, CHAR,
USHORT, SHORT, UINT, INT,
112 ULONG, LONG, LONGLONG,
ULONGLONG, FLOAT, DOUBLE, LDOUBLE} IOComponentType;
116 typedef enum {ASCII, BINARY, TYPENOTAPPLICABLE} FileType;
120 typedef enum {BigEndian, LittleEndian, OrderNotApplicable} ByteOrder;
123 typedef enum {VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
126 LAST_ITK_CELL, MAX_ITK_CELLS = 255} CellGeometryType;
133 itkSetEnumMacro(PointPixelType, IOPixelType);
134 itkGetEnumMacro(PointPixelType, IOPixelType);
135 itkSetEnumMacro(CellPixelType, IOPixelType);
136 itkGetEnumMacro(CellPixelType, IOPixelType);
141 itkSetEnumMacro(PointComponentType, IOComponentType);
142 itkGetEnumMacro(PointComponentType, IOComponentType);
143 itkSetEnumMacro(CellComponentType, IOComponentType);
144 itkGetEnumMacro(CellComponentType, IOComponentType);
145 itkSetEnumMacro(PointPixelComponentType, IOComponentType);
146 itkGetEnumMacro(PointPixelComponentType, IOComponentType);
147 itkSetEnumMacro(CellPixelComponentType, IOComponentType);
148 itkGetEnumMacro(CellPixelComponentType, IOComponentType);
151 template<
typename T >
156 template<
typename T >
157 void SetPixelType(
const T & itkNotUsed(dummy),
bool UsePointPixel =
true)
161 SetNumberOfPointPixelComponents(1);
163 SetPointPixelType(SCALAR);
167 SetNumberOfCellPixelComponents(1);
169 SetCellPixelType(SCALAR);
173 template<
typename T >
174 void SetPixelType(
const RGBPixel< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
178 SetNumberOfPointPixelComponents(3);
180 SetPointPixelType(RGB);
184 SetNumberOfCellPixelComponents(3);
186 SetCellPixelType(RGB);
190 template<
typename T >
191 void SetPixelType(
const RGBAPixel< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
195 SetNumberOfPointPixelComponents(4);
197 SetPointPixelType(RGBA);
201 SetNumberOfCellPixelComponents(4);
203 SetCellPixelType(RGBA);
207 template<
typename T,
unsigned int VLength >
212 SetNumberOfPointPixelComponents(VLength);
214 SetPointPixelType(VECTOR);
218 SetNumberOfCellPixelComponents(VLength);
220 SetCellPixelType(VECTOR);
224 template<
typename T,
unsigned int VLength >
229 SetNumberOfPointPixelComponents(VLength);
231 SetPointPixelType(COVARIANTVECTOR);
235 SetNumberOfCellPixelComponents(VLength);
237 SetCellPixelType(COVARIANTVECTOR);
241 template<
typename T,
unsigned int VLength >
246 SetNumberOfPointPixelComponents(VLength);
248 SetPointPixelType(FIXEDARRAY);
252 SetNumberOfCellPixelComponents(VLength);
254 SetCellPixelType(FIXEDARRAY);
258 template<
typename T,
unsigned int VLength >
263 SetNumberOfPointPixelComponents(VLength * ( VLength + 1 ) / 2);
265 SetPointPixelType(SYMMETRICSECONDRANKTENSOR);
269 SetNumberOfCellPixelComponents(VLength * ( VLength + 1 ) / 2);
271 SetCellPixelType(SYMMETRICSECONDRANKTENSOR);
275 template<
typename T >
280 SetNumberOfPointPixelComponents(6);
282 SetPointPixelType(DIFFUSIONTENSOR3D);
286 SetNumberOfCellPixelComponents(6);
288 SetCellPixelType(DIFFUSIONTENSOR3D);
292 template<
typename T,
unsigned int NR,
unsigned int NC >
297 SetNumberOfPointPixelComponents(
NR * NC);
299 SetPointPixelType(MATRIX);
303 SetNumberOfCellPixelComponents(
NR * NC);
305 SetCellPixelType(MATRIX);
309 template<
typename T >
310 void SetPixelType(
const std::complex< T > & itkNotUsed(dummy),
bool UsePointPixel =
true)
314 SetNumberOfPointPixelComponents(2);
316 SetPointPixelType(COMPLEX);
320 SetNumberOfCellPixelComponents(2);
322 SetCellPixelType(COMPLEX);
326 template<
typename T >
327 void SetPixelType(
const Array< T > & array,
bool UsePointPixel =
true)
331 SetNumberOfPointPixelComponents( array.
Size() );
333 SetPointPixelType(ARRAY);
337 SetNumberOfCellPixelComponents( array.
Size() );
339 SetCellPixelType(ARRAY);
343 template<
typename T >
348 SetNumberOfPointPixelComponents( vector.
Size() );
350 SetPointPixelType(VARIABLELENGTHVECTOR);
354 SetNumberOfCellPixelComponents( vector.
Size() );
356 SetCellPixelType(VARIABLELENGTHVECTOR);
360 template<
typename T >
365 SetNumberOfPointPixelComponents( matrix.
Rows() * matrix.
Cols() );
367 SetPointPixelType(VARIABLESIZEMATRIX);
371 SetNumberOfCellPixelComponents( matrix.
Rows() * matrix.
Cols() );
373 SetCellPixelType(VARIABLESIZEMATRIX);
381 itkSetMacro(NumberOfPointPixelComponents,
unsigned int);
382 itkGetConstMacro(NumberOfPointPixelComponents,
unsigned int);
383 itkSetMacro(NumberOfCellPixelComponents,
unsigned int);
384 itkGetConstMacro(NumberOfCellPixelComponents,
unsigned int);
385 itkSetMacro(PointDimension,
unsigned int);
386 itkGetConstMacro(PointDimension,
unsigned int);
397 itkSetMacro(UpdatePoints,
bool);
398 itkGetConstMacro(UpdatePoints,
bool);
399 itkSetMacro(UpdateCells,
bool);
400 itkGetConstMacro(UpdateCells,
bool);
401 itkSetMacro(UpdatePointData,
bool);
402 itkGetConstMacro(UpdatePointData,
bool);
403 itkSetMacro(UpdateCellData,
bool);
404 itkGetConstMacro(UpdateCellData,
bool);
407 unsigned int GetComponentSize(IOComponentType componentType)
const;
411 std::string GetComponentTypeAsString(IOComponentType)
const;
415 std::string GetPixelTypeAsString(IOPixelType)
const;
419 itkSetEnumMacro(FileType, FileType);
420 itkGetEnumMacro(FileType, FileType);
423 void SetFileTypeToASCII()
425 this->SetFileType(ASCII);
428 void SetFileTypeToBinary()
430 this->SetFileType(BINARY);
444 itkSetEnumMacro(ByteOrder, ByteOrder);
445 itkGetEnumMacro(ByteOrder, ByteOrder);
448 void SetByteOrderToBigEndian()
450 this->SetByteOrder(BigEndian);
453 void SetByteOrderToLittleEndian()
455 this->SetByteOrder(LittleEndian);
459 itkSetMacro(UseCompression,
bool);
460 itkGetConstMacro(UseCompression,
bool);
461 itkBooleanMacro(UseCompression);
466 std::string GetFileTypeAsString(FileType)
const;
470 std::string GetByteOrderAsString(ByteOrder)
const;
475 virtual bool CanReadFile(
const char *) = 0;
479 virtual void ReadMeshInformation() = 0;
482 virtual void ReadPoints(
void *buffer) = 0;
484 virtual void ReadCells(
void *buffer) = 0;
486 virtual void ReadPointData(
void *buffer) = 0;
488 virtual void ReadCellData(
void *buffer) = 0;
494 virtual bool CanWriteFile(
const char *) = 0;
496 virtual void WriteMeshInformation() = 0;
498 virtual void WritePoints(
void *buffer) = 0;
500 virtual void WriteCells(
void *buffer) = 0;
502 virtual void WritePointData(
void *buffer) = 0;
504 virtual void WriteCellData(
void *buffer) = 0;
506 virtual void Write() = 0;
512 const ArrayOfExtensionsType & GetSupportedReadExtensions()
const;
518 const ArrayOfExtensionsType & GetSupportedWriteExtensions()
const;
524 void PrintSelf(std::ostream & os,
Indent indent)
const;
527 void AddSupportedReadExtension(
const char *extension);
530 void AddSupportedWriteExtension(
const char *extension);
534 void ReadBufferAsAscii(T *buffer, std::ifstream & inputFile,
SizeValueType numberOfComponents)
538 inputFile >> buffer[i];
545 void ReadBufferAsBinary(T *buffer, std::ifstream & inputFile,
SizeValueType numberOfComponents)
547 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
549 if ( m_ByteOrder == BigEndian )
556 else if ( m_ByteOrder == LittleEndian )
574 outputFile << convert(buffer[ii * numberOfComponents + jj]) <<
" ";
582 template<
class TOutput,
class TInput >
583 void WriteBufferAsBinary(TInput *buffer, std::ofstream & outputFile,
SizeValueType numberOfComponents)
585 if (
typeid( TInput ) ==
typeid( TOutput ) )
597 outputFile.write(reinterpret_cast< char * >( buffer ), numberOfComponents);
601 TOutput *data =
new TOutput[numberOfComponents];
604 data[ii] =
static_cast< TOutput
>( buffer[ii] );
616 outputFile.write(reinterpret_cast< char * >( data ), numberOfComponents);
623 template<
class TInput,
class TOutput >
624 void ReadCellsBuffer(TInput *input, TOutput *output)
626 if ( input && output )
633 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
634 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
636 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
646 template<
class TInput,
class TOutput >
649 if ( input && output )
658 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
659 if ( cellType == type )
661 output[outputIndex++] = nn;
662 for (
unsigned int jj = 0; jj < nn; jj++ )
664 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
677 template<
class TInput,
class TOutput >
680 if ( input && output )
686 output[outputIndex++] =
static_cast< TOutput
>( cellType );
687 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
688 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
690 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
699 template<
class TInput,
class TOutput >
702 if ( input && output )
708 unsigned int numberOfPoints =
static_cast< unsigned int >( input[inputIndex++] );
709 output[outputIndex++] =
static_cast< TOutput
>( cellType );
710 output[outputIndex++] =
static_cast< TOutput
>( numberOfPoints );
711 for (
unsigned int jj = 0; jj < numberOfPoints; jj++ )
713 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
767 void operator=(
const Self &);
772 #define MESHIOBASE_TYPEMAP(type, ctype) \
774 struct MeshIOBase:: MapComponentType< type > \
776 static const IOComponentType CType = ctype; \
792 #undef MESHIOBASE_TYPEMAP