Skip to content

Commit

Permalink
STYLE: Manual review of .Fill([0-9]*) patterns
Browse files Browse the repository at this point in the history
Identified code style improvements based on manually
reviewing use of .Fill for assignment of values
when initialization could have been used.
  • Loading branch information
hjmjohnson committed Dec 10, 2024
1 parent f7508c0 commit 9bc3ea0
Show file tree
Hide file tree
Showing 36 changed files with 228 additions and 373 deletions.
30 changes: 15 additions & 15 deletions Modules/Core/Common/include/itkConnectedComponentAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ template <typename TIterator>
TIterator *
setConnectivity(TIterator * it, bool fullyConnected = false)
{
typename TIterator::OffsetType offset;

it->ClearActiveList();
if (!fullyConnected)
{
// only activate the neighbors that are face connected
// to the current pixel. do not include the center pixel
offset.Fill(0);
typename TIterator::OffsetType offset{};
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
{
offset[d] = -1;
Expand All @@ -50,11 +50,11 @@ setConnectivity(TIterator * it, bool fullyConnected = false)
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = 0; d < centerIndex * 2 + 1; ++d)
{
offset = it->GetOffset(d);
typename TIterator::OffsetType offset = it->GetOffset(d);
it->ActivateOffset(offset);
}
offset.Fill(0);
it->DeactivateOffset(offset);
typename TIterator::OffsetType offset_zeros{};
it->DeactivateOffset(offset_zeros);
}
return it;
}
Expand All @@ -64,13 +64,13 @@ TIterator *
setConnectivityPrevious(TIterator * it, bool fullyConnected = false)
{
// activate the "previous" neighbours
typename TIterator::OffsetType offset;

it->ClearActiveList();
if (!fullyConnected)
{
// only activate the neighbors that are face connected
// to the current pixel. do not include the center pixel
offset.Fill(0);
typename TIterator::OffsetType offset{};
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
{
offset[d] = -1;
Expand All @@ -85,11 +85,11 @@ setConnectivityPrevious(TIterator * it, bool fullyConnected = false)
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = 0; d < centerIndex; ++d)
{
offset = it->GetOffset(d);
typename TIterator::OffsetType offset = it->GetOffset(d);
it->ActivateOffset(offset);
}
offset.Fill(0);
it->DeactivateOffset(offset);
typename TIterator::OffsetType offset_zeros{};
it->DeactivateOffset(offset_zeros);
}
return it;
}
Expand All @@ -99,13 +99,13 @@ TIterator *
setConnectivityLater(TIterator * it, bool fullyConnected = false)
{
// activate the "later" neighbours
typename TIterator::OffsetType offset;

it->ClearActiveList();
if (!fullyConnected)
{
// only activate the neighbors that are face connected
// to the current pixel. do not include the center pixel
offset.Fill(0);
typename TIterator::OffsetType offset{};
for (unsigned int d = 0; d < TIterator::Dimension; ++d)
{
offset[d] = 1;
Expand All @@ -120,11 +120,11 @@ setConnectivityLater(TIterator * it, bool fullyConnected = false)
unsigned int centerIndex = it->GetCenterNeighborhoodIndex();
for (unsigned int d = centerIndex + 1; d < 2 * centerIndex + 1; ++d)
{
offset = it->GetOffset(d);
typename TIterator::OffsetType offset = it->GetOffset(d);
it->ActivateOffset(offset);
}
offset.Fill(0);
it->DeactivateOffset(offset);
typename TIterator::OffsetType offset_zeros{};
it->DeactivateOffset(offset_zeros);
}
return it;
}
Expand Down
15 changes: 1 addition & 14 deletions Modules/Core/Common/include/itkCrossHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,14 @@ class CrossHelper
VectorType
operator()(const VectorType & iU, const VectorType & iV) const
{
VectorType oCross;
VectorType oCross{};

if constexpr (Dimension > 2)
{
oCross[0] = iU[1] * iV[2] - iV[1] * iU[2];
oCross[1] = iV[0] * iU[2] - iU[0] * iV[2];
oCross[2] = iU[0] * iV[1] - iV[0] * iU[1];

if constexpr (Dimension > 3)
{
for (unsigned int dim = 3; dim < Dimension; ++dim)
{
oCross[dim] = 0.0;
}
}
}
else
{
oCross.Fill(0.);
}

return oCross;
}
};
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkImageAlgorithm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType &
}

