Skip to content

Commit

Permalink
ENH: ShapedImageNeighborhoodRange support C-array of offsets (by C++17)
Browse files Browse the repository at this point in the history
Allowed the shape of a neighborhood to be specified by a C-array of offset, by
using C++17 `std::data` and `std::size` internally, instead of `data()` and
`size()` member functions.
  • Loading branch information
N-Dekker authored and dzenanz committed Nov 9, 2023
1 parent 2b8ce77 commit 77e147b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkShapedImageNeighborhoodRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,8 @@ class ShapedImageNeighborhoodRange final
const OptionalPixelAccessParameterType optionalPixelAccessParameter = {})
: ShapedImageNeighborhoodRange{ image,
location,
shapeOffsets.data(),
shapeOffsets.size(),
std::data(shapeOffsets),
std::size(shapeOffsets),
optionalPixelAccessParameter }
{}

Expand Down
27 changes: 27 additions & 0 deletions Modules/Core/Common/test/itkShapedImageNeighborhoodRangeGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,33 @@ TEST(ShapedImageNeighborhoodRange, ConstructorSupportsRValueShapeOffsets)
}


// Tests that the shape of the neighborhood can be specified by a C-array of offsets.
TEST(ShapedImageNeighborhoodRange, ConstructorSupportsCArrayOfShapeOffsets)
{
using ImageType = itk::Image<unsigned char>;
using RangeType = itk::ShapedImageNeighborhoodRange<ImageType>;
using OffsetType = ImageType::OffsetType;

const auto image = CreateImageFilledWithSequenceOfNaturalNumbers<ImageType>(1, 2);
const ImageType::IndexType location{ { 1, 1 } };

// A rather arbitrary shape, specified by a C-array of offsets.
const OffsetType arrayOfShapeOffsets[] = { OffsetType{}, itk::MakeFilled<OffsetType>(1) };

// An std::vector that represents the very same shape.
const std::vector<OffsetType> vectorOfShapeOffsets(std::begin(arrayOfShapeOffsets), std::end(arrayOfShapeOffsets));

const RangeType rangeFromArrayOfShapeOffsets(*image, location, arrayOfShapeOffsets);
const RangeType rangeFromVectorOfShapeOffsets(*image, location, vectorOfShapeOffsets);

// Assert that both ranges iterate over the same neighborhood.
ASSERT_TRUE(std::equal(rangeFromArrayOfShapeOffsets.cbegin(),
rangeFromArrayOfShapeOffsets.cend(),
rangeFromVectorOfShapeOffsets.cbegin(),
rangeFromVectorOfShapeOffsets.cend()));
}


// Tests that an arbitrary (possibly non-zero) index of the buffered region is supported.
TEST(ShapedImageNeighborhoodRange, SupportsArbitraryBufferedRegionIndex)
{
Expand Down

0 comments on commit 77e147b

Please sign in to comment.