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();
110 void PrintSelf(std::ostream & os,
Indent indent)
const;
112 template<
typename T >
113 void UpdateCellInformation(T *buffer)
115 unsigned int numberOfVertices = 0;
116 unsigned int numberOfVertexIndices = 0;
117 unsigned int numberOfLines = 0;
118 unsigned int numberOfLineIndices = 0;
119 unsigned int numberOfPolygons = 0;
120 unsigned int numberOfPolygonIndices = 0;
124 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
127 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
132 numberOfVertexIndices += nn + 1;
136 numberOfLineIndices += nn + 1;
140 numberOfPolygonIndices += nn + 1;
144 numberOfPolygonIndices += nn + 1;
146 case QUADRILATERAL_CELL:
148 numberOfPolygonIndices += nn + 1;
151 itkExceptionMacro(<<
"Currently we dont support this cell type");
158 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
159 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
160 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
161 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
162 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
163 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
167 template<
typename T >
168 void ReadPointsBufferAsASCII(std::ifstream & inputFile, T *buffer)
172 while ( !inputFile.eof() )
174 std::getline(inputFile, line,
'\n');
176 if ( line.find(
"POINTS") != std::string::npos )
179 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
182 inputFile >> buffer[ii];
188 template<
typename T >
189 void ReadPointsBufferAsBINARY(std::ifstream & inputFile, T *buffer)
193 while ( !inputFile.eof() )
195 std::getline(inputFile, line,
'\n');
197 if ( line.find(
"POINTS") != std::string::npos )
200 SizeValueType numberOfComponents = this->m_NumberOfPoints * this->m_PointDimension;
201 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
211 void ReadCellsBufferAsASCII(std::ifstream & inputFile,
void *buffer);
213 void ReadCellsBufferAsBINARY(std::ifstream & inputFile,
void *buffer);
215 template<
typename T >
216 void ReadPointDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
220 while ( !inputFile.eof() )
222 std::getline(inputFile, line,
'\n');
223 if ( line.find(
"POINT_DATA") != std::string::npos )
225 if ( !inputFile.eof() )
227 std::getline(inputFile, line,
'\n');
231 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
235 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
237 if ( !inputFile.eof() )
239 std::getline(inputFile, line,
'\n');
240 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
242 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
247 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
253 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
256 inputFile >> buffer[ii];
262 template<
typename T >
263 void ReadPointDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
267 while ( !inputFile.eof() )
269 std::getline(inputFile, line,
'\n');
270 if ( line.find(
"POINT_DATA") != std::string::npos )
272 if ( !inputFile.eof() )
274 std::getline(inputFile, line,
'\n');
278 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
282 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
284 if ( !inputFile.eof() )
286 std::getline(inputFile, line,
'\n');
287 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
289 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
294 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
300 SizeValueType numberOfComponents = this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents;
301 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
311 template<
typename T >
312 void ReadCellDataBufferAsASCII(std::ifstream & inputFile, T *buffer)
316 while ( !inputFile.eof() )
318 std::getline(inputFile, line,
'\n');
319 if ( line.find(
"CELL_DATA") != std::string::npos )
321 if ( !inputFile.eof() )
323 std::getline(inputFile, line,
'\n');
327 itkExceptionMacro(
"UnExpected end of line while trying to read CELL_DATA");
331 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
333 if ( !inputFile.eof() )
335 std::getline(inputFile, line,
'\n');
336 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
338 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
343 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
349 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
352 inputFile >> buffer[ii];
358 template<
typename T >
359 void ReadCellDataBufferAsBINARY(std::ifstream & inputFile, T *buffer)
363 while ( !inputFile.eof() )
365 std::getline(inputFile, line,
'\n');
366 if ( line.find(
"POINT_DATA") != std::string::npos )
368 if ( !inputFile.eof() )
370 std::getline(inputFile, line,
'\n');
374 itkExceptionMacro(
"UnExpected end of line while trying to read POINT_DATA");
378 if ( line.find(
"SCALARS") != std::string::npos && line.find(
"COLOR_SCALARS") == std::string::npos )
380 if ( !inputFile.eof() )
382 std::getline(inputFile, line,
'\n');
383 if ( line.find(
"LOOKUP_TABLE") == std::string::npos )
385 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
390 itkExceptionMacro(
"UnExpected end of line while trying to read LOOKUP_TABLE");
395 SizeValueType numberOfComponents = this->m_NumberOfCellPixels * this->m_NumberOfCellPixelComponents;
396 inputFile.read( reinterpret_cast< char * >( buffer ), numberOfComponents *
sizeof( T ) );
406 template<
typename T >
407 void WritePointsBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
410 outputFile <<
"POINTS " << this->m_NumberOfPoints;
412 outputFile << pointComponentType <<
'\n';
413 for (
SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
415 for (
unsigned int jj = 0; jj < this->m_PointDimension - 1; jj++ )
417 outputFile << buffer[ii * this->m_PointDimension + jj] <<
" ";
420 outputFile << buffer[ii * this->m_PointDimension + this->m_PointDimension - 1] <<
'\n';
426 template<
typename T >
427 void WritePointsBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointComponentType)
430 outputFile <<
"POINTS " << this->m_NumberOfPoints;
431 outputFile << pointComponentType <<
"\n";
438 template<
typename T >
439 void WriteCellsBufferAsASCII(std::ofstream & outputFile, T *buffer)
442 unsigned int numberOfVertices = 0;
443 unsigned int numberOfVertexIndices = 0;
444 unsigned int numberOfLines = 0;
445 unsigned int numberOfLineIndices = 0;
446 unsigned int numberOfPolygons = 0;
447 unsigned int numberOfPolygonIndices = 0;
452 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
453 if ( numberOfVertices )
455 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
456 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
457 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
460 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
461 if ( cellType == VERTEX_CELL )
464 for (
unsigned int jj = 0; jj < nn; jj++ )
466 outputFile <<
" " << buffer[index++];
479 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
482 numberOfLineIndices = 0;
486 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
489 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
490 if ( cellType == LINE_CELL )
492 if ( pointIds.size() >= nn )
495 if (
id == static_cast< SizeValueType >( buffer[index] ) )
497 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
499 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
501 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
505 polylines->InsertElement(numberOfPolylines++, pointIds);
506 numberOfLineIndices += pointIds.size();
510 for (
unsigned int jj = 0; jj < nn; jj++ )
512 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
518 for (
unsigned int jj = 0; jj < nn; jj++ )
520 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
527 polylines->InsertElement(numberOfPolylines++, pointIds);
528 numberOfLineIndices += pointIds.size();
531 numberOfLines = polylines->Size();
532 numberOfLineIndices += numberOfLines;
533 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
534 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
535 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
538 unsigned int nn = polylines->ElementAt(ii).size();
540 for (
unsigned int jj = 0; jj < nn; ++jj )
542 outputFile <<
" " << polylines->ElementAt(ii)[jj];
550 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
551 if ( numberOfPolygons )
553 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
554 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
555 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
558 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
559 if ( cellType == POLYGON_CELL ||
560 cellType == TRIANGLE_CELL ||
561 cellType == QUADRILATERAL_CELL )
564 for (
unsigned int jj = 0; jj < nn; jj++ )
566 outputFile <<
" " << buffer[index++];
579 template<
typename T >
580 void WriteCellsBufferAsBINARY(std::ofstream & outputFile, T *buffer)
583 unsigned int numberOfVertices = 0;
584 unsigned int numberOfVertexIndices = 0;
585 unsigned int numberOfLines = 0;
586 unsigned int numberOfLineIndices = 0;
587 unsigned int numberOfPolygons = 0;
588 unsigned int numberOfPolygonIndices = 0;
593 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertices", numberOfVertices);
594 if ( numberOfVertices )
596 ExposeMetaData< unsigned int >(metaDic,
"numberOfVertexIndices", numberOfVertexIndices);
597 outputFile <<
"VERTICES " << numberOfVertices <<
" " << numberOfVertexIndices <<
'\n';
598 unsigned int *data =
new unsigned int[numberOfVertexIndices];
599 ReadCellsBuffer(buffer, data);
607 ExposeMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
610 numberOfLineIndices = 0;
614 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
617 unsigned int nn =
static_cast< unsigned int >( buffer[index++] );
618 if ( cellType == LINE_CELL )
620 if ( pointIds.size() >= nn )
623 if (
id == static_cast< SizeValueType >( buffer[index] ) )
625 pointIds.push_back( static_cast< SizeValueType >( buffer[index + 1] ) );
627 else if (
id == static_cast< SizeValueType >( buffer[index + 1] ) )
629 pointIds.push_back( static_cast< SizeValueType >( buffer[index] ) );
633 polylines->InsertElement(numberOfPolylines++, pointIds);
634 numberOfLineIndices += pointIds.size();
638 for (
unsigned int jj = 0; jj < nn; jj++ )
640 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
646 for (
unsigned int jj = 0; jj < nn; jj++ )
648 pointIds.push_back( static_cast< SizeValueType >( buffer[index + jj] ) );
655 polylines->InsertElement(numberOfPolylines++, pointIds);
656 numberOfLineIndices += pointIds.size();
659 numberOfLines = polylines->Size();
660 numberOfLineIndices += numberOfLines;
661 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLines", numberOfLines);
662 EncapsulateMetaData< unsigned int >(metaDic,
"numberOfLineIndices", numberOfLineIndices);
664 outputFile <<
"LINES " << numberOfLines <<
" " << numberOfLineIndices <<
'\n';
665 unsigned int *data =
new unsigned int[numberOfLineIndices];
666 unsigned long outputIndex = 0;
669 unsigned int nn = polylines->ElementAt(ii).size();
670 data[outputIndex++] = nn;
671 for (
unsigned int jj = 0; jj < nn; ++jj )
673 data[outputIndex++] = polylines->ElementAt(ii)[jj];
684 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygons", numberOfPolygons);
685 if ( numberOfPolygons )
687 ExposeMetaData< unsigned int >(metaDic,
"numberOfPolygonIndices", numberOfPolygonIndices);
688 outputFile <<
"POLYGONS " << numberOfPolygons <<
" " << numberOfPolygonIndices <<
'\n';
689 unsigned int *data =
new unsigned int[numberOfPolygonIndices];
690 ReadCellsBuffer(buffer, data);
698 template<
typename T >
699 void WritePointDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
704 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
'\n';
705 switch ( this->m_PointPixelType )
709 outputFile <<
"SCALARS ";
710 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
711 outputFile << dataName <<
" ";
716 case COVARIANTVECTOR:
719 outputFile <<
"VECTORS ";
720 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
721 outputFile << dataName <<
" ";
724 case SYMMETRICSECONDRANKTENSOR:
725 case DIFFUSIONTENSOR3D:
727 outputFile <<
"TENSORS ";
728 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
729 outputFile << dataName <<
" ";
733 case VARIABLELENGTHVECTOR:
735 outputFile <<
"COLOR_SCALARS ";
736 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
737 outputFile << dataName <<
" ";
738 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
743 itkExceptionMacro(<<
"Unknown point pixel type");
747 outputFile << pointPixelComponentName <<
'\n';
749 if ( this->m_PointPixelType == SCALAR )
751 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
755 if ( this->m_PointPixelType == SYMMETRICSECONDRANKTENSOR )
759 const SizeValueType num = this->m_NumberOfPointPixelComponents * this->m_NumberOfPointPixels;
762 if( this->m_NumberOfPointPixelComponents == 3 )
769 outputFile << *ptr++ << indent;
771 outputFile << e12 << indent;
772 outputFile << zero <<
'\n';
774 outputFile << e12 << indent;
775 outputFile << *ptr++ << indent;
776 outputFile << zero <<
'\n';
778 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
782 else if( this->m_NumberOfPointPixelComponents == 6 )
790 outputFile << *ptr++ << indent;
792 outputFile << e12 << indent;
794 outputFile << e13 <<
'\n';
796 outputFile << e12 << indent;
797 outputFile << *ptr++ << indent;
799 outputFile << e23 <<
'\n';
801 outputFile << e13 << indent;
802 outputFile << e23 << indent;
803 outputFile << *ptr++ <<
"\n\n";
810 "itk::ERROR: VTKImageIO2: Unsupported number of components in tensor.",
818 for (
SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ii++ )
820 for ( jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; jj++ )
822 outputFile << buffer[ii * this->m_NumberOfPointPixelComponents + jj] << indent;
824 outputFile << buffer[ii * this->m_NumberOfPointPixelComponents + jj];
832 template<
typename T >
833 void WritePointDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & pointPixelComponentName)
838 outputFile <<
"POINT_DATA " << this->m_NumberOfPointPixels <<
"\n";
839 switch ( this->m_PointPixelType )
843 outputFile <<
"SCALARS ";
844 ExposeMetaData< StringType >(metaDic,
"pointScalarDataName", dataName);
845 outputFile << dataName <<
" ";
850 case COVARIANTVECTOR:
853 outputFile <<
"VECTORS ";
854 ExposeMetaData< StringType >(metaDic,
"pointVectorDataName", dataName);
855 outputFile << dataName <<
" ";
858 case SYMMETRICSECONDRANKTENSOR:
859 case DIFFUSIONTENSOR3D:
861 outputFile <<
"TENSORS ";
862 ExposeMetaData< StringType >(metaDic,
"pointTensorDataName", dataName);
863 outputFile << dataName <<
" ";
867 case VARIABLELENGTHVECTOR:
869 outputFile <<
"COLOR_SCALARS ";
870 ExposeMetaData< StringType >(metaDic,
"pointColorScalarDataName", dataName);
871 outputFile << dataName <<
" ";
872 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfPointPixelComponents, this->m_NumberOfPointPixels);
877 itkExceptionMacro(<<
"Unknown point pixel type");
881 outputFile << pointPixelComponentName <<
"\n";
882 if ( this->m_PointPixelType == SCALAR )
884 outputFile <<
"LOOKUP_TABLE default\n";
888 this->m_NumberOfPointPixels * this->m_NumberOfPointPixelComponents,
894 template<
typename T >
895 void WriteCellDataBufferAsASCII(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
900 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
'\n';
901 switch ( this->m_CellPixelType )
905 outputFile <<
"SCALARS ";
906 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
907 outputFile << dataName <<
" ";
912 case COVARIANTVECTOR:
915 outputFile <<
"VECTORS ";
916 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
917 outputFile << dataName <<
" ";
920 case SYMMETRICSECONDRANKTENSOR:
921 case DIFFUSIONTENSOR3D:
923 outputFile <<
"TENSORS ";
924 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
925 outputFile << dataName <<
" ";
929 case VARIABLELENGTHVECTOR:
931 outputFile <<
"COLOR_SCALARS ";
932 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
933 outputFile << dataName <<
" ";
934 WriteColorScalarBufferAsASCII(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
939 itkExceptionMacro(<<
"Unknown cell pixel type");
943 outputFile << cellPixelComponentName <<
'\n';
944 if ( this->m_CellPixelType == SCALAR )
946 outputFile <<
"LOOKUP_TABLE default" <<
'\n';
950 if ( this->m_CellPixelType == SYMMETRICSECONDRANKTENSOR )
954 const SizeValueType num = this->m_NumberOfCellPixelComponents * this->m_NumberOfCellPixels;
955 if( this->m_NumberOfCellPixelComponents == 3 )
962 outputFile << *ptr++ << indent;
964 outputFile << e12 << indent;
965 outputFile << zero <<
'\n';
967 outputFile << e12 << indent;
968 outputFile << *ptr++ << indent;
969 outputFile << zero <<
'\n';
971 outputFile << zero << indent << zero << indent << zero <<
"\n\n";
975 else if( this->m_NumberOfCellPixelComponents == 3 )
983 outputFile << *ptr++ << indent;
985 outputFile << e12 << indent;
987 outputFile << e13 <<
'\n';
989 outputFile << e12 << indent;
990 outputFile << *ptr++ << indent;
992 outputFile << e23 <<
'\n';
994 outputFile << e13 << indent;
995 outputFile << e23 << indent;
996 outputFile << *ptr++ <<
"\n\n";
1003 "itk::ERROR: VTKPolyDataMeshIO: Unsupported number of components in tensor.",
1011 for (
SizeValueType ii = 0; ii < this->m_NumberOfCellPixels; ii++ )
1013 for ( jj = 0; jj < this->m_NumberOfCellPixelComponents - 1; jj++ )
1015 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj] << indent;
1017 outputFile << buffer[ii * this->m_NumberOfCellPixelComponents + jj];
1025 template<
typename T >
1026 void WriteCellDataBufferAsBINARY(std::ofstream & outputFile, T *buffer,
const StringType & cellPixelComponentName)
1031 outputFile <<
"CELL_DATA " << this->m_NumberOfCellPixels <<
"\n";
1032 switch ( this->m_CellPixelType )
1036 outputFile <<
"SCALARS ";
1037 ExposeMetaData< StringType >(metaDic,
"cellScalarDataName", dataName);
1038 outputFile << dataName <<
" ";
1043 case COVARIANTVECTOR:
1046 outputFile <<
"VECTORS ";
1047 ExposeMetaData< StringType >(metaDic,
"cellVectorDataName", dataName);
1048 outputFile << dataName <<
" ";
1051 case SYMMETRICSECONDRANKTENSOR:
1052 case DIFFUSIONTENSOR3D:
1054 outputFile <<
"TENSORS ";
1055 ExposeMetaData< StringType >(metaDic,
"cellTensorDataName", dataName);
1056 outputFile << dataName <<
" ";
1060 case VARIABLELENGTHVECTOR:
1062 outputFile <<
"COLOR_SCALARS ";
1063 ExposeMetaData< StringType >(metaDic,
"cellColorScalarDataName", dataName);
1064 outputFile << dataName <<
" ";
1065 WriteColorScalarBufferAsBINARY(outputFile, buffer, this->m_NumberOfCellPixelComponents, this->m_NumberOfCellPixels);
1070 itkExceptionMacro(<<
"Unknown cell pixel type");
1074 outputFile << cellPixelComponentName <<
"\n";
1075 if ( this->m_CellPixelType == SCALAR )
1077 outputFile <<
"LOOKUP_TABLE default\n";
1081 this->m_NumberOfCells * this->m_NumberOfCellPixelComponents,
1087 template<
typename T >
1088 void WriteColorScalarBufferAsASCII(std::ofstream & outputFile,
1090 unsigned int numberOfPixelComponents,
1093 outputFile << numberOfPixelComponents <<
"\n";
1097 for (
unsigned int jj = 0; jj < numberOfPixelComponents; ++jj )
1099 outputFile << static_cast< float >( buffer[ii * numberOfPixelComponents + jj] ) << indent;
1108 template<
typename T >
1109 void WriteColorScalarBufferAsBINARY(std::ofstream & outputFile,
1111 unsigned int numberOfPixelComponents,
1114 outputFile << numberOfPixelComponents <<
"\n";
1115 SizeValueType numberOfElements = numberOfPixelComponents * numberOfPixels;
1116 unsigned char *data =
new unsigned char[numberOfElements];
1119 data[ii] =
static_cast< unsigned char >( buffer[ii] );
1122 outputFile.write(reinterpret_cast< char * >( data ), numberOfElements);
1131 template<
typename TInput,
typename TOutput >
1132 void ReadCellsBuffer(TInput *input, TOutput *output)
1137 if ( input && output )
1139 for (
SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
1142 unsigned int nn =
static_cast< unsigned int >( input[inputIndex++] );
1143 output[outputIndex++] = nn;
1144 for (
unsigned int jj = 0; jj < nn; jj++ )
1146 output[outputIndex++] =
static_cast< TOutput
>( input[inputIndex++] );
1154 void operator=(
const Self &);
1158 #endif // __itkVTKPolyDataMeshIO_h