Skip to content

Commit d6c9eed

Browse files
committed
STYLE: Replace Fill calls with auto var = itk::MakeFilled<T> in tests
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 Follow-up to - pull request InsightSoftwareConsortium#4881 - pull request InsightSoftwareConsortium#4884 - pull request InsightSoftwareConsortium#4887
1 parent 0883d0c commit d6c9eed

File tree

173 files changed

+374
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+374
-670
lines changed

Modules/Core/Common/test/itkAdaptorComparisonTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ itkAdaptorComparisonTest(int, char *[])
204204
vector_image->SetRegions(region);
205205
vector_image->Allocate();
206206

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

211210
// Time trials

Modules/Core/Common/test/itkAggregateTypesGTest.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,10 @@ class CommonIndexOffsetMathOps
287287

288288
//============ Test Copy with Round/Cast Type ====================================
289289
{
290-
AggregateType known3s{ { 3, 3, 3, 3 } };
291-
AggregateType threes{};
292-
AggregateType known4s{ { 4, 4, 4, 4 } };
293-
itk::Point<double, 4> p1;
294-
p1.Fill(3.5);
290+
AggregateType known3s{ { 3, 3, 3, 3 } };
291+
AggregateType threes{};
292+
AggregateType known4s{ { 4, 4, 4, 4 } };
293+
auto p1 = itk::MakeFilled<itk::Point<double, 4>>(3.5);
295294
threes.CopyWithRound(p1);
296295
ITK_EXPECT_VECTOR_NEAR(threes, known4s, 0);
297296

Modules/Core/Common/test/itkConicShellInteriorExteriorSpatialFunctionTest.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ itkConicShellInteriorExteriorSpatialFunctionTest(int, char *[])
5050
InteriorExteriorSpatialFunction);
5151

5252
// Set the conic shell properties
53-
ConicShellInteriorExteriorSpatialFunctionType::InputType origin;
54-
origin.Fill(1.0);
53+
auto origin = itk::MakeFilled<ConicShellInteriorExteriorSpatialFunctionType::InputType>(1.0);
5554

5655
conicShellInteriorExteriorSpatialFunction->SetOrigin(origin);
5756
ITK_TEST_SET_GET_VALUE(origin, conicShellInteriorExteriorSpatialFunction->GetOrigin());
5857

59-
ConicShellInteriorExteriorSpatialFunctionType::GradientType originGradient;
60-
originGradient.Fill(1.6);
58+
auto originGradient = itk::MakeFilled<ConicShellInteriorExteriorSpatialFunctionType::GradientType>(1.6);
6159
originGradient.GetVnlVector().normalize();
6260
conicShellInteriorExteriorSpatialFunction->SetOriginGradient(originGradient);
6361

Modules/Core/Common/test/itkConstNeighborhoodIteratorTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ itkConstNeighborhoodIteratorTest(int, char *[])
192192
printnb<itk::ConstNeighborhoodIterator<TestImageType>>(ra_it, false);
193193

194194
println("Adding [1, 1, 1, 1]");
195-
OffsetType a_off;
196-
a_off.Fill(1);
195+
auto a_off = itk::MakeFilled<OffsetType>(1);
197196
ra_it += a_off;
198197
printnb<itk::ConstNeighborhoodIterator<TestImageType>>(ra_it, false);
199198

Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ itkConstNeighborhoodIteratorWithOnlyIndexTestRun()
241241
ra_it.SetLocation(loc);
242242

