From d81cbc6e37eed18e172de1ec1c14265f7d373095 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 31 Oct 2022 15:56:37 -0600 Subject: [PATCH] Fix reading global ids of permuted cells The legacy VTK reader sometimes has to permute cell data because some VTK cells are not directly supported in VTK-m. (For example, triangle strips are not supported. They have to be converted to triangles.) The global and petigree identifiers were not properly getting permuted. This is now fixed. --- .../read-permuted-global-cell-ids.md | 8 +++++++ vtkm/io/VTKDataSetReaderBase.cxx | 6 ++--- vtkm/io/testing/UnitTestVTKDataSetReader.cxx | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/read-permuted-global-cell-ids.md diff --git a/docs/changelog/read-permuted-global-cell-ids.md b/docs/changelog/read-permuted-global-cell-ids.md new file mode 100644 index 000000000..ba07b5165 --- /dev/null +++ b/docs/changelog/read-permuted-global-cell-ids.md @@ -0,0 +1,8 @@ +# Fix reading global ids of permuted cells + +The legacy VTK reader sometimes has to permute cell data because some VTK +cells are not directly supported in VTK-m. (For example, triangle strips +are not supported. They have to be converted to triangles.) + +The global and petigree identifiers were not properly getting permuted. +This is now fixed. diff --git a/vtkm/io/VTKDataSetReaderBase.cxx b/vtkm/io/VTKDataSetReaderBase.cxx index ef613a208..03f28c7bd 100644 --- a/vtkm/io/VTKDataSetReaderBase.cxx +++ b/vtkm/io/VTKDataSetReaderBase.cxx @@ -664,10 +664,10 @@ void VTKDataSetReaderBase::ReadGlobalOrPedigreeIds(vtkm::cont::Field::Associatio std::string dataType; this->DataFile->Stream >> dataName >> dataType >> std::ws; internal::parseAssert(dataType == "vtkIdType"); + // vtk writes vtkIdType as int - std::vector buffer(numElements); // vtk writes vtkIdType as int - this->ReadArray(buffer); - vtkm::cont::UnknownArrayHandle data(vtkm::cont::make_ArrayHandleMove(std::move(buffer))); + vtkm::cont::UnknownArrayHandle data = + this->DoReadArrayVariant(association, "int", numElements, 1); this->AddField(dataName, association, data); this->SkipArrayMetaData(1); diff --git a/vtkm/io/testing/UnitTestVTKDataSetReader.cxx b/vtkm/io/testing/UnitTestVTKDataSetReader.cxx index f3acc02df..0d3dadadd 100644 --- a/vtkm/io/testing/UnitTestVTKDataSetReader.cxx +++ b/vtkm/io/testing/UnitTestVTKDataSetReader.cxx @@ -140,6 +140,29 @@ void TestReadingV5Format(Format format) VTKM_TEST_ASSERT(ds.GetNumberOfCells() == 15, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType>(), "Incorrect cellset type"); + + for (vtkm::IdComponent fieldIdx = 0; fieldIdx < ds.GetNumberOfFields(); ++fieldIdx) + { + vtkm::cont::Field field = ds.GetField(fieldIdx); + switch (field.GetAssociation()) + { + case vtkm::cont::Field::Association::Points: + VTKM_TEST_ASSERT(field.GetData().GetNumberOfValues() == ds.GetNumberOfPoints(), + "Field ", + field.GetName(), + " is the wrong size"); + break; + case vtkm::cont::Field::Association::Cells: + VTKM_TEST_ASSERT(field.GetData().GetNumberOfValues() == ds.GetNumberOfCells(), + "Field ", + field.GetName(), + " is the wrong size"); + break; + default: + // Could be any size. + break; + } + } } void TestReadingUnstructuredGridEmpty()