From b3cf50ce43cff491b8c1db7ab52a140db3d3f942 Mon Sep 17 00:00:00 2001 From: Hadrien LACOUR Date: Mon, 16 Jun 2025 15:42:12 +0200 Subject: [PATCH 1/3] BUG: fix an infinite loop in itk::VoronoiDiagram2DGenerator The loop exit condition was present in the code, but never wired and removed via https://github.com/InsightSoftwareConsortium/ITK/commit/cd97879e6bfec6cd9a33a3dd374d68cf4ff4303e Fixes #4386 --- .../Voronoi/include/itkVoronoiDiagram2DGenerator.hxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx b/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx index fb56ba15d58..8f9534f9218 100644 --- a/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx +++ b/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx @@ -274,8 +274,10 @@ VoronoiDiagram2DGenerator::ConstructDiagram() buildEdges.push_back(curr); EdgeInfo front = curr; EdgeInfo back = curr; - while (!(rawEdges[i].empty())) + auto maxStop = rawEdges[i].size(); + while (!(rawEdges[i].empty()) && (maxStop != 0)) { + --maxStop; curr = rawEdges[i].front(); rawEdges[i].pop_front(); unsigned char frontbnd = Pointonbnd(front[0]); From cec88e2214014f49bd26fe20fd43e9dbc4d81191 Mon Sep 17 00:00:00 2001 From: Hadrien LACOUR Date: Mon, 16 Jun 2025 16:30:05 +0200 Subject: [PATCH 2/3] ENH: Add test of infinite loop in VoronoiDiagram2DGenerator Tests and resolves #4386 where specific values caused deadlocks. --- .../Segmentation/Voronoi/test/CMakeLists.txt | 8 ++++ .../itkVoronoiDiagram2DInfiniteLoopTest.cxx | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Modules/Segmentation/Voronoi/test/itkVoronoiDiagram2DInfiniteLoopTest.cxx diff --git a/Modules/Segmentation/Voronoi/test/CMakeLists.txt b/Modules/Segmentation/Voronoi/test/CMakeLists.txt index c1a263e918e..5924f267c8c 100644 --- a/Modules/Segmentation/Voronoi/test/CMakeLists.txt +++ b/Modules/Segmentation/Voronoi/test/CMakeLists.txt @@ -5,6 +5,7 @@ set( itkVoronoiSegmentationRGBImageFilterTest.cxx itkVoronoiDiagram2DTest.cxx itkVoronoiPartitioningImageFilterTest.cxx + itkVoronoiDiagram2DInfiniteLoopTest.cxx ) createtestdriver(ITKVoronoi "${ITKVoronoi-Test_LIBRARIES}" "${ITKVoronoiTests}") @@ -29,6 +30,13 @@ itk_add_test( ITKVoronoiTestDriver itkVoronoiSegmentationRGBImageFilterTest ) +itk_add_test( + NAME itkVoronoiDiagram2DInfiniteLoopTest + COMMAND + ITKVoronoiTestDriver + itkVoronoiDiagram2DInfiniteLoopTest +) + itk_add_test( NAME itkVoronoiDiagram2DTest COMMAND diff --git a/Modules/Segmentation/Voronoi/test/itkVoronoiDiagram2DInfiniteLoopTest.cxx b/Modules/Segmentation/Voronoi/test/itkVoronoiDiagram2DInfiniteLoopTest.cxx new file mode 100644 index 00000000000..0bc337c22ec --- /dev/null +++ b/Modules/Segmentation/Voronoi/test/itkVoronoiDiagram2DInfiniteLoopTest.cxx @@ -0,0 +1,48 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#include "itkVoronoiDiagram2DGenerator.h" +#include "itkTestingMacros.h" + +int +itkVoronoiDiagram2DInfiniteLoopTest(int argc, char * argv[]) +{ + if (argc != 1) + { + std::cerr << "Takes no parameters, but " << argc << "parameters given" << std::endl; + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << std::endl; + return EXIT_FAILURE; + } + + // From https://github.com/InsightSoftwareConsortium/ITK/issues/4386 + using VoronoiDiagramType = itk::VoronoiDiagram2D; + using VoronoiGeneratorType = itk::VoronoiDiagram2DGenerator; + using PointType = VoronoiDiagramType::PointType; + VoronoiGeneratorType::Pointer vg = VoronoiGeneratorType::New(); + vg->SetOrigin(PointType{ { -1.61569, -1.76726 } }); + vg->SetBoundary(PointType{ { 1.60174, 1.76345 } }); + vg->AddOneSeed(PointType{ { -1.39649, 0.322212 } }); + vg->AddOneSeed(PointType{ { -1.30128, 0.231786 } }); + vg->AddOneSeed(PointType{ { -1.21509, 0.0515039 } }); + vg->AddOneSeed(PointType{ { -1.22364, -0.030281 } }); + vg->AddOneSeed(PointType{ { -1.22125, -0.120815 } }); + vg->AddOneSeed(PointType{ { -1.25159, -0.23593 } }); + vg->Update(); + + return EXIT_SUCCESS; +} From 150da41473c71271412a6bf179e68d9384f55640 Mon Sep 17 00:00:00 2001 From: VXL Maintainers Date: Sun, 16 Nov 2025 08:18:43 -0600 Subject: [PATCH 3/3] VXL 2025-11-16 (3096fc83) Code extracted from: https://github.com/vxl/vxl.git at commit 3096fc83b3e5dc1c958e421e99defcb935d9b70b (master). --- Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_complex_traits.h | 2 +- Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_math.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_complex_traits.h b/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_complex_traits.h index 060e199c2ec..5be898b6265 100644 --- a/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_complex_traits.h +++ b/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_complex_traits.h @@ -206,7 +206,7 @@ struct VNL_EXPORT vnl_complex_traits> isreal = false }; static std::complex - conjugate(std::complex x) + conjugate(std::complex /* x */) { throw std::runtime_error("Can not call complexify on non floating point data type"); return std::complex(0., 0.); diff --git a/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_math.h b/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_math.h index e8fcb4895e8..ca8ca09156c 100644 --- a/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_math.h +++ b/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_math.h @@ -147,7 +147,7 @@ angle_minuspi_to_pi(double angle); namespace vnl_math { #if defined(_MSC_VER) -// MSVC does not properly implement isfinite, iinf, isnan for C++11 conformance for integral types +// MSVC does not properly implement isfinite, isinf, isnan for C++11 conformance for integral types // For integral types only: template _Check_return_ typename std::enable_if::value, bool>::type