Skip to content

Commit

Permalink
Merge pull request #381 from N-Dekker/Replace-postfix-by-prefix-incre…
Browse files Browse the repository at this point in the history
…ment-CXX

STYLE: Replace postfix by prefix increment in C++ `for` loops
  • Loading branch information
thewtex authored May 21, 2022
2 parents 6f0e16b + 0613c33 commit 2ac631b
Show file tree
Hide file tree
Showing 88 changed files with 192 additions and 192 deletions.
2 changes: 1 addition & 1 deletion src/Core/Common/ComputeTimeBetweenPoints/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
void
LongFunction()
{
for (int i = 0; i < itk::NumericTraits<int>::max() / 100; i++)
for (int i = 0; i < itk::NumericTraits<int>::max() / 100; ++i)
{
double a = 0;
(void)a;
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Common/ConvertArrayToImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ main()
const double radius2 = radius * radius;
PixelType * it = localBuffer;

for (unsigned int z = 0; z < size[2]; z++)
for (unsigned int z = 0; z < size[2]; ++z)
{
const double dz = static_cast<double>(z) - static_cast<double>(size[2]) / 2.0;
for (unsigned int y = 0; y < size[1]; y++)
for (unsigned int y = 0; y < size[1]; ++y)
{
const double dy = static_cast<double>(y) - static_cast<double>(size[1]) / 2.0;
for (unsigned int x = 0; x < size[0]; x++)
for (unsigned int x = 0; x < size[0]; ++x)
{
const double dx = static_cast<double>(x) - static_cast<double>(size[0]) / 2.0;
const double d2 = dx * dx + dy * dy + dz * dz;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CovariantVectorNorm/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ main()
// another way to normalize
if (vnorm != 0.)
{
for (unsigned int i = 0; i < u.GetNumberOfComponents(); i++)
for (unsigned int i = 0; i < u.GetNumberOfComponents(); ++i)
{
u[i] /= vnorm;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateABackwardDifferenceOperator/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main()

std::cout << backwardDifferenceOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << backwardDifferenceOperator.GetOffset(i) << " " << backwardDifferenceOperator.GetElement(i)
<< std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateDerivativeKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main()

std::cout << derivativeOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << derivativeOperator.GetOffset(i) << " " << derivativeOperator.GetElement(i) << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateForwardDifferenceKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main()

std::cout << forwardDifferenceOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << forwardDifferenceOperator.GetOffset(i) << " " << forwardDifferenceOperator.GetElement(i) << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateGaussianDerivativeKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main()

std::cout << gaussianDerivativeOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << gaussianDerivativeOperator.GetOffset(i) << " " << gaussianDerivativeOperator.GetElement(i)
<< std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateGaussianKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main()

std::cout << gaussianOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << gaussianOperator.GetOffset(i) << " " << gaussianOperator.GetElement(i) << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateLaplacianKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ main()

std::cout << laplacianOperator << std::endl;

for (unsigned int i = 0; i < laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]; i++)
for (unsigned int i = 0; i < laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]; ++i)
{
std::cout << laplacianOperator.GetOffset(i) << " " << laplacianOperator.GetElement(i) << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateSobelKernel/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ main()

std::cout << sobelOperator << std::endl;

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
std::cout << sobelOperator.GetElement(i) << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/DemonstrateAllOperators/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ main()
// operators[operatorId]->Print(std::cout);
// std::cout << operators[operatorId]->GetNameOfClass() << std::endl;

for (auto i = -operatorId->GetSize()[0] / 2; i <= operatorId->GetSize()[0] / 2; i++)
for (auto i = -operatorId->GetSize()[0] / 2; i <= operatorId->GetSize()[0] / 2; ++i)
{
for (auto j = -operatorId->GetSize()[1] / 2; j <= operatorId->GetSize()[1] / 2; j++)
for (auto j = -operatorId->GetSize()[1] / 2; j <= operatorId->GetSize()[1] / 2; ++j)
{
itk::Offset<2> offset;
offset[0] = i;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/DisplayImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ CreateImage(ImageType * const image)
image->Allocate();

// Make a square
for (unsigned int r = 40; r < 100; r++)
for (unsigned int r = 40; r < 100; ++r)
{
for (unsigned int c = 40; c < 100; c++)
for (unsigned int c = 40; c < 100; ++c)
{
ImageType::IndexType pixelIndex;
pixelIndex[0] = r;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/ImportPixelBufferIntoAnImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ main(int argc, char * argv[])
const double radius2 = radius * radius;
PixelType * it = localBuffer;

for (unsigned int y = 0; y < size[1]; y++)
for (unsigned int y = 0; y < size[1]; ++y)
{
const double dy = static_cast<double>(y) - static_cast<double>(size[1]) / 2.0;
for (unsigned int x = 0; x < size[0]; x++)
for (unsigned int x = 0; x < size[0]; ++x)
{
const double dx = static_cast<double>(x) - static_cast<double>(size[0]) / 2.0;
const double d2 = dx * dx + dy * dy;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/IterateRegionWithNeighborhood/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ main(int argc, char * argv[])
// Set the current pixel to white
iterator.SetCenterPixel(255);

for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
ImageType::IndexType index = iterator.GetIndex(i);
std::cout << index[0] << " " << index[1] << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ main(int argc, char * argv[])

while (!iterator.IsAtEnd())
{
for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
ImageType::IndexType index = iterator.GetIndex(i);
std::cout << index[0] << " " << index[1] << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ main()

while (!iterator.IsAtEnd())
{
for (unsigned int i = 0; i < 9; i++)
for (unsigned int i = 0; i < 9; ++i)
{
ImageType::IndexType index = iterator.GetIndex(i);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/MiniPipeline/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ CreateImage(TImage * const image)
image->Allocate();

// Make another square
for (unsigned int r = 40; r < 100; r++)
for (unsigned int r = 40; r < 100; ++r)
{
for (unsigned int c = 40; c < 100; c++)
for (unsigned int c = 40; c < 100; ++c)
{
typename TImage::IndexType pixelIndex;
pixelIndex[0] = r;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/PermuteSequenceOfIndices/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ main()

std::cout << std::endl;

for (unsigned int i = 0; i < 5; i++)
for (unsigned int i = 0; i < 5; ++i)
{
std::cout << rp[i] << " ";
}
std::cout << std::endl << std::endl;

rp.Shuffle();
std::cout << "After shuffle" << std::endl;
for (unsigned int i = 0; i < 5; i++)
for (unsigned int i = 0; i < 5; ++i)
{
std::cout << rp[i] << " ";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/ReadAPointSet/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ main(int argc, char * argv[])
}

// Retrieve points
for (unsigned int i = 0; i < numberOfPoints; i++)
for (unsigned int i = 0; i < numberOfPoints; ++i)
{
PointType pp;
bool pointExists = mesh->GetPoint(i, &pp);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/SetPixelValueInOneImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ main(int argc, char * argv[])

ImageType::IndexType pixelIndex;

for (ImageType::IndexValueType r = 0; r < 50; r++)
for (ImageType::IndexValueType r = 0; r < 50; ++r)
{
pixelIndex[0] = 4 * r;
pixelIndex[1] = 4 * r;
Expand All @@ -67,7 +67,7 @@ main(int argc, char * argv[])
image->SetPixel(pixelIndex, 255);
}

for (ImageType::IndexValueType r = 0; r < 25; r++)
for (ImageType::IndexValueType r = 0; r < 25; ++r)
{
pixelIndex[0] = 8 * r;
pixelIndex[1] = 200 + 4 * r;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/UseParallelizeImageRegion/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ segmentationAndCustomColorization(InputImageType::Pointer inImage)
OutputPixelType p;
p.SetAlpha(iIt.Get());
static_assert(Dimension <= 3, "Dimension has to be 2 or 3");
for (unsigned d = 0; d < Dimension; d++)
for (unsigned d = 0; d < Dimension; ++d)
{
p.SetElement(d, ind[d]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Common/VariableLengthVector/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main()
v[1] = 2;
std::cout << v << std::endl;

for (unsigned int i = 0; i < v.Size(); i++)
for (unsigned int i = 0; i < v.Size(); ++i)
{
std::cout << v[i] << " ";
}
Expand Down Expand Up @@ -81,7 +81,7 @@ VariableLengthVectorToVector()
using FixedVectorType = itk::Vector<double, 2>;
FixedVectorType fixedLengthVector;

for (unsigned int i = 0; i < FixedVectorType::GetVectorDimension(); i++)
for (unsigned int i = 0; i < FixedVectorType::GetVectorDimension(); ++i)
{
fixedLengthVector[i] = variableLengthVector[i];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CreateImage(ImageType::Pointer image)
image->SetRegions(region);
image->Allocate();

for (unsigned int i = 0; i < 10; i++)
for (unsigned int i = 0; i < 10; ++i)
{
ImageType::IndexType pixelIndex;
pixelIndex[0] = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ CreateImage(UnsignedCharImageType::Pointer image)
image->FillBuffer(0);

// Make a square
for (unsigned int r = 20; r < 80; r++)
for (unsigned int r = 20; r < 80; ++r)
{
for (unsigned int c = 20; c < 80; c++)
for (unsigned int c = 20; c < 80; ++c)
{
UnsignedCharImageType::IndexType pixelIndex;
pixelIndex[0] = r;
Expand Down
8 changes: 4 additions & 4 deletions src/Core/QuadEdgeMesh/CreateTriangularQuadEdgeMesh/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ main(int argc, char * argv[])
using PointIdentifier = MeshType::PointIdentifier;
PointIdentifier k = 0;

for (int i = 0; i < 10; i++)
for (int i = 0; i < 10; ++i)
{
p[0] = static_cast<CoordType>(i);

for (int j = 0; j < 10; j++)
for (int j = 0; j < 10; ++j)
{
p[1] = static_cast<CoordType>(j);
points->SetElement(k, p);
Expand All @@ -69,9 +69,9 @@ main(int argc, char * argv[])

k = 0;

for (int i = 0; i < 9; i++)
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; j++)
for (int j = 0; j < 9; ++j)
{
mesh->AddFaceTriangle(k, k + 1, k + 11);
mesh->AddFaceTriangle(k, k + 11, k + 10);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/SpatialObjects/Blob/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main(int itkNotUsed(argc), char * itkNotUsed(argv)[])

// Create a list of points
BlobType::BlobPointListType points;
for (unsigned int i = 0; i < 20; i++)
for (unsigned int i = 0; i < 20; ++i)
{
BlobType::BlobPointType point;
point.SetPositionInObjectSpace(i, i);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/SpatialObjects/CreateALineSpatialObject/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ main(int itkNotUsed(argc), char * itkNotUsed(argv)[])

// Create a list of points
std::vector<LineType::LinePointType> points;
for (unsigned int i = 0; i < 20; i++)
for (unsigned int i = 0; i < 20; ++i)
{
LineType::LinePointType point;
point.SetPositionInObjectSpace(10, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ main(int argc, char * argv[])

// get transform parameters from MatrixType
TransformType::ParametersType parameters(Dimension * Dimension + Dimension);
for (unsigned int i = 0; i < Dimension; i++)
for (unsigned int i = 0; i < Dimension; ++i)
{
for (unsigned int j = 0; j < Dimension; j++)
for (unsigned int j = 0; j < Dimension; ++j)
{
parameters[i * Dimension + j] = matrix[i][j];
}
}
for (unsigned int i = 0; i < Dimension; i++)
for (unsigned int i = 0; i < Dimension; ++i)
{
parameters[i + Dimension * Dimension] = matrix[i][Dimension];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ main(int itkNotUsed(argc), char * itkNotUsed(argv)[])

TransformType::PhysicalDimensionsType fixedPhysicalDimensions;
TransformType::MeshSizeType meshSize;
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
fixedPhysicalDimensions[i] =
fixedImage->GetSpacing()[i] * static_cast<double>(fixedImage->GetLargestPossibleRegion().GetSize()[i] - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Transform/ScaleAnImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ CreateImage(ImageType::Pointer image)
image->FillBuffer(0);

// Make a white square
for (unsigned int r = 40; r < 60; r++)
for (unsigned int r = 40; r < 60; ++r)
{
for (unsigned int c = 40; c < 60; c++)
for (unsigned int c = 40; c < 60; ++c)
{
ImageType::IndexType pixelIndex;
pixelIndex[0] = r;
Expand Down
4 changes: 2 additions & 2 deletions src/Developer/ImageFilterY.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ ImageFilter<TImage>::GenerateData()
InternalGaussianFilterPointer smoothingFilters[ImageDimension];

// Instantiate all filters
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
smoothingFilters[i] = InternalGaussianFilterType::New();
smoothingFilters[i]->SetOrder(GaussianOrderEnum::ZeroOrder);
smoothingFilters[i]->SetDirection(i);
}

// Connect all filters (start at 1 because 0th filter is connected to the input
for (unsigned int i = 1; i < ImageDimension; i++)
for (unsigned int i = 1; i < ImageDimension; ++i)
{
smoothingFilters[i]->SetInput(smoothingFilters[i - 1]->GetOutput());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Developer/MiniPipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ CreateImage(TImage * const image)
image->Allocate();

// Make another square
for (unsigned int r = 40; r < 100; r++)
for (unsigned int r = 40; r < 100; ++r)
{
for (unsigned int c = 40; c < 100; c++)
for (unsigned int c = 40; c < 100; ++c)
{
typename TImage::IndexType pixelIndex;
pixelIndex[0] = r;
Expand Down
4 changes: 2 additions & 2 deletions src/Developer/itkOilPaintingImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ OilPaintingImageFilter<TImage>::DynamicThreadedGenerateData(const typename TImag

while (!out.IsAtEnd())
{
for (unsigned int i = 0; i < m_NumberOfBins; i++)
for (unsigned int i = 0; i < m_NumberOfBins; ++i)
{
bins[i] = 0; // reset histogram
}
Expand All @@ -69,7 +69,7 @@ OilPaintingImageFilter<TImage>::DynamicThreadedGenerateData(const typename TImag
// find the peak
unsigned maxIndex = 0;
unsigned long long maxBin = bins[0];
for (unsigned int i = 1; i < m_NumberOfBins; i++)
for (unsigned int i = 1; i < m_NumberOfBins; ++i)
{
if (bins[i] > maxBin)
{
Expand Down
Loading

1 comment on commit 2ac631b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.