Skip to content

Comments

Use an iterator 'WithIndex' when the index is retrieved during each iteration#5814

Merged
thewtex merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Use-iterator-WithIndex
Feb 20, 2026
Merged

Use an iterator 'WithIndex' when the index is retrieved during each iteration#5814
thewtex merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Use-iterator-WithIndex

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Feb 19, 2026

When the index is retrieved during each iteration, an iterator with index (like ImageRegionIteratorWithIndex) is much faster than an iterator that computes the index (like ImageRegionIterator).

This pull request proposes to use an iterator with index, instead of an iterator that computes the index, in such cases.

It aims to speed up the following filters:

  • AccumulateImageFilter
  • BinomialBlurImageFilter
  • DifferenceOfGaussiansGradientImageFilter
  • HardConnectedComponentImageFilter
  • InvertDisplacementFieldImageFilter
  • IterativeInverseDisplacementFieldImageFilter
  • LabelGeometryImageFilter
  • MirrorPadImageFilter
  • SpatialFunctionImageEvaluatorFilter

As well as:

  • GaussianImageSource
  • ScalarChanAndVeseLevelSetFunction

This pull request also proposes to deprecate IterativeInverseDisplacementFieldImageFilter::OutputIterator, as it is no longer used by now.

@github-actions github-actions bot added area:Filtering Issues affecting the Filtering module area:Segmentation Issues affecting the Segmentation module labels Feb 19, 2026
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be squashed into one or two commits (the one with future legacy deprecation could be separate commit). Good even as-is.

Replaced iterators "without index" with the corresponding iterators "with
index", and replaced `ComputeIndex()` calls with `GetIndex()`.

In these cases, an iterator _with index_ is much faster than an iterator that
_computes_ the index, because in these cases the index is retrieved during
_each_ iteration of the loop.

Aims to speed up of the following filters:
- AccumulateImageFilter
- BinomialBlurImageFilter
- DifferenceOfGaussiansGradientImageFilter
- HardConnectedComponentImageFilter
- InvertDisplacementFieldImageFilter
- IterativeInverseDisplacementFieldImageFilter
- LabelGeometryImageFilter
- MirrorPadImageFilter
- SpatialFunctionImageEvaluatorFilter

As well as:
- GaussianImageSource
- ScalarChanAndVeseLevelSetFunction
Deprecated ("future removed") the nested type alias `OutputIterator` from
IterativeInverseDisplacementFieldImageFilter, as it is no longer used by now.
@N-Dekker N-Dekker force-pushed the Use-iterator-WithIndex branch from c677a0b to cbf4246 Compare February 19, 2026 16:38
@N-Dekker N-Dekker marked this pull request as ready for review February 19, 2026 17:18
@thewtex thewtex merged commit 4db53ff into InsightSoftwareConsortium:main Feb 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Filtering Issues affecting the Filtering module area:Segmentation Issues affecting the Segmentation module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants