Skip to content

Commit 787267e

Browse files
hjmjohnsonclaude
andcommitted
STYLE: Use {}-initialization for zero-filled FixedArray-derived types
Using find_declare_then_init.py --pattern fill_zero, replaced the two-line pattern: Type var; var.Fill(0); with the single-line value-initialization: Type var{}; {}-initialization zero-initializes all elements for FixedArray and its subclasses (IndexType, SizeType, SpacingType, PointType, VectorType, etc.), which is the canonical C++ idiom for zero-initialization and preserves the correct derived type (unlike ::Filled(0) which returns the base class). Applies to 25 files in Modules/ (excluding Remote/, BridgeOpenCV, BridgeVXL). Follow-up to commit 427df79 by hjmjohnson "STYLE: Use {}-initialization for zero-filled FixedArray-derived types" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5305a6f commit 787267e

25 files changed

Lines changed: 42 additions & 82 deletions

Modules/Core/ImageFunction/include/itkGaussianInterpolateImageFunction.hxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ GaussianInterpolateImageFunction<TImageType, TCoordinate>::EvaluateAtContinuousI
109109

110110
RealType sum_me = 0.0;
111111
RealType sum_m = 0.0;
112-
ArrayType dsum_me;
113-
ArrayType dsum_m;
114-
ArrayType dw;
112+
ArrayType dsum_me{};
113+
ArrayType dsum_m{};
114+
ArrayType dw{};
115115

116-
dsum_m.Fill(0.0);
117-
dsum_me.Fill(0.0);
118-
dw.Fill(0.0);
119116

