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

WIP: STYLE: Use ImageRegion auto [index, size] = region structured bindings #4379

Closed
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
8 changes: 2 additions & 6 deletions Modules/Bridge/VTK/include/itkVTKImageExport.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ VTKImageExport<TInputImage>::WholeExtentCallback()
itkExceptionMacro("Need to set an input");
}

InputRegionType region = input->GetLargestPossibleRegion();
InputSizeType size = region.GetSize();
InputIndexType index = region.GetIndex();
const auto [index, size] = input->GetLargestPossibleRegion();

unsigned int i = 0;
// Fill in the known portion of the extent.
Expand Down Expand Up @@ -386,9 +384,7 @@ VTKImageExport<TInputImage>::DataExtentCallback()
itkExceptionMacro("Need to set an input");
}

InputRegionType region = input->GetBufferedRegion();
InputSizeType size = region.GetSize();
InputIndexType index = region.GetIndex();
const auto [index, size] = input->GetBufferedRegion();

unsigned int i = 0;
for (; i < InputImageDimension; ++i)
Expand Down
4 changes: 1 addition & 3 deletions Modules/Bridge/VTK/include/itkVTKImageImport.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ VTKImageImport<TOutputImage>::PropagateRequestedRegion(DataObject * outputPtr)
Superclass::PropagateRequestedRegion(output);
if (m_PropagateUpdateExtentCallback)
{
OutputRegionType region = output->GetRequestedRegion();
OutputSizeType size = region.GetSize();
OutputIndexType index = region.GetIndex();
const auto [index, size] = output->GetRequestedRegion();

int updateExtent[6];
unsigned int i = 0;
Expand Down
9 changes: 3 additions & 6 deletions Modules/Core/Common/include/itkConstNeighborhoodIterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,8 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::SetRegion(const RegionTyp
m_End = m_ConstImage->GetBufferPointer() + m_ConstImage->ComputeOffset(m_EndIndex);

// now determine whether boundary conditions are going to be needed
const IndexType bStart = m_ConstImage->GetBufferedRegion().GetIndex();
const SizeType bSize = m_ConstImage->GetBufferedRegion().GetSize();
const IndexType rStart = region.GetIndex();
const SizeType rSize = region.GetSize();
const auto [bStart, bSize] = m_ConstImage->GetBufferedRegion();
const auto [rStart, rSize] = region;

m_NeedToUseBoundaryCondition = false;
for (DimensionValueType i = 0; i < Dimension; ++i)
Expand Down Expand Up @@ -627,8 +625,7 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::SetBound(const SizeType &
{
SizeType radius = this->GetRadius();
const OffsetValueType * offset = m_ConstImage->GetOffsetTable();
const IndexType imageBRStart = m_ConstImage->GetBufferedRegion().GetIndex();
SizeType imageBRSize = m_ConstImage->GetBufferedRegion().GetSize();
const auto [imageBRStart, imageBRSize] = m_ConstImage->GetBufferedRegion();

// Set the bounds and the wrapping offsets. Inner bounds are the loop
// indices where the iterator will begin to overlap the edge of the image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ ConstNeighborhoodIteratorWithOnlyIndex<TImage>::Initialize(const SizeType & ra
this->SetEndIndex();

// now determine whether boundary conditions are going to be needed
const IndexType bStart = ptr->GetBufferedRegion().GetIndex();
const SizeType bSize = ptr->GetBufferedRegion().GetSize();
const IndexType rStart = region.GetIndex();
const SizeType rSize = region.GetSize();
const auto [bStart, bSize] = ptr->GetBufferedRegion();
const auto [rStart, rSize] = region;

m_NeedToUseBoundaryCondition = false;
for (DimensionValueType i = 0; i < Dimension; ++i)
Expand Down Expand Up @@ -456,9 +454,8 @@ template <typename TImage>
void
ConstNeighborhoodIteratorWithOnlyIndex<TImage>::SetBound(const SizeType & size)
{
SizeType radius = this->GetRadius();
const IndexType imageBRStart = m_ConstImage->GetBufferedRegion().GetIndex();
SizeType imageBRSize = m_ConstImage->GetBufferedRegion().GetSize();
SizeType radius = this->GetRadius();
const auto [imageBRStart, imageBRSize] = m_ConstImage->GetBufferedRegion();

// Set the bounds and the wrapping offsets. Inner bounds are the loop
// indices where the iterator will begin to overlap the edge of the image
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/Common/include/itkNeighborhoodAlgorithm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ ImageBoundaryFacesCalculator<TImage>::Compute(const TImage & img, RegionType reg
return result;
}

const IndexType bStart = bufferedRegion.GetIndex();
const SizeType bSize = bufferedRegion.GetSize();
const IndexType rStart = regionToProcess.GetIndex();
const SizeType rSize = regionToProcess.GetSize();
const auto [bStart, bSize] = bufferedRegion;
const auto [rStart, rSize] = regionToProcess;

SizeType nbSize = rSize; // Non-boundary region
IndexType nbStart = rStart; // data.
Expand Down
10 changes: 3 additions & 7 deletions Modules/Core/Common/include/itkPeriodicBoundaryCondition.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ PeriodicBoundaryCondition<TInputImage, TOutputImage>::GetInputRequestedRegion(
const RegionType & inputLargestPossibleRegion,
const RegionType & outputRequestedRegion) const -> RegionType
{
IndexType imageIndex = inputLargestPossibleRegion.GetIndex();
SizeType imageSize = inputLargestPossibleRegion.GetSize();
const auto [imageIndex, imageSize] = inputLargestPossibleRegion;

IndexType outputIndex = outputRequestedRegion.GetIndex();
SizeType outputSize = outputRequestedRegion.GetSize();
const auto [outputIndex, outputSize] = outputRequestedRegion;

IndexType inputRequestedIndex;
SizeType inputRequestedSize;
Expand Down Expand Up @@ -183,9 +181,7 @@ auto
PeriodicBoundaryCondition<TInputImage, TOutputImage>::GetPixel(const IndexType & index, const TInputImage * image) const
-> OutputPixelType
{
RegionType imageRegion = image->GetLargestPossibleRegion();
IndexType imageIndex = imageRegion.GetIndex();
SizeType imageSize = imageRegion.GetSize();
const auto [imageIndex, imageSize] = image->GetLargestPossibleRegion();

IndexType lookupIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ ZeroFluxNeumannBoundaryCondition<TInputImage, TOutputImage>::GetInputRequestedRe
const RegionType & inputLargestPossibleRegion,
const RegionType & outputRequestedRegion) const -> RegionType
{
IndexType inputIndex = inputLargestPossibleRegion.GetIndex();
SizeType inputSize = inputLargestPossibleRegion.GetSize();
const auto [inputIndex, inputSize] = inputLargestPossibleRegion;

IndexType outputIndex = outputRequestedRegion.GetIndex();
SizeType outputSize = outputRequestedRegion.GetSize();
const auto [outputIndex, outputSize] = outputRequestedRegion;

IndexType requestIndex;
SizeType requestSize;
Expand Down Expand Up @@ -156,8 +154,7 @@ ZeroFluxNeumannBoundaryCondition<TInputImage, TOutputImage>::GetPixel(const Inde
-> OutputPixelType
{
RegionType imageRegion = image->GetLargestPossibleRegion();
IndexType imageIndex = imageRegion.GetIndex();
SizeType imageSize = imageRegion.GetSize();
const auto [imageIndex, imageSize] = imageRegion;

IndexType lookupIndex;

Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/GPUCommon/include/itkGPUImageDataManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ GPUImageDataManager<ImageType>::SetImagePointer(ImageType * img)
using IndexType = typename ImageType::IndexType;
using SizeType = typename ImageType::SizeType;

RegionType region = m_Image->GetBufferedRegion();
IndexType index = region.GetIndex();
SizeType size = region.GetSize();
const auto [index, size] = m_Image->GetBufferedRegion();

for (unsigned int d = 0; d < ImageDimension; ++d)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ GaussianInterpolateImageFunction<TImageType, TCoordRep>::ComputeBoundingBox()

typename InputImageType::ConstPointer input = this->GetInputImage();
typename InputImageType::SpacingType spacing = input->GetSpacing();
typename InputImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex();
typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
const auto [index, size] = input->GetLargestPossibleRegion();

for (unsigned int d = 0; d < ImageDimension; ++d)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ SpatialObjectToImageStatisticsCalculator<TInputImage, TInputSpatialObject, TSamp
ptMin[i] = bounds[i * 2];
ptMax[i] = bounds[i * 2 + 1];
}
auto indMin = m_Image->TransformPhysicalPointToIndex(ptMin);
auto indMax = m_Image->TransformPhysicalPointToIndex(ptMax);
IndexType imageIndex = m_Image->GetLargestPossibleRegion().GetIndex();
SizeType imageSize = m_Image->GetLargestPossibleRegion().GetSize();
auto indMin = m_Image->TransformPhysicalPointToIndex(ptMin);
auto indMax = m_Image->TransformPhysicalPointToIndex(ptMax);
const auto [imageIndex, imageSize] = m_Image->GetLargestPossibleRegion();
for (unsigned int i = 0; i < Self::ObjectDimension; ++i)
{
if (indMin[i] > indMax[i])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,7 @@ MRIBiasFieldCorrectionFilter<TInputImage, TOutputImage, TMaskImage>::CorrectInte
IndexValueType lastSlice =
region.GetIndex()[m_SlicingDirection] + static_cast<IndexValueType>(region.GetSize()[m_SlicingDirection]);
InputImageRegionType sliceRegion;
InputImageIndexType index = region.GetIndex();
InputImageSizeType size = region.GetSize();
auto [index, size] = region;

sliceRegion.SetSize(size);
BiasFieldType bias = this->EstimateBiasField(sliceRegion, 0, m_InterSliceCorrectionMaximumIteration);
Expand Down Expand Up @@ -882,8 +881,7 @@ MRIBiasFieldCorrectionFilter<TInputImage, TOutputImage, TMaskImage>::AdjustSlabR
SlabRegionVectorType & slabs,
OutputImageRegionType requestedRegion)
{
OutputImageIndexType indexFirst = requestedRegion.GetIndex();
OutputImageSizeType size = requestedRegion.GetSize();
const auto [indexFirst, size] = requestedRegion;
OutputImageIndexType indexLast = indexFirst;

for (SizeValueType i = 0; i < ImageDimension; ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ ConvolutionImageFilterBase<TInputImage, TKernelImage, TOutputImage>::GetValidReg
{
typename InputImageType::ConstPointer inputPtr = this->GetInput();

InputRegionType inputLargestPossibleRegion = inputPtr->GetLargestPossibleRegion();

OutputIndexType validIndex = inputLargestPossibleRegion.GetIndex();
OutputSizeType validSize = inputLargestPossibleRegion.GetSize();
auto [validIndex, validSize] = inputPtr->GetLargestPossibleRegion();

// Shrink the output largest possible region by the kernel radius.
KernelSizeType kernelSize = this->GetKernelImage()->GetLargestPossibleRegion().GetSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,11 @@ FFTConvolutionImageFilter<TInputImage, TKernelImage, TOutputImage, TInternalPrec
{
float remainingProgress = 1.0f;

InputRegionType inputLargestRegion = input->GetLargestPossibleRegion();
InputSizeType inputLargestSize = inputLargestRegion.GetSize();
InputIndexType inputLargestIndex = inputLargestRegion.GetIndex();
InputRegionType inputRequestedRegion = input->GetRequestedRegion();
InputSizeType inputRequestedSize = inputRequestedRegion.GetSize();
InputIndexType inputRequestedIndex = inputRequestedRegion.GetIndex();
InputRegionType inputLargestRegion = input->GetLargestPossibleRegion();
const auto [inputLargestIndex, inputLargestSize] = inputLargestRegion;
const auto [inputRequestedIndex, inputRequestedSize] = input->GetRequestedRegion();
OutputRegionType outputRequestedRegion = this->GetOutput()->GetRequestedRegion();
OutputSizeType outputRequestedSize = outputRequestedRegion.GetSize();
OutputIndexType outputRequestedIndex = outputRequestedRegion.GetIndex();
const auto [outputRequestedIndex, outputRequestedSize] = outputRequestedRegion;

// Pad the input image such that the requested region, expanded by
// twice the kernel radius, lies entirely within the buffered region.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ GaussianExponentialDiffeomorphicTransform<TParametersValueType, VDimension>::Gau
}
ScalarType weight2 = 1.0 - weight1;

const typename ConstantVelocityFieldType::RegionType region = field->GetLargestPossibleRegion();
const typename ConstantVelocityFieldType::SizeType size = region.GetSize();
const typename ConstantVelocityFieldType::IndexType startIndex = region.GetIndex();
const auto [startIndex, size] = field->GetLargestPossibleRegion();

ImageRegionIteratorWithIndex<ConstantVelocityFieldType> fieldIt(field, field->GetLargestPossibleRegion());
ImageRegionConstIteratorWithIndex<ConstantVelocityFieldType> smoothedFieldIt(smoothField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ GaussianSmoothingOnUpdateDisplacementFieldTransform<TParametersValueType, VDimen
ScalarType weight2 = 1.0 - weight1;

const typename DisplacementFieldType::RegionType region = field->GetLargestPossibleRegion();
const typename DisplacementFieldType::SizeType size = region.GetSize();
const typename DisplacementFieldType::IndexType startIndex = region.GetIndex();
const auto [startIndex, size] = region;

ImageRegionIteratorWithIndex<DisplacementFieldType> fieldIt(field, field->GetLargestPossibleRegion());
ImageRegionConstIteratorWithIndex<DisplacementFieldType> smoothedFieldIt(smoothField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ GaussianSmoothingOnUpdateTimeVaryingVelocityFieldTransform<TParametersValueType,
}
ScalarType weight2 = 1.0 - weight1;

using TimeVaryingVelocityFieldSizeType = typename VelocityFieldType::SizeType;
using TimeVaryingVelocityFieldIndexType = typename VelocityFieldType::IndexType;

TimeVaryingVelocityFieldSizeType size = field->GetLargestPossibleRegion().GetSize();
TimeVaryingVelocityFieldIndexType startIndex = field->GetLargestPossibleRegion().GetIndex();
const auto [startIndex, size] = field->GetLargestPossibleRegion();

ImageRegionIteratorWithIndex<VelocityFieldType> fieldIt(field, field->GetLargestPossibleRegion());
ImageRegionConstIteratorWithIndex<VelocityFieldType> smoothedFieldIt(smoothField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ template <typename TInputImage, typename TOutputImage>
void
InvertDisplacementFieldImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(const RegionType & region)
{
const typename DisplacementFieldType::RegionType fullRegion = this->m_ComposedField->GetRequestedRegion();
const typename DisplacementFieldType::SizeType size = fullRegion.GetSize();
const typename DisplacementFieldType::IndexType startIndex = fullRegion.GetIndex();
const typename DisplacementFieldType::PixelType zeroVector{};
const auto [startIndex, size] = this->m_ComposedField->GetRequestedRegion();
const typename DisplacementFieldType::PixelType zeroVector{};

ImageRegionIterator<DisplacementFieldType> ItE(this->m_ComposedField, region);
ImageRegionIterator<RealImageType> ItS(this->m_ScaledNormImage, region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ TimeVaryingVelocityFieldIntegrationImageFilter<TTimeVaryingVelocityField, TDispl
{
typename TimeVaryingVelocityFieldType::PointType spaceTimeOrigin = inputField->GetOrigin();

using RegionType = typename TimeVaryingVelocityFieldType::RegionType;
RegionType region = inputField->GetLargestPossibleRegion();

typename RegionType::IndexType lastIndex = region.GetIndex();
typename RegionType::SizeType size = region.GetSize();
auto [lastIndex, size] = inputField->GetLargestPossibleRegion();
for (unsigned int d = 0; d < InputImageDimension; ++d)
{
lastIndex[d] += (size[d] - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ SignedMaurerDistanceMapImageFilter<TInputImage, TOutputImage>::SplitRequestedReg

const OutputSizeType & requestedRegionSize = splitRegion.GetSize();

OutputIndexType splitIndex = splitRegion.GetIndex();
OutputSizeType splitSize = splitRegion.GetSize();
auto [splitIndex, splitSize] = splitRegion;

// split on the outermost dimension available
// and avoid the current dimension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ HalfToFullHermitianImageFilter<TInputImage>::DynamicThreadedGenerateData(

// Now copy the redundant complex conjugate region, if there is one
// in this thread's output region.
OutputImageIndexType outputRegionIndex = outputRegionForThread.GetIndex();
OutputImageSizeType outputRegionSize = outputRegionForThread.GetSize();
const auto [outputRegionIndex, outputRegionSize] = outputRegionForThread;
OutputImageIndexType outputRegionMaximumIndex = outputRegionIndex + outputRegionSize;

if (outputRegionMaximumIndex[0] > inputRegionMaximumIndex[0])
Expand All @@ -140,9 +139,8 @@ HalfToFullHermitianImageFilter<TInputImage>::DynamicThreadedGenerateData(
OutputImageIndexType index(conjugateIndex);
for (unsigned int i = 0; i < ImageDimension; ++i)
{
OutputImageRegionType outputLargestPossibleRegion = outputPtr->GetLargestPossibleRegion();
OutputImageIndexType outputLargestPossibleRegionIndex = outputLargestPossibleRegion.GetIndex();
OutputImageSizeType outputLargestPossibleRegionSize = outputLargestPossibleRegion.GetSize();
const auto [outputLargestPossibleRegionIndex, outputLargestPossibleRegionSize] =
outputPtr->GetLargestPossibleRegion();
if (conjugateIndex[i] != outputLargestPossibleRegionIndex[i])
{
index[i] = outputLargestPossibleRegionSize[i] - conjugateIndex[i] + 2 * outputLargestPossibleRegionIndex[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ RealToHalfHermitianForwardFFTImageFilter<TInputImage, TOutputImage>::GenerateOut
// This is all based on the same function in itk::ShrinkImageFilter
// ShrinkImageFilter also modifies the image spacing, but spacing
// has no meaning in the result of an FFT.
const InputSizeType inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
const InputIndexType inputStartIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
const auto [inputStartIndex, inputSize] = inputPtr->GetLargestPossibleRegion();

OutputSizeType outputSize;
OutputIndexType outputStartIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ VnlHalfHermitianToRealInverseFFTImageFilter<TInputImage, TOutputImage>::Generate
// reports the beginning and the end of the process.
ProgressReporter progress(this, 0, 1);

const InputSizeType inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
const InputIndexType inputIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
const OutputSizeType outputSize = outputPtr->GetLargestPossibleRegion().GetSize();
const OutputIndexType outputIndex = outputPtr->GetLargestPossibleRegion().GetIndex();
const auto [inputIndex, inputSize] = inputPtr->GetLargestPossibleRegion();
const auto [outputIndex, outputSize] = outputPtr->GetLargestPossibleRegion();

// Allocate output buffer memory
outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ MaskFeaturePointSelectionFilter<TImage, TMask, TFeatures>::GenerateData()
}

// set safe region for picking feature points depending on whether tensors are computed
IndexType safeIndex = region.GetIndex();
SizeType safeSize = region.GetSize();
auto [safeIndex, safeSize] = region;

if (m_ComputeStructureTensors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ class ITK_TEMPLATE_EXPORT FrequencyShiftedFFTLayoutImageRegionConstIteratorWithI
void
Init()
{
IndexType minIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
const auto [minIndex, sizeImage] = this->m_Image->GetLargestPossibleRegion();
for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
{
this->m_ZeroFrequencyIndex[dim] =
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filtering/ImageGrid/include/itkCropImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ CropImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
SizeType sz;
OutputImageIndexType idx;

InputImageSizeType input_sz = inputPtr->GetLargestPossibleRegion().GetSize();
InputImageIndexType input_idx = inputPtr->GetLargestPossibleRegion().GetIndex();
const auto [input_idx, input_sz] = inputPtr->GetLargestPossibleRegion();

for (unsigned int i = 0; i < InputImageDimension; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ CyclicShiftImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(
const InputImageType * inputImage = this->GetInput();

// The index and size of the image needed to compute the shift
const IndexType outIdx = this->GetOutput()->GetLargestPossibleRegion().GetIndex();
const SizeType outSize = this->GetOutput()->GetLargestPossibleRegion().GetSize();
const auto [outIdx, outSize] = this->GetOutput()->GetLargestPossibleRegion();

TotalProgressReporter progress(this, this->GetOutput()->GetRequestedRegion().GetNumberOfPixels());

Expand Down
Loading