Skip to content

Commit

Permalink
STYLE: Replace index.Fill with auto index = Index::Filled in tests
Browse files Browse the repository at this point in the history
Replaced code of the form

    IndexType index;
    index.Fill(x);

with `auto index = IndexType::Filled(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: ^([ ]+ )(.*::Index.*[^ ])[ ]+(\w+);[\r\n]+ [ ]+\3\.Fill\(
    Find what: ^([ ]+ )(IndexType)[ ]+(\w+);[\r\n]+ [ ]+\3\.Fill\(
    Replace with: $1auto $3 = $2::Filled\(
    Filters: itk*Test*.cxx
    [v] Match case
    (*) Regular expression

Removed "typename" keywords from `typename T::::IndexType::Filled` calls.

Follow-up to pull request #4881
commit 569a8b6
"STYLE: Replace Fill(0) with {} initializer for local variables in tests"
  • Loading branch information
N-Dekker committed Oct 19, 2024
1 parent 1f5043a commit e991e27
Show file tree
Hide file tree
Showing 43 changed files with 53 additions and 105 deletions.
6 changes: 2 additions & 4 deletions Modules/Core/Common/test/itkConstNeighborhoodIteratorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ itkConstNeighborhoodIteratorTest(int, char *[])
}

// Setup and iterate over the first region
ChangeRegionTestImageType::IndexType region1Start;
region1Start.Fill(1);
auto region1Start = ChangeRegionTestImageType::IndexType::Filled(1);

auto regionSize = ChangeRegionTestImageType::SizeType::Filled(1);

Expand Down Expand Up @@ -382,8 +381,7 @@ itkConstNeighborhoodIteratorTest(int, char *[])
}

// Change iteration region
ChangeRegionTestImageType::IndexType region2start;
region2start.Fill(2);
auto region2start = ChangeRegionTestImageType::IndexType::Filled(2);

ChangeRegionTestImageType::RegionType region2(region2start, regionSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
}

// Setup and iterate over the first region
ChangeRegionTestImageType::IndexType region1Start;
region1Start.Fill(1);
auto region1Start = ChangeRegionTestImageType::IndexType::Filled(1);

auto regionSize = ChangeRegionTestImageType::SizeType::Filled(1);

Expand Down Expand Up @@ -495,8 +494,7 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
//}

// Change iteration region
ChangeRegionTestImageType::IndexType region2start;
region2start.Fill(2);
auto region2start = ChangeRegionTestImageType::IndexType::Filled(2);

ChangeRegionTestImageType::RegionType region2(region2start, regionSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ itkImageRegionExclusionIteratorWithIndexTest(int, char *[])
}

// Test exclusion region completely outside the region.
IndexType exclusionStart;
exclusionStart.Fill(-3);
auto exclusionStart = IndexType::Filled(-3);
auto exclusionSize = SizeType::Filled(2);
RegionType exclusionRegion(exclusionStart, exclusionSize);

Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkImageRegionIteratorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ itkImageRegionIteratorTest(int, char *[])
}

// Change iteration region
TestImageType::IndexType region2start;
region2start.Fill(1);
auto region2start = TestImageType::IndexType::Filled(1);

TestImageType::RegionType region2(region2start, regionSize);

Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkImageScanlineIteratorTest1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ itkImageScanlineIteratorTest1(int, char *[])
}

// Change iteration region
TestImageType::IndexType region2start;
region2start.Fill(1);
auto region2start = TestImageType::IndexType::Filled(1);

TestImageType::RegionType region2(region2start, regionSize);

Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkImageTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ TestTransform()
auto size = SizeType::Filled(10);
region.SetSize(size);

IndexType index;
index.Fill(5);
auto index = IndexType::Filled(5);

std::cout << "TransformIndexToPhysicalPoint..." << std::endl;
orientedImage->TransformIndexToPhysicalPoint(index, point);
Expand Down
12 changes: 4 additions & 8 deletions Modules/Core/ImageAdaptors/test/itkVectorImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ testVectorImageAdaptor(typename TAdaptor::Pointer &
bool failed = false;

using AdaptedImageType = itk::Image<PixelType, Dimension>;
typename AdaptedImageType::IndexType index;
index.Fill(10);
auto index = AdaptedImageType::IndexType::Filled(10);
std::cout << "Before adaptor initialization, vectorImage->GetPixel(" << index << ")[" << componentToExtract
<< "] = " << vectorImage->GetPixel(index)[componentToExtract] << std::endl;

Expand Down Expand Up @@ -559,8 +558,7 @@ itkVectorImageTest(int, char * argv[])
lcit.NextLine();
}

VectorImageType::IndexType idx;
idx.Fill(1);
auto idx = VectorImageType::IndexType::Filled(1);
LinearIteratorType lit(vectorImage, vectorImage->GetBufferedRegion());
lit.SetIndex(idx);
lit.Set(f);
Expand Down Expand Up @@ -714,8 +712,7 @@ itkVectorImageTest(int, char * argv[])

ConstNeighborhoodIteratorType::RegionType region = vectorImage->GetBufferedRegion();
auto size = ConstNeighborhoodIteratorType::SizeType::Filled(4);
ConstNeighborhoodIteratorType::IndexType index;
index.Fill(1);
auto index = ConstNeighborhoodIteratorType::IndexType::Filled(1);
region.SetIndex(index);
region.SetSize(size);

Expand Down Expand Up @@ -754,8 +751,7 @@ itkVectorImageTest(int, char * argv[])
// Test GoToEnd()
cNit.GoToEnd();
--cNit;
ConstNeighborhoodIteratorType::IndexType endIndex;
endIndex.Fill(4);
auto endIndex = ConstNeighborhoodIteratorType::IndexType::Filled(4);
if (cNit.GetPixel(centerIndex) != vectorImage->GetPixel(endIndex))
{
std::cerr << " GoToEnd [FAILED]" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ itkVectorImageToImageAdaptorTest(int, char *[])
}

// test Get/SetPixel() methods
VectorImageToImageAdaptorType::IndexType index;
index.Fill(10);
auto index = VectorImageToImageAdaptorType::IndexType::Filled(10);
ITK_TEST_EXPECT_EQUAL(PixelType(componentToExtract), vectorImageToImageAdaptor->GetPixel(index));

PixelType v = 4.4f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,7 @@ set2DInterpData(ImageType2D::Pointer imgPtr)
-225.6000, -84.6000, 0, 28.2000, 0, -84.6000, -543.0000, -289.6000, -108.6000,
0, 36.2000, 0, -108.6000 };

ImageType2D::IndexType index;
index.Fill(10);
auto index = ImageType2D::IndexType::Filled(10);

ImageType2D::RegionType region{ index, size };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ itkGaussianBlurImageFunctionTest(int, char *[])
// Test the derivative of Gaussian image function
auto gaussianFunction = GFunctionType::New();
gaussianFunction->SetInputImage(image);
itk::Index<2> index;
index.Fill(25);
auto index = itk::Index<2>::Filled(25);

// Testing Set/GetVariance()
std::cout << "Testing Set/GetVariance(): ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ TestGaussianDerivativeImageFunction()
std::cout << "[PASSED] " << std::endl;

std::cout << "Testing consistency within Index/Point/ContinuousIndex: ";
itk::Index<Dimension> index;
index.Fill(25);
auto index = itk::Index<Dimension>::Filled(25);
typename DoGFunctionType::OutputType gradientIndex;
gradientIndex = DoG->EvaluateAtIndex(index);

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

function->SetOperator(oper);

itk::Index<3> index;
index.Fill(25);
auto index = itk::Index<3>::Filled(25);

FunctionType::OutputType Blur;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ itkBSplineDeformableTransformTest1()
/**
* Populate the spline coefficients with some values.
*/
CoefficientImageType::IndexType index;
index.Fill(5);
auto index = CoefficientImageType::IndexType::Filled(5);

coeffImage[1]->SetPixel(index, 1.0);

Expand Down Expand Up @@ -646,8 +645,7 @@ itkBSplineDeformableTransformTest3()
/**
* Populate the spline coefficients with some values.
*/
CoefficientImageType::IndexType index;
index.Fill(5);
auto index = CoefficientImageType::IndexType::Filled(5);

coeffImage[1]->SetPixel(index, 1.0);

Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/Transform/test/itkBSplineTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ itkBSplineTransformTest1()
/**
* Populate the spline coefficients with some values.
*/
CoefficientImageType::IndexType index;
index.Fill(5);
auto index = CoefficientImageType::IndexType::Filled(5);

coeffImage[1]->SetPixel(index, 1.0);

Expand Down Expand Up @@ -674,8 +673,7 @@ itkBSplineTransformTest3()
/**
* Populate the spline coefficients with some values.
*/
CoefficientImageType::IndexType index;
index.Fill(5);
auto index = CoefficientImageType::IndexType::Filled(5);

coeffImage[1]->SetPixel(index, 1.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ itkConvolutionImageFilterTest(int argc, char * argv[])
}

// Test for invalid request region.
ImageType::IndexType invalidIndex;
invalidIndex.Fill(1000);
auto invalidIndex = ImageType::IndexType::Filled(1000);
auto invalidSize = ImageType::SizeType::Filled(1000);
ImageType::RegionType invalidRequestRegion(invalidIndex, invalidSize);
convoluter->GetOutput()->SetRequestedRegion(invalidRequestRegion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ itkFFTConvolutionImageFilterTest(int argc, char * argv[])
ITK_TRY_EXPECT_EXCEPTION(convoluter->Update());

// Test for invalid request region.
ImageType::IndexType invalidIndex;
invalidIndex.Fill(1000);
auto invalidIndex = ImageType::IndexType::Filled(1000);
auto invalidSize = ImageType::SizeType::Filled(1000);
ImageType::RegionType invalidRequestRegion(invalidIndex, invalidSize);
convoluter->GetOutput()->SetRequestedRegion(invalidRequestRegion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ doDenoising(const std::string & inputFileName,
filter->GetNoiseModel() == FilterType::NoiseModelEnum::POISSON)
{
typename ImageT::IndexType::IndexValueType indexValue = 0;
typename ImageT::IndexType pixelIndex;
pixelIndex.Fill(indexValue);
auto pixelIndex = ImageT::IndexType::Filled(indexValue);

typename ImageT::PixelType originalPixelValue = inputImage->GetPixel(pixelIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ itkTransformToDisplacementFieldFilterTest1(int argc, char * argv[])
auto eulerTransform = TransformType::New();
{
// Set the options.
IndexType imageCenter;
imageCenter.Fill(11);
auto imageCenter = IndexType::Filled(11);
PointType centerPoint;
image->TransformIndexToPhysicalPoint(imageCenter, centerPoint);
eulerTransform->SetCenter(centerPoint);
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filtering/FastMarching/test/itkFastMarchingTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ itkFastMarchingTest(int argc, char * argv[])

auto outputRegionIndexValue =
static_cast<typename FloatFMType::LevelSetImageType::IndexType::IndexValueType>(std::stoi(argv[5]));
typename FloatFMType::LevelSetImageType::IndexType outputRegionIndex;
outputRegionIndex.Fill(outputRegionIndexValue);
auto outputRegionIndex = FloatFMType::LevelSetImageType::IndexType::Filled(outputRegionIndexValue);
typename FloatFMType::OutputRegionType outputRegion{ outputRegionIndex, size };
marcher->SetOutputRegion(outputRegion);
ITK_TEST_SET_GET_VALUE(outputRegion, marcher->GetOutputRegion());
Expand Down
11 changes: 4 additions & 7 deletions Modules/Filtering/ImageGrid/test/itkSliceImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ TEST(SliceImageFilterTests, Empty)
SourceType::SizeValueType size[] = { 32, 32 };
source->SetSize(size);

int step[ImageDimension] = { 1, 1 };
ImageType::IndexType start;
start.Fill(10);
ImageType::IndexType stop;
stop.Fill(10);
int step[ImageDimension] = { 1, 1 };
auto start = ImageType::IndexType::Filled(10);
auto stop = ImageType::IndexType::Filled(10);


ImageType::Pointer img;
Expand Down Expand Up @@ -255,8 +253,7 @@ TEST(SliceImageFilterTests, Coverage)
auto filter = FilterType::New();
std::cout << filter;

FilterType::IndexType idx;
idx.Fill(10);
auto idx = FilterType::IndexType::Filled(10);

filter->SetStart(idx);
EXPECT_EQ(idx, filter->GetStart());
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filtering/ImageGrid/test/itkWarpImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ itkWarpImageFilterTest(int, char *[])
ITK_TEST_SET_GET_VALUE(outputDirection, warper->GetOutputDirection());

typename WarperType::IndexType::value_type outputStartIndexVal = 0;
typename WarperType::IndexType outputStartIndex;
outputStartIndex.Fill(outputStartIndexVal);
auto outputStartIndex = WarperType::IndexType::Filled(outputStartIndexVal);
warper->SetOutputStartIndex(outputStartIndex);
ITK_TEST_SET_GET_VALUE(outputStartIndex, warper->GetOutputStartIndex());

Expand Down
3 changes: 1 addition & 2 deletions Modules/Nonunit/Review/test/itkImageFunctionTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ itkImageFunctionTest(int, char *[])

auto image = ImageType::New();

IndexType start;
start.Fill(1);
auto start = IndexType::Filled(1);
SizeType size;
size[0] = 3;
size[1] = 4;
Expand Down
3 changes: 1 addition & 2 deletions Modules/Numerics/Statistics/test/itkSubsampleTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ itkSubsampleTest(int, char *[])

std::cout << subsample->GetTotalFrequency() << std::endl;

ArrayPixelImageType::IndexType index;
index.Fill(2); // index {2, 2, 2} = instance identifier (offset from image)
auto index = ArrayPixelImageType::IndexType::Filled(2); // index {2, 2, 2} = instance identifier (offset from image)
ArrayPixelImageType::PixelType pixel = filter->GetInput()->GetPixel(index);
ListSampleType::InstanceIdentifier ind =
static_cast<FloatImage::OffsetValueType>(filter->GetInput()->ComputeOffset(index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ itkBSplineExponentialDiffeomorphicTransformParametersAdaptorTest(int, char *[])
TransformType::OutputVectorType nonzeroVector;
nonzeroVector.Fill(10.3);

DisplacementFieldType::IndexType index;
index.Fill(40);
auto index = DisplacementFieldType::IndexType::Filled(40);
displacementField->SetPixel(index, nonzeroVector);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ itkBSplineSmoothingOnUpdateDisplacementFieldTransformParametersAdaptorTest(int,
TransformType::OutputVectorType nonzeroVector;
nonzeroVector.Fill(10.3);

DisplacementFieldType::IndexType index;
index.Fill(40);
auto index = DisplacementFieldType::IndexType::Filled(40);
displacementField->SetPixel(index, nonzeroVector);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ itkBSplineTransformParametersAdaptorTest(int, char *[])
transform->SetParameters(parameters);

using CoefficientImageType = TransformType::ImageType;
CoefficientImageType::IndexType index;
index.Fill(5);
auto index = CoefficientImageType::IndexType::Filled(5);
transform->GetCoefficientImages()[0]->SetPixel(index, 5.0);

TransformType::InputPointType point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ itkDisplacementFieldTransformParametersAdaptorTest(int, char *[])
TransformType::OutputVectorType nonzeroVector;
nonzeroVector.Fill(10.3);

DisplacementFieldType::IndexType index;
index.Fill(40);
auto index = DisplacementFieldType::IndexType::Filled(40);
displacementField->SetPixel(index, nonzeroVector);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ itkGaussianExponentialDiffeomorphicTransformParametersAdaptorTest(int, char *[])
TransformType::OutputVectorType nonzeroVector;
nonzeroVector.Fill(10.3);

DisplacementFieldType::IndexType index;
index.Fill(40);
auto index = DisplacementFieldType::IndexType::Filled(40);
displacementField->SetPixel(index, nonzeroVector);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ itkGaussianSmoothingOnUpdateDisplacementFieldTransformParametersAdaptorTest(int,
TransformType::OutputVectorType nonzeroVector;
nonzeroVector.Fill(10.3);

DisplacementFieldType::IndexType index;
index.Fill(40);
auto index = DisplacementFieldType::IndexType::Filled(40);
displacementField->SetPixel(index, nonzeroVector);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ itkCurvesLevelSetImageFilterTest(int, char *[])
inputImage->Allocate();
inputImage->FillBuffer(background);

ImageType::IndexType squareStart;
squareStart.Fill(20);
auto squareStart = ImageType::IndexType::Filled(20);
auto squareSize = ImageType::SizeType::Filled(60);
ImageType::RegionType squareRegion{ squareStart, squareSize };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ itkCurvesLevelSetImageFilterZeroSigmaTest(int, char *[])
inputImage->Allocate();
inputImage->FillBuffer(background);

ImageType::IndexType squareStart;
squareStart.Fill(20);
auto squareStart = ImageType::IndexType::Filled(20);
auto squareSize = ImageType::SizeType::Filled(60);
ImageType::RegionType squareRegion{ squareStart, squareSize };

Expand Down
Loading

0 comments on commit e991e27

Please sign in to comment.