Commit 52cecefb authored by Kenneth Moreland's avatar Kenneth Moreland

Fix crash when loading poly data with no cells

parent 3e398bbb
...@@ -210,6 +210,15 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle<vtkm::Id>& connectivity, ...@@ -210,6 +210,15 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
inline bool IsSingleShape(const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes) 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(); auto shapesPortal = shapes.ReadPortal();
vtkm::UInt8 shape0 = shapesPortal.Get(0); vtkm::UInt8 shape0 = shapesPortal.Get(0);
for (vtkm::Id i = 1; i < shapes.GetNumberOfValues(); ++i) for (vtkm::Id i = 1; i < shapes.GetNumberOfValues(); ++i)
......
...@@ -62,6 +62,17 @@ void TestReadingPolyData(Format format) ...@@ -62,6 +62,17 @@ void TestReadingPolyData(Format format)
"Incorrect cellset type"); "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) void TestReadingStructuredPoints(Format format)
{ {
std::string testFileName = (format == FORMAT_ASCII) std::string testFileName = (format == FORMAT_ASCII)
...@@ -114,6 +125,17 @@ void TestReadingUnstructuredGrid(Format format) ...@@ -114,6 +125,17 @@ void TestReadingUnstructuredGrid(Format format)
"Incorrect cellset type"); "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) void TestReadingUnstructuredGridVisIt(Format format)
{ {
VTKM_TEST_ASSERT(format == FORMAT_ASCII); VTKM_TEST_ASSERT(format == FORMAT_ASCII);
...@@ -452,6 +474,8 @@ void TestReadingVTKDataSet() ...@@ -452,6 +474,8 @@ void TestReadingVTKDataSet()
TestReadingPolyData(FORMAT_ASCII); TestReadingPolyData(FORMAT_ASCII);
std::cout << "Test reading VTK Polydata file in BINARY" << std::endl; std::cout << "Test reading VTK Polydata file in BINARY" << std::endl;
TestReadingPolyData(FORMAT_BINARY); 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; std::cout << "Test reading VTK StructuredPoints file in ASCII" << std::endl;
TestReadingStructuredPoints(FORMAT_ASCII); TestReadingStructuredPoints(FORMAT_ASCII);
...@@ -461,6 +485,8 @@ void TestReadingVTKDataSet() ...@@ -461,6 +485,8 @@ void TestReadingVTKDataSet()
TestReadingUnstructuredGrid(FORMAT_ASCII); TestReadingUnstructuredGrid(FORMAT_ASCII);
std::cout << "Test reading VTK UnstructuredGrid file in BINARY" << std::endl; std::cout << "Test reading VTK UnstructuredGrid file in BINARY" << std::endl;
TestReadingUnstructuredGrid(FORMAT_BINARY); 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; std::cout << "Test reading VTK RectilinearGrid file in ASCII" << std::endl;
TestReadingRectilinearGrid1(FORMAT_ASCII); TestReadingRectilinearGrid1(FORMAT_ASCII);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment