18 #ifndef __itkVTKPolyDataMeshIO_h
19 #define __itkVTKPolyDataMeshIO_h
70 virtual bool CanReadFile(
const char *FileNameToRead);
73 virtual void ReadMeshInformation();
76 virtual void ReadPoints(
void *buffer);
78 virtual void ReadCells(
void *buffer);
80 virtual void ReadPointData(
void *buffer);
82 virtual void ReadCellData(
void *buffer);
90 virtual bool CanWriteFile(
const char *FileNameToWrite);
93 virtual void WriteMeshInformation();
97 virtual void WritePoints(
void *buffer);
99 virtual void WriteCells(
void *buffer);
101 virtual void WritePointData(
void *buffer);
103 virtual void WriteCellData(
void *buffer);
105 virtual void Write();
111 void PrintSelf(std::ostream & os,
Indent indent)
const;
113 template<
typename T >
114 void UpdateCellInformation(T *buffer)
116 unsigned int numberOfVertices = 0;
117 unsigned int numberOfVertexIndices = 0;
118 unsigned int numberOfLines = 0;
119 unsigned int numberOfLineIndices = 0;
120 unsigned int numberOfPolygons = 0;
121 unsigned int numberOfPolygonIndices = 0;
125 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
128 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
133 numberOfVertexIndices += nn + 1;
137 numberOfLineIndices += nn + 1;
141 numberOfPolygonIndices += nn + 1;
145 numberOfPolygonIndices += nn + 1;
147 case QUADRILATERAL_CELL:
149 numberOfPolygonIndices += nn + 1;
152 itkExceptionMacro(<<
"Currently we dont support this cell type");
159 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
160 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
161 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
162 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
163 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
164 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
168 template<
typename T >
169 void ReadPointsBufferAsASCII(std::ifstream & inputFile, T *buffer)
173 while ( !inputFile.eof() )
175 std::getline(inputFile, line,
'\n');
177 if ( line.find(
"POINTS") != std::string::npos )
180 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
183 inputFile >> buffer[ii];
189 template<
typename T >
190 void ReadPointsBufferAsBINARY(std::ifstream & inputFile, T *buffer)
194 while ( !inputFile.eof() )
196 std::getline(inputFile, line,
'\n');
198 if ( line.find(
"POINTS") != std::string::npos )
201 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
202 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
212 void ReadCellsBufferAsASCII(std::ifstream & inputFile,
void *buffer);
214 void ReadCellsBufferAsBINARY(std::ifstream & inputFile,
void *buffer);
216 template<
typename T >
217 void ReadPointDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
221 while ( !inputFile.eof() )
223 std::getline(inputFile, line,
'\n');
224 if ( line.find(
"POINT_DATA") != std::string::npos )
226 if ( !inputFile.eof() )
228 std::getline(inputFile, line,
'\n');
232 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
236 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
238 if ( !inputFile.eof() )
240 std::getline(inputFile, line,
'\n');
241 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
243 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
248 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
254 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
257 inputFile >> buffer[ii];
263 template<
typename T >
264 void ReadPointDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
268 while ( !inputFile.eof() )
270 std::getline(inputFile, line,
'\n');
271 if ( line.find(
"POINT_DATA") != std::string::npos )
273 if ( !inputFile.eof() )
275 std::getline(inputFile, line,
'\n');
279 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
283 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
285 if ( !inputFile.eof() )
287 std::getline(inputFile, line,
'\n');
288 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
290 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
295 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
301 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
302 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
312 template<
typename T >
313 void ReadCellDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
317 while ( !inputFile.eof() )
319 std::getline(inputFile, line,
'\n');
320 if ( line.find(
"CELL_DATA") != std::string::npos )
322 if ( !inputFile.eof() )
324 std::getline(inputFile, line,
'\n');
328 itkExceptionMacro(
"UnExpected end of line while trying to read CELL_DATA");
332 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
334 if ( !inputFile.eof() )
336 std::getline(inputFile, line,
'\n');
337 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
339 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
344 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
350 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
353 inputFile >> buffer[ii];
359 template<
typename T >
360 void ReadCellDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
364 while ( !inputFile.eof() )
366 std::getline(inputFile, line,
'\n');
367 if ( line.find(
"POINT_DATA") != std::string::npos )
369 if ( !inputFile.eof() )
371 std::getline(inputFile, line,
'\n');
375 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
379 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
381 if ( !inputFile.eof() )
383 std::getline(inputFile, line,
'\n');
384 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
386 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
391 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
396 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
397 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
407 template<
typename T >
408 void WritePointsBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
412 outputFile <<
"POINTS " << this->m_NumberOfPoints;
414 outputFile << pointComponentType <<
'\n';
415 for (
SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
417 for (
unsigned int jj = 0; jj < this->m_PointDimension - 1; jj++ )
419 outputFile << convert(buffer[ii * this->m_PointDimension + jj]) <<
" ";
422 outputFile << convert(buffer[ii * this->m_PointDimension + this->m_PointDimension - 1]) <<
'\n';
428 template<
typename T >
429 void WritePointsBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
432 outputFile <<
"POINTS " << this->m_NumberOfPoints;
433 outputFile << pointComponentType <<
"\n";
440 template<
typename T >
441 void WriteCellsBufferAsASCII(std::ofstream & outputFile, T *buffer)
444 unsigned int numberOfVertices = 0;
445 unsigned int numberOfVertexIndices = 0;
446 unsigned int numberOfLines = 0;
447 unsigned int numberOfLineIndices = 0;
448 unsigned int numberOfPolygons = 0;
449 unsigned int numberOfPolygonIndices = 0;
454 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
455 if ( numberOfVertices )
457 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
458 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
459 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
462 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
463 if ( cellType == VERTEX_CELL )
466 for (
unsigned int jj = 0; jj < nn; jj++ )
468 outputFile <<
" " << buffer[index++];
481 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
484 numberOfLineIndices = 0;
488 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
491 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
492 if ( cellType == LINE_CELL )
494 if ( pointIds.size() >= nn )
497 if (
id == static_cast< SizeValueType >( buffer[index] ) )
499 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
501 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
503 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
507 polylines->InsertElement(numberOfPolylines++, pointIds);
508 numberOfLineIndices += pointIds.size();
512 for (
unsigned int jj = 0; jj < nn; jj++ )
514 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
520 for (
unsigned int jj = 0; jj < nn; jj++ )
522 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
529 polylines->InsertElement(numberOfPolylines++, pointIds);
530 numberOfLineIndices += pointIds.size();
533 numberOfLines = polylines->Size();
534 numberOfLineIndices += numberOfLines;
535 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
536 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
537 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
540 unsigned int nn = polylines->ElementAt(ii).size();
542 for (
unsigned int jj = 0; jj < nn; ++jj )
544 outputFile <<
" " << polylines->ElementAt(ii)[jj];
552 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
553 if ( numberOfPolygons )
555 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
556 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
557 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
560 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
561 if ( cellType == POLYGON_CELL ||
562 cellType == TRIANGLE_CELL ||
563 cellType == QUADRILATERAL_CELL )
566 for (
unsigned int jj = 0; jj < nn; jj++ )
568 outputFile <<
" " << buffer[index++];
581 template<
typename T >
582 void WriteCellsBufferAsBINARY(std::ofstream & outputFile, T *buffer)
585 unsigned int numberOfVertices = 0;
586 unsigned int numberOfVertexIndices = 0;
587 unsigned int numberOfLines = 0;
588 unsigned int numberOfLineIndices = 0;
589 unsigned int numberOfPolygons = 0;
590 unsigned int numberOfPolygonIndices = 0;
595 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
596 if ( numberOfVertices )
598 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
599 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
600 unsigned int *data =
new unsigned int[numberOfVertexIndices];
601 ReadCellsBuffer(buffer, data);
609 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
612 numberOfLineIndices = 0;
616 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
619 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
620 if ( cellType == LINE_CELL )
622 if ( pointIds.size() >= nn )
625 if (
id == static_cast< SizeValueType >( buffer[index] ) )
627 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
629 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
631 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
635 polylines->InsertElement(numberOfPolylines++, pointIds);
636 numberOfLineIndices += pointIds.size();
640 for (
unsigned int jj = 0; jj < nn; jj++ )
642 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
648 for (
unsigned int jj = 0; jj < nn; jj++ )
650 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
657 polylines->InsertElement(numberOfPolylines++, pointIds);
658 numberOfLineIndices += pointIds.size();
661 numberOfLines = polylines->Size();
662 numberOfLineIndices += numberOfLines;
663 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
664 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
666 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
667 unsigned int *data =
new unsigned int[numberOfLineIndices];
668 unsigned long outputIndex = 0;
671 unsigned int nn = polylines->ElementAt(ii).size();
672 data[outputIndex++] = nn;
673 for (
unsigned int jj = 0; jj < nn; ++jj )
675 data[outputIndex++] = polylines->ElementAt(ii)[jj];
686 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
687 if ( numberOfPolygons )
689 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
690 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
691 unsigned int *data =
new unsigned int[numberOfPolygonIndices];
692 ReadCellsBuffer(buffer, data);
700 template<
typename T >
701 void WritePointDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
707 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
'\n';
708 switch ( this->m_PointPixelType )
712 outputFile <<
"SCALARS ";
713 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
714 outputFile << dataName <<
" ";
719 case COVARIANTVECTOR:
722 outputFile <<
"VECTORS ";
723 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
724 outputFile << dataName <<
" ";
727 case SYMMETRICSECONDRANKTENSOR:
728 case DIFFUSIONTENSOR3D:
730 outputFile <<
"TENSORS ";
731 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
732 outputFile << dataName <<
" ";
736 case VARIABLELENGTHVECTOR:
738 outputFile <<
"COLOR_SCALARS ";
739 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
740 outputFile << dataName <<
" ";
741 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
746 itkExceptionMacro(<<
"Unknown point pixel type");
750 outputFile << pointPixelComponentName <<
'\n';
752 if ( this->m_PointPixelType == SCALAR )
754 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
758 if ( this->m_PointPixelType == SYMMETRICSECONDRANKTENSOR )
762 const SizeValueType num = this->m_NumberOfPointPixelComponents * this->m_NumberOfPointPixels;
765 if( this->m_NumberOfPointPixelComponents == 3 )
772 outputFile << convert(*ptr++) << indent;
774 outputFile << convert(e12) << indent;
775 outputFile << convert(zero) <<
'\n';
777 outputFile << convert(e12) << indent;
778 outputFile << convert(*ptr++) << indent;
779 outputFile << convert(zero) <<
'\n';
781 outputFile << convert(zero) << indent << convert(zero) << indent << convert(zero) <<
"\n\n";
785 else if( this->m_NumberOfPointPixelComponents == 6 )
793 outputFile << convert(*ptr++) << indent;
795 outputFile << convert(e12) << indent;
797 outputFile << convert(e13) <<
'\n';
799 outputFile << convert(e12) << indent;
800 outputFile << convert(*ptr++) << indent;
802 outputFile << convert(e23) <<
'\n';
804 outputFile << convert(e13) << indent;
805 outputFile << convert(e23) << indent;
806 outputFile << convert(*ptr++) <<
"\n\n";
813 "itk::ERROR: VTKImageIO2: Unsupported number of components in tensor.",
821 for (
SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ii++ )
823 for ( jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; jj++ )
825 outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
827 outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
835 template<
typename T >
836 void WritePointDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
841 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
"\n";
842 switch ( this->m_PointPixelType )
846 outputFile <<
"SCALARS ";
847 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
848 outputFile << dataName <<
" ";
853 case COVARIANTVECTOR:
856 outputFile <<
"VECTORS ";
857 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
858 outputFile << dataName <<
" ";
861 case SYMMETRICSECONDRANKTENSOR:
862 case DIFFUSIONTENSOR3D:
864 outputFile <<
"TENSORS ";
865 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
866 outputFile << dataName <<
" ";
870 case VARIABLELENGTHVECTOR:
872 outputFile <<
"COLOR_SCALARS ";
873 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
874 outputFile << dataName <<
" ";
875 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
880 itkExceptionMacro(<<
"Unknown point pixel type");
884 outputFile << pointPixelComponentName <<
"\n";
885 if ( this->m_PointPixelType == SCALAR )
887 outputFile <<
"LOOKUP_TABLE default\n";
891 this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents,
897 template<
typename T >
898 void WriteCellDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
903 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
'\n';
904 switch ( this->m_CellPixelType )
908 outputFile <<
"SCALARS ";
909 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
910 outputFile << dataName <<
" ";
915 case COVARIANTVECTOR:
918 outputFile <<
"VECTORS ";
919 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
920 outputFile << dataName <<
" ";
923 case SYMMETRICSECONDRANKTENSOR:
924 case DIFFUSIONTENSOR3D:
926 outputFile <<
"TENSORS ";
927 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
928 outputFile << dataName <<
" ";
932 case VARIABLELENGTHVECTOR:
934 outputFile <<
"COLOR_SCALARS ";
935 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
936 outputFile << dataName <<
" ";
937 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
942 itkExceptionMacro(<<
"Unknown cell pixel type");
946 outputFile << cellPixelComponentName <<
'\n';
947 if ( this->m_CellPixelType == SCALAR )
949 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
953 if ( this->m_CellPixelType == SYMMETRICSECONDRANKTENSOR )
957 const SizeValueType num = this->m_NumberOfCellPixelComponents * this->m_NumberOfCellPixels;
958 if( this->m_NumberOfCellPixelComponents == 3 )
965 outputFile << *ptr++ << indent;
967 outputFile << e12 << indent;
968 outputFile << zero <<
'\n';
970 outputFile << e12 << indent;
971 outputFile << *ptr++ << indent;
972 outputFile << zero <<
'\n';
974 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
978 else if( this->m_NumberOfCellPixelComponents == 3 )
986 outputFile << *ptr++ << indent;
988 outputFile << e12 << indent;
990 outputFile << e13 <<
'\n';
992 outputFile << e12 << indent;
993 outputFile << *ptr++ << indent;
995 outputFile << e23 <<
'\n';
997 outputFile << e13 << indent;
998 outputFile << e23 << indent;
999 outputFile << *ptr++ <<
"\n\n";
1006 "itk::ERROR: VTKPolyDataMeshIO: Unsupported number of components in tensor.",
1014 for (
SizeValueType ii = 0; ii < this->m_NumberOfCellPixels; ii++ )
1016 for ( jj = 0; jj < this->m_NumberOfCellPixelComponents - 1; jj++ )
1018 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj] << indent;
1020 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj];
1028 template<
typename T >
1029 void WriteCellDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
1034 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
"\n";
1035 switch ( this->m_CellPixelType )
1039 outputFile <<
"SCALARS ";
1040 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
1041 outputFile << dataName <<
" ";
1046 case COVARIANTVECTOR:
1049 outputFile <<
"VECTORS ";
1050 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
1051 outputFile << dataName <<
" ";
1054 case SYMMETRICSECONDRANKTENSOR:
1055 case DIFFUSIONTENSOR3D:
1057 outputFile <<
"TENSORS ";
1058 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
1059 outputFile << dataName <<
" ";
1063 case VARIABLELENGTHVECTOR:
1065 outputFile <<
"COLOR_SCALARS ";
1066 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
1067 outputFile << dataName <<
" ";
1068 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
1073 itkExceptionMacro(<<
"Unknown cell pixel type");
1077 outputFile << cellPixelComponentName <<
"\n";
1078 if ( this->m_CellPixelType == SCALAR )
1080 outputFile <<
"LOOKUP_TABLE default\n";
1084 this->m_NumberOfCells * this->m_NumberOfCellPixelComponents,
1090 template<
typename T >
1091 void WriteColorScalarBufferAsASCII(std::ofstream & outputFile,
1093 unsigned int numberOfPixelComponents,
1097 outputFile << numberOfPixelComponents <<
"\n";
1101 for (
unsigned int jj = 0; jj < numberOfPixelComponents; ++jj )
1103 outputFile << convert(static_cast< float >( buffer[ii * numberOfPixelComponents + jj])) << indent;
1112 template<
typename T >
1113 void WriteColorScalarBufferAsBINARY(std::ofstream & outputFile,
1115 unsigned int numberOfPixelComponents,
1118 outputFile << numberOfPixelComponents <<
"\n";
1119 SizeValueType numberOfElements = numberOfPixelComponents * numberOfPixels;
1120 unsigned char *data =
new unsigned char[numberOfElements];
1123 data[ii] =
static_cast< unsigned char >( buffer[ii] );
1126 outputFile.write(reinterpret_cast< char * >( data ), numberOfElements);
1135 template<
typename TInput,
typename TOutput >
1136 void ReadCellsBuffer(TInput *input, TOutput *output)
1141 if ( input && output )
1143 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
1146 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
1147 output[outputIndex++] = nn;
1148 for (
unsigned int jj = 0; jj < nn; jj++ )
1150 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
1158 void operator=(
const Self &);
1162 #endif // __itkVTKPolyDataMeshIO_h