Fix bug with voxels in legacy vtk files

The legacy VTK file reader for unstructured grids had a bug when reading
cells of type voxel. VTK-m does not support the voxel cell type in
unstructured grids (i.e. explicit cell sets), so it has to convert them to
hexahedron cells. A bug in the reader was mangling the cell array index
during this conversion.
This commit is contained in:
Kenneth Moreland 2022-07-06 09:23:40 -06:00
parent 2a5b792b02
commit b2ce30e690
5 changed files with 124 additions and 1 deletions

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6372aec0eb79ee7c99de0e1546ff946dcfac2ea0eb7fb575fddc80decf0a438b
size 572

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a272a8d800bca5bc879d52cb4999562378c5ac108d953634b1dbad7ad07d8c8a
size 1031

@ -0,0 +1,7 @@
# Fix bug with voxels in legacy vtk files
The legacy VTK file reader for unstructured grids had a bug when reading
cells of type voxel. VTK-m does not support the voxel cell type in
unstructured grids (i.e. explicit cell sets), so it has to convert them to
hexahedron cells. A bug in the reader was mangling the cell array index
during this conversion.

@ -172,7 +172,7 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
newConnectivity.push_back(connPortal.Get(connIdx + 7));
newConnectivity.push_back(connPortal.Get(connIdx + 6));
permutationVec.push_back(i);
connIdx += 6;
connIdx += 8;
break;
}
default:

@ -153,6 +153,112 @@ void TestReadingUnstructuredGridEmpty()
VTKM_TEST_ASSERT(data.GetNumberOfFields() == 2);
}
void TestReadingUnstructuredPixels()
{
// VTK has a special pixel cell type that is the same as a quad but with a different
// vertex order. The reader must convert pixels to quads. Make sure this is happening
// correctly. This file has only axis-aligned pixels.
vtkm::cont::DataSet ds =
readVTKDataSet(vtkm::cont::testing::Testing::DataPath("unstructured/pixel_cells.vtk"));
vtkm::cont::CellSetSingleType<> cellSet;
ds.GetCellSet().AsCellSet(cellSet);
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> coords;
ds.GetCoordinateSystem().GetData().AsArrayHandle(coords);
for (vtkm::Id cellIndex = 0; cellIndex < cellSet.GetNumberOfCells(); ++cellIndex)
{
VTKM_TEST_ASSERT(cellSet.GetCellShape(cellIndex) == vtkm::CELL_SHAPE_QUAD);
constexpr vtkm::IdComponent NUM_VERTS = 4;
vtkm::Vec<vtkm::Id, NUM_VERTS> pointIndices;
cellSet.GetIndices(cellIndex, pointIndices);
vtkm::Vec<vtkm::Vec3f, NUM_VERTS> pointCoords;
auto coordPortal = coords.ReadPortal();
for (vtkm::IdComponent vertIndex = 0; vertIndex < NUM_VERTS; ++vertIndex)
{
pointCoords[vertIndex] = coordPortal.Get(pointIndices[vertIndex]);
}
VTKM_TEST_ASSERT(pointCoords[0][0] != pointCoords[1][0]);
VTKM_TEST_ASSERT(pointCoords[0][1] == pointCoords[1][1]);
VTKM_TEST_ASSERT(pointCoords[0][2] == pointCoords[1][2]);
VTKM_TEST_ASSERT(pointCoords[1][0] == pointCoords[2][0]);
VTKM_TEST_ASSERT(pointCoords[1][1] != pointCoords[2][1]);
VTKM_TEST_ASSERT(pointCoords[1][2] == pointCoords[2][2]);
VTKM_TEST_ASSERT(pointCoords[2][0] != pointCoords[3][0]);
VTKM_TEST_ASSERT(pointCoords[2][1] == pointCoords[3][1]);
VTKM_TEST_ASSERT(pointCoords[2][2] == pointCoords[3][2]);
VTKM_TEST_ASSERT(pointCoords[3][0] == pointCoords[0][0]);
VTKM_TEST_ASSERT(pointCoords[3][1] != pointCoords[0][1]);
VTKM_TEST_ASSERT(pointCoords[3][2] == pointCoords[0][2]);
}
}
void TestReadingUnstructuredVoxels()
{
// VTK has a special voxel cell type that is the same as a hexahedron but with a different
// vertex order. The reader must convert voxels to hexahedra. Make sure this is happening
// correctly. This file has only axis-aligned voxels.
vtkm::cont::DataSet ds =
readVTKDataSet(vtkm::cont::testing::Testing::DataPath("unstructured/voxel_cells.vtk"));
vtkm::cont::CellSetSingleType<> cellSet;
ds.GetCellSet().AsCellSet(cellSet);
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> coords;
ds.GetCoordinateSystem().GetData().AsArrayHandle(coords);
for (vtkm::Id cellIndex = 0; cellIndex < cellSet.GetNumberOfCells(); ++cellIndex)
{
VTKM_TEST_ASSERT(cellSet.GetCellShape(cellIndex) == vtkm::CELL_SHAPE_HEXAHEDRON);
constexpr vtkm::IdComponent NUM_VERTS = 8;
vtkm::Vec<vtkm::Id, NUM_VERTS> pointIndices;
cellSet.GetIndices(cellIndex, pointIndices);
vtkm::Vec<vtkm::Vec3f, NUM_VERTS> pointCoords;
auto coordPortal = coords.ReadPortal();
for (vtkm::IdComponent vertIndex = 0; vertIndex < NUM_VERTS; ++vertIndex)
{
pointCoords[vertIndex] = coordPortal.Get(pointIndices[vertIndex]);
}
VTKM_TEST_ASSERT(pointCoords[0][0] != pointCoords[1][0]);
VTKM_TEST_ASSERT(pointCoords[0][1] == pointCoords[1][1]);
VTKM_TEST_ASSERT(pointCoords[0][2] == pointCoords[1][2]);
VTKM_TEST_ASSERT(pointCoords[1][0] == pointCoords[2][0]);
VTKM_TEST_ASSERT(pointCoords[1][1] != pointCoords[2][1]);
VTKM_TEST_ASSERT(pointCoords[1][2] == pointCoords[2][2]);
VTKM_TEST_ASSERT(pointCoords[2][0] != pointCoords[3][0]);
VTKM_TEST_ASSERT(pointCoords[2][1] == pointCoords[3][1]);
VTKM_TEST_ASSERT(pointCoords[2][2] == pointCoords[3][2]);
VTKM_TEST_ASSERT(pointCoords[3][0] == pointCoords[0][0]);
VTKM_TEST_ASSERT(pointCoords[3][1] != pointCoords[0][1]);
VTKM_TEST_ASSERT(pointCoords[3][2] == pointCoords[0][2]);
VTKM_TEST_ASSERT(pointCoords[0][0] == pointCoords[4][0]);
VTKM_TEST_ASSERT(pointCoords[0][1] == pointCoords[4][1]);
VTKM_TEST_ASSERT(pointCoords[0][2] != pointCoords[4][2]);
VTKM_TEST_ASSERT(pointCoords[1][0] == pointCoords[5][0]);
VTKM_TEST_ASSERT(pointCoords[1][1] == pointCoords[5][1]);
VTKM_TEST_ASSERT(pointCoords[1][2] != pointCoords[5][2]);
VTKM_TEST_ASSERT(pointCoords[2][0] == pointCoords[6][0]);
VTKM_TEST_ASSERT(pointCoords[2][1] == pointCoords[6][1]);
VTKM_TEST_ASSERT(pointCoords[2][2] != pointCoords[6][2]);
VTKM_TEST_ASSERT(pointCoords[3][0] == pointCoords[7][0]);
VTKM_TEST_ASSERT(pointCoords[3][1] == pointCoords[7][1]);
VTKM_TEST_ASSERT(pointCoords[3][2] != pointCoords[7][2]);
}
}
void TestReadingUnstructuredGridVisIt(Format format)
{
VTKM_TEST_ASSERT(format == FORMAT_ASCII);
@ -521,6 +627,10 @@ void TestReadingVTKDataSet()
TestReadingUnstructuredGrid(FORMAT_BINARY);
std::cout << "Test reading VTK UnstructuredGrid with no cells" << std::endl;
TestReadingUnstructuredGridEmpty();
std::cout << "Test reading VTK UnstructuredGrid with pixels" << std::endl;
TestReadingUnstructuredPixels();
std::cout << "Test reading VTK UnstructuredGrid with voxels" << std::endl;
TestReadingUnstructuredVoxels();
std::cout << "Test reading VTK RectilinearGrid file in ASCII" << std::endl;
TestReadingRectilinearGrid1(FORMAT_ASCII);