18 #ifndef __itkVTKPolyDataMeshIO_h
19 #define __itkVTKPolyDataMeshIO_h
69 virtual bool CanReadFile(
const char *FileNameToRead);
72 virtual void ReadMeshInformation();
75 virtual void ReadPoints(
void *buffer);
77 virtual void ReadCells(
void *buffer);
79 virtual void ReadPointData(
void *buffer);
81 virtual void ReadCellData(
void *buffer);
89 virtual bool CanWriteFile(
const char *FileNameToWrite);
92 virtual void WriteMeshInformation();
96 virtual void WritePoints(
void *buffer);
98 virtual void WriteCells(
void *buffer);
100 virtual void WritePointData(
void *buffer);
102 virtual void WriteCellData(
void *buffer);
104 virtual void Write();
109 void PrintSelf(std::ostream & os,
Indent indent)
const;
111 template<
typename T >
112 void UpdateCellInformation(T *buffer)
114 unsigned int numberOfVertices = 0;
115 unsigned int numberOfVertexIndices = 0;
116 unsigned int numberOfLines = 0;
117 unsigned int numberOfLineIndices = 0;
118 unsigned int numberOfPolygons = 0;
119 unsigned int numberOfPolygonIndices = 0;
123 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
126 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
131 numberOfVertexIndices += nn + 1;
135 numberOfLineIndices += nn + 1;
139 numberOfPolygonIndices += nn + 1;
143 numberOfPolygonIndices += nn + 1;
145 case QUADRILATERAL_CELL:
147 numberOfPolygonIndices += nn + 1;
150 itkExceptionMacro(<<
"Currently we dont support this cell type");
157 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
158 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
159 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
160 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
161 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
162 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
166 template<
typename T >
167 void ReadPointsBufferAsASCII(std::ifstream & inputFile, T *buffer)
171 while ( !inputFile.eof() )
173 std::getline(inputFile, line,
'\n');
175 if ( line.find(
"POINTS") != std::string::npos )
178 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
181 inputFile >> buffer[ii];
187 template<
typename T >
188 void ReadPointsBufferAsBINARY(std::ifstream & inputFile, T *buffer)
192 while ( !inputFile.eof() )
194 std::getline(inputFile, line,
'\n');
196 if ( line.find(
"POINTS") != std::string::npos )
199 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
200 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
210 void ReadCellsBufferAsASCII(std::ifstream & inputFile,
void *buffer);
212 void ReadCellsBufferAsBINARY(std::ifstream & inputFile,
void *buffer);
214 template<
typename T >
215 void ReadPointDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
219 while ( !inputFile.eof() )
221 std::getline(inputFile, line,
'\n');
222 if ( line.find(
"POINT_DATA") != std::string::npos )
224 if ( !inputFile.eof() )
226 std::getline(inputFile, line,
'\n');
230 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
234 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
236 if ( !inputFile.eof() )
238 std::getline(inputFile, line,
'\n');
239 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
241 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
246 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
252 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
255 inputFile >> buffer[ii];
261 template<
typename T >
262 void ReadPointDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
266 while ( !inputFile.eof() )
268 std::getline(inputFile, line,
'\n');
269 if ( line.find(
"POINT_DATA") != std::string::npos )
271 if ( !inputFile.eof() )
273 std::getline(inputFile, line,
'\n');
277 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
281 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
283 if ( !inputFile.eof() )
285 std::getline(inputFile, line,
'\n');
286 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
288 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
293 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
299 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
300 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
310 template<
typename T >
311 void ReadCellDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
315 while ( !inputFile.eof() )
317 std::getline(inputFile, line,
'\n');
318 if ( line.find(
"CELL_DATA") != std::string::npos )
320 if ( !inputFile.eof() )
322 std::getline(inputFile, line,
'\n');
326 itkExceptionMacro(
"UnExpected end of line while trying to read CELL_DATA");
330 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
332 if ( !inputFile.eof() )
334 std::getline(inputFile, line,
'\n');
335 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
337 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
342 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
348 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
351 inputFile >> buffer[ii];
357 template<
typename T >
358 void ReadCellDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
362 while ( !inputFile.eof() )
364 std::getline(inputFile, line,
'\n');
365 if ( line.find(
"POINT_DATA") != std::string::npos )
367 if ( !inputFile.eof() )
369 std::getline(inputFile, line,
'\n');
373 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
377 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
379 if ( !inputFile.eof() )
381 std::getline(inputFile, line,
'\n');
382 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
384 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
389 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
394 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
395 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
405 template<
typename T >
406 void WritePointsBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
409 outputFile <<
"POINTS " << this->m_NumberOfPoints;
411 outputFile << pointComponentType <<
'\n';
412 for (
SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
414 for (
unsigned int jj = 0; jj < this->m_PointDimension - 1; jj++ )
416 outputFile << buffer[ii * this->m_PointDimension + jj] <<
" ";
419 outputFile << buffer[ii * this->m_PointDimension + this->m_PointDimension - 1] <<
'\n';
425 template<
typename T >
426 void WritePointsBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
429 outputFile <<
"POINTS " << this->m_NumberOfPoints;
430 outputFile << pointComponentType <<
"\n";
437 template<
typename T >
438 void WriteCellsBufferAsASCII(std::ofstream & outputFile, T *buffer)
441 unsigned int numberOfVertices = 0;
442 unsigned int numberOfVertexIndices = 0;
443 unsigned int numberOfLines = 0;
444 unsigned int numberOfLineIndices = 0;
445 unsigned int numberOfPolygons = 0;
446 unsigned int numberOfPolygonIndices = 0;
451 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
452 if ( numberOfVertices )
454 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
455 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
456 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
459 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
460 if ( cellType == VERTEX_CELL )
463 for (
unsigned int jj = 0; jj < nn; jj++ )
465 outputFile <<
" " << buffer[index++];
478 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
481 numberOfLineIndices = 0;
485 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
488 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
489 if ( cellType == LINE_CELL )
491 if ( pointIds.size() >= nn )
494 if (
id == static_cast< SizeValueType >( buffer[index] ) )
496 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
498 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
500 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
504 polylines->InsertElement(numberOfPolylines++, pointIds);
505 numberOfLineIndices += pointIds.size();
509 for (
unsigned int jj = 0; jj < nn; jj++ )
511 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
517 for (
unsigned int jj = 0; jj < nn; jj++ )
519 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
526 polylines->InsertElement(numberOfPolylines++, pointIds);
527 numberOfLineIndices += pointIds.size();
530 numberOfLines = polylines->Size();
531 numberOfLineIndices += numberOfLines;
532 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
533 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
534 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
537 unsigned int nn = polylines->ElementAt(ii).size();
539 for (
unsigned int jj = 0; jj < nn; ++jj )
541 outputFile <<
" " << polylines->ElementAt(ii)[jj];
549 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
550 if ( numberOfPolygons )
552 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
553 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
554 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
557 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
558 if ( cellType == POLYGON_CELL ||
559 cellType == TRIANGLE_CELL ||
560 cellType == QUADRILATERAL_CELL )
563 for (
unsigned int jj = 0; jj < nn; jj++ )
565 outputFile <<
" " << buffer[index++];
578 template<
typename T >
579 void WriteCellsBufferAsBINARY(std::ofstream & outputFile, T *buffer)
582 unsigned int numberOfVertices = 0;
583 unsigned int numberOfVertexIndices = 0;
584 unsigned int numberOfLines = 0;
585 unsigned int numberOfLineIndices = 0;
586 unsigned int numberOfPolygons = 0;
587 unsigned int numberOfPolygonIndices = 0;
592 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
593 if ( numberOfVertices )
595 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
596 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
597 unsigned int *data =
new unsigned int[numberOfVertexIndices];
598 ReadCellsBuffer(buffer, data);
606 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
609 numberOfLineIndices = 0;
613 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
616 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
617 if ( cellType == LINE_CELL )
619 if ( pointIds.size() >= nn )
622 if (
id == static_cast< SizeValueType >( buffer[index] ) )
624 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
626 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
628 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
632 polylines->InsertElement(numberOfPolylines++, pointIds);
633 numberOfLineIndices += pointIds.size();
637 for (
unsigned int jj = 0; jj < nn; jj++ )
639 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
645 for (
unsigned int jj = 0; jj < nn; jj++ )
647 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
654 polylines->InsertElement(numberOfPolylines++, pointIds);
655 numberOfLineIndices += pointIds.size();
658 numberOfLines = polylines->Size();
659 numberOfLineIndices += numberOfLines;
660 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
661 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
663 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
664 unsigned int *data =
new unsigned int[numberOfLineIndices];
665 unsigned long outputIndex = 0;
668 unsigned int nn = polylines->ElementAt(ii).size();
669 data[outputIndex++] = nn;
670 for (
unsigned int jj = 0; jj < nn; ++jj )
672 data[outputIndex++] = polylines->ElementAt(ii)[jj];
683 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
684 if ( numberOfPolygons )
686 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
687 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
688 unsigned int *data =
new unsigned int[numberOfPolygonIndices];
689 ReadCellsBuffer(buffer, data);
697 template<
typename T >
698 void WritePointDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
703 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
'\n';
704 switch ( this->m_PointPixelType )
708 outputFile <<
"SCALARS ";
709 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
710 outputFile << dataName <<
" ";
715 case COVARIANTVECTOR:
718 outputFile <<
"VECTORS ";
719 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
720 outputFile << dataName <<
" ";
723 case SYMMETRICSECONDRANKTENSOR:
724 case DIFFUSIONTENSOR3D:
726 outputFile <<
"TENSORS ";
727 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
728 outputFile << dataName <<
" ";
732 case VARIABLELENGTHVECTOR:
734 outputFile <<
"COLOR_SCALARS ";
735 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
736 outputFile << dataName <<
" ";
737 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
742 itkExceptionMacro(<<
"Unknown point pixel type");
746 outputFile << pointPixelComponentName <<
'\n';
748 if ( this->m_PointPixelType == SCALAR )
750 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
754 if ( this->m_PointPixelType == SYMMETRICSECONDRANKTENSOR )
758 const SizeValueType num = this->m_NumberOfPointPixelComponents * this->m_NumberOfPointPixels;
759 if( this->m_NumberOfPointPixelComponents == 3 )
766 outputFile << *ptr++ << indent;
768 outputFile << e12 << indent;
769 outputFile << zero <<
'\n';
771 outputFile << e12 << indent;
772 outputFile << *ptr++ << indent;
773 outputFile << zero <<
'\n';
775 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
779 else if( this->m_NumberOfPointPixelComponents == 3 )
787 outputFile << *ptr++ << indent;
789 outputFile << e12 << indent;
791 outputFile << e13 <<
'\n';
793 outputFile << e12 << indent;
794 outputFile << *ptr++ << indent;
796 outputFile << e23 <<
'\n';
798 outputFile << e13 << indent;
799 outputFile << e23 << indent;
800 outputFile << *ptr++ <<
"\n\n";
807 "itk::ERROR: VTKImageIO2: Unsupported number of components in tensor.",
815 for (
SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ii++ )
817 for ( jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; jj++ )
819 outputFile << buffer[ii * this->m_NumberOfPointPixelComponents + jj] << indent;
821 outputFile << buffer[ii * this->m_NumberOfPointPixelComponents + jj];
829 template<
typename T >
830 void WritePointDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
835 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
"\n";
836 switch ( this->m_PointPixelType )
840 outputFile <<
"SCALARS ";
841 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
842 outputFile << dataName <<
" ";
847 case COVARIANTVECTOR:
850 outputFile <<
"VECTORS ";
851 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
852 outputFile << dataName <<
" ";
855 case SYMMETRICSECONDRANKTENSOR:
856 case DIFFUSIONTENSOR3D:
858 outputFile <<
"TENSORS ";
859 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
860 outputFile << dataName <<
" ";
864 case VARIABLELENGTHVECTOR:
866 outputFile <<
"COLOR_SCALARS ";
867 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
868 outputFile << dataName <<
" ";
869 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
874 itkExceptionMacro(<<
"Unknown point pixel type");
878 outputFile << pointPixelComponentName <<
"\n";
879 if ( this->m_PointPixelType == SCALAR )
881 outputFile <<
"LOOKUP_TABLE default\n";
885 this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents,
891 template<
typename T >
892 void WriteCellDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
897 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
'\n';
898 switch ( this->m_CellPixelType )
902 outputFile <<
"SCALARS ";
903 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
904 outputFile << dataName <<
" ";
909 case COVARIANTVECTOR:
912 outputFile <<
"VECTORS ";
913 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
914 outputFile << dataName <<
" ";
917 case SYMMETRICSECONDRANKTENSOR:
918 case DIFFUSIONTENSOR3D:
920 outputFile <<
"TENSORS ";
921 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
922 outputFile << dataName <<
" ";
926 case VARIABLELENGTHVECTOR:
928 outputFile <<
"COLOR_SCALARS ";
929 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
930 outputFile << dataName <<
" ";
931 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
936 itkExceptionMacro(<<
"Unknown cell pixel type");
940 outputFile << cellPixelComponentName <<
'\n';
941 if ( this->m_CellPixelType == SCALAR )
943 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
947 if ( this->m_CellPixelType == SYMMETRICSECONDRANKTENSOR )
951 const SizeValueType num = this->m_NumberOfCellPixelComponents * this->m_NumberOfCellPixels;
952 if( this->m_NumberOfCellPixelComponents == 3 )
959 outputFile << *ptr++ << indent;
961 outputFile << e12 << indent;
962 outputFile << zero <<
'\n';
964 outputFile << e12 << indent;
965 outputFile << *ptr++ << indent;
966 outputFile << zero <<
'\n';
968 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
972 else if( this->m_NumberOfCellPixelComponents == 3 )
980 outputFile << *ptr++ << indent;
982 outputFile << e12 << indent;
984 outputFile << e13 <<
'\n';
986 outputFile << e12 << indent;
987 outputFile << *ptr++ << indent;
989 outputFile << e23 <<
'\n';
991 outputFile << e13 << indent;
992 outputFile << e23 << indent;
993 outputFile << *ptr++ <<
"\n\n";
1000 "itk::ERROR: VTKPolyDataMeshIO: Unsupported number of components in tensor.",
1008 for (
SizeValueType ii = 0; ii < this->m_NumberOfCellPixels; ii++ )
1010 for ( jj = 0; jj < this->m_NumberOfCellPixelComponents - 1; jj++ )
1012 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj] << indent;
1014 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj];
1022 template<
typename T >
1023 void WriteCellDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
1028 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
"\n";
1029 switch ( this->m_CellPixelType )
1033 outputFile <<
"SCALARS ";
1034 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
1035 outputFile << dataName <<
" ";
1040 case COVARIANTVECTOR:
1043 outputFile <<
"VECTORS ";
1044 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
1045 outputFile << dataName <<
" ";
1048 case SYMMETRICSECONDRANKTENSOR:
1049 case DIFFUSIONTENSOR3D:
1051 outputFile <<
"TENSORS ";
1052 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
1053 outputFile << dataName <<
" ";
1057 case VARIABLELENGTHVECTOR:
1059 outputFile <<
"COLOR_SCALARS ";
1060 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
1061 outputFile << dataName <<
" ";
1062 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
1067 itkExceptionMacro(<<
"Unknown cell pixel type");
1071 outputFile << cellPixelComponentName <<
"\n";
1072 if ( this->m_CellPixelType == SCALAR )
1074 outputFile <<
"LOOKUP_TABLE default\n";
1078 this->m_NumberOfCells * this->m_NumberOfCellPixelComponents,
1084 template<
typename T >
1085 void WriteColorScalarBufferAsASCII(std::ofstream & outputFile,
1087 unsigned int numberOfPixelComponents,
1090 outputFile << numberOfPixelComponents <<
"\n";
1094 for (
unsigned int jj = 0; jj < numberOfPixelComponents; ++jj )
1096 outputFile << static_cast< float >( buffer[ii * numberOfPixelComponents + jj] ) << indent;
1105 template<
typename T >
1106 void WriteColorScalarBufferAsBINARY(std::ofstream & outputFile,
1108 unsigned int numberOfPixelComponents,
1111 outputFile << numberOfPixelComponents <<
"\n";
1112 SizeValueType numberOfElements = numberOfPixelComponents * numberOfPixels;
1113 unsigned char *data =
new unsigned char[numberOfElements];
1116 data[ii] =
static_cast< unsigned char >( buffer[ii] );
1119 outputFile.write(reinterpret_cast< char * >( data ), numberOfElements);
1128 template<
typename TInput,
typename TOutput >
1129 void ReadCellsBuffer(TInput *input, TOutput *output)
1134 if ( input && output )
1136 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
1139 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
1140 output[outputIndex++] = nn;
1141 for (
unsigned int jj = 0; jj < nn; jj++ )
1143 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
1151 void operator=(
const Self &);
1155 #endif // __itkVTKPolyDataMeshIO_h