18 #ifndef itkVTKPolyDataMeshIO_h
19 #define itkVTKPolyDataMeshIO_h
20 #include "ITKIOMeshExport.h"
71 virtual bool CanReadFile(
const char *FileNameToRead) ITK_OVERRIDE;
74 virtual void ReadMeshInformation() ITK_OVERRIDE;
77 virtual
void ReadPoints(
void *buffer) ITK_OVERRIDE;
79 virtual
void ReadCells(
void *buffer) ITK_OVERRIDE;
81 virtual
void ReadPointData(
void *buffer) ITK_OVERRIDE;
83 virtual
void ReadCellData(
void *buffer) ITK_OVERRIDE;
91 virtual
bool CanWriteFile(const
char *FileNameToWrite) ITK_OVERRIDE;
94 virtual
void WriteMeshInformation() ITK_OVERRIDE;
98 virtual
void WritePoints(
void *buffer) ITK_OVERRIDE;
100 virtual
void WriteCells(
void *buffer) ITK_OVERRIDE;
102 virtual
void WritePointData(
void *buffer) ITK_OVERRIDE;
104 virtual
void WriteCellData(
void *buffer) ITK_OVERRIDE;
106 virtual
void Write() ITK_OVERRIDE;
110 virtual ~VTKPolyDataMeshIO() ITK_OVERRIDE;
112 virtual
void PrintSelf(std::ostream & os,
Indent indent) const ITK_OVERRIDE;
114 template< typename T >
115 void UpdateCellInformation(T *buffer)
117 unsigned int numberOfVertices = 0;
118 unsigned int numberOfVertexIndices = 0;
119 unsigned int numberOfLines = 0;
121 unsigned int numberOfPolygons = 0;
122 unsigned int numberOfPolygonIndices = 0;
126 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
129 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
134 numberOfVertexIndices += nn + 1;
138 numberOfLineIndices += nn + 1;
142 numberOfPolygonIndices += nn + 1;
146 numberOfPolygonIndices += nn + 1;
148 case QUADRILATERAL_CELL:
150 numberOfPolygonIndices += nn + 1;
153 itkExceptionMacro(<<
"Currently we dont support this cell type");
160 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
161 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
162 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
163 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
164 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
165 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
169 template<
typename T >
174 while ( !inputFile.eof() )
176 std::getline(inputFile, line,
'\n');
178 if ( line.find(
"POINTS") != std::string::npos )
181 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
184 inputFile >> buffer[ii];
190 template<
typename T >
195 while ( !inputFile.eof() )
197 std::getline(inputFile, line,
'\n');
199 if ( line.find(
"POINTS") != std::string::npos )
202 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
203 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
213 void ReadCellsBufferAsASCII(std::ifstream & inputFile,
void *buffer);
215 void ReadCellsBufferAsBINARY(std::ifstream & inputFile,
void *buffer);
217 template<
typename T >
222 while ( !inputFile.eof() )
224 std::getline(inputFile, line,
'\n');
225 if ( line.find(
"POINT_DATA") != std::string::npos )
227 if ( !inputFile.eof() )
229 std::getline(inputFile, line,
'\n');
233 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
237 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
239 if ( !inputFile.eof() )
241 std::getline(inputFile, line,
'\n');
242 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
244 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
249 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
255 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
258 inputFile >> buffer[ii];
264 template<
typename T >
269 while ( !inputFile.eof() )
271 std::getline(inputFile, line,
'\n');
272 if ( line.find(
"POINT_DATA") != std::string::npos )
274 if ( !inputFile.eof() )
276 std::getline(inputFile, line,
'\n');
280 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
284 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
286 if ( !inputFile.eof() )
288 std::getline(inputFile, line,
'\n');
289 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
291 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
296 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
302 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
303 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
313 template<
typename T >
318 while ( !inputFile.eof() )
320 std::getline(inputFile, line,
'\n');
321 if ( line.find(
"CELL_DATA") != std::string::npos )
323 if ( !inputFile.eof() )
325 std::getline(inputFile, line,
'\n');
329 itkExceptionMacro(
"UnExpected end of line while trying to read CELL_DATA");
333 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
335 if ( !inputFile.eof() )
337 std::getline(inputFile, line,
'\n');
338 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
340 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
345 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
351 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
354 inputFile >> buffer[ii];
360 template<
typename T >
365 while ( !inputFile.eof() )
367 std::getline(inputFile, line,
'\n');
368 if ( line.find(
"POINT_DATA") != std::string::npos )
370 if ( !inputFile.eof() )
372 std::getline(inputFile, line,
'\n');
376 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
380 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
382 if ( !inputFile.eof() )
384 std::getline(inputFile, line,
'\n');
385 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
387 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
392 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
397 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
398 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
408 template<
typename T >
413 outputFile <<
"POINTS " << this->m_NumberOfPoints;
415 outputFile << pointComponentType <<
'\n';
416 for (
SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
418 for (
unsigned int jj = 0; jj < this->m_PointDimension - 1; jj++ )
420 outputFile << convert(buffer[ii * this->m_PointDimension + jj]) <<
" ";
423 outputFile << convert(buffer[ii * this->m_PointDimension + this->m_PointDimension - 1]) <<
'\n';
429 template<
typename T >
433 outputFile <<
"POINTS " << this->m_NumberOfPoints;
434 outputFile << pointComponentType <<
"\n";
441 template<
typename T >
445 unsigned int numberOfVertices = 0;
446 unsigned int numberOfVertexIndices = 0;
447 unsigned int numberOfLines = 0;
448 unsigned int numberOfLineIndices = 0;
449 unsigned int numberOfPolygons = 0;
450 unsigned int numberOfPolygonIndices = 0;
455 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
456 if ( numberOfVertices )
458 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
459 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
460 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
463 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
464 if ( cellType == VERTEX_CELL )
467 for (
unsigned int jj = 0; jj < nn; jj++ )
469 outputFile <<
" " << buffer[index++];
482 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
485 numberOfLineIndices = 0;
489 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
492 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
493 if ( cellType == LINE_CELL )
495 if ( pointIds.size() >= nn )
498 if (
id == static_cast< SizeValueType >( buffer[index] ) )
500 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
502 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
504 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
508 polylines->InsertElement(numberOfPolylines++, pointIds);
509 numberOfLineIndices += pointIds.size();
513 for (
unsigned int jj = 0; jj < nn; jj++ )
515 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
521 for (
unsigned int jj = 0; jj < nn; jj++ )
523 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
530 polylines->InsertElement(numberOfPolylines++, pointIds);
531 numberOfLineIndices += pointIds.size();
534 numberOfLines = polylines->Size();
535 numberOfLineIndices += numberOfLines;
536 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
537 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
538 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
541 unsigned int nn =
static_cast<unsigned int>( polylines->ElementAt(ii).size() );
543 for (
unsigned int jj = 0; jj < nn; ++jj )
545 outputFile <<
" " << polylines->ElementAt(ii)[jj];
553 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
554 if ( numberOfPolygons )
556 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
557 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
558 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
561 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
562 if ( cellType == POLYGON_CELL ||
563 cellType == TRIANGLE_CELL ||
564 cellType == QUADRILATERAL_CELL )
567 for (
unsigned int jj = 0; jj < nn; jj++ )
569 outputFile <<
" " << buffer[index++];
582 template<
typename T >
586 unsigned int numberOfVertices = 0;
587 unsigned int numberOfVertexIndices = 0;
588 unsigned int numberOfLines = 0;
589 unsigned int numberOfLineIndices = 0;
590 unsigned int numberOfPolygons = 0;
591 unsigned int numberOfPolygonIndices = 0;
596 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
597 if ( numberOfVertices )
599 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
600 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
601 unsigned int *data =
new unsigned int[numberOfVertexIndices];
602 ReadCellsBuffer(buffer, data);
610 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
613 numberOfLineIndices = 0;
617 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
620 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
621 if ( cellType == LINE_CELL )
623 if ( pointIds.size() >= nn )
626 if (
id == static_cast< SizeValueType >( buffer[index] ) )
628 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
630 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
632 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
636 polylines->InsertElement(numberOfPolylines++, pointIds);
637 numberOfLineIndices += pointIds.size();
641 for (
unsigned int jj = 0; jj < nn; jj++ )
643 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
649 for (
unsigned int jj = 0; jj < nn; jj++ )
651 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
658 polylines->InsertElement(numberOfPolylines++, pointIds);
659 numberOfLineIndices += pointIds.size();
662 numberOfLines = polylines->Size();
663 numberOfLineIndices += numberOfLines;
664 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
665 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
667 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
668 unsigned int *data =
new unsigned int[numberOfLineIndices];
669 unsigned long outputIndex = 0;
672 unsigned int nn =
static_cast<unsigned int>( polylines->ElementAt(ii).size() );
673 data[outputIndex++] = nn;
674 for (
unsigned int jj = 0; jj < nn; ++jj )
676 data[outputIndex++] = polylines->ElementAt(ii)[jj];
687 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
688 if ( numberOfPolygons )
690 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
691 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
692 unsigned int *data =
new unsigned int[numberOfPolygonIndices];
693 ReadCellsBuffer(buffer, data);
701 template<
typename T >
708 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
'\n';
709 switch ( this->m_PointPixelType )
713 outputFile <<
"SCALARS ";
714 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
715 outputFile << dataName <<
" ";
720 case COVARIANTVECTOR:
723 outputFile <<
"VECTORS ";
724 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
725 outputFile << dataName <<
" ";
728 case SYMMETRICSECONDRANKTENSOR:
729 case DIFFUSIONTENSOR3D:
731 outputFile <<
"TENSORS ";
732 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
733 outputFile << dataName <<
" ";
737 case VARIABLELENGTHVECTOR:
739 outputFile <<
"COLOR_SCALARS ";
740 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
741 outputFile << dataName <<
" ";
742 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
747 itkExceptionMacro(<<
"Unknown point pixel type");
751 outputFile << pointPixelComponentName <<
'\n';
753 if ( this->m_PointPixelType == SCALAR )
755 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
759 if ( this->m_PointPixelType == SYMMETRICSECONDRANKTENSOR )
763 const SizeValueType num = this->m_NumberOfPointPixelComponents * this->m_NumberOfPointPixels;
766 if( this->m_NumberOfPointPixelComponents == 3 )
773 outputFile << convert(*ptr++) << indent;
775 outputFile << convert(e12) << indent;
776 outputFile << convert(zero) <<
'\n';
778 outputFile << convert(e12) << indent;
779 outputFile << convert(*ptr++) << indent;
780 outputFile << convert(zero) <<
'\n';
782 outputFile << convert(zero) << indent << convert(zero) << indent << convert(zero) <<
"\n\n";
786 else if( this->m_NumberOfPointPixelComponents == 6 )
794 outputFile << convert(*ptr++) << indent;
796 outputFile << convert(e12) << indent;
798 outputFile << convert(e13) <<
'\n';
800 outputFile << convert(e12) << indent;
801 outputFile << convert(*ptr++) << indent;
803 outputFile << convert(e23) <<
'\n';
805 outputFile << convert(e13) << indent;
806 outputFile << convert(e23) << indent;
807 outputFile << convert(*ptr++) <<
"\n\n";
814 "itk::ERROR: VTKImageIO2: Unsupported number of components in tensor.",
822 for (
SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ii++ )
824 for ( jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; jj++ )
826 outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
828 outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
836 template<
typename T >
842 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
"\n";
843 switch ( this->m_PointPixelType )
847 outputFile <<
"SCALARS ";
848 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
849 outputFile << dataName <<
" ";
854 case COVARIANTVECTOR:
857 outputFile <<
"VECTORS ";
858 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
859 outputFile << dataName <<
" ";
862 case SYMMETRICSECONDRANKTENSOR:
863 case DIFFUSIONTENSOR3D:
865 outputFile <<
"TENSORS ";
866 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
867 outputFile << dataName <<
" ";
871 case VARIABLELENGTHVECTOR:
873 outputFile <<
"COLOR_SCALARS ";
874 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
875 outputFile << dataName <<
" ";
876 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
881 itkExceptionMacro(<<
"Unknown point pixel type");
885 outputFile << pointPixelComponentName <<
"\n";
886 if ( this->m_PointPixelType == SCALAR )
888 outputFile <<
"LOOKUP_TABLE default\n";
892 this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents,
898 template<
typename T >
904 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
'\n';
905 switch ( this->m_CellPixelType )
909 outputFile <<
"SCALARS ";
910 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
911 outputFile << dataName <<
" ";
916 case COVARIANTVECTOR:
919 outputFile <<
"VECTORS ";
920 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
921 outputFile << dataName <<
" ";
924 case SYMMETRICSECONDRANKTENSOR:
925 case DIFFUSIONTENSOR3D:
927 outputFile <<
"TENSORS ";
928 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
929 outputFile << dataName <<
" ";
933 case VARIABLELENGTHVECTOR:
935 outputFile <<
"COLOR_SCALARS ";
936 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
937 outputFile << dataName <<
" ";
938 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
943 itkExceptionMacro(<<
"Unknown cell pixel type");
947 outputFile << cellPixelComponentName <<
'\n';
948 if ( this->m_CellPixelType == SCALAR )
950 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
954 if ( this->m_CellPixelType == SYMMETRICSECONDRANKTENSOR )
958 const SizeValueType num = this->m_NumberOfCellPixelComponents * this->m_NumberOfCellPixels;
959 if( this->m_NumberOfCellPixelComponents == 2 )
966 outputFile << *ptr++ << indent;
968 outputFile << e12 << indent;
969 outputFile << zero <<
'\n';
971 outputFile << e12 << indent;
972 outputFile << *ptr++ << indent;
973 outputFile << zero <<
'\n';
975 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
979 else if( this->m_NumberOfCellPixelComponents == 3 )
987 outputFile << *ptr++ << indent;
989 outputFile << e12 << indent;
991 outputFile << e13 <<
'\n';
993 outputFile << e12 << indent;
994 outputFile << *ptr++ << indent;
996 outputFile << e23 <<
'\n';
998 outputFile << e13 << indent;
999 outputFile << e23 << indent;
1000 outputFile << *ptr++ <<
"\n\n";
1007 "itk::ERROR: VTKPolyDataMeshIO: Unsupported number of components in tensor.",
1015 for (
SizeValueType ii = 0; ii < this->m_NumberOfCellPixels; ii++ )
1017 for ( jj = 0; jj < this->m_NumberOfCellPixelComponents - 1; jj++ )
1019 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj] << indent;
1021 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj];
1029 template<
typename T >
1035 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
"\n";
1036 switch ( this->m_CellPixelType )
1040 outputFile <<
"SCALARS ";
1041 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
1042 outputFile << dataName <<
" ";
1047 case COVARIANTVECTOR:
1050 outputFile <<
"VECTORS ";
1051 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
1052 outputFile << dataName <<
" ";
1055 case SYMMETRICSECONDRANKTENSOR:
1056 case DIFFUSIONTENSOR3D:
1058 outputFile <<
"TENSORS ";
1059 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
1060 outputFile << dataName <<
" ";
1064 case VARIABLELENGTHVECTOR:
1066 outputFile <<
"COLOR_SCALARS ";
1067 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
1068 outputFile << dataName <<
" ";
1069 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
1074 itkExceptionMacro(<<
"Unknown cell pixel type");
1078 outputFile << cellPixelComponentName <<
"\n";
1079 if ( this->m_CellPixelType == SCALAR )
1081 outputFile <<
"LOOKUP_TABLE default\n";
1085 this->m_NumberOfCells * this->m_NumberOfCellPixelComponents,
1091 template<
typename T >
1094 unsigned int numberOfPixelComponents,
1098 outputFile << numberOfPixelComponents <<
"\n";
1102 for (
unsigned int jj = 0; jj < numberOfPixelComponents; ++jj )
1104 outputFile << convert(static_cast< float >( buffer[ii * numberOfPixelComponents + jj])) << indent;
1113 template<
typename T >
1116 unsigned int numberOfPixelComponents,
1119 outputFile << numberOfPixelComponents <<
"\n";
1120 SizeValueType numberOfElements = numberOfPixelComponents * numberOfPixels;
1121 unsigned char *data =
new unsigned char[numberOfElements];
1124 data[ii] =
static_cast< unsigned char >( buffer[ii] );
1127 outputFile.write(reinterpret_cast< char * >( data ), numberOfElements);
1136 template<
typename TInput,
typename TOutput >
1142 if ( input && output )
1144 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
1147 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
1148 output[outputIndex++] = nn;
1149 for (
unsigned int jj = 0; jj < nn; jj++ )
1151 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
1158 IOComponentType GetComponentTypeFromString(
const std::string & pixelType);
1165 #endif // itkVTKPolyDataMeshIO_h
Light weight base class for most itk classes.
SmartPointer< const Self > ConstPointer
void WritePointsBufferAsASCII(std::ofstream &outputFile, T *buffer, const StringType &pointComponentType)
This class defines how to read and write vtk legacy file format.
SmartPointer< Self > Pointer
void ReadPointsBufferAsASCII(std::ifstream &inputFile, T *buffer)
void ReadCellDataBufferAsASCII(std::ifstream &inputFile, T *buffer)
std::vector< StringType > StringVectorType
std::stringstream StringStreamType
IdentifierType SizeValueType
void WritePointsBufferAsBINARY(std::ofstream &outputFile, T *buffer, const StringType &pointComponentType)
unsigned long SizeValueType
void WriteColorScalarBufferAsBINARY(std::ofstream &outputFile, T *buffer, unsigned int numberOfPixelComponents, SizeValueType numberOfPixels)
void ReadCellsBuffer(TInput *input, TOutput *output)
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
void WriteCellsBufferAsBINARY(std::ofstream &outputFile, T *buffer)
Convert floating and fixed point numbers to strings.
void ReadCellDataBufferAsBINARY(std::ifstream &inputFile, T *buffer)
Standard exception handling object.
VectorContainer< SizeValueType, PointIdVector > PolylinesContainerType
void WriteCellDataBufferAsASCII(std::ofstream &outputFile, T *buffer, const StringType &cellPixelComponentName)
void WriteCellDataBufferAsBINARY(std::ofstream &outputFile, T *buffer, const StringType &cellPixelComponentName)
void ReadPointsBufferAsBINARY(std::ifstream &inputFile, T *buffer)
PolylinesContainerType::Pointer PolylinesContainerPointer
std::vector< SizeValueType > PointIdVector
void WritePointDataBufferAsBINARY(std::ofstream &outputFile, T *buffer, const StringType &pointPixelComponentName)
void ReadPointDataBufferAsBINARY(std::ifstream &inputFile, T *buffer)
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
void WriteCellsBufferAsASCII(std::ofstream &outputFile, T *buffer)
Control indentation during Print() invocation.
static void SwapWriteRangeFromSystemToBigEndian(T *p, int num, OStreamType *fp)
Superclass::SizeValueType SizeValueType
Abstract superclass defines mesh IO interface.
void WritePointDataBufferAsASCII(std::ofstream &outputFile, T *buffer, const StringType &pointPixelComponentName)
Define additional traits for native types such as int or float.
void WriteColorScalarBufferAsASCII(std::ofstream &outputFile, T *buffer, unsigned int numberOfPixelComponents, SizeValueType numberOfPixels)
Perform machine dependent byte swapping.
void ReadPointDataBufferAsASCII(std::ifstream &inputFile, T *buffer)