120117
for (ImageRegionConstIteratorWithIndex It(this->GetInputImage(), region); !It.IsAtEnd(); ++It)
121118
{

Modules/Core/ImageFunction/test/itkGaussianInterpolateImageFunctionTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ itkGaussianInterpolateImageFunctionTest(int, char *[])
4949
image->SetRegions(region);
5050
image->Allocate();
5151

52-
ImageType::PointType origin;
52+
ImageType::PointType origin{};
5353
auto spacing = itk::MakeFilled<ImageType::SpacingType>(1.0);
5454

55-
origin.Fill(0.0);
5655

5756
image->SetOrigin(origin);
5857
image->SetSpacing(spacing);

Modules/Core/ImageFunction/test/itkNearestNeighborInterpolateImageFunctionTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ itkNearestNeighborInterpolateImageFunctionTest(int, char *[])
7171
variablevectorimage->SetRegions(region);
7272
variablevectorimage->Allocate();
7373

74-
ImageType::PointType origin;
74+
ImageType::PointType origin{};
7575
auto spacing = itk::MakeFilled<ImageType::SpacingType>(1.0);
7676

77-
origin.Fill(0.0);
7877

7978
image->SetOrigin(origin);
8079
image->SetSpacing(spacing);

Modules/Filtering/DisplacementField/test/itkComposeDisplacementFieldsImageFilterTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ itkComposeDisplacementFieldsImageFilterTest(int, char *[])
2828
using DisplacementFieldType = itk::Image<VectorType, ImageDimension>;
2929

3030
// Create a displacement field
31-
DisplacementFieldType::PointType origin;
31+
DisplacementFieldType::PointType origin{};
3232
auto spacing = itk::MakeFilled<DisplacementFieldType::SpacingType>(0.5);
3333
auto size = itk::MakeFilled<DisplacementFieldType::SizeType>(100);
3434
DisplacementFieldType::DirectionType direction;
3535

3636
direction.SetIdentity();
37-
origin.Fill(0.0);
3837

3938
auto ones = itk::MakeFilled<VectorType>(1);
4039

Modules/Filtering/DisplacementField/test/itkDisplacementFieldToBSplineImageFilterTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ itkDisplacementFieldToBSplineImageFilterTest(int, char *[])
2929
using PointSetType = itk::PointSet<VectorType, ImageDimension>;
3030

3131
// Create a displacement field
32-
DisplacementFieldType::PointType origin;
32+
DisplacementFieldType::PointType origin{};
3333
auto spacing = itk::MakeFilled<DisplacementFieldType::SpacingType>(0.5);
3434
auto size = itk::MakeFilled<DisplacementFieldType::SizeType>(100);
3535
DisplacementFieldType::DirectionType direction;
3636

3737
direction.SetIdentity();
38-
origin.Fill(0.0);
3938

4039
auto ones = itk::MakeFilled<VectorType>(1);
4140

Modules/Filtering/DisplacementField/test/itkInvertDisplacementFieldImageFilterTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ itkInvertDisplacementFieldImageFilterTest(int argc, char * argv[])
3737
using DisplacementFieldType = itk::Image<VectorType, ImageDimension>;
3838

3939
// Create a displacement field
40-
DisplacementFieldType::PointType origin;
40+
DisplacementFieldType::PointType origin{};
4141
auto spacing = itk::MakeFilled<DisplacementFieldType::SpacingType>(0.5);
4242
auto size = itk::MakeFilled<DisplacementFieldType::SizeType>(100);
4343
DisplacementFieldType::DirectionType direction;
4444

4545
direction.SetIdentity();
46-
origin.Fill(0.0);
4746

4847
auto ones = itk::MakeFilled<VectorType>(1);
4948

Modules/Filtering/ImageGradient/test/itkGradientRecursiveGaussianFilterTest3.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ itkGradientRecursiveGaussianFilterTest3(int argc, char * argv[])
200200
using myImageVector1DType = itk::Image<myVector1DType, myDimension>;
201201

202202
myGradImage1DType::Pointer vector1DGradImage = nullptr;
203-
myVector1DType vector1Dborder;
203+
myVector1DType vector1Dborder{};
204204
auto vector1Dfill = itk::MakeFilled<myVector1DType>(100.0);
205-
vector1Dborder.Fill(0.0);
206205
int runResult = itkGradientRecursiveGaussianFilterTest3Run<myImageVector1DType, myGradImage1DType, myComponents1D>(
207206
vector1Dborder, vector1Dfill, vector1DGradImage, argv[1]);
208207
if (runResult == EXIT_FAILURE)

Modules/Filtering/ImageGrid/test/itkBSplineControlPointImageFunctionTest.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ itkBSplineControlPointImageFunctionTest(int, char *[])
3737

3838
auto size = itk::MakeFilled<VectorImageType::SizeType>(4);
3939
auto spacing = itk::MakeFilled<VectorImageType::SpacingType>(1.0);
40-
VectorImageType::PointType origin;
40+
VectorImageType::PointType origin{};
4141

42-
origin.Fill(0.0);
4342
phiLattice->SetOrigin(origin);
4443
phiLattice->SetSpacing(spacing);
4544
phiLattice->SetRegions(size);
@@ -48,9 +47,8 @@ itkBSplineControlPointImageFunctionTest(int, char *[])
4847
// To create the specified function, the first and last control points have
4948
// a value of 1.0;
5049

51-
VectorImageType::IndexType index;
50+
VectorImageType::IndexType index{};
5251
auto value = itk::MakeFilled<VectorImageType::PixelType>(1.0);
53-
index.Fill(0);
5452
phiLattice->SetPixel(index, value);
5553
index.Fill(3);
5654
value.Fill(1.0);

Modules/Filtering/Path/include/itkChainCodeToFourierSeriesPathFilter.hxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ ChainCodeToFourierSeriesPathFilter<TInputChainCodePath, TOutputFourierSeriesPath
6464
for (unsigned int n = 0; n < numHarmonics; ++n)
6565
{
6666
auto index = inputPtr->GetStart();
67-
VectorType cosCoefficient;
68-
cosCoefficient.Fill(0.0);
69-
VectorType sinCoefficient;
70-
sinCoefficient.Fill(0.0);
67+
VectorType cosCoefficient{};
68+
VectorType sinCoefficient{};
7169

7270
for (InputPathInputType step = 0; step < numSteps; ++step)
7371
{

Modules/Filtering/Path/include/itkFourierSeriesPath.hxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ auto
2727
FourierSeriesPath<VDimension>::Evaluate(const InputType & input) const -> OutputType
2828
{
2929
InputType theta;
30-
OutputType output;
30+
OutputType output{};
3131
const int numHarmonics = m_CosCoefficients->Size();
32-
output.Fill(0);
3332

3433
const double PI = 4.0 * std::atan(1.0);
3534

@@ -54,9 +53,8 @@ auto
5453
FourierSeriesPath<VDimension>::EvaluateDerivative(const InputType & input) const -> VectorType
5554
{
5655
InputType theta;
57-
VectorType output;
56+
VectorType output{};
5857
const int numHarmonics = m_CosCoefficients->Size();
59-
output.Fill(0);
6058

6159
const double PI = 4.0 * std::atan(1.0);
6260

0 commit comments

Comments
 (0)