From 997ff54d59335b3dc55ff54e8175c9050a84a3c3 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 2 Sep 2023 01:20:03 +0200 Subject: [PATCH] BUG: ImageRandomIteratorWithIndex should not assign data in constructor The constructors of `ImageRandomConstIteratorWithIndex` and `ImageRandomConstIteratorWithOnlyIndex` that support two arguments (image and region) accidentally still assigned their data members, while they were already initialized by in-class default member initialization. This in-class default member initialization was added as part of pull request https://github.com/InsightSoftwareConsortium/ITK/pull/3929 commit 4e46cb6ef56658353c14bd58e6b28b63c410f1c8 "STYLE: Default default-constructor of ImageRandom ConstIterator classes", merged on February 24, 2023 and included with tag ITK v5.4rc01. This caused extra `MersenneTwisterRandomVariateGenerator::New()` calls, which changed the seeds of random number generation. These changes can possibly cause regression failures in unit tests of client applications, including elastix. This commit removes all data member assignments from the bodies of these constructors. --- .../include/itkImageRandomConstIteratorWithIndex.hxx | 8 ++------ .../include/itkImageRandomConstIteratorWithOnlyIndex.hxx | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Modules/Core/Common/include/itkImageRandomConstIteratorWithIndex.hxx b/Modules/Core/Common/include/itkImageRandomConstIteratorWithIndex.hxx index 152166c669a..5295a2b7c8d 100644 --- a/Modules/Core/Common/include/itkImageRandomConstIteratorWithIndex.hxx +++ b/Modules/Core/Common/include/itkImageRandomConstIteratorWithIndex.hxx @@ -26,12 +26,8 @@ template ImageRandomConstIteratorWithIndex::ImageRandomConstIteratorWithIndex(const ImageType * ptr, const RegionType & region) : ImageConstIteratorWithIndex(ptr, region) -{ - m_NumberOfPixelsInRegion = region.GetNumberOfPixels(); - m_NumberOfSamplesRequested = 0L; - m_NumberOfSamplesDone = 0L; - m_Generator = Statistics::MersenneTwisterRandomVariateGenerator::New(); -} + , m_NumberOfPixelsInRegion{ region.GetNumberOfPixels() } +{} template void diff --git a/Modules/Core/Common/include/itkImageRandomConstIteratorWithOnlyIndex.hxx b/Modules/Core/Common/include/itkImageRandomConstIteratorWithOnlyIndex.hxx index 309b0974f2e..fffea4e9941 100644 --- a/Modules/Core/Common/include/itkImageRandomConstIteratorWithOnlyIndex.hxx +++ b/Modules/Core/Common/include/itkImageRandomConstIteratorWithOnlyIndex.hxx @@ -26,12 +26,8 @@ template ImageRandomConstIteratorWithOnlyIndex::ImageRandomConstIteratorWithOnlyIndex(const ImageType * ptr, const RegionType & region) : ImageConstIteratorWithOnlyIndex(ptr, region) -{ - m_NumberOfPixelsInRegion = region.GetNumberOfPixels(); - m_NumberOfSamplesRequested = 0L; - m_NumberOfSamplesDone = 0L; - m_Generator = Statistics::MersenneTwisterRandomVariateGenerator::New(); -} + , m_NumberOfPixelsInRegion{ region.GetNumberOfPixels() } +{} template void