From c0812b34445c0f61f171e9cf2d9e5d33632923cd Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 30 Aug 2024 22:43:17 +0200 Subject: [PATCH] STYLE: Remove unnecessary iterator `GoToBegin()` calls from Core When an ITK iterator is just constructed by `IteratorType(image, region)`, it is already initialized at the begin of the region, as was tested and documented by pull request https://github.com/InsightSoftwareConsortium/ITK/pull/4815 commit 66e6d8be08c45d29cb120fd925451a35480fc631 and 9eb13596cef6009c026b2ee837ea52ee05d00f11. - Follow-up to pull request https://github.com/InsightSoftwareConsortium/ITK/pull/3953 commit 5a60ed00adbc108e5c81bd2ddfbc988f28eaf722 "STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023 --- .../include/itkUnaryFunctorImageFilter.hxx | 2 -- .../itkDenseFiniteDifferenceImageFilter.hxx | 4 ---- .../Mesh/include/itkBinaryMask3DMeshSource.hxx | 5 ----- .../include/itkImageToParametricSpaceFilter.hxx | 2 -- ...kSpatialObjectToImageStatisticsCalculator.hxx | 16 +++++++--------- .../itkTestingStretchIntensityImageFilter.hxx | 3 --- 6 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Modules/Core/Common/include/itkUnaryFunctorImageFilter.hxx b/Modules/Core/Common/include/itkUnaryFunctorImageFilter.hxx index 2c80b29401e..39d8b4c4d1b 100644 --- a/Modules/Core/Common/include/itkUnaryFunctorImageFilter.hxx +++ b/Modules/Core/Common/include/itkUnaryFunctorImageFilter.hxx @@ -88,8 +88,6 @@ UnaryFunctorImageFilter::DynamicThreadedGe ImageScanlineConstIterator inputIt(inputPtr, inputRegionForThread); ImageScanlineIterator outputIt(outputPtr, outputRegionForThread); - inputIt.GoToBegin(); - outputIt.GoToBegin(); while (!inputIt.IsAtEnd()) { while (!inputIt.IsAtEndOfLine()) diff --git a/Modules/Core/FiniteDifference/include/itkDenseFiniteDifferenceImageFilter.hxx b/Modules/Core/FiniteDifference/include/itkDenseFiniteDifferenceImageFilter.hxx index 54f4e0e8a9c..ac8850191f4 100644 --- a/Modules/Core/FiniteDifference/include/itkDenseFiniteDifferenceImageFilter.hxx +++ b/Modules/Core/FiniteDifference/include/itkDenseFiniteDifferenceImageFilter.hxx @@ -191,9 +191,6 @@ DenseFiniteDifferenceImageFilter::ThreadedApplyUpdate ImageRegionIterator u(m_UpdateBuffer, regionToProcess); ImageRegionIterator o(this->GetOutput(), regionToProcess); - u.GoToBegin(); - o.GoToBegin(); - while (!u.IsAtEnd()) { o.Value() += static_cast(u.Value() * dt); // no adaptor @@ -259,7 +256,6 @@ DenseFiniteDifferenceImageFilter::ThreadedCalculateCh UpdateIteratorType bU(m_UpdateBuffer, *fIt); bD.GoToBegin(); - bU.GoToBegin(); while (!bD.IsAtEnd()) { bU.Value() = df->ComputeUpdate(bD, globalData); diff --git a/Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx b/Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx index 033d7291bc1..fb5b5d95ee6 100644 --- a/Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx +++ b/Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx @@ -1037,11 +1037,6 @@ BinaryMask3DMeshSource::CreateMesh() InputImageIterator it3(m_InputImage, m_RegionOfInterest); InputImageIterator it4(m_InputImage, m_RegionOfInterest); - it1.GoToBegin(); - it2.GoToBegin(); - it3.GoToBegin(); - it4.GoToBegin(); - InputImageSizeType inputImageSize = m_RegionOfInterest.GetSize(); m_ImageWidth = inputImageSize[0]; m_ImageHeight = inputImageSize[1]; diff --git a/Modules/Core/Mesh/include/itkImageToParametricSpaceFilter.hxx b/Modules/Core/Mesh/include/itkImageToParametricSpaceFilter.hxx index bffba193639..8db2f8d632d 100644 --- a/Modules/Core/Mesh/include/itkImageToParametricSpaceFilter.hxx +++ b/Modules/Core/Mesh/include/itkImageToParametricSpaceFilter.hxx @@ -108,7 +108,6 @@ ImageToParametricSpaceFilter::GenerateData() PointsContainerIterator point = points->Begin(); - itr.GoToBegin(); while (!itr.IsAtEnd()) { (point.Value())[component] = itr.Get(); @@ -123,7 +122,6 @@ ImageToParametricSpaceFilter::GenerateData() PointDataContainerIterator data = pointData->Begin(); image = this->GetInput(0); ImageRegionConstIteratorWithIndex itr(image, image->GetRequestedRegion()); - itr.GoToBegin(); while (!itr.IsAtEnd()) { // The data at each point is the index diff --git a/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageStatisticsCalculator.hxx b/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageStatisticsCalculator.hxx index 944dcc91399..d81768de545 100644 --- a/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageStatisticsCalculator.hxx +++ b/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageStatisticsCalculator.hxx @@ -119,11 +119,10 @@ SpatialObjectToImageStatisticsCalculator; MaskIteratorType it(maskImage, maskImage->GetLargestPossibleRegion()); - it.GoToBegin(); - IndexType ind; - PointType pnt; - PointType tPnt; - VectorType mv; + IndexType ind; + PointType pnt; + PointType tPnt; + VectorType mv; while (!it.IsAtEnd()) { if (it.Get() > 0) // if inside the mask @@ -186,10 +185,9 @@ SpatialObjectToImageStatisticsCalculator; IteratorType it(m_Image, region); - it.GoToBegin(); - IndexType ind; - PointType pnt; - VectorType mv; + IndexType ind; + PointType pnt; + VectorType mv; while (!it.IsAtEnd()) { ind = it.GetIndex(); diff --git a/Modules/Core/TestKernel/include/itkTestingStretchIntensityImageFilter.hxx b/Modules/Core/TestKernel/include/itkTestingStretchIntensityImageFilter.hxx index fa9388d4986..3cc38139af9 100644 --- a/Modules/Core/TestKernel/include/itkTestingStretchIntensityImageFilter.hxx +++ b/Modules/Core/TestKernel/include/itkTestingStretchIntensityImageFilter.hxx @@ -110,9 +110,6 @@ StretchIntensityImageFilter::DynamicThreadedGenerateD ImageRegionConstIterator inputIt(inputPtr, inputRegionForThread); ImageRegionIterator outputIt(outputPtr, outputRegionForThread); - inputIt.GoToBegin(); - outputIt.GoToBegin(); - while (!inputIt.IsAtEnd()) { const InputPixelType x = inputIt.Get();