Skip to content

Simplify initialization of local region iterators in hxx files#6019

Merged
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Simplify-local-region-iterator-initializations-hxx
Apr 9, 2026
Merged

Simplify initialization of local region iterators in hxx files#6019
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Simplify-local-region-iterator-initializations-hxx

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Apr 7, 2026

Replaced code like T x; x = T(a, b), T x = T(a, b) and auto x = T(a, b) with T x(a, b), for local region iterators.

Cases found, using Notepad++ with the following regular expression: \w+ =[\r\n]*[ ]+Image\w*Iterator.

Replaced code like `T x = T(a, b)` and `auto x = T(a, b)` with `T x(a, b)`.
@github-actions github-actions Bot added area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module labels Apr 7, 2026
Comment thread Modules/Segmentation/Watersheds/include/itkWatershedSegmenter.hxx
Merged declaration and assignment together, for local region iterator variables.

Removed `LocalLevelSetImageType` from ExtensionVelocitiesImageFilter, as it
has become unnecessary with this commit.
@N-Dekker N-Dekker force-pushed the Simplify-local-region-iterator-initializations-hxx branch from 204d82a to d866701 Compare April 8, 2026 12:26
@N-Dekker N-Dekker marked this pull request as ready for review April 8, 2026 20:39
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 8, 2026

Greptile Summary

This PR simplifies local iterator variable declarations across 7 .hxx files by replacing the two-step default-construct-then-assign pattern (and auto x = T(a, b) variants) with direct C++17 CTAD-based initialization (T x(a, b)). All deduction guides for ImageRegionIterator, ImageRegionConstIterator, and ImageRegionConstIteratorWithIndex are in place and cover both SmartPointer inputs (explicit guides) and raw pointer inputs (implicit constructor-derived guides), so all resulting types are identical to the originals.

Confidence Score: 5/5

Safe to merge — all changes are semantically equivalent refactors with no behavioral impact.

Every changed site produces the same concrete iterator type as before: CTAD resolves correctly in all cases (SmartPointer inputs hit the explicit deduction guides; raw pointer inputs hit the implicit constructor guides). The one reordering in itkHessian3DToVesselnessMeasureImageFilter.hxx — moving oit construction to after AllocateOutputs() — is actually an improvement. No logic, data flow, or lifetime changes were introduced. All remaining notes are P2 style observations.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryMorphologyImageFilter.hxx Simplifies ImageRegionIterator declaration from two-line default-construct-then-assign pattern to a single direct construction using CTAD; tmpSEImage is a SmartPointer so the explicit deduction guide applies.
Modules/Filtering/BinaryMathematicalMorphology/include/itkObjectMorphologyImageFilter.hxx Replaces auto x = ImageRegionConstIterator(...) / auto y = ImageRegionIterator(...) with typed direct-initialization; semantically equivalent, both paths use CTAD.
Modules/Filtering/ImageFeature/include/itkHessian3DToVesselnessMeasureImageFilter.hxx Moves oit declaration to after AllocateOutputs() and initializes it inline; this is actually a slight correctness improvement since the iterator is now constructed on already-allocated output data.
Modules/Filtering/ImageFeature/include/itkZeroCrossingImageFilter.hxx Replaces ImageRegionIterator<TOutputImage> it = ImageRegionIterator(output, face) with direct CTAD initialization; cosmetic and equivalent.
Modules/Registration/PDEDeformable/include/itkCurvatureRegistrationFilter.hxx Collapses five separate declare-then-assign lines into four direct-initialization declarations; CTAD deduction is correct for all four iterators (SmartPointer inputs trigger explicit guides; raw pointers use implicit constructor guides).
Modules/Segmentation/LevelSets/include/itkExtensionVelocitiesImageFilter.hxx Removes now-unused LocalLevelSetImageType typedef and the early tempIt declaration, replacing the late assignment with a direct inline construction after m_Marcher->Update(); logic is unchanged.
Modules/Segmentation/Watersheds/include/itkWatershedSegmenter.hxx Two ImageRegionIterator<BoundaryType::face_t> copy-initialize patterns simplified to direct CTAD construction; face is a SmartPointer so the explicit deduction guide fires correctly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Old pattern:\nT x;\nx = T(a, b);\n— or —\nauto x = T(a, b);"] -->|"CTAD + direct init"| B["New pattern:\nT x(a, b);"]
    B --> C{"First arg type?"}
    C -->|"SmartPointer&lt;TImage&gt;"| D["Explicit deduction guide\nImageRegionIterator&lt;TImage&gt;"]
    C -->|"Raw pointer\n(const TImage*)"| E["Implicit constructor guide\nImageRegionIterator&lt;TImage&gt;"]
    D --> F["Same concrete type\nas before"]
    E --> F
Loading

Reviews (1): Last reviewed commit: "STYLE: Replace declare-then-assign of re..." | Re-trigger Greptile

@hjmjohnson hjmjohnson merged commit c4a34f0 into InsightSoftwareConsortium:main Apr 9, 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:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants