Skip to content

Commit

Permalink
STYLE: Replace Fill calls with itk::MakeFilled in tests
Browse files Browse the repository at this point in the history
Replaced code of the form

    T var;
    var.Fill(x);

with `auto var = itk::MakeFilled<T>(x);`

Following C++ Core Guidelines, Oct 3, 2024, "Always initialize an object",
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*)[ ]+(\w+);[\r\n]+\1\3\.Fill\(
    Replace with: $1auto $3 = itk::MakeFilled<$2>\(
    Filters: itk*Test*.cxx
    [v] Match case
    (*) Regular expression
  • Loading branch information
N-Dekker committed Oct 22, 2024
1 parent 19c7b5a commit c87f0da
Show file tree
Hide file tree
Showing 146 changed files with 340 additions and 606 deletions.
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkAdaptorComparisonTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ itkAdaptorComparisonTest(int, char *[])
vector_image->SetRegions(region);
vector_image->Allocate();

VectorImageType::PixelType initialVectorValue;
initialVectorValue.Fill(1.2345); // arbitrary value;
auto initialVectorValue = itk::MakeFilled<VectorImageType::PixelType>(1.2345); // arbitrary value;
vector_image->FillBuffer(initialVectorValue);

// Time trials
Expand Down
9 changes: 4 additions & 5 deletions Modules/Core/Common/test/itkAggregateTypesGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,10 @@ class CommonIndexOffsetMathOps

//============ Test Copy with Round/Cast Type ====================================
{
AggregateType known3s{ { 3, 3, 3, 3 } };
AggregateType threes{};
AggregateType known4s{ { 4, 4, 4, 4 } };
itk::Point<double, 4> p1;
p1.Fill(3.5);
AggregateType known3s{ { 3, 3, 3, 3 } };
AggregateType threes{};
AggregateType known4s{ { 4, 4, 4, 4 } };
auto p1 = itk::MakeFilled<itk::Point<double, 4>>(3.5);
threes.CopyWithRound(p1);
ITK_EXPECT_VECTOR_NEAR(threes, known4s, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ itkConstNeighborhoodIteratorTest(int, char *[])
printnb<itk::ConstNeighborhoodIterator<TestImageType>>(ra_it, false);

println("Adding [1, 1, 1, 1]");
OffsetType a_off;
a_off.Fill(1);
auto a_off = itk::MakeFilled<OffsetType>(1);
ra_it += a_off;
printnb<itk::ConstNeighborhoodIterator<TestImageType>>(ra_it, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ itkConstNeighborhoodIteratorWithOnlyIndexTestRun()
ra_it.SetLocation(loc);

std::cout << "Adding [1, 1, 1, 1]" << std::endl;
OffsetType a_off;
a_off.Fill(1);
auto a_off = itk::MakeFilled<OffsetType>(1);
ra_it += a_off;
for (unsigned int i = 0; i < 4; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ ComputeOffset(TImage * image, unsigned int count, unsigned int repeat)
typename TImage::OffsetValueType offset = 0;
typename TImage::OffsetValueType accum = 0;
typename TImage::IndexType index;
typename TImage::OffsetType indexIncr;
indexIncr.Fill(1);
auto indexIncr = itk::MakeFilled<typename TImage::OffsetType>(1);

for (unsigned int j = 0; j < repeat; ++j)
{
Expand All @@ -86,8 +85,7 @@ ComputeFastOffset(TImage * image, unsigned int count, unsigned int repeat)
typename TImage::OffsetValueType offset = 0;
typename TImage::OffsetValueType accum = 0;
typename TImage::IndexType index;
typename TImage::OffsetType indexIncr;
indexIncr.Fill(1);
auto indexIncr = itk::MakeFilled<typename TImage::OffsetType>(1);

const typename TImage::OffsetValueType * offsetTable = image->GetOffsetTable();

Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkImageIteratorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ itkImageIteratorTest(int, char *[])
o3->SetSpacing(spacing3D);

o3->Allocate();
itk::Vector<unsigned short, 5> fillValue;
fillValue.Fill(itk::NumericTraits<unsigned short>::max());
auto fillValue = itk::MakeFilled<itk::Vector<unsigned short, 5>>(itk::NumericTraits<unsigned short>::max());
o3->FillBuffer(fillValue);

std::cout << "Setting/Getting a pixel" << std::endl;
Expand Down
24 changes: 8 additions & 16 deletions Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<char,4>, 3 > " << std::endl;
using VC = itk::Vector<char, 4>;
VC vc;
vc.Fill(127);
auto vc = itk::MakeFilled<VC>(127);
itkImageIteratorWithIndexTestIteratorTester<VC> TesterVC(vc);
if (TesterVC.TestIterator() == false)
{
Expand All @@ -282,8 +281,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<unsigned char,4>, 3 > " << std::endl;
using VUC = itk::Vector<unsigned char, 4>;
VUC vuc;
vuc.Fill(10);
auto vuc = itk::MakeFilled<VUC>(10);
itkImageIteratorWithIndexTestIteratorTester<VUC> TesterVUC(vuc);
if (TesterVUC.TestIterator() == false)
{
Expand All @@ -300,8 +298,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<short,4>, 3 > " << std::endl;
using VS = itk::Vector<short, 4>;
VS vs;
vs.Fill(10);
auto vs = itk::MakeFilled<VS>(10);
itkImageIteratorWithIndexTestIteratorTester<VS> TesterVS(vs);
if (TesterVS.TestIterator() == false)
{
Expand All @@ -318,8 +315,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<unsigned short,4>, 3 > " << std::endl;
using VUS = itk::Vector<unsigned short, 4>;
VUS vus;
vus.Fill(10);
auto vus = itk::MakeFilled<VUS>(10);
itkImageIteratorWithIndexTestIteratorTester<VUS> TesterVUS(vus);
if (TesterVUS.TestIterator() == false)
{
Expand All @@ -336,8 +332,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<int,4>, 3 > " << std::endl;
using VI = itk::Vector<int, 4>;
VI vi;
vi.Fill(10);
auto vi = itk::MakeFilled<VI>(10);
itkImageIteratorWithIndexTestIteratorTester<VI> TesterVI(vi);
if (TesterVI.TestIterator() == false)
{
Expand All @@ -354,8 +349,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<unsigned int,4>, 3 > " << std::endl;
using VUI = itk::Vector<unsigned int, 4>;
VUI vui;
vui.Fill(10);
auto vui = itk::MakeFilled<VUI>(10);
itkImageIteratorWithIndexTestIteratorTester<VUI> TesterVUI(vui);
if (TesterVUI.TestIterator() == false)
{
Expand All @@ -372,8 +366,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<float,4>, 3 > " << std::endl;
using VF = itk::Vector<float, 4>;
VF vf;
vf.Fill(10);
auto vf = itk::MakeFilled<VF>(10);
itkImageIteratorWithIndexTestIteratorTester<VF> TesterVF(vf);
if (TesterVF.TestIterator() == false)
{
Expand All @@ -390,8 +383,7 @@ itkImageIteratorWithIndexTest(int, char *[])

std::cout << "Testing with Image< itk::Vector<double,4>, 3 > " << std::endl;
using VD = itk::Vector<double, 4>;
VD vd;
vd.Fill(10);
auto vd = itk::MakeFilled<VD>(10);
itkImageIteratorWithIndexTestIteratorTester<VD> TesterVD(vd);
if (TesterVD.TestIterator() == false)
{
Expand Down
16 changes: 6 additions & 10 deletions Modules/Core/Common/test/itkImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ itkImageTest(int, char *[])
image->GetSource();
image->DisconnectPipeline();

Image::SpacingType spacing;
spacing.Fill(1.0);
Image::PointType origin;
origin.Fill(1.0);
auto spacing = itk::MakeFilled<Image::SpacingType>(1.0);
auto origin = itk::MakeFilled<Image::PointType>(1.0);
Image::DirectionType direction;
direction[0][0] = .5;
direction[0][1] = .7;
Expand Down Expand Up @@ -127,9 +125,8 @@ itkImageTest(int, char *[])
region.SetSize(size);
image->SetRegions(region);

auto imageRef = Image::New();
Image::SpacingType spacingRef;
spacingRef.Fill(2);
auto imageRef = Image::New();
auto spacingRef = itk::MakeFilled<Image::SpacingType>(2);
Image::PointType originRef{};
Image::DirectionType directionRef;
directionRef.SetIdentity();
Expand Down Expand Up @@ -161,9 +158,8 @@ itkImageTest(int, char *[])
}

using Image3D = itk::Image<float, 3>;
auto volume = Image3D::New();
Image3D::SpacingType spacingVol;
spacingVol.Fill(1);
auto volume = Image3D::New();
auto spacingVol = itk::MakeFilled<Image3D::SpacingType>(1);
Image3D::PointType originVol{};
Image3D::DirectionType directionVol;
directionVol.SetIdentity();
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/Common/test/itkMatrixTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ itkMatrixTest(int, char *[])
MatrixType matrix4;
matrix4 = matrix.GetTranspose();

MatrixType matrix5;
matrix5.Fill(1.7);
auto matrix5 = itk::MakeFilled<MatrixType>(1.7);

constexpr NumericType value = 2;
matrix5[1][1] = value;
Expand Down Expand Up @@ -332,8 +331,7 @@ itkMatrixTest(int, char *[])
}

using LargeMatrixType = itk::Matrix<NumericType, 7, 7>;
LargeMatrixType matrixBad;
matrixBad.Fill(2.0);
auto matrixBad = itk::MakeFilled<LargeMatrixType>(2.0);
ITK_TRY_EXPECT_EXCEPTION(matrixBad.GetInverse());

matrixBad.SetIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ itkSymmetricSecondRankTensorTest(int, char *[])
tensor3D(2, 1) = 0.0; // overrides (1,2)
tensor3D(2, 2) = 29.0;

Double3DMatrixType matrix3D;
matrix3D.Fill(1.0);
auto matrix3D = itk::MakeFilled<Double3DMatrixType>(1.0);
std::vector<double> ans;
ans.push_back(26);
ans.push_back(23);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class DomainThreaderAssociate
BeforeThreadedExecution() override
{
this->m_DomainInThreadedExecution.resize(this->GetNumberOfWorkUnitsUsed());
DomainType unsetDomain;
unsetDomain.Fill(-1);
auto unsetDomain = itk::MakeFilled<DomainType>(-1);
for (auto & i : m_DomainInThreadedExecution)
{
i = unsetDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ itkTorusInteriorExteriorSpatialFunctionTest(int, char *[])
torusInteriorExteriorSpatialFunction, TorusInteriorExteriorSpatialFunction, InteriorExteriorSpatialFunction);

// Set the torus properties
TorusInteriorExteriorSpatialFunctionType::InputType origin;
origin.Fill(1.0);
auto origin = itk::MakeFilled<TorusInteriorExteriorSpatialFunctionType::InputType>(1.0);

torusInteriorExteriorSpatialFunction->SetOrigin(origin);
ITK_TEST_SET_GET_VALUE(origin, torusInteriorExteriorSpatialFunction->GetOrigin());
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/ImageAdaptors/test/itkImageAdaptorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ itkImageAdaptorTest(int, char *[])
}


myImageType::PointType imageOrigin;
imageOrigin.Fill(10.0);
auto imageOrigin = itk::MakeFilled<myImageType::PointType>(10.0);
myImage->SetOrigin(imageOrigin);
if (myImage->GetOrigin() != myAdaptor->GetOrigin())
{
Expand Down Expand Up @@ -184,8 +183,7 @@ itkImageAdaptorTest(int, char *[])
}


myImageType::SpacingType imageSpacing;
imageSpacing.Fill(10.0);
auto imageSpacing = itk::MakeFilled<myImageType::SpacingType>(10.0);

myImage->SetSpacing(imageSpacing);
if (myImage->GetSpacing() != myAdaptor->GetSpacing())
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/ImageAdaptors/test/itkVectorImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ itkVectorImageTest(int, char * argv[])
std::cout << "Testing ConstNeighborhoodIterator...." << std::endl;

using ConstNeighborhoodIteratorType = itk::ConstNeighborhoodIterator<VectorImageType>;
ConstNeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = itk::MakeFilled<ConstNeighborhoodIteratorType::RadiusType>(1);

ConstNeighborhoodIteratorType::RegionType region = vectorImage->GetBufferedRegion();
auto size = ConstNeighborhoodIteratorType::SizeType::Filled(4);
Expand Down Expand Up @@ -782,8 +781,7 @@ itkVectorImageTest(int, char * argv[])

// Test operator-
--cNit;
ConstNeighborhoodIteratorType::OffsetType offset;
offset.Fill(1);
auto offset = itk::MakeFilled<ConstNeighborhoodIteratorType::OffsetType>(1);
cNit -= offset;
itk::VariableLengthVector<PixelType> pixel = cNit.GetCenterPixel();
itk::VariableLengthVector<PixelType> correctAnswer(VectorLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ itkCentralDifferenceImageFunctionOnVectorTestRun()
}

// test continuous index
typename FunctionType::ContinuousIndexType cindex;
cindex.Fill(8.0);
auto cindex = itk::MakeFilled<typename FunctionType::ContinuousIndexType>(8.0);
OutputType continuousIndexOutput = function->EvaluateAtContinuousIndex(cindex);
std::cout << "ContinuousIndex: " << cindex << " Derivative: ";
std::cout << continuousIndexOutput << std::endl;
Expand All @@ -144,8 +143,7 @@ itkCentralDifferenceImageFunctionOnVectorTestRun()
result = EXIT_FAILURE;
}

typename FunctionType::PointType point;
point.Fill(8.0);
auto point = itk::MakeFilled<typename FunctionType::PointType>(8.0);
OutputType pointOutput = function->Evaluate(point);
std::cout << "Point: " << point << " Derivative: ";
std::cout << pointOutput << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ itkGaussianInterpolateImageFunctionTest(int, char *[])

ITK_EXERCISE_BASIC_OBJECT_METHODS(interpolator, GaussianInterpolateImageFunction, InterpolateImageFunction);

InterpolatorType::ArrayType sigma;
sigma.Fill(1.0);
auto sigma = itk::MakeFilled<InterpolatorType::ArrayType>(1.0);
interpolator->SetSigma(sigma);
ITK_TEST_SET_GET_VALUE(sigma, interpolator->GetSigma());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ itkLabelImageGaussianInterpolateImageFunctionTest(int, char *[])
small_image->Allocate();

{
ImageType::SpacingType spacing;
spacing.Fill(FOV / static_cast<double>(small_ySize));
ImageType::PointType origin;
origin.Fill(0.5 * FOV / static_cast<double>(small_ySize));
auto spacing = itk::MakeFilled<ImageType::SpacingType>(FOV / static_cast<double>(small_ySize));
auto origin = itk::MakeFilled<ImageType::PointType>(0.5 * FOV / static_cast<double>(small_ySize));

small_image->SetOrigin(origin);
small_image->SetSpacing(spacing);
Expand Down Expand Up @@ -128,10 +126,8 @@ itkLabelImageGaussianInterpolateImageFunctionTest(int, char *[])
large_image->Allocate();

{
ImageType::SpacingType spacing;
spacing.Fill(FOV / static_cast<double>(large_ySize));
ImageType::PointType origin;
origin.Fill(0.5 * FOV / static_cast<double>(large_ySize));
auto spacing = itk::MakeFilled<ImageType::SpacingType>(FOV / static_cast<double>(large_ySize));
auto origin = itk::MakeFilled<ImageType::PointType>(0.5 * FOV / static_cast<double>(large_ySize));

large_image->SetOrigin(origin);
large_image->SetSpacing(spacing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ itkNeighborhoodOperatorImageFunctionTest(int, char *[])

std::cout << "EvaluateAtContinuousIndex: ";

FunctionType::ContinuousIndexType continuousIndex;
continuousIndex.Fill(25);
auto continuousIndex = itk::MakeFilled<FunctionType::ContinuousIndexType>(25);

function->EvaluateAtContinuousIndex(continuousIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ itkRayCastInterpolateImageFunctionTest(int itkNotUsed(argc), char * itkNotUsed(a

PointType origin{};

SpacingType spacing;
spacing.Fill(1.0);
auto spacing = itk::MakeFilled<SpacingType>(1.0);

/* Set origin and spacing of physical coordinates */
image->SetOrigin(origin);
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/Mesh/test/itkRegularSphereMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ itkRegularSphereMeshSourceTest(int, char *[])
using PointType = SphereMeshSourceType::PointType;
using VectorType = SphereMeshSourceType::VectorType;

PointType center;
center.Fill(7.4);
auto center = itk::MakeFilled<PointType>(7.4);

constexpr double radius = 1.5;
const double tolerance = 1e-5;

VectorType scale;
scale.Fill(radius);
auto scale = itk::MakeFilled<VectorType>(radius);

mySphereMeshSource->SetCenter(center);
ITK_TEST_SET_GET_VALUE(center, mySphereMeshSource->GetCenter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ itkSimplexMeshAdaptTopologyFilterTest(int argc, char * argv[])
// declare the triangle to simplex mesh filter
using SimplexFilterType = itk::TriangleMeshToSimplexMeshFilter<TriangleMeshType, SimplexMeshType>;

auto mySphereMeshSource = SphereMeshSourceType::New();
PointType center;
center.Fill(10);
auto mySphereMeshSource = SphereMeshSourceType::New();
auto center = itk::MakeFilled<PointType>(10);
PointType::ValueType scaleInit[3] = { 3, 3, 3 };
VectorType scale = scaleInit;

Expand Down
Loading

0 comments on commit c87f0da

Please sign in to comment.