using InputPointType = Point<SpacePrecisionType, InputImageType::ImageDimension>;
const InputPointType inputPoint =
inputImage->template TransformContinuousIndexToPhysicalPoint<SpacePrecisionType, SpacePrecisionType>(
currentInputCornerIndex);
using OutputPointType = Point<SpacePrecisionType, OutputImageType::ImageDimension>;
InputPointType inputPoint;
OutputPointType outputPoint;
inputImage->TransformContinuousIndexToPhysicalPoint(currentInputCornerIndex, inputPoint);
OutputPointType outputPoint{};
if (transform != nullptr)
{
outputPoint = transform->TransformPoint(inputPoint);
Expand All @@ -253,7 +254,6 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType &
// if InputDimension < OutputDimension then embed point in Output space.
// else if InputDimension == OutputDimension copy the points.
// else if InputDimension > OutputDimension project the point to first N-Dimensions of Output space.
outputPoint.Fill(0.0);
for (unsigned int d = 0; d < std::min(inputPoint.GetPointDimension(), outputPoint.GetPointDimension()); ++d)
{
outputPoint[d] = inputPoint[d];
Expand Down
7 changes: 2 additions & 5 deletions Modules/Core/Common/include/itkImageIORegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,8 @@ class ImageIORegionAdaptor
ImageRegionType & outImageRegion,
const ImageIndexType & largestRegionIndex)
{
ImageSizeType size;
ImageIndexType index;

size.Fill(1); // initialize with default values
index.Fill(0);
auto size = MakeFilled<ImageSizeType>(1); // initialize with default values
ImageIndexType index{};

//
// The ImageRegion and ImageIORegion objects may have different dimensions.
Expand Down
9 changes: 3 additions & 6 deletions Modules/Core/Common/include/itkImageRegion.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,9 @@ ImageRegion<VImageDimension>::Slice(const unsigned int dim) const -> SliceRegion
"The dimension to remove: " << dim << " is greater than the dimension of the image: " << VImageDimension);
}

Index<SliceDimension> sliceIndex;
Size<SliceDimension> sliceSize;

sliceIndex.Fill(0);
sliceSize.Fill(0);
unsigned int ii = 0;
Index<SliceDimension> sliceIndex{};
Size<SliceDimension> sliceSize{};
unsigned int ii = 0;
for (unsigned int i = 0; i < VImageDimension; ++i)
{
if (i != dim)
Expand Down
7 changes: 1 addition & 6 deletions Modules/Core/Common/include/itkNeighborhood.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ template <typename TPixel, unsigned int VDimension, typename TContainer>
void
Neighborhood<TPixel, VDimension, TContainer>::SetRadius(const SizeValueType s)
{
SizeType k;

for (DimensionValueType i = 0; i < VDimension; ++i)
{
k[i] = s;
}
auto k = MakeFilled<SizeType>(s);
this->SetRadius(k);
}

Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/include/itkTriangleCell.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,10 @@ TriangleCell<TCellInterface>::ComputeBarycenter(CoordinateType * iWeights, Point
p[i] = iPoints->GetElement(m_PointIds[i]);
}

PointType oP;
PointType oP{};

if (sum_weights != 0.)
{
oP.Fill(0.);
for (i = 0; i < 3; ++i)
{
oP += p[i].GetVectorFromOrigin() * iWeights[i] / sum_weights;
Expand Down
5 changes: 1 addition & 4 deletions Modules/Core/Common/include/itkTriangleHelper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ TriangleHelper<TPoint>::ComputeBarycenter(const CoordinateType & iA1,
const CoordinateType & iA3,
const PointType & iP3) -> PointType
{
PointType oPt;

CoordinateType total = iA1 + iA2 + iA3;

PointType oPt{};
if (Math::AlmostEquals(total, CoordinateType{}))
{
// in such case there is no barycenter;
oPt.Fill(0.);
return oPt;
}

Expand Down
Loading

0 comments on commit 9bc3ea0

Please sign in to comment.