From 3f8579739c104342bcc9c78d17d792f50984da2f Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 26 Sep 2025 17:41:17 +0200 Subject: [PATCH 1/3] STYLE: Use CalculateProductOfElements in PatchBasedDenoisingBase filter Replaced a `for` loop with a call to `Size::CalculateProductOfElements()`. --- .../include/itkPatchBasedDenoisingBaseImageFilter.hxx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Modules/Filtering/Denoising/include/itkPatchBasedDenoisingBaseImageFilter.hxx b/Modules/Filtering/Denoising/include/itkPatchBasedDenoisingBaseImageFilter.hxx index 7b784ddca8e..bb499f1b3c5 100644 --- a/Modules/Filtering/Denoising/include/itkPatchBasedDenoisingBaseImageFilter.hxx +++ b/Modules/Filtering/Denoising/include/itkPatchBasedDenoisingBaseImageFilter.hxx @@ -174,12 +174,7 @@ PatchBasedDenoisingBaseImageFilter::GetPatchLengthInV { const PatchRadiusType diameter = this->GetPatchDiameterInVoxels(); - typename PatchRadiusType::SizeValueType length = 1; - for (unsigned int dim = 0; dim < ImageDimension; ++dim) - { - length *= diameter[dim]; - } - return length; + return diameter.CalculateProductOfElements(); } template From c1e2f78747a4425e79dd2c915f11d49330e7efd5 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 2 Oct 2025 14:47:08 +0200 Subject: [PATCH 2/3] STYLE: Use CalculateProductOfElements in ImageStatistics/PCA Replaced a `for` loop with a call to `CalculateProductOfElements()`, in both ImagePCADecompositionCalculator and ImagePCAShapeModelEstimator. --- .../include/itkImagePCADecompositionCalculator.hxx | 6 +----- .../include/itkImagePCAShapeModelEstimator.hxx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Modules/Filtering/ImageStatistics/include/itkImagePCADecompositionCalculator.hxx b/Modules/Filtering/ImageStatistics/include/itkImagePCADecompositionCalculator.hxx index a94b4a54104..34d9b9047b8 100644 --- a/Modules/Filtering/ImageStatistics/include/itkImagePCADecompositionCalculator.hxx +++ b/Modules/Filtering/ImageStatistics/include/itkImagePCADecompositionCalculator.hxx @@ -63,11 +63,7 @@ void ImagePCADecompositionCalculator::CalculateBasisMatrix() { m_Size = m_BasisImages[0]->GetRequestedRegion().GetSize(); - m_NumPixels = 1; - for (unsigned int i = 0; i < BasisImageDimension; ++i) - { - m_NumPixels *= m_Size[i]; - } + m_NumPixels = m_Size.CalculateProductOfElements(); m_BasisMatrix = BasisMatrixType(static_cast(m_BasisImages.size()), m_NumPixels); diff --git a/Modules/Filtering/ImageStatistics/include/itkImagePCAShapeModelEstimator.hxx b/Modules/Filtering/ImageStatistics/include/itkImagePCAShapeModelEstimator.hxx index 7ae4c1b4982..548ef7ce0cf 100644 --- a/Modules/Filtering/ImageStatistics/include/itkImagePCAShapeModelEstimator.hxx +++ b/Modules/Filtering/ImageStatistics/include/itkImagePCAShapeModelEstimator.hxx @@ -271,11 +271,7 @@ ImagePCAShapeModelEstimator::CalculateInnerProduct() // training data m_InputImageSize = (inputImagePointerArray[0])->GetBufferedRegion().GetSize(); - m_NumberOfPixels = 1; - for (unsigned int i = 0; i < InputImageDimension; ++i) - { - m_NumberOfPixels *= m_InputImageSize[i]; - } + m_NumberOfPixels = m_InputImageSize.CalculateProductOfElements(); // Calculate the means m_Means.set_size(m_NumberOfPixels); From 66b4758ca991cf271eda4a908bc6e5034e647e42 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 2 Oct 2025 22:11:51 +0200 Subject: [PATCH 3/3] STYLE: Use CalculateProductOfElements in large image write/read tests Replaced a `for` loop with a call to `CalculateProductOfElements()`, in each of the three large image write/read tests. --- Modules/IO/ImageBase/test/itkLargeImageWriteReadTest.cxx | 6 +----- Modules/IO/Meta/test/itkLargeMetaImageWriteReadTest.cxx | 6 +----- Modules/IO/TIFF/test/itkLargeTIFFImageWriteReadTest.cxx | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Modules/IO/ImageBase/test/itkLargeImageWriteReadTest.cxx b/Modules/IO/ImageBase/test/itkLargeImageWriteReadTest.cxx index dc65cb519b4..20cc46b6114 100644 --- a/Modules/IO/ImageBase/test/itkLargeImageWriteReadTest.cxx +++ b/Modules/IO/ImageBase/test/itkLargeImageWriteReadTest.cxx @@ -47,11 +47,7 @@ ActualTest(std::string filename, typename TImageType::SizeType size) image->SetRegions(region); - size_t numberOfPixels = 1; - for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) - { - numberOfPixels *= region.GetSize(i); - } + const size_t numberOfPixels = size.CalculateProductOfElements(); const size_t sizeInMebiBytes = sizeof(PixelType) * numberOfPixels / (1024 * 1024); diff --git a/Modules/IO/Meta/test/itkLargeMetaImageWriteReadTest.cxx b/Modules/IO/Meta/test/itkLargeMetaImageWriteReadTest.cxx index 7b012884784..ea6b7ae21b5 100644 --- a/Modules/IO/Meta/test/itkLargeMetaImageWriteReadTest.cxx +++ b/Modules/IO/Meta/test/itkLargeMetaImageWriteReadTest.cxx @@ -53,11 +53,7 @@ ActualTest(std::string filename, typename TImageType::SizeType size) image->SetRegions(region); - size_t numberOfPixels = 1; - for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) - { - numberOfPixels *= region.GetSize(i); - } + const size_t numberOfPixels = size.CalculateProductOfElements(); const size_t sizeInMebiBytes = sizeof(PixelType) * numberOfPixels / (1024 * 1024); diff --git a/Modules/IO/TIFF/test/itkLargeTIFFImageWriteReadTest.cxx b/Modules/IO/TIFF/test/itkLargeTIFFImageWriteReadTest.cxx index 7957c52b368..d15ee4acae7 100644 --- a/Modules/IO/TIFF/test/itkLargeTIFFImageWriteReadTest.cxx +++ b/Modules/IO/TIFF/test/itkLargeTIFFImageWriteReadTest.cxx @@ -50,11 +50,7 @@ itkLargeTIFFImageWriteReadTestHelper(std::string filename, typename TImage::Size image->SetRegions(region); - SizeValueType numberOfPixels = 1; - for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) - { - numberOfPixels *= static_cast(region.GetSize(i)); - } + const SizeValueType numberOfPixels = size.CalculateProductOfElements(); constexpr SizeValueType oneMebiByte = static_cast(1024) * static_cast(1024);