diff --git a/Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx b/Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx index 7129af2b97b..7b75d3f70ee 100644 --- a/Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx +++ b/Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx @@ -655,6 +655,52 @@ VTKPolyDataMeshIO::ReadMeshInformation() this->m_NumberOfPointPixelComponents = this->m_PointDimension * (this->m_PointDimension + 1) / 2; this->m_UpdatePointData = true; } + if (line.find("FIELD") != std::string::npos) + { + // define string stream and put line into it + StringStreamType sss; + sss << line; + + // Get each item + sss >> item; // should be "FIELD" + if (item == "FIELD") + { + sss >> item; // e.g. "FieldData" -- the field data name + sss >> item; // the number of field data arrays + if (std::stoi(item) >= 1) + { + // Note: we only use the first field data array + std::getline(inputFile, line, '\n'); + + StringStreamType asss; + asss << line; + asss >> item; // array name + + asss >> item; // numComponents + const unsigned int numComponents = std::stoi(item); + + asss >> item; // numTuples + const unsigned int numTuples = std::stoi(item); + + asss >> item; // data type + const IOComponentEnum componentType = this->GetComponentTypeFromString(item); + + if (this->m_NumberOfPoints == numTuples) + { + this->m_NumberOfPointPixelComponents = numComponents; + this->m_PointPixelType = IOPixelEnum::VARIABLELENGTHVECTOR; + + this->m_PointPixelComponentType = componentType; + if (this->m_PointPixelComponentType == IOComponentEnum::UNKNOWNCOMPONENTTYPE) + { + itkExceptionMacro("Unknown cell component type"); + } + + this->m_UpdatePointData = true; + } + } + } + } } else if (line.find("CELL_DATA") != std::string::npos) { @@ -788,6 +834,52 @@ VTKPolyDataMeshIO::ReadMeshInformation() this->m_NumberOfCellPixelComponents = this->m_PointDimension * (this->m_PointDimension + 1) / 2; this->m_UpdateCellData = true; } + if (line.find("FIELD") != std::string::npos) + { + // define string stream and put line into it + StringStreamType sss; + sss << line; + + // Get each item + sss >> item; // should be "FIELD" + if (item == "FIELD") + { + sss >> item; // e.g. "FieldData" -- the field data name + sss >> item; // the number of field data arrays + if (std::stoi(item) >= 1) + { + // Note: we only use the first field data array + std::getline(inputFile, line, '\n'); + + StringStreamType asss; + asss << line; + asss >> item; // array name + + asss >> item; // numComponents + const unsigned int numComponents = std::stoi(item); + + asss >> item; // numTuples + const unsigned int numTuples = std::stoi(item); + + asss >> item; // data type + const IOComponentEnum componentType = this->GetComponentTypeFromString(item); + + if (this->m_NumberOfCells == numTuples) + { + this->m_NumberOfCellPixelComponents = numComponents; + this->m_CellPixelType = IOPixelEnum::VARIABLELENGTHVECTOR; + + this->m_CellPixelComponentType = componentType; + if (this->m_CellPixelComponentType == IOComponentEnum::UNKNOWNCOMPONENTTYPE) + { + itkExceptionMacro("Unknown cell component type"); + } + + this->m_UpdateCellData = true; + } + } + } + } } else if (line.find("OFFSETS") != std::string::npos) { diff --git a/Modules/IO/MeshVTK/test/CMakeLists.txt b/Modules/IO/MeshVTK/test/CMakeLists.txt index 982ec69c556..413f0b239e2 100644 --- a/Modules/IO/MeshVTK/test/CMakeLists.txt +++ b/Modules/IO/MeshVTK/test/CMakeLists.txt @@ -176,6 +176,14 @@ itk_add_test( 2 1 1) +itk_add_test( + NAME + itkMeshFileReadWriteTestField + COMMAND + ITKIOMeshVTKTestDriver + itkMeshFileReadWriteTest + DATA{Input/gourd.vtk} + ${ITK_TEST_OUTPUT_DIR}/gourd.vtk) set(ITKIOMeshVTKGTests itkVTKPolyDataMeshIOGTest.cxx) diff --git a/Modules/IO/MeshVTK/test/Input/gourd.vtk.cid b/Modules/IO/MeshVTK/test/Input/gourd.vtk.cid new file mode 100755 index 00000000000..fb4ea539551 --- /dev/null +++ b/Modules/IO/MeshVTK/test/Input/gourd.vtk.cid @@ -0,0 +1 @@ +bafkreidv66i2s5mleluikmvcpq32yziqt7qo3tvc5imncrx4auoimwtdua