Skip to content

Commit cc5b301

Browse files
committed
STYLE: Replace GetIndex() calls on iterators with ComputeIndex()
Replaced function calls of the form `iterator.GetIndex()` with `iterator.ComputeIndex()`, for iterators derived from `ImageConstIterator`. For those iterators, it may take a relatively expensive computation to get the index. Using `ComputeIndex()` instead of the equivalent `GetIndex()` aims to raise awareness of the potential performance cost of those function calls.
1 parent 3e5a75a commit cc5b301

File tree

31 files changed

+53
-53
lines changed

31 files changed

+53
-53
lines changed

Modules/Core/Common/include/itkImageReverseConstIterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class ITK_TEMPLATE_EXPORT ImageReverseConstIterator
207207
{
208208

209209

210-
const IndexType ind = it.GetIndex();
210+
const IndexType ind = it.ComputeIndex();
211211

212212
m_Offset = m_Image->ComputeOffset(ind);
213213

Modules/Core/Common/include/itkImageScanlineConstIterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ITK_TEMPLATE_EXPORT ImageScanlineConstIterator : public ImageConstIterator
117117
{
118118
this->ImageConstIterator<TImage>::operator=(it);
119119

120-
IndexType ind = this->GetIndex();
120+
IndexType ind = this->ComputeIndex();
121121
m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
122122
(ind[0] - this->m_Region.GetIndex()[0]);
123123
m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);

Modules/Filtering/DisplacementField/include/itkInvertDisplacementFieldImageFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ InvertDisplacementFieldImageFilter<TInputImage, TOutputImage>::DynamicThreadedGe
194194
}
195195
update = ItI.Get() + update * this->m_Epsilon;
196196
ItI.Set(update);
197-
typename DisplacementFieldType::IndexType index = ItI.GetIndex();
197+
typename DisplacementFieldType::IndexType index = ItI.ComputeIndex();
198198
if (this->m_EnforceBoundaryCondition)
199199
{
200200
for (unsigned int d = 0; d < ImageDimension; ++d)

Modules/Filtering/DisplacementField/include/itkIterativeInverseDisplacementFieldImageFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ IterativeInverseDisplacementFieldImageFilter<TInputImage, TOutputImage>::Generat
9898
while (!OutputIt.IsAtEnd())
9999
{
100100
// get the output image index
101-
const OutputImageIndexType index = OutputIt.GetIndex();
101+
const OutputImageIndexType index = OutputIt.ComputeIndex();
102102
OutputImagePointType originalPoint;
103103
outputPtr->TransformIndexToPhysicalPoint(index, originalPoint);
104104

Modules/Filtering/DisplacementField/include/itkTransformToDisplacementFieldFilter.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ TransformToDisplacementFieldFilter<TOutputImage, TParametersValueType>::Nonlinea
192192
while (!outIt.IsAtEndOfLine())
193193
{
194194
// Determine the index of the current output pixel
195-
output->TransformIndexToPhysicalPoint(outIt.GetIndex(), outputPoint);
195+
output->TransformIndexToPhysicalPoint(outIt.ComputeIndex(), outputPoint);
196196

197197
// Compute corresponding input pixel position
198198
transformedPoint = transform->TransformPoint(outputPoint);
@@ -235,7 +235,7 @@ TransformToDisplacementFieldFilter<TOutputImage, TParametersValueType>::LinearTh
235235
// The region may be split along the fast scan-line direction, so
236236
// the computation is done for the beginning and end of the largest
237237
// possible region to improve consistent numerics.
238-
IndexType index = outIt.GetIndex();
238+
IndexType index = outIt.ComputeIndex();
239239
index[0] = largestPossibleRegion.GetIndex(0);
240240

241241
outputPtr->TransformIndexToPhysicalPoint(index, outputPoint);
@@ -247,7 +247,7 @@ TransformToDisplacementFieldFilter<TOutputImage, TParametersValueType>::LinearTh
247247
inputPoint = transformPtr->TransformPoint(outputPoint);
248248
const typename PointType::VectorType endDisplacement = inputPoint - outputPoint;
249249

250-
IndexValueType scanlineIndex = outIt.GetIndex()[0];
250+
IndexValueType scanlineIndex = outIt.ComputeIndex()[0];
251251

252252
while (!outIt.IsAtEndOfLine())
253253
{

Modules/Filtering/ImageFeature/include/itkCannyEdgeDetectionImageFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ CannyEdgeDetectionImageFilter<TInputImage, TOutputImage>::HysteresisThresholding
294294
if (value > m_UpperThreshold)
295295
{
296296
node = m_NodeStore->Borrow();
297-
node->m_Value = oit.GetIndex();
297+
node->m_Value = oit.ComputeIndex();
298298
m_NodeList->PushFront(node);
299-
FollowEdge(oit.GetIndex(), multiplyImageFilterOutput);
299+
FollowEdge(oit.ComputeIndex(), multiplyImageFilterOutput);
300300
}
301301

302302
++oit;

Modules/Filtering/ImageFeature/include/itkHoughTransform2DLinesImageFilter.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ HoughTransform2DLinesImageFilter<TInputPixelType, TOutputPixelType>::GetLines()
282282
// Create the line.
283283
LineType::LinePointListType list; // Insert two points per line.
284284

285-
const double radius = it_input.GetIndex()[0];
286-
const double teta = ((it_input.GetIndex()[1]) * 2 * Math::pi / this->GetAngleResolution()) - Math::pi;
285+
const double radius = it_input.ComputeIndex()[0];
286+
const double teta = ((it_input.ComputeIndex()[1]) * 2 * Math::pi / this->GetAngleResolution()) - Math::pi;
287287
const double Vx = radius * std::cos(teta);
288288
const double Vy = radius * std::sin(teta);
289289
const double norm = std::sqrt(Vx * Vx + Vy * Vy);
@@ -326,8 +326,8 @@ HoughTransform2DLinesImageFilter<TInputPixelType, TOutputPixelType>::GetLines()
326326
{
327327
for (double length = 0; length < m_DiscRadius; length += 1)
328328
{
329-
index[0] = static_cast<IndexValueType>(it_input.GetIndex()[0] + length * std::cos(angle));
330-
index[1] = static_cast<IndexValueType>(it_input.GetIndex()[1] + length * std::sin(angle));
329+
index[0] = static_cast<IndexValueType>(it_input.ComputeIndex()[0] + length * std::cos(angle));
330+
index[1] = static_cast<IndexValueType>(it_input.ComputeIndex()[1] + length * std::sin(angle));
331331
if (postProcessImage->GetBufferedRegion().IsInside(index))
332332
{
333333
postProcessImage->SetPixel(index, 0);

Modules/Filtering/ImageGradient/include/itkDifferenceOfGaussiansGradientImageFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ DifferenceOfGaussiansGradientImageFilter<TInputImage, TDataType>::GenerateData()
7676
for (; !outIt.IsAtEnd(); ++outIt)
7777
{
7878
// determine the index of the output pixel
79-
outputIndex = outIt.GetIndex();
79+
outputIndex = outIt.ComputeIndex();
8080

8181
// is the current index an acceptable distance from the edges
8282
// of the image?

Modules/Filtering/ImageGrid/include/itkBinShrinkImageFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ BinShrinkImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(
155155
for (ImageScanlineIterator outputIterator(outputPtr, outputRegionForThread); !outputIterator.IsAtEnd();
156156
outputIterator.NextLine())
157157
{
158-
const OutputIndexType outputIndex = outputIterator.GetIndex();
158+
const OutputIndexType outputIndex = outputIterator.ComputeIndex();
159159

160160
auto offset = offsets.begin();
161161
const InputIndexType startInputIndex = outputIndex * factorSize;

Modules/Filtering/ImageGrid/include/itkExpandImageFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ExpandImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(
113113
// Walk the output region, and interpolate the input image
114114
for (ImageScanlineIterator outIt(outputPtr, outputRegionForThread); !outIt.IsAtEnd(); outIt.NextLine())
115115
{
116-
const typename OutputImageType::IndexType outputIndex = outIt.GetIndex();
116+
const typename OutputImageType::IndexType outputIndex = outIt.ComputeIndex();
117117

118118

119119
// Determine the input pixel location associated with this output

0 commit comments

Comments
 (0)