diff --git a/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx b/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx index 51530a8ca82..bd2eccdffc4 100644 --- a/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx +++ b/Modules/Segmentation/Voronoi/include/itkVoronoiDiagram2DGenerator.hxx @@ -273,8 +273,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]); 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; +} 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