Skip to content

Commit

Permalink
STYLE: Use MakeFilled, () or {}, instead of Vector(const ValueType &)
Browse files Browse the repository at this point in the history
A call to `MakeFilled<VectorType>(value)` expresses more clearly than
`Vector(const ValueType &)` that an _entire_ Vector is to be filled by
the specific scalar value.

Zero-initialization of a Vector is achieved in the most generic way, by
an empty pair of parentheses `()` or an empty pair of braces `{}`,
rather than by passing 0.0 to the explicit `Vector(const ValueType &)`
constructor.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Mar 10, 2022
1 parent aa2354e commit 82001f3
Show file tree
Hide file tree
Showing 58 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkAnnulusOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ITK_TEMPLATE_EXPORT AnnulusOperator : public NeighborhoodOperator<TPixel,
PixelType m_InteriorValue{ NumericTraits<PixelType>::ZeroValue() };
PixelType m_AnnulusValue{ NumericTraits<PixelType>::OneValue() };
PixelType m_ExteriorValue{ NumericTraits<PixelType>::ZeroValue() };
SpacingType m_Spacing{ 1.0 };
SpacingType m_Spacing{ MakeFilled<SpacingType>(1.0) };
};
} // namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
/** Origin, spacing, and direction in physical coordinates. This variables are
* protected for efficiency. They are referenced frequently by
* inner loop calculations. */
SpacingType m_Spacing{ 1.0 };
SpacingType m_Spacing{ MakeFilled<SpacingType>(1.0) };
PointType m_Origin{};
DirectionType m_Direction{ DirectionType::GetIdentity() };
DirectionType m_InverseDirection{ DirectionType::GetIdentity() };
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ class NumericTraits<FixedArray<T, D>>
#define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D) \
template <> \
ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::Zero = \
GENERIC_ARRAY<T, D>((T)(NumericTraits<T>::Zero)); \
MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::Zero); \
template <> \
ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::One = \
GENERIC_ARRAY<T, D>((T)(NumericTraits<T>::One));
MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::One);

//
// List here the array dimension specializations of these static
Expand Down
14 changes: 7 additions & 7 deletions Modules/Core/Common/include/itkNumericTraitsVectorPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,43 @@ class NumericTraits<Vector<T, D>>
static const Self
max(const Self &)
{
return Self(NumericTraits<T>::max());
return MakeFilled<Self>(NumericTraits<T>::max());
}

static const Self
min(const Self &)
{
return Self(NumericTraits<T>::min());
return MakeFilled<Self>(NumericTraits<T>::min());
}

static const Self
max()
{
return Self(NumericTraits<T>::max());
return MakeFilled<Self>(NumericTraits<T>::max());
}

static const Self
min()
{
return Self(NumericTraits<T>::min());
return MakeFilled<Self>(NumericTraits<T>::min());
}

static const Self
NonpositiveMin()
{
return Self(NumericTraits<T>::NonpositiveMin());
return MakeFilled<Self>(NumericTraits<T>::NonpositiveMin());
}

static const Self
ZeroValue()
{
return Self(NumericTraits<T>::ZeroValue());
return MakeFilled<Self>(NumericTraits<T>::ZeroValue());
}

static const Self
OneValue()
{
return Self(NumericTraits<T>::OneValue());
return MakeFilled<Self>(NumericTraits<T>::OneValue());
}

static const Self
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkImageBaseGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ CheckInvalidSpacingExceptions()

// Test exceptions
const SpacingType initialSpacing = imageBase->GetSpacing();
const SpacingType negativeSpacing(-1.0);
const SpacingType zeroSpacing(0.0);
const auto negativeSpacing = itk::MakeFilled<SpacingType>(-1.0);
const SpacingType zeroSpacing{};

