Skip to content

Commit

Permalink
BUG: ImageRandomIteratorWithIndex should not assign data in constructor
Browse files Browse the repository at this point in the history
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
InsightSoftwareConsortium#3929 commit
4e46cb6 "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.
  • Loading branch information
N-Dekker committed Sep 1, 2023
1 parent 3a73368 commit 997ff54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ template <typename TImage>
ImageRandomConstIteratorWithIndex<TImage>::ImageRandomConstIteratorWithIndex(const ImageType * ptr,
const RegionType & region)
: ImageConstIteratorWithIndex<TImage>(ptr, region)
{
m_NumberOfPixelsInRegion = region.GetNumberOfPixels();
m_NumberOfSamplesRequested = 0L;
m_NumberOfSamplesDone = 0L;
m_Generator = Statistics::MersenneTwisterRandomVariateGenerator::New();
}
, m_NumberOfPixelsInRegion{ region.GetNumberOfPixels() }
{}

template <typename TImage>
void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ template <typename TImage>
ImageRandomConstIteratorWithOnlyIndex<TImage>::ImageRandomConstIteratorWithOnlyIndex(const ImageType * ptr,
const RegionType & region)
: ImageConstIteratorWithOnlyIndex<TImage>(ptr, region)
{
m_NumberOfPixelsInRegion = region.GetNumberOfPixels();
m_NumberOfSamplesRequested = 0L;
m_NumberOfSamplesDone = 0L;
m_Generator = Statistics::MersenneTwisterRandomVariateGenerator::New();
}
, m_NumberOfPixelsInRegion{ region.GetNumberOfPixels() }
{}

template <typename TImage>
void
Expand Down

0 comments on commit 997ff54

Please sign in to comment.