243243
std::cout << "Adding [1, 1, 1, 1]" << std::endl;
244-
OffsetType a_off;
245-
a_off.Fill(1);
244+
auto a_off = itk::MakeFilled<OffsetType>(1);
246245
ra_it += a_off;
247246
for (unsigned int i = 0; i < 4; ++i)
248247
{

Modules/Core/Common/test/itkFrustumSpatialFunctionTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ itkFrustumSpatialFunctionTest(int, char *[])
4343
ITK_EXERCISE_BASIC_OBJECT_METHODS(frustrumSpatialFunction, FrustumSpatialFunction, InteriorExteriorSpatialFunction);
4444

4545
// Set the frustum properties
46-
FrustumSpatialFunctionType::InputType apex;
47-
apex.Fill(1.1);
46+
auto apex = itk::MakeFilled<FrustumSpatialFunctionType::InputType>(1.1);
4847

4948
frustrumSpatialFunction->SetApex(apex);
5049
ITK_TEST_SET_GET_VALUE(apex, frustrumSpatialFunction->GetApex());

Modules/Core/Common/test/itkImageComputeOffsetAndIndexTest.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ ComputeOffset(TImage * image, unsigned int count, unsigned int repeat)
6262
typename TImage::OffsetValueType offset = 0;
6363
typename TImage::OffsetValueType accum = 0;
6464
typename TImage::IndexType index;
65-
typename TImage::OffsetType indexIncr;
66-
indexIncr.Fill(1);
65+
auto indexIncr = itk::MakeFilled<typename TImage::OffsetType>(1);
6766

6867
for (unsigned int j = 0; j < repeat; ++j)
6968
{
@@ -86,8 +85,7 @@ ComputeFastOffset(TImage * image, unsigned int count, unsigned int repeat)
8685
typename TImage::OffsetValueType offset = 0;
8786
typename TImage::OffsetValueType accum = 0;
8887
typename TImage::IndexType index;
89-
typename TImage::OffsetType indexIncr;
90-
indexIncr.Fill(1);
88+
auto indexIncr = itk::MakeFilled<typename TImage::OffsetType>(1);
9189

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

Modules/Core/Common/test/itkImageIteratorTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ itkImageIteratorTest(int, char *[])
6868
o3->SetSpacing(spacing3D);
6969

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

7574
std::cout << "Setting/Getting a pixel" << std::endl;

Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ itkImageIteratorWithIndexTest(int, char *[])
264264

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

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

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

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

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

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

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

391384
std::cout << "Testing with Image< itk::Vector<double,4>, 3 > " << std::endl;
392385
using VD = itk::Vector<double, 4>;
393-
VD vd;
394-
vd.Fill(10);
386+
auto vd = itk::MakeFilled<VD>(10);
395387
itkImageIteratorWithIndexTestIteratorTester<VD> TesterVD(vd);
396388
if (TesterVD.TestIterator() == false)
397389
{

Modules/Core/Common/test/itkImageTest.cxx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ itkImageTest(int, char *[])
6262
image->GetSource();
6363
image->DisconnectPipeline();
6464

65-
Image::SpacingType spacing;
66-
spacing.Fill(1.0);
67-
Image::PointType origin;
68-
origin.Fill(1.0);
65+
auto spacing = itk::MakeFilled<Image::SpacingType>(1.0);
66+
auto origin = itk::MakeFilled<Image::PointType>(1.0);
6967
Image::DirectionType direction;
7068
direction[0][0] = .5;
7169
direction[0][1] = .7;
@@ -127,9 +125,8 @@ itkImageTest(int, char *[])
127125
region.SetSize(size);
128126
image->SetRegions(region);
129127

130-
auto imageRef = Image::New();
131-
Image::SpacingType spacingRef;
132-
spacingRef.Fill(2);
128+
auto imageRef = Image::New();
129+
auto spacingRef = itk::MakeFilled<Image::SpacingType>(2);
133130
Image::PointType originRef{};
134131
Image::DirectionType directionRef;
135132
directionRef.SetIdentity();
@@ -161,9 +158,8 @@ itkImageTest(int, char *[])
161158
}
162159

163160
using Image3D = itk::Image<float, 3>;
164-
auto volume = Image3D::New();
165-
Image3D::SpacingType spacingVol;
166-
spacingVol.Fill(1);
161+
auto volume = Image3D::New();
162+
auto spacingVol = itk::MakeFilled<Image3D::SpacingType>(1);
167163
Image3D::PointType originVol{};
168164
Image3D::DirectionType directionVol;
169165
directionVol.SetIdentity();

0 commit comments

Comments
 (0)