Add itk::MakeIndexRange functions and use them#5812
Add itk::MakeIndexRange functions and use them#5812thewtex merged 7 commits intoInsightSoftwareConsortium:mainfrom
itk::MakeIndexRange functions and use them#5812Conversation
There are two kinds of IndexRange's: `ZeroBasedIndexRange` is optimized for an image region that has a start index of all zeros. `ImageRegionIndexRange` supports any arbitrary image region, having any arbitrary start index. The overload set of `MakeIndexRange` functions aims to ease creating the most appropriate IndexRange type: - `MakeIndexRange(size)` returns a `ZeroBasedIndexRange` - `MakeIndexRange(imageRegion)` returns an `ImageRegionIndexRange` - `MakeIndexRange(index, size)` returns an `ImageRegionIndexRange` Adjusted the IndexRange unit tests and the Doxygen code example to use `MakeIndexRange`.
25e110a to
276e3c0
Compare
itk::MakeIndexRange functions, to ease creating an IndexRangeitk::MakeIndexRange functions and use them
Simplified unit tests by calling the new `itk::MakeIndexRange` function, instead of constructing an `itk::ZeroBasedIndexRange<Dimension>` or an `itk::ImageRegionIndexRange<Dimension>`.
Modernized `TimeVaryingBSplineVelocityFieldImageRegistrationMethod` by calling MakeIndexRange within range-based `for` loops, instead of using local `ImageRegionConstIteratorWithOnlyIndex` variables.
Simplified its Evaluate member function by calling the new `MakeIndexRange` function, instead of constructing a `ZeroBasedIndexRange<SpaceDimension>`.
Simplified its Fill member function by calling `MakeIndexRange(index, size)`, instead of manually constructing an `ImageRegionIndexRange<VDimension>`.
Simplified the code by replacing `ImageRegionIndexRange<InputImageDimension>` with `MakeIndexRange`.
Simplified its CreateSingleContour member function by replacing the use of its RegionIndexRange type alias with a call to `MakeIndexRange`. Deprecated its RegionIndexRange type alias, marking it "future remove".
276e3c0 to
3a00f63
Compare
.../RegistrationMethodsv4/include/itkTimeVaryingBSplineVelocityFieldImageRegistrationMethod.hxx
Show resolved
Hide resolved
| using RegionIndexRange = ImageRegionIndexRange<InputImageType::ImageDimension>; | ||
| #ifndef ITK_FUTURE_LEGACY_REMOVE | ||
| using RegionIndexRange ITK_FUTURE_DEPRECATED( | ||
| "Please use `itk::ImageRegionIndexRange` or `itk::MakeIndexRange` directly!") = | ||
| ImageRegionIndexRange<InputImageType::ImageDimension>; | ||
| #endif |
There was a problem hiding this comment.
It appears that this nested RegionIndexRange type alias was only used internally by the filter itself, so now it is no longer necessary!
| /* Creates a range of indices for the specified grid size. */ | ||
| template <unsigned int VDimension> | ||
| [[nodiscard]] constexpr auto | ||
| MakeIndexRange(const Size<VDimension> & gridSize) | ||
| { | ||
| return ZeroBasedIndexRange<VDimension>(gridSize); | ||
| } | ||
|
|
||
| /* Creates a range of indices for the specified image region. */ | ||
| template <unsigned int VDimension> | ||
| [[nodiscard]] auto | ||
| MakeIndexRange(const ImageRegion<VDimension> & imageRegion) | ||
| { | ||
| return ImageRegionIndexRange<VDimension>(imageRegion); | ||
| } | ||
|
|
||
| /* Creates a range of indices for the image region specified by its index and size. */ | ||
| template <unsigned int VDimension> | ||
| [[nodiscard]] auto | ||
| MakeIndexRange(const Index<VDimension> & imageRegionIndex, const Size<VDimension> & imageRegionSize) | ||
| { | ||
| return ImageRegionIndexRange<VDimension>(ImageRegion<VDimension>{ imageRegionIndex, imageRegionSize }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Instead of these simple MakeIndexRange functions, I think we might as well add similar functionality by using CTAD (class template argument deduction). But we had discussion about CTAD before. It might sometimes be risky to use CTAD (looking at Arthur O'Dwyer's blog). And it might sometimes cause compiler warnings (warning: 'T' may not intend to support class template argument deduction [-Wctad-maybe-unsupported]). So maybe we should just stick with such simple Make functions 🤷
|
macOS-Build22156645989-MakeIndexRange fails, saying: Does anyone have a clue? 🤷 🎉 Update: The CI is green now! Apparently it was sufficient to re-run "ARMBUILD-x86_64-rosetta". Still wondering why...! |
aff0a03
into
InsightSoftwareConsortium:main
There are two kinds of IndexRange's:
ZeroBasedIndexRangeis optimized for an image region that has a start index of all zeros.ImageRegionIndexRangesupports any arbitrary image region, having any arbitrary start index.The proposed overload set of
MakeIndexRangefunctions aims to ease creating the most appropriate IndexRange type for each use case:MakeIndexRange(size)returns aZeroBasedIndexRangeMakeIndexRange(imageRegion)returns anImageRegionIndexRangeMakeIndexRange(index, size)returns anImageRegionIndexRangeThis pull request also proposes to start using
MakeIndexRangein various tests, filters and other components, to improve code readability.