Skip to content

Commit c0812b3

Browse files
committed
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 InsightSoftwareConsortium#4815 commit 66e6d8b and 9eb1359. - Follow-up to pull request InsightSoftwareConsortium#3953 commit 5a60ed0 "STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023
1 parent 923ee4e commit c0812b3

File tree

6 files changed

+7
-25
lines changed

6 files changed

+7
-25
lines changed

Modules/Core/Common/include/itkUnaryFunctorImageFilter.hxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ UnaryFunctorImageFilter<TInputImage, TOutputImage, TFunction>::DynamicThreadedGe
8888
ImageScanlineConstIterator inputIt(inputPtr, inputRegionForThread);
8989
ImageScanlineIterator outputIt(outputPtr, outputRegionForThread);
9090

91-
inputIt.GoToBegin();
92-
outputIt.GoToBegin();
9391
while (!inputIt.IsAtEnd())
9492
{
9593
while (!inputIt.IsAtEndOfLine())

Modules/Core/FiniteDifference/include/itkDenseFiniteDifferenceImageFilter.hxx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ DenseFiniteDifferenceImageFilter<TInputImage, TOutputImage>::ThreadedApplyUpdate
191191
ImageRegionIterator<UpdateBufferType> u(m_UpdateBuffer, regionToProcess);
192192
ImageRegionIterator<OutputImageType> o(this->GetOutput(), regionToProcess);
193193

194-
u.GoToBegin();
195-
o.GoToBegin();
196-
197194
while (!u.IsAtEnd())
198195
{
199196
o.Value() += static_cast<PixelType>(u.Value() * dt); // no adaptor
@@ -259,7 +256,6 @@ DenseFiniteDifferenceImageFilter<TInputImage, TOutputImage>::ThreadedCalculateCh
259256
UpdateIteratorType bU(m_UpdateBuffer, *fIt);
260257

261258
bD.GoToBegin();
262-
bU.GoToBegin();
263259
while (!bD.IsAtEnd())
264260
{
265261
bU.Value() = df->ComputeUpdate(bD, globalData);

Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,6 @@ BinaryMask3DMeshSource<TInputImage, TOutputMesh>::CreateMesh()
10371037
InputImageIterator it3(m_InputImage, m_RegionOfInterest);
10381038
InputImageIterator it4(m_InputImage, m_RegionOfInterest);
10391039

1040-
it1.GoToBegin();
1041-
it2.GoToBegin();
1042-
it3.GoToBegin();
1043-
it4.GoToBegin();
1044-
10451040
InputImageSizeType inputImageSize = m_RegionOfInterest.GetSize();
10461041
m_ImageWidth = inputImageSize[0];
10471042
m_ImageHeight = inputImageSize[1];

Modules/Core/Mesh/include/itkImageToParametricSpaceFilter.hxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ ImageToParametricSpaceFilter<TInputImage, TOutputMesh>::GenerateData()
108108

109109
PointsContainerIterator point = points->Begin();
110110

111-
itr.GoToBegin();
112111
while (!itr.IsAtEnd())
113112
{
114113
(point.Value())[component] = itr.Get();
@@ -123,7 +122,6 @@ ImageToParametricSpaceFilter<TInputImage, TOutputMesh>::GenerateData()
123122
PointDataContainerIterator data = pointData->Begin();
124123
image = this->GetInput(0);
125124
ImageRegionConstIteratorWithIndex<InputImageType> itr(image, image->GetRequestedRegion());
126-
itr.GoToBegin();
127125
while (!itr.IsAtEnd())
128126
{
129127
// The data at each point is the index

Modules/Core/SpatialObjects/include/itkSpatialObjectToImageStatisticsCalculator.hxx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ SpatialObjectToImageStatisticsCalculator<TInputImage, TInputSpatialObject, TSamp
119119

120120
using MaskIteratorType = ImageRegionConstIteratorWithIndex<MaskImageType>;
121121
MaskIteratorType it(maskImage, maskImage->GetLargestPossibleRegion());
122-
it.GoToBegin();
123-
IndexType ind;
124-
PointType pnt;
125-
PointType tPnt;
126-
VectorType mv;
122+
IndexType ind;
123+
PointType pnt;
124+
PointType tPnt;
125+
VectorType mv;
127126
while (!it.IsAtEnd())
128127
{
129128
if (it.Get() > 0) // if inside the mask
@@ -186,10 +185,9 @@ SpatialObjectToImageStatisticsCalculator<TInputImage, TInputSpatialObject, TSamp
186185

187186
using IteratorType = ImageRegionConstIteratorWithIndex<ImageType>;
188187
IteratorType it(m_Image, region);
189-
it.GoToBegin();
190-
IndexType ind;
191-
PointType pnt;
192-
VectorType mv;
188+
IndexType ind;
189+
PointType pnt;
190+
VectorType mv;
193191
while (!it.IsAtEnd())
194192
{
195193
ind = it.GetIndex();

Modules/Core/TestKernel/include/itkTestingStretchIntensityImageFilter.hxx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ StretchIntensityImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateD
110110
ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
111111
ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
112112

113-
inputIt.GoToBegin();
114-
outputIt.GoToBegin();
115-
116113
while (!inputIt.IsAtEnd())
117114
{
118115
const InputPixelType x = inputIt.Get();

0 commit comments

Comments
 (0)