#if !defined(ITK_LEGACY_REMOVE)
// Only a warning is displayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ GaussianDerivativeImageFunction<TInputImage, TOutput>::RecomputeGaussianKernel()
else
{
using SpacingType = typename TInputImage::SpacingType;
const SpacingType spacing = m_UseImageSpacing ? inputImage->GetSpacing() : SpacingType(1);
const SpacingType spacing = m_UseImageSpacing ? inputImage->GetSpacing() : MakeFilled<SpacingType>(1);

for (unsigned int direction = 0; direction < Self::ImageDimension; ++direction)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ RunLinearInterpolateTest()

const InterpolatedVectorType & vectorpixel = vectorinterpolator->Evaluate(point);

const InterpolatedVectorType expectedvector(expectedValue);
const auto expectedvector = itk::MakeFilled<InterpolatedVectorType>(expectedValue);

const AccumulatorType & errornorm = (expectedvector - vectorpixel).GetNorm();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ itkNearestNeighborInterpolateImageFunctionTest(int, char *[])

// test image of vectors
const InterpolatedVectorType vectorpixel = vectorinterpolator->Evaluate(point);
const InterpolatedVectorType expectedvector(expectedValue);
const auto expectedvector = itk::MakeFilled<InterpolatedVectorType>(expectedValue);
const double errornorm = (expectedvector - vectorpixel).GetNorm();

if (errornorm > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ImageMaskSpatialObject<TDimension, TPixel>::ComputeMyBoundingBox()
typename Superclass::ContinuousIndexType maxContinuousIndex{ minIndex + boundingBoxInIndexSpace.GetSize() };

// Allow a margin of half a pixel in each direction.
const typename SpatialObject<TDimension>::VectorType half_pixel_size{ 0.5 };
const auto half_pixel_size = MakeFilled<typename SpatialObject<TDimension>::VectorType>(0.5);
minContinuousIndex -= half_pixel_size;
maxContinuousIndex -= half_pixel_size;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ itkSpatialObjectToImageStatisticsCalculatorTest(int, char *[])
std::cout << "Sample mean = " << calculator->GetMean() << std::endl;
std::cout << "Sample covariance = " << calculator->GetCovarianceMatrix();

if (calculator->GetMean() != CalculatorType::VectorType(255) ||
if (calculator->GetMean() != itk::MakeFilled<CalculatorType::VectorType>(255) ||
itk::Math::NotAlmostEquals(calculator->GetCovarianceMatrix()[0][0],
itk::NumericTraits<CalculatorType::MatrixType::ValueType>::ZeroValue()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ BSplineTransformInitializer<TTransform, TImage>::InitializeTransform() const
{
minAngle[d] = NumericTraits<double>::max();

VectorType vectorAxis(0.0);
VectorType vectorAxis{};
vectorAxis[d] = 1.0;

for (unsigned int i = 0; i < SpaceDimension; ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ itkComposeScaleSkewVersor3DTransformTest(int, char *[])

auto transform = TransformType::New();

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -109,7 +109,7 @@ itkComposeScaleSkewVersor3DTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -267,7 +267,7 @@ itkComposeScaleSkewVersor3DTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -343,7 +343,7 @@ itkComposeScaleSkewVersor3DTransformTest(int, char *[])
std::cout << " Exercise the SetIdentity() method " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -396,8 +396,8 @@ itkComposeScaleSkewVersor3DTransformTest(int, char *[])
std::cout << " Exercise the Scaling methods " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);
const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees
transform->SetRotation(axis, angle);

TransformType::InputPointType center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ itkScaleSkewVersor3DTransformTest(int, char *[])

auto transform = TransformType::New();

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -112,7 +112,7 @@ itkScaleSkewVersor3DTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -270,7 +270,7 @@ itkScaleSkewVersor3DTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -409,7 +409,7 @@ itkScaleSkewVersor3DTransformTest(int, char *[])
std::cout << " Exercise the SetIdentity() method " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -464,7 +464,7 @@ itkScaleSkewVersor3DTransformTest(int, char *[])
std::cout << " Exercise the Scaling methods " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Transform/test/itkScaleVersor3DTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ itkScaleVersor3DTransformTest(int, char *[])

transform->Print(std::cout);

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -126,7 +126,7 @@ itkScaleVersor3DTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -284,7 +284,7 @@ itkScaleVersor3DTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -421,7 +421,7 @@ itkScaleVersor3DTransformTest(int, char *[])
std::cout << " Exercise the SetIdentity() method " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -470,7 +470,7 @@ itkScaleVersor3DTransformTest(int, char *[])
std::cout << " Exercise the Scaling methods " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Transform/test/itkSimilarity3DTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ itkSimilarity3DTransformTest(int, char *[])
return EXIT_FAILURE;
}

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -114,7 +114,7 @@ itkSimilarity3DTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -270,7 +270,7 @@ itkSimilarity3DTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -396,7 +396,7 @@ itkSimilarity3DTransformTest(int, char *[])
std::cout << " Exercise the SetIdentity() method " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -443,7 +443,7 @@ itkSimilarity3DTransformTest(int, char *[])
std::cout << " Exercise the Scaling methods " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Transform/test/itkVersorRigid3DTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ itkVersorRigid3DTransformTest(int, char *[])

auto transform = TransformType::New();

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -106,7 +106,7 @@ itkVersorRigid3DTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -264,7 +264,7 @@ itkVersorRigid3DTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down Expand Up @@ -385,7 +385,7 @@ itkVersorRigid3DTransformTest(int, char *[])
std::cout << " Exercise the SetIdentity() method " << std::endl;
auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Transform/test/itkVersorTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ itkVersorTransformTest(int, char *[])

auto transform = TransformType::New();

VectorType axis(1.5);
auto axis = itk::MakeFilled<VectorType>(1.5);

ValueType angle = 120.0 * std::atan(1.0) / 45.0;

Expand Down Expand Up @@ -103,7 +103,7 @@ itkVersorTransformTest(int, char *[])

auto rotation = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 120.0; // turn 120 degrees

Expand Down Expand Up @@ -261,7 +261,7 @@ itkVersorTransformTest(int, char *[])

auto transform = TransformType::New();

itk::Vector<double, 3> axis(1);
auto axis = itk::MakeFilled<itk::Vector<double, 3>>(1);

const double angle = (std::atan(1.0) / 45.0) * 30.0; // turn 30 degrees

Expand Down
Loading

0 comments on commit 82001f3

Please sign in to comment.