Skip to content

Commit d92dc14

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Code cleanup ImageRandomConstIteratorWith(Only)Index RandomJump()
Removed unnecessary local `randomPosition` variables, reduced scope of `residual`, avoided redundant `m_Region.GetSize()` calls, etc.
1 parent a4a46cc commit d92dc14

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Modules/Core/Common/include/itkImageRandomConstIteratorWithIndex.hxx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,15 @@ ImageRandomConstIteratorWithIndex<TImage>::RandomJump()
6464
{
6565
using PositionValueType = IndexValueType;
6666

67-
const PositionValueType randomPosition = static_cast<PositionValueType>(
67+
auto position = static_cast<PositionValueType>(
6868
m_Generator->GetVariateWithOpenRange(static_cast<double>(m_NumberOfPixelsInRegion) - 0.5));
69-
/*
70-
vnl_sample_uniform(0.0f,
71-
static_cast<double>(m_NumberOfPixelsInRegion)-0.5) );
72-
*/
7369

74-
PositionValueType position = randomPosition;
75-
PositionValueType residual;
70+
const SizeType regionSize = this->m_Region.GetSize();
7671

7772
for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
7873
{
79-
const SizeValueType sizeInThisDimension = this->m_Region.GetSize()[dim];
80-
residual = position % sizeInThisDimension;
74+
const SizeValueType sizeInThisDimension = regionSize[dim];
75+
const PositionValueType residual = position % sizeInThisDimension;
8176
this->m_PositionIndex[dim] = residual + this->m_BeginIndex[dim];
8277
position -= residual;
8378
position /= sizeInThisDimension;

Modules/Core/Common/include/itkImageRandomConstIteratorWithOnlyIndex.hxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ ImageRandomConstIteratorWithOnlyIndex<TImage>::RandomJump()
6363
{
6464
using PositionValueType = IndexValueType;
6565

66-
const PositionValueType randomPosition = static_cast<PositionValueType>(
66+
auto position = static_cast<PositionValueType>(
6767
m_Generator->GetVariateWithOpenRange(static_cast<double>(m_NumberOfPixelsInRegion) - 0.5));
68-
PositionValueType position = randomPosition;
69-
PositionValueType residual;
68+
69+
const SizeType regionSize = this->m_Region.GetSize();
7070

7171
for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
7272
{
73-
const SizeValueType sizeInThisDimension = this->m_Region.GetSize()[dim];
74-
residual = position % sizeInThisDimension;
73+
const SizeValueType sizeInThisDimension = regionSize[dim];
74+
const PositionValueType residual = position % sizeInThisDimension;
7575
this->m_PositionIndex[dim] = residual + this->m_BeginIndex[dim];
7676
position -= residual;
7777
position /= sizeInThisDimension;

0 commit comments

Comments
 (0)