Skip to content

Commit

Permalink
STYLE: Use ITK 5.4 Size::CalculateProductOfElements()
Browse files Browse the repository at this point in the history
Following ITK pull request InsightSoftwareConsortium/ITK#4371 commit InsightSoftwareConsortium/ITK@c4ef860 "ENH: Add Size::CalculateProductOfElements(), to compute number of pixels".
  • Loading branch information
N-Dekker committed Jun 10, 2024
1 parent 2b764d7 commit f03cef1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 3 additions & 9 deletions Common/ImageSamplers/itkImageGridSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ ImageGridSampler<TInputImage>::GenerateWorkUnits(const ThreadIdType
}
workUnits.push_back({ gridIndexForThread, gridSizeForThread, sampleData });

// TODO Use ITK 5.4: sampleData += gridSizeForThread.CalculateProductOfElements()
sampleData +=
std::accumulate(gridSizeForThread.cbegin(), gridSizeForThread.cend(), size_t{ 1 }, std::multiplies<>{});
sampleData += gridSizeForThread.CalculateProductOfElements();
}();
}
assert(workUnits.size() <= numberOfSubregions);
Expand All @@ -167,9 +165,7 @@ ImageGridSampler<TInputImage>::SingleThreadedGenerateData(const TInputImage &
/** Determine the grid. */
const auto [gridIndex, gridSize] = DetermineGridIndexAndSize(croppedInputImageRegion, gridSpacing);

// TODO Use ITK 5.4: numberOfSamplesOnGrid = gridSize.CalculateProductOfElements()
const std::size_t numberOfSamplesOnGrid =
std::accumulate(gridSize.cbegin(), gridSize.cend(), std::size_t{ 1 }, std::multiplies<>{});
const std::size_t numberOfSamplesOnGrid = gridSize.CalculateProductOfElements();
samples.resize(numberOfSamplesOnGrid);
WorkUnit workUnit{ gridIndex, gridSize, samples.data(), size_t{} };

Expand Down Expand Up @@ -212,9 +208,7 @@ ImageGridSampler<TInputImage>::MultiThreadedGenerateData(MultiThreaderBase &
/** Determine the grid. */
const auto [gridIndex, gridSize] = DetermineGridIndexAndSize(croppedInputImageRegion, gridSpacing);

// TODO Use ITK 5.4: numberOfSamplesOnGrid = gridSize.CalculateProductOfElements()
const std::size_t numberOfSamplesOnGrid =
std::accumulate(gridSize.cbegin(), gridSize.cend(), std::size_t{ 1 }, std::multiplies<>{});
const std::size_t numberOfSamplesOnGrid = gridSize.CalculateProductOfElements();
samples.resize(numberOfSamplesOnGrid);

const bool maskHasSameImageDomain = mask ? elastix::MaskHasSameImageDomain(*mask, inputImage) : false;
Expand Down
3 changes: 1 addition & 2 deletions Core/Main/GTesting/itkTransformixFilterGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,7 @@ GTEST_TEST(itkTransformixFilter, SetCombinationTransform)
using ImageType = itk::Image<PixelType, ImageDimension>;
const itk::Size<ImageDimension> imageSize{ { 5, 6 } };

const auto numberOfPixels =
std::accumulate(imageSize.cbegin(), imageSize.cend(), std::size_t{ 1 }, std::multiplies<>{});
const auto numberOfPixels = imageSize.CalculateProductOfElements();

const auto fixedImage = CreateImage<PixelType>(imageSize);
const auto movingImage = CreateImage<PixelType>(imageSize);
Expand Down

0 comments on commit f03cef1

Please sign in to comment.