Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: ShapedImageNeighborhoodRange support C-array of offsets (by C++17) #4301

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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