Skip to content

Commit

Permalink
STYLE: Replace postfix by prefix increment in for loops in Core/Common
Browse files Browse the repository at this point in the history
Followed common C++ guidelines, including:

Google C++ Style Guide: "Use the prefix form (++i) of the increment and
decrement operators unless you need postfix semantics."
https://google.github.io/styleguide/cppguide.html#Preincrement_and_Predecrement

Herb Sutter, Andrei Alexandrescu - C++ Coding Standards: 101 Rules,
Guidelines, and Best Practices: "Prefer the canonical form of ++ and --.
Prefer calling the prefix forms"
https://www.oreilly.com/library/view/c-coding-standards/0321113586/ch29.html

Applied at GNU bash, by the following command:

	find . \( -iname *.cxx -or -iname *.hxx -or -iname *.h \) -exec perl -pi -w -e 's/(\s+for \(.*; .+); (\w+)\+\+\)/$1; ++$2)/g;' {} \;

Manually replaced a few more postfix increments, which were not detected
by this regex command, as remarked by Mikhail Isakov (issakomi).
  • Loading branch information
N-Dekker committed Apr 20, 2021
1 parent deb0af7 commit d7eea8a
Show file tree
Hide file tree
Showing 179 changed files with 701 additions and 701 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ITK_TEMPLATE_EXPORT Array : public vnl_vector<TValue>
{
this->m_LetArrayManageMemory = true;
this->SetSize(r.GetSize());
for (SizeValueType i = 0; i < r.GetSize(); i++)
for (SizeValueType i = 0; i < r.GetSize(); ++i)
{
this->operator[](i) = static_cast<TValue>(r[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::BS

for (const IndexType index : ZeroBasedIndexRange<VSpaceDimension>(m_SupportSize))
{
for (unsigned int j = 0; j < SpaceDimension; j++)
for (unsigned int j = 0; j < SpaceDimension; ++j)
{
m_OffsetToIndexTable[counter][j] = index[j];
}
Expand Down Expand Up @@ -95,7 +95,7 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev
unsigned int j, k;

// Find the starting index of the support region
for (j = 0; j < SpaceDimension; j++)
for (j = 0; j < SpaceDimension; ++j)
{
// Note that the expression passed to Math::Floor is adapted to work around
// a compiler bug which caused endless compilations (apparently), by
Expand All @@ -105,22 +105,22 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev

// Compute the weights
Matrix<double, SpaceDimension, SplineOrder + 1> weights1D;
for (j = 0; j < SpaceDimension; j++)
for (j = 0; j < SpaceDimension; ++j)
{
double x = index[j] - static_cast<double>(startIndex[j]);

for (k = 0; k <= SplineOrder; k++)
for (k = 0; k <= SplineOrder; ++k)
{
weights1D[j][k] = m_Kernel->Evaluate(x);
x -= 1.0;
}
}

for (k = 0; k < m_NumberOfWeights; k++)
for (k = 0; k < m_NumberOfWeights; ++k)
{
weights[k] = 1.0;

for (j = 0; j < SpaceDimension; j++)
for (j = 0; j < SpaceDimension; ++j)
{
weights[k] *= weights1D[j][m_OffsetToIndexTable[k][j]];
}
Expand Down
28 changes: 14 additions & 14 deletions Modules/Core/Common/include/itkBoundingBox.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Pri
Superclass::PrintSelf(os, indent);

os << indent << "Bounding Box: ( ";
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
os << m_Bounds[2 * i] << "," << m_Bounds[2 * i + 1] << " ";
}
Expand Down Expand Up @@ -85,15 +85,15 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Com
PointType center = this->GetCenter();
PointType radius;

for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
radius[i] = m_Bounds[2 * i + 1] - center[i];
}

for (SizeValueType j = 0; j < NumberOfCorners; j++)
for (SizeValueType j = 0; j < NumberOfCorners; ++j)
{
PointType pnt;
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
pnt[i] = center[i] + std::pow(-1.0, ((double)(j / (int(std::pow(2.0, (double)i)))))) * radius[i];
}
Expand Down Expand Up @@ -158,7 +158,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Com

PointsContainerConstIterator ci = m_PointsContainer->Begin();
Point<TCoordRep, VPointDimension> point = ci->Value(); // point value
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
m_Bounds[2 * i] = point[i];
m_Bounds[2 * i + 1] = point[i];
Expand All @@ -170,7 +170,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Com
while (ci != m_PointsContainer->End())
{
point = ci->Value(); // point value
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
if (point[i] < m_Bounds[2 * i])
{
Expand All @@ -197,7 +197,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Get
this->ComputeBoundingBox();

PointType center;
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
center[i] = (m_Bounds[2 * i] + m_Bounds[2 * i + 1]) / 2.0;
}
Expand All @@ -212,7 +212,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Get
this->ComputeBoundingBox();

PointType minimum;
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
minimum[i] = m_Bounds[2 * i];
}
Expand All @@ -224,7 +224,7 @@ template <typename TPointIdentifier, unsigned int VPointDimension, typename TCoo
void
BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::SetMinimum(const PointType & point)
{
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
m_Bounds[2 * i] = point[i];
}
Expand All @@ -239,7 +239,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Get
this->ComputeBoundingBox();

PointType maximum;
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
maximum[i] = m_Bounds[2 * i + 1];
}
Expand All @@ -251,7 +251,7 @@ template <typename TPointIdentifier, unsigned int VPointDimension, typename TCoo
void
BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::SetMaximum(const PointType & point)
{
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
m_Bounds[2 * i + 1] = point[i];
}
Expand All @@ -265,7 +265,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Con
{
bool changed = false;

for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
if (point[i] < m_Bounds[2 * i])
{
Expand Down Expand Up @@ -293,7 +293,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Get

if (this->ComputeBoundingBox())
{
for (unsigned int i = 0; i < PointDimension; i++)
for (unsigned int i = 0; i < PointDimension; ++i)
{
dist2 += (m_Bounds[2 * i] - m_Bounds[2 * i + 1]) * (m_Bounds[2 * i] - m_Bounds[2 * i + 1]);
}
Expand Down Expand Up @@ -367,7 +367,7 @@ BoundingBox<TPointIdentifier, VPointDimension, TCoordRep, TPointsContainer>::Dee
#endif

// Copy the bounds into the clone
for (unsigned int i = 0; i < 2 * PointDimension; i++)
for (unsigned int i = 0; i < 2 * PointDimension; ++i)
{
clone->m_Bounds[i] = this->m_Bounds[i];
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkBresenhamLine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ BresenhamLine<VDimension>::BuildLine(LType Direction, unsigned int length)
// we are going to start at 0
m_CurrentImageIndex.Fill(0);
StartIndex.Fill(0);
for (unsigned i = 0; i < VDimension; i++)
for (unsigned i = 0; i < VDimension; ++i)
{
LastIndex[i] = (IndexValueType)(length * Direction[i]);
}
// Find the dominant direction
IndexValueType maxDistance = 0;
unsigned int maxDistanceDimension = 0;
for (unsigned i = 0; i < VDimension; i++)
for (unsigned i = 0; i < VDimension; ++i)
{
auto distance = static_cast<long>(itk::Math::abs(LastIndex[i]));
if (distance > maxDistance)
Expand Down Expand Up @@ -118,7 +118,7 @@ BresenhamLine<VDimension>::BuildLine(IndexType p0, IndexType p1)
{
itk::Point<float, VDimension> point0;
itk::Point<float, VDimension> point1;
for (unsigned int i = 0; i < VDimension; i++)
for (unsigned int i = 0; i < VDimension; ++i)
{
point0[i] = p0[i];
point1[i] = p1[i];
Expand All @@ -128,7 +128,7 @@ BresenhamLine<VDimension>::BuildLine(IndexType p0, IndexType p1)
OffsetArray offsets = this->BuildLine(point1 - point0, distance);

IndexArray indices(offsets.size());
for (unsigned int i = 0; i < offsets.size(); i++)
for (unsigned int i = 0; i < offsets.size(); ++i)
{
indices[i] = p0 + offsets[i];
}
Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Common/include/itkByteSwapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void
ByteSwapper<T>::Swap2Range(void * ptr, BufferSizeType num)
{
auto * pos = static_cast<char *>(ptr);
for (BufferSizeType i = 0; i < num; i++)
for (BufferSizeType i = 0; i < num; ++i)
{
const char one_byte = pos[0];
pos[0] = pos[1];
Expand All @@ -312,7 +312,7 @@ ByteSwapper<T>::SwapWrite2Range(void * ptr, BufferSizeType num, OStreamType * fp
memcpy(cpy, ptr, chunkSize * 2);

char * pos = cpy;
for (BufferSizeType i = 0; i < chunkSize; i++)
for (BufferSizeType i = 0; i < chunkSize; ++i)
{
const char one_byte = pos[0];
pos[0] = pos[1];
Expand Down Expand Up @@ -356,7 +356,7 @@ ByteSwapper<T>::Swap4Range(void * ptr, BufferSizeType num)
{
auto * pos = static_cast<char *>(ptr);

for (BufferSizeType i = 0; i < num; i++)
for (BufferSizeType i = 0; i < num; ++i)
{
char one_byte = pos[0];
pos[0] = pos[3];
Expand Down Expand Up @@ -387,7 +387,7 @@ ByteSwapper<T>::SwapWrite4Range(void * ptr, BufferSizeType num, OStreamType * fp
memcpy(cpy, ptr, chunkSize * 4);

char * pos = cpy;
for (BufferSizeType i = 0; i < chunkSize; i++)
for (BufferSizeType i = 0; i < chunkSize; ++i)
{
char one_byte = pos[0];
pos[0] = pos[3];
Expand Down Expand Up @@ -443,7 +443,7 @@ ByteSwapper<T>::Swap8Range(void * ptr, BufferSizeType num)
{
auto * pos = static_cast<char *>(ptr);

for (BufferSizeType i = 0; i < num; i++)
for (BufferSizeType i = 0; i < num; ++i)
{
char one_byte = pos[0];
pos[0] = pos[7];
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkCellInterface.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename TPixelType, typename TCellTraits>
void
CellInterface<TPixelType, TCellTraits>::SetPointIdsContainer(const PointIdentifierContainerType & container)
{
for (unsigned int i = 0; i < container.Size(); i++)
for (unsigned int i = 0; i < container.Size(); ++i)
{
this->SetPointId(i, container[i]);
}
Expand Down
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ColorTable<TPixel>::UseGrayColors(unsigned int n)
// Converting from TPixel to RealType may introduce a rounding error, so do static_cast
constexpr auto max_value_converted =
static_cast<typename NumericTraits<TPixel>::RealType>(NumericTraits<TPixel>::max());
for (i = 0; i < m_NumberOfColors; i++)
for (i = 0; i < m_NumberOfColors; ++i)
{
typename NumericTraits<TPixel>::RealType realGray(minimum + i * delta);

Expand Down Expand Up @@ -182,7 +182,7 @@ ColorTable<TPixel>::UseHeatColors(unsigned int n)
// Converting from TPixel to RealType may introduce a rounding error, so do static_cast
constexpr auto max_value_converted =
static_cast<typename NumericTraits<TPixel>::RealType>(NumericTraits<TPixel>::max());
for (i = 0; i < n / 2.0; i++)
for (i = 0; i < n / 2.0; ++i)
{
//
// avoid overflow
Expand All @@ -200,7 +200,7 @@ ColorTable<TPixel>::UseHeatColors(unsigned int n)
m_ColorName[i] = name.str();
}

for (i = 0; i < n / 2; i++)
for (i = 0; i < n / 2; ++i)
{
typename NumericTraits<TPixel>::RealType rdouble(1.0 * scale + shift);
TPixel r(NumericTraits<TPixel>::max());
Expand Down Expand Up @@ -240,7 +240,7 @@ ColorTable<TPixel>::UseRandomColors(unsigned int n)
minimum = NumericTraits<TPixel>::ZeroValue();
maximum = NumericTraits<TPixel>::OneValue();
}
for (i = 0; i < n; i++)
for (i = 0; i < n; ++i)
{
r = static_cast<TPixel>(vnl_sample_uniform(minimum, maximum));
m_Color[i][0] = r;
Expand Down Expand Up @@ -346,7 +346,7 @@ ColorTable<TPixel>::GetClosestColorTableId(TPixel r, TPixel g, TPixel b)
double bestMatch = 0.0;
unsigned int bestMatchColor = 0;

for (unsigned int i = 0; i < m_NumberOfColors; i++)
for (unsigned int i = 0; i < m_NumberOfColors; ++i)
{
double match;
match = (r - (double)m_Color[i].GetRed()) * (r - (double)m_Color[i].GetRed());
Expand All @@ -368,7 +368,7 @@ ColorTable<TPixel>::PrintSelf(std::ostream & os, Indent indent) const
Superclass::PrintSelf(os, indent);

os << indent << "NumberOfColors = " << m_NumberOfColors << std::endl;
for (unsigned int i = 0; i < m_NumberOfColors; i++)
for (unsigned int i = 0; i < m_NumberOfColors; ++i)
{
os << indent << "ColorName[" << i << "] = " << m_ColorName[i] << ", "
<< "Color[" << i << "] = " << m_Color[i] << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ ConicShellInteriorExteriorSpatialFunction<VDimension, TInput>::PrintSelf(std::os

unsigned int i;
os << indent << "Origin: [";
for (i = 0; i < VDimension - 1; i++)
for (i = 0; i < VDimension - 1; ++i)
{
os << m_Origin[i] << ", ";
}
os << "]" << std::endl;

os << indent << "Gradient at origin: [";
for (i = 0; i < VDimension - 1; i++)
for (i = 0; i < VDimension - 1; ++i)
{
os << m_OriginGradient[i] << ", ";
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkConnectedComponentAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ setConnectivity(TIterator * it, bool fullyConnected = false)
// activate all neighbors that are face+edge+vertex
// connected to the current pixel. do not include the center pixel
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = 0; d < centerIndex * 2 + 1; d++)
for (unsigned int d = 0; d < centerIndex * 2 + 1; ++d)
{
offset = it->GetOffset(d);
it->ActivateOffset(offset);
Expand Down Expand Up @@ -83,7 +83,7 @@ setConnectivityPrevious(TIterator * it, bool fullyConnected = false)
// activate all neighbors that are face+edge+vertex
// connected to the current pixel. do not include the center pixel
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = 0; d < centerIndex; d++)
for (unsigned int d = 0; d < centerIndex; ++d)
{
offset = it->GetOffset(d);
it->ActivateOffset(offset);
Expand Down Expand Up @@ -118,7 +118,7 @@ setConnectivityLater(TIterator * it, bool fullyConnected = false)
// activate all neighbors that are face+edge+vertex
// connected to the current pixel. do not include the center pixel
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = centerIndex + 1; d < 2 * centerIndex + 1; d++)
for (unsigned int d = centerIndex + 1; d < 2 * centerIndex + 1; ++d)
{
offset = it->GetOffset(d);
it->ActivateOffset(offset);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkConstNeighborhoodIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ITK_TEMPLATE_EXPORT ConstNeighborhoodIterator
ConstNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
{
this->Initialize(radius, ptr, region);
for (DimensionValueType i = 0; i < Dimension; i++)
for (DimensionValueType i = 0; i < Dimension; ++i)
{
m_InBounds[i] = false;
}
Expand Down
Loading

0 comments on commit d7eea8a

Please sign in to comment.