From 6e674ddea63891e88455cb175d2edeb531ad5553 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 24 Aug 2023 16:10:50 -0400 Subject: [PATCH] Fix degenerate polygon removal There was a bug in `CleanGrid` when removing degenerate polygons where it would not detect if the first and last point were the same. This has been fixed. There was also an error with function overloading that was causing 0D and 3D cells to enter the wrong computation for degenerate cells. This has also been fixed. Fixes #796 --- docs/changelog/fix-degenerates.md | 9 +++++++++ .../clean_grid/testing/UnitTestCleanGrid.cxx | 2 +- .../worklet/RemoveDegenerateCells.h | 19 +++++++++++-------- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 docs/changelog/fix-degenerates.md diff --git a/docs/changelog/fix-degenerates.md b/docs/changelog/fix-degenerates.md new file mode 100644 index 000000000..1c648e6fa --- /dev/null +++ b/docs/changelog/fix-degenerates.md @@ -0,0 +1,9 @@ +# Fix degenerate cell removal + +There was a bug in `CleanGrid` when removing degenerate polygons where it +would not detect if the first and last point were the same. This has been +fixed. + +There was also an error with function overloading that was causing 0D and +3D cells to enter the wrong computation for degenerate cells. This has also +been fixed. diff --git a/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx b/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx index c5eb5cc3f..6173982b1 100644 --- a/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx +++ b/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx @@ -140,7 +140,7 @@ void TestPointMerging() << std::endl; cleanGrid.SetRemoveDegenerateCells(true); vtkm::cont::DataSet noDegenerateCells = cleanGrid.Execute(inData); - constexpr vtkm::Id numNonDegenerateCells = 33; + constexpr vtkm::Id numNonDegenerateCells = 18; VTKM_TEST_ASSERT(noDegenerateCells.GetNumberOfCells() == numNonDegenerateCells); VTKM_TEST_ASSERT(noDegenerateCells.GetCellSet().GetNumberOfPoints() == farFastMergeNumPoints); VTKM_TEST_ASSERT(noDegenerateCells.GetNumberOfPoints() == farFastMergeNumPoints); diff --git a/vtkm/filter/clean_grid/worklet/RemoveDegenerateCells.h b/vtkm/filter/clean_grid/worklet/RemoveDegenerateCells.h index 03b5d934e..54eceba64 100644 --- a/vtkm/filter/clean_grid/worklet/RemoveDegenerateCells.h +++ b/vtkm/filter/clean_grid/worklet/RemoveDegenerateCells.h @@ -44,18 +44,20 @@ struct RemoveDegenerateCells { const vtkm::IdComponent numPoints = pointIds.GetNumberOfComponents(); vtkm::IdComponent numUnduplicatedPoints = 0; - for (vtkm::IdComponent localPointId = 0; localPointId < numPoints; ++localPointId) + // Skip first point if it is the same as the last. + for (vtkm::IdComponent localPointId = ((pointIds[0] != pointIds[numPoints - 1]) ? 0 : 1); + localPointId < numPoints; + ++localPointId) { ++numUnduplicatedPoints; if (numUnduplicatedPoints >= dimensionality + 1) { return true; } - while (((localPointId < numPoints - 1) && - (pointIds[localPointId] == pointIds[localPointId + 1])) || - ((localPointId == numPoints - 1) && (pointIds[localPointId] == pointIds[0]))) + // Skip over any repeated points. Assume any repeated points are adjacent. + while ((localPointId < numPoints - 1) && + (pointIds[localPointId] == pointIds[localPointId + 1])) { - // Skip over any repeated points. Assume any repeated points are adjacent. ++localPointId; } } @@ -65,7 +67,7 @@ struct RemoveDegenerateCells template VTKM_EXEC bool CheckForDimensionality(vtkm::CellTopologicalDimensionsTag<0>, CellShapeTag, - PointVecType&&) + PointVecType&&) const { return true; } @@ -73,9 +75,10 @@ struct RemoveDegenerateCells template VTKM_EXEC bool CheckForDimensionality(vtkm::CellTopologicalDimensionsTag<3>, CellShapeTag shape, - PointVecType&& pointIds) + PointVecType&& pointIds) const { - const vtkm::IdComponent numFaces = vtkm::exec::CellFaceNumberOfFaces(shape, *this); + vtkm::IdComponent numFaces; + vtkm::exec::CellFaceNumberOfFaces(shape, numFaces); vtkm::Id numValidFaces = 0; for (vtkm::IdComponent faceId = 0; faceId < numFaces; ++faceId) {