Skip to content

Commit 3e6e8ac

Browse files
committed
STYLE: Manual review of .Fill([0-9]*) patterns
Identified code style improvements based on manually reviewing use of .Fill for assignment of values when initialization could have been used.
1 parent 346a7bf commit 3e6e8ac

36 files changed

+228
-373
lines changed

Modules/Core/Common/include/itkConnectedComponentAlgorithm.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ template <typename TIterator>
2727
TIterator *
2828
setConnectivity(TIterator * it, bool fullyConnected = false)
2929
{
30-
typename TIterator::OffsetType offset;
30+
3131
it->ClearActiveList();
3232
if (!fullyConnected)
3333
{
3434
// only activate the neighbors that are face connected
3535
// to the current pixel. do not include the center pixel
36-
offset.Fill(0);
36+
typename TIterator::OffsetType offset{};
3737
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
3838
{
3939
offset[d] = -1;
@@ -50,11 +50,11 @@ setConnectivity(TIterator * it, bool fullyConnected = false)
5050
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
5151
for (unsigned int d = 0; d < centerIndex * 2 + 1; ++d)
5252
{
53-
offset = it->GetOffset(d);
53+
typename TIterator::OffsetType offset = it->GetOffset(d);
5454
it->ActivateOffset(offset);
5555
}
56-
offset.Fill(0);
57-
it->DeactivateOffset(offset);
56+
typename TIterator::OffsetType offset_zeros{};
57+
it->DeactivateOffset(offset_zeros);
5858
}
5959
return it;
6060
}
@@ -64,13 +64,13 @@ TIterator *
6464
setConnectivityPrevious(TIterator * it, bool fullyConnected = false)
6565
{
6666
// activate the "previous" neighbours
67-
typename TIterator::OffsetType offset;
67+
6868
it->ClearActiveList();
6969
if (!fullyConnected)
7070
{
7171
// only activate the neighbors that are face connected
7272
// to the current pixel. do not include the center pixel
73-
offset.Fill(0);
73+
typename TIterator::OffsetType offset{};
7474
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
7575
{
7676
offset[d] = -1;
@@ -85,11 +85,11 @@ setConnectivityPrevious(TIterator * it, bool fullyConnected = false)
8585
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
8686
for (unsigned int d = 0; d < centerIndex; ++d)
8787
{
88-
offset = it->GetOffset(d);
88+
typename TIterator::OffsetType offset = it->GetOffset(d);
8989
it->ActivateOffset(offset);
9090
}
91-
offset.Fill(0);
92-
it->DeactivateOffset(offset);
91+
typename TIterator::OffsetType offset_zeros{};
92+
it->DeactivateOffset(offset_zeros);
9393
}
9494
return it;
9595
}
@@ -99,13 +99,13 @@ TIterator *
9999
setConnectivityLater(TIterator * it, bool fullyConnected = false)
100100
{
101101
// activate the "later" neighbours
102-
typename TIterator::OffsetType offset;
102+
103103
it->ClearActiveList();
104104
if (!fullyConnected)
105105
{
106106
// only activate the neighbors that are face connected
107107
// to the current pixel. do not include the center pixel
108-
offset.Fill(0);
108+
typename TIterator::OffsetType offset{};
109109
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
110110
{
111111
offset[d] = 1;
@@ -120,11 +120,11 @@ setConnectivityLater(TIterator * it, bool fullyConnected = false)
120120
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
121121
for (unsigned int d = centerIndex + 1; d < 2 * centerIndex + 1; ++d)
122122
{
123-
offset = it->GetOffset(d);
123+
typename TIterator::OffsetType offset = it->GetOffset(d);
124124
it->ActivateOffset(offset);
125125
}
126-
offset.Fill(0);
127-
it->DeactivateOffset(offset);
126+
typename TIterator::OffsetType offset_zeros{};
127+
it->DeactivateOffset(offset_zeros);
128128
}
129129
return it;
130130
}

Modules/Core/Common/include/itkCrossHelper.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,14 @@ class CrossHelper
4949
VectorType
5050
operator()(const VectorType & iU, const VectorType & iV) const
5151
{
52-
VectorType oCross;
52+
VectorType oCross{};
5353

5454
if constexpr (Dimension > 2)
5555
{
5656
oCross[0] = iU[1] * iV[2] - iV[1] * iU[2];
5757
oCross[1] = iV[0] * iU[2] - iU[0] * iV[2];
5858
oCross[2] = iU[0] * iV[1] - iV[0] * iU[1];
59-
60-
if constexpr (Dimension > 3)
61-
{
62-
for (unsigned int dim = 3; dim < Dimension; ++dim)
63-
{
64-
oCross[dim] = 0.0;
65-
}
66-
}
67-
}
68-
else
69-
{
70-
oCross.Fill(0.);
7159
}
72-
7360
return oCross;
7461
}
7562
};

Modules/Core/Common/include/itkImageAlgorithm.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,11 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType &
240240
}
241241

242242
using InputPointType = Point<SpacePrecisionType, InputImageType::ImageDimension>;
243+
const InputPointType inputPoint =
244+
inputImage->template TransformContinuousIndexToPhysicalPoint<SpacePrecisionType, SpacePrecisionType>(
245+
currentInputCornerIndex);
243246
using OutputPointType = Point<SpacePrecisionType, OutputImageType::ImageDimension>;
244-
InputPointType inputPoint;
245-
OutputPointType outputPoint;
246-
inputImage->TransformContinuousIndexToPhysicalPoint(currentInputCornerIndex, inputPoint);
247+
OutputPointType outputPoint{};
247248
if (transform != nullptr)
248249
{
249250
outputPoint = transform->TransformPoint(inputPoint);
@@ -253,7 +254,6 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType &
253254
// if InputDimension < OutputDimension then embed point in Output space.
254255
// else if InputDimension == OutputDimension copy the points.
255256
// else if InputDimension > OutputDimension project the point to first N-Dimensions of Output space.
256-
outputPoint.Fill(0.0);
257257
for (unsigned int d = 0; d < std::min(inputPoint.GetPointDimension(), outputPoint.GetPointDimension()); ++d)
258258
{
259259
outputPoint[d] = inputPoint[d];

Modules/Core/Common/include/itkImageIORegion.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,8 @@ class ImageIORegionAdaptor
251251
ImageRegionType & outImageRegion,
252252
const ImageIndexType & largestRegionIndex)
253253
{
254-
ImageSizeType size;
255-
ImageIndexType index;
256-
257-
size.Fill(1); // initialize with default values
258-
index.Fill(0);
254+
auto size = MakeFilled<ImageSizeType>(1); // initialize with default values
255+
ImageIndexType index{};
259256

260257
//
261258
// The ImageRegion and ImageIORegion objects may have different dimensions.

Modules/Core/Common/include/itkImageRegion.hxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,9 @@ ImageRegion<VImageDimension>::Slice(const unsigned int dim) const -> SliceRegion
231231
"The dimension to remove: " << dim << " is greater than the dimension of the image: " << VImageDimension);
232232
}
233233

234-
Index<SliceDimension> sliceIndex;
235-
Size<SliceDimension> sliceSize;
236-
237-
sliceIndex.Fill(0);
238-
sliceSize.Fill(0);
239-
unsigned int ii = 0;
234+
Index<SliceDimension> sliceIndex{};
235+
Size<SliceDimension> sliceSize{};
236+
unsigned int ii = 0;
240237
for (unsigned int i = 0; i < VImageDimension; ++i)
241238
{
242239
if (i != dim)

Modules/Core/Common/include/itkNeighborhood.hxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ template <typename TPixel, unsigned int VDimension, typename TContainer>
7070
void
7171
Neighborhood<TPixel, VDimension, TContainer>::SetRadius(const SizeValueType s)
7272
{
73-
SizeType k;
74-
75-
for (DimensionValueType i = 0; i < VDimension; ++i)
76-
{
77-
k[i] = s;
78-
}
73+
auto k = MakeFilled<SizeType>(s);
7974
this->SetRadius(k);
8075
}
8176

Modules/Core/Common/include/itkTriangleCell.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,10 @@ TriangleCell<TCellInterface>::ComputeBarycenter(CoordinateType * iWeights, Point
295295
p[i] = iPoints->GetElement(m_PointIds[i]);
296296
}
297297

298-
PointType oP;
298+
PointType oP{};
299299

300300
if (sum_weights != 0.)
301301
{
302-
oP.Fill(0.);
303302
for (i = 0; i < 3; ++i)
304303
{
305304
oP += p[i].GetVectorFromOrigin() * iWeights[i] / sum_weights;

Modules/Core/Common/include/itkTriangleHelper.hxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,11 @@ TriangleHelper<TPoint>::ComputeBarycenter(const CoordinateType & iA1,
106106
const CoordinateType & iA3,
107107
const PointType & iP3) -> PointType
108108
{
109-
PointType oPt;
110-
111109
CoordinateType total = iA1 + iA2 + iA3;
112-
110+
PointType oPt{};
113111
if (Math::AlmostEquals(total, CoordinateType{}))
114112
{
115113
// in such case there is no barycenter;
116-
oPt.Fill(0.);
117114
return oPt;
118115
}
119116

0 commit comments

Comments
 (0)