From 52f0d5b2d5c66ac9fff53686c94c02f52d44ed1e Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Mon, 4 May 2020 15:32:41 -0600 Subject: [PATCH] Fix MarchingCell for Wedge Fixed error in one entry of number_of_triangles table for MarchineCells that results in missing triangles for wedge cell type as reported by issue #496. --- data/data/unstructured/box-with-errors.vtk | 3 + vtkm/filter/testing/UnitTestContourFilter.cxx | 150 +++++++++++------- vtkm/worklet/contour/MarchingCellTables.h | 2 +- 3 files changed, 96 insertions(+), 59 deletions(-) create mode 100644 data/data/unstructured/box-with-errors.vtk diff --git a/data/data/unstructured/box-with-errors.vtk b/data/data/unstructured/box-with-errors.vtk new file mode 100644 index 000000000..7641c24e6 --- /dev/null +++ b/data/data/unstructured/box-with-errors.vtk @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e415c5dfd711901fdb0abb4dab2606b41c032938867200bdceebc13414b3bc8 +size 4045 diff --git a/vtkm/filter/testing/UnitTestContourFilter.cxx b/vtkm/filter/testing/UnitTestContourFilter.cxx index 8cc640807..428abbb7e 100644 --- a/vtkm/filter/testing/UnitTestContourFilter.cxx +++ b/vtkm/filter/testing/UnitTestContourFilter.cxx @@ -10,87 +10,121 @@ #include #include -#include -#include #include #include #include +#include #include -namespace vtkm_ut_mc_filter +namespace { -void TestContourUniformGrid() +class TestContourFilter { - std::cout << "Testing Contour filter on a uniform grid" << std::endl; - - vtkm::Id3 dims(4, 4, 4); - vtkm::source::Tangle tangle(dims); - vtkm::cont::DataSet dataSet = tangle.Execute(); - - vtkm::filter::Contour mc; - - mc.SetGenerateNormals(true); - mc.SetIsoValue(0, 0.5); - mc.SetActiveField("nodevar"); - mc.SetFieldsToPass(vtkm::filter::FieldSelection::MODE_NONE); - - auto result = mc.Execute(dataSet); +public: + void TestContourUniformGrid() const { - VTKM_TEST_ASSERT(result.GetNumberOfCoordinateSystems() == 1, - "Wrong number of coordinate systems in the output dataset"); - //since normals is on we have one field - VTKM_TEST_ASSERT(result.GetNumberOfFields() == 1, - "Wrong number of fields in the output dataset"); + std::cout << "Testing Contour filter on a uniform grid" << std::endl; + + vtkm::Id3 dims(4, 4, 4); + vtkm::source::Tangle tangle(dims); + vtkm::cont::DataSet dataSet = tangle.Execute(); + + vtkm::filter::Contour mc; + + mc.SetGenerateNormals(true); + mc.SetIsoValue(0, 0.5); + mc.SetActiveField("nodevar"); + mc.SetFieldsToPass(vtkm::filter::FieldSelection::MODE_NONE); + + auto result = mc.Execute(dataSet); + { + VTKM_TEST_ASSERT(result.GetNumberOfCoordinateSystems() == 1, + "Wrong number of coordinate systems in the output dataset"); + //since normals is on we have one field + VTKM_TEST_ASSERT(result.GetNumberOfFields() == 1, + "Wrong number of fields in the output dataset"); + } + + // let's execute with mapping fields. + mc.SetFieldsToPass("nodevar"); + result = mc.Execute(dataSet); + { + const bool isMapped = result.HasField("nodevar"); + VTKM_TEST_ASSERT(isMapped, "mapping should pass"); + + VTKM_TEST_ASSERT(result.GetNumberOfFields() == 2, + "Wrong number of fields in the output dataset"); + + vtkm::cont::CoordinateSystem coords = result.GetCoordinateSystem(); + vtkm::cont::DynamicCellSet dcells = result.GetCellSet(); + using CellSetType = vtkm::cont::CellSetSingleType<>; + const CellSetType& cells = dcells.Cast(); + + //verify that the number of points is correct (72) + //verify that the number of cells is correct (160) + VTKM_TEST_ASSERT(coords.GetNumberOfPoints() == 72, + "Should have less coordinates than the unmerged version"); + VTKM_TEST_ASSERT(cells.GetNumberOfCells() == 160, ""); + } + + //Now try with vertex merging disabled. Since this + //we use FlyingEdges we now which does point merging for free + //so we should see the number of points not change + mc.SetMergeDuplicatePoints(false); + mc.SetFieldsToPass(vtkm::filter::FieldSelection::MODE_ALL); + result = mc.Execute(dataSet); + { + vtkm::cont::CoordinateSystem coords = result.GetCoordinateSystem(); + + VTKM_TEST_ASSERT(coords.GetNumberOfPoints() == 72, + "Shouldn't have less coordinates than the unmerged version"); + + //verify that the number of cells is correct (160) + vtkm::cont::DynamicCellSet dcells = result.GetCellSet(); + + using CellSetType = vtkm::cont::CellSetSingleType<>; + const CellSetType& cells = dcells.Cast(); + VTKM_TEST_ASSERT(cells.GetNumberOfCells() == 160, ""); + } } - // let's execute with mapping fields. - mc.SetFieldsToPass("nodevar"); - result = mc.Execute(dataSet); + void TestContourWedges() const { - const bool isMapped = result.HasField("nodevar"); - VTKM_TEST_ASSERT(isMapped, "mapping should pass"); + auto pathname = + vtkm::cont::testing::Testing::GetTestDataBasePath() + "/unstructured/box-with-errors.vtk"; + vtkm::io::reader::VTKDataSetReader reader(pathname); - VTKM_TEST_ASSERT(result.GetNumberOfFields() == 2, - "Wrong number of fields in the output dataset"); + vtkm::cont::DataSet dataSet = reader.ReadDataSet(); - vtkm::cont::CoordinateSystem coords = result.GetCoordinateSystem(); - vtkm::cont::DynamicCellSet dcells = result.GetCellSet(); - using CellSetType = vtkm::cont::CellSetSingleType<>; - const CellSetType& cells = dcells.Cast(); + vtkm::cont::CellSetExplicit<> cellSet; + dataSet.GetCellSet().CopyTo(cellSet); - //verify that the number of points is correct (72) - //verify that the number of cells is correct (160) - VTKM_TEST_ASSERT(coords.GetNumberOfPoints() == 72, - "Should have less coordinates than the unmerged version"); - VTKM_TEST_ASSERT(cells.GetNumberOfCells() == 160, ""); + vtkm::cont::ArrayHandle fieldArray; + dataSet.GetPointField("gyroid").GetData().CopyTo(fieldArray); + + vtkm::worklet::Contour isosurfaceFilter; + isosurfaceFilter.SetMergeDuplicatePoints(false); + + vtkm::cont::ArrayHandle verticesArray; + vtkm::cont::ArrayHandle normalsArray; + + auto result = isosurfaceFilter.Run( + { 0.0f }, cellSet, dataSet.GetCoordinateSystem(), fieldArray, verticesArray, normalsArray); + VTKM_TEST_ASSERT(result.GetNumberOfCells() == 52); } - //Now try with vertex merging disabled. Since this - //we use FlyingEdges we now which does point merging for free - //so we should see the number of points not change - mc.SetMergeDuplicatePoints(false); - mc.SetFieldsToPass(vtkm::filter::FieldSelection::MODE_ALL); - result = mc.Execute(dataSet); + void operator()() const { - vtkm::cont::CoordinateSystem coords = result.GetCoordinateSystem(); - - VTKM_TEST_ASSERT(coords.GetNumberOfPoints() == 72, - "Shouldn't have less coordinates than the unmerged version"); - - //verify that the number of cells is correct (160) - vtkm::cont::DynamicCellSet dcells = result.GetCellSet(); - - using CellSetType = vtkm::cont::CellSetSingleType<>; - const CellSetType& cells = dcells.Cast(); - VTKM_TEST_ASSERT(cells.GetNumberOfCells() == 160, ""); + this->TestContourUniformGrid(); + this->TestContourWedges(); } -} +}; // class TestContourFilter } // namespace int UnitTestContourFilter(int argc, char* argv[]) { - return vtkm::cont::testing::Testing::Run(vtkm_ut_mc_filter::TestContourUniformGrid, argc, argv); + return vtkm::cont::testing::Testing::Run(TestContourFilter{}, argc, argv); } diff --git a/vtkm/worklet/contour/MarchingCellTables.h b/vtkm/worklet/contour/MarchingCellTables.h index afef52b50..9a2c2c92c 100644 --- a/vtkm/worklet/contour/MarchingCellTables.h +++ b/vtkm/worklet/contour/MarchingCellTables.h @@ -81,7 +81,7 @@ VTKM_STATIC_CONSTEXPR_ARRAY vtkm::IdComponent NumTrianglesTable[] = { 3, 4, 4, 5, 4, 5, 3, 4, 4, 5, 5, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 2, 1, 3, 2, 4, 1, 2, 1, 1, 0, // CELL_SHAPE_WEDGE, case 0 - 63 - 0, 1, 1, 2, 1, 2, 1, 1, 1, 2, 2, 3, 2, 3, 3, 2, + 0, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 3, 2, 3, 3, 2, 1, 2, 2, 3, 2, 3, 3, 2, 2, 3, 3, 2, 3, 4, 4, 1, 1, 2, 2, 3, 2, 3, 3, 2, 2, 3, 3, 4, 3, 2, 4, 1, 2, 3, 3, 4, 3, 4, 2, 1, 1, 2, 2, 1, 2, 1, 1, 0,