Use an iterator 'WithIndex' when the index is retrieved during each iteration#5814
Merged
thewtex merged 2 commits intoInsightSoftwareConsortium:mainfrom Feb 20, 2026
Merged
Conversation
dzenanz
approved these changes
Feb 19, 2026
Member
dzenanz
left a comment
There was a problem hiding this comment.
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.
c677a0b to
cbf4246
Compare
thewtex
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the index is retrieved during each iteration, an iterator with index (like
ImageRegionIteratorWithIndex) is much faster than an iterator that computes the index (likeImageRegionIterator).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:
As well as:
This pull request also proposes to deprecate
IterativeInverseDisplacementFieldImageFilter::OutputIterator, as it is no longer used by now.