Fix crash when loading poly data with no cells

This commit is contained in:
Kenneth Moreland 2020-09-01 14:20:11 -06:00
parent 3e398bbb3d
commit 52cecefba0
4 changed files with 41 additions and 0 deletions

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

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

@ -210,6 +210,15 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
inline bool IsSingleShape(const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes)
{
if (shapes.GetNumberOfValues() < 1)
{
// If the data has no cells, is it single shape? That would make sense, but having
// a single shape cell set requires you to slect a shape, and there are no cells to
// make that selection from. We could get around that, but it's easier just to treat
// it as a general explicit grid.
return false;
}
auto shapesPortal = shapes.ReadPortal();
vtkm::UInt8 shape0 = shapesPortal.Get(0);
for (vtkm::Id i = 1; i < shapes.GetNumberOfValues(); ++i)

@ -62,6 +62,17 @@ void TestReadingPolyData(Format format)
"Incorrect cellset type");
}
void TestReadingPolyDataEmpty()
{
vtkm::cont::DataSet data =
readVTKDataSet(vtkm::cont::testing::Testing::DataPath("unstructured/empty_poly.vtk"));
VTKM_TEST_ASSERT(data.GetNumberOfPoints() == 8);
VTKM_TEST_ASSERT(data.GetNumberOfCells() == 0);
VTKM_TEST_ASSERT(data.GetCellSet().GetNumberOfPoints() == 8);
VTKM_TEST_ASSERT(data.GetNumberOfFields() == 1);
}
void TestReadingStructuredPoints(Format format)
{
std::string testFileName = (format == FORMAT_ASCII)
@ -114,6 +125,17 @@ void TestReadingUnstructuredGrid(Format format)
"Incorrect cellset type");
}
void TestReadingUnstructuredGridEmpty()
{
vtkm::cont::DataSet data =
readVTKDataSet(vtkm::cont::testing::Testing::DataPath("unstructured/empty_unstructured.vtk"));
VTKM_TEST_ASSERT(data.GetNumberOfPoints() == 26);
VTKM_TEST_ASSERT(data.GetNumberOfCells() == 0);
VTKM_TEST_ASSERT(data.GetCellSet().GetNumberOfPoints() == 26);
VTKM_TEST_ASSERT(data.GetNumberOfFields() == 2);
}
void TestReadingUnstructuredGridVisIt(Format format)
{
VTKM_TEST_ASSERT(format == FORMAT_ASCII);
@ -452,6 +474,8 @@ void TestReadingVTKDataSet()
TestReadingPolyData(FORMAT_ASCII);
std::cout << "Test reading VTK Polydata file in BINARY" << std::endl;
TestReadingPolyData(FORMAT_BINARY);
std::cout << "Test reading VTK Polydata with no cells" << std::endl;
TestReadingPolyDataEmpty();
std::cout << "Test reading VTK StructuredPoints file in ASCII" << std::endl;
TestReadingStructuredPoints(FORMAT_ASCII);
@ -461,6 +485,8 @@ void TestReadingVTKDataSet()
TestReadingUnstructuredGrid(FORMAT_ASCII);
std::cout << "Test reading VTK UnstructuredGrid file in BINARY" << std::endl;
TestReadingUnstructuredGrid(FORMAT_BINARY);
std::cout << "Test reading VTK UnstructuredGrid with no cells" << std::endl;
TestReadingUnstructuredGridEmpty();
std::cout << "Test reading VTK RectilinearGrid file in ASCII" << std::endl;
TestReadingRectilinearGrid1(FORMAT_ASCII);