Skip to content

Commit 3279b33

Browse files
committed
COMP: Tests use aggregate types for initialization
Initialization of regions and sizes is simpler with aggregate types Changes made to the tests directories as a followup to changes made in 6281dc8 Prefer initialization to declaration and assignment. Prefer constexpr for size and index initialization.
1 parent 7af874d commit 3279b33

File tree

180 files changed

+566
-1636
lines changed

Some content is hidden

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

180 files changed

+566
-1636
lines changed

Modules/Core/Common/test/itkAdaptorComparisonTest.cxx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,9 @@ itkAdaptorComparisonTest(int, char *[])
170170
using VectorImageType = itk::Image<itk::Vector<float, 3>, 3>;
171171

172172
// Set up some images
173-
itk::ImageRegion<3> region;
174-
itk::Size<3> size;
175-
size[0] = 100;
176-
size[1] = 100;
177-
size[2] = 100;
178-
itk::Index<3> index;
179-
index[0] = 0;
180-
index[1] = 0;
181-
index[2] = 0;
182-
region = { index, size };
173+
constexpr itk::Size<3> size{ 100, 100, 100 };
174+
constexpr itk::Index<3> index{ 0, 0, 0 };
175+
itk::ImageRegion<3> region = { index, size };
183176

184177
auto scalar_image = ScalarImageType::New();
185178
auto vector_image = VectorImageType::New();

Modules/Core/Common/test/itkConstNeighborhoodIteratorTest.cxx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,13 @@ GetTestImage(int d1, int d2, int d3, int d4)
5151
int
5252
itkConstNeighborhoodIteratorTest(int, char *[])
5353
{
54-
const TestImageType::Pointer img = GetTestImage(10, 10, 5, 3);
55-
itk::ConstNeighborhoodIterator<TestImageType>::IndexType loc;
56-
loc[0] = 4;
57-
loc[1] = 4;
58-
loc[2] = 2;
59-
loc[3] = 1;
60-
61-
itk::ConstNeighborhoodIterator<TestImageType>::RadiusType radius;
62-
radius[0] = radius[1] = radius[2] = radius[3] = 1;
54+
const TestImageType::Pointer img = GetTestImage(10, 10, 5, 3);
55+
itk::ConstNeighborhoodIterator<TestImageType>::IndexType loc{ 4, 4, 2, 1 };
56+
itk::ConstNeighborhoodIterator<TestImageType>::RadiusType radius{ 1, 1, 1, 1 };
6357

64-
itk::ConstNeighborhoodIterator<TestImageType>::RegionType reg;
65-
itk::ConstNeighborhoodIterator<TestImageType>::SizeType sz;
66-
itk::ConstNeighborhoodIterator<TestImageType>::IndexType idx;
67-
idx[0] = idx[1] = idx[2] = 0;
68-
idx[3] = 1;
69-
sz[0] = sz[1] = 10;
70-
sz[2] = 5;
71-
sz[3] = 1;
72-
reg = { idx, sz };
58+
constexpr itk::ConstNeighborhoodIterator<TestImageType>::SizeType sz{ 10, 10, 5, 1 };
59+
constexpr itk::ConstNeighborhoodIterator<TestImageType>::IndexType idx{ 0, 0, 0, 1 };
60+
itk::ConstNeighborhoodIterator<TestImageType>::RegionType reg = { idx, sz };
7361

7462
println("Creating ConstNeighborhoodIterator");
7563
itk::ConstNeighborhoodIterator<TestImageType> it(radius, img, reg);

Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,12 @@ itkConstNeighborhoodIteratorWithOnlyIndexTestRun()
4949
using ConstNeighborhoodIteratorType = itk::ConstNeighborhoodIteratorWithOnlyIndex<ImageType>;
5050
using IndexType = typename ConstNeighborhoodIteratorType::IndexType;
5151

52-
IndexType loc;
53-
loc[0] = 4;
54-
loc[1] = 4;
55-
loc[2] = 2;
56-
loc[3] = 1;
57-
58-
typename ConstNeighborhoodIteratorType::RadiusType radius;
59-
radius[0] = radius[1] = radius[2] = radius[3] = 1;
52+
IndexType loc{ 4, 4, 2, 1 };
6053

61-
typename ConstNeighborhoodIteratorType::RegionType reg;
62-
typename ConstNeighborhoodIteratorType::SizeType sz;
63-
IndexType idx;
64-
idx[0] = idx[1] = idx[2] = 0;
65-
idx[3] = 1;
66-
sz[0] = sz[1] = 10;
67-
sz[2] = 5;
68-
sz[3] = 1;
69-
reg = { idx, sz };
54+
typename ConstNeighborhoodIteratorType::RadiusType radius{ 1, 1, 1, 1 };
55+
constexpr typename ConstNeighborhoodIteratorType::SizeType sz{ 10, 10, 5, 1 };
56+
constexpr IndexType idx{ 0, 0, 0, 1 };
57+
typename ConstNeighborhoodIteratorType::RegionType reg = { idx, sz };
7058

7159
std::cout << "Creating ConstNeighborhoodIterator" << std::endl;
7260
ConstNeighborhoodIteratorType it(radius, img, reg);

Modules/Core/Common/test/itkConstShapedNeighborhoodIteratorTest.cxx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,12 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
4242
loc[3] = 1;
4343

4444
// radius of the iterator
45-
itk::ConstShapedNeighborhoodIterator<TestImageType>::RadiusType radius;
46-
radius[0] = radius[1] = radius[2] = radius[3] = 1;
47-
45+
itk::ConstShapedNeighborhoodIterator<TestImageType>::RadiusType radius{ 1, 1, 1, 1 };
4846
// region over which the iterator is defined
49-
itk::ConstShapedNeighborhoodIterator<TestImageType>::RegionType reg;
50-
itk::ConstShapedNeighborhoodIterator<TestImageType>::SizeType sz;
51-
itk::ConstShapedNeighborhoodIterator<TestImageType>::IndexType idx;
52-
idx[0] = idx[1] = idx[2] = 0;
53-
idx[3] = 1;
54-
sz[0] = sz[1] = 10;
55-
sz[2] = 5;
56-
sz[3] = 1;
57-
reg = { idx, sz };
47+
48+
constexpr itk::ConstShapedNeighborhoodIterator<TestImageType>::SizeType sz{ 10, 10, 5, 1 };
49+
constexpr itk::ConstShapedNeighborhoodIterator<TestImageType>::IndexType idx{ 0, 0, 0, 1 };
50+
itk::ConstShapedNeighborhoodIterator<TestImageType>::RegionType reg = { idx, sz };
5851

5952
// initialize an iterator
6053
println("Creating ConstShapedNeighborhoodIterator");

Modules/Core/Common/test/itkConstShapedNeighborhoodIteratorTest2.cxx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,15 @@ MyDerivedCSNI<ImageType>::TestNewExposedProtectedMembers()
5353
int
5454
itkConstShapedNeighborhoodIteratorTest2(int, char *[])
5555
{
56-
const TestImageType::Pointer img = GetTestImage(10, 10, 5, 3);
57-
MyDerivedCSNI<TestImageType>::IndexType loc;
58-
loc[0] = 4;
59-
loc[1] = 4;
60-
loc[2] = 2;
61-
loc[3] = 1;
56+
const TestImageType::Pointer img = GetTestImage(10, 10, 5, 3);
6257

6358
// radius of the iterator
64-
MyDerivedCSNI<TestImageType>::RadiusType radius;
65-
radius[0] = radius[1] = radius[2] = radius[3] = 1;
59+
constexpr MyDerivedCSNI<TestImageType>::RadiusType radius{ 1, 1, 1, 1 };
6660

6761
// region over which the iterator is defined
68-
MyDerivedCSNI<TestImageType>::RegionType reg;
69-
MyDerivedCSNI<TestImageType>::SizeType sz;
70-
MyDerivedCSNI<TestImageType>::IndexType idx;
71-
idx[0] = idx[1] = idx[2] = 0;
72-
idx[3] = 1;
73-
sz[0] = sz[1] = 10;
74-
sz[2] = 5;
75-
sz[3] = 1;
76-
reg = { idx, sz };
62+
constexpr MyDerivedCSNI<TestImageType>::SizeType sz{ 10, 10, 5, 1 };
63+
constexpr MyDerivedCSNI<TestImageType>::IndexType idx{ 0, 0, 0, 1 };
64+
MyDerivedCSNI<TestImageType>::RegionType reg = { idx, sz };
7765

7866
// initialize an iterator
7967
println("Creating ConstShapedNeighborhoodIterator");

Modules/Core/Common/test/itkExtractImageTest.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ itkExtractImageTest(int, char *[])
150150
<< extract->GetOutput()->GetSpacing()[1] << std::endl;
151151

152152

153-
ShortImage::RegionType requestedRegion;
154-
155153
// CASE 1
156154
extractIndex[0] = 1;
157155
extractIndex[1] = 2;
@@ -160,7 +158,7 @@ itkExtractImageTest(int, char *[])
160158
extractRegion = { extractIndex, extractSize };
161159
extract->SetExtractionRegion(extractRegion);
162160
extract->UpdateLargestPossibleRegion();
163-
requestedRegion = extract->GetOutput()->GetRequestedRegion();
161+
ShortImage::RegionType requestedRegion = extract->GetOutput()->GetRequestedRegion();
164162

165163
itk::ImageRegionIterator<ShortImage> iteratorIn1(extract->GetOutput(), requestedRegion);
166164

Modules/Core/Common/test/itkImageAlgorithmCopyTest.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ AverageTestCopy(typename TImage::SizeType & size)
2929

3030
using PixelType = typename TImage::PixelType;
3131
using ImageType = TImage;
32-
typename ImageType::RegionType region;
3332

34-
35-
const typename ImageType::IndexType index{};
36-
region = { index, size };
33+
constexpr typename ImageType::IndexType index{};
34+
typename ImageType::RegionType region = { index, size };
3735

3836
auto inImage = ImageType::New();
3937
inImage->SetRegions(region);

Modules/Core/Common/test/itkImageDuplicatorTest.cxx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ int
2828
itkImageDuplicatorTest(int, char *[])
2929
{
3030
using ImageType = itk::Image<float, 3>;
31-
ImageType::RegionType region;
32-
ImageType::SizeType size;
33-
size[0] = 10;
34-
size[1] = 20;
35-
size[2] = 30;
31+
constexpr ImageType::SizeType size{ 10, 20, 30 };
3632
constexpr ImageType::IndexType index{};
37-
region = { index, size };
33+
ImageType::RegionType region = { index, size };
3834

3935
{
4036
/** Create an image */

Modules/Core/Common/test/itkImageRegionTest.cxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ itkImageRegionTest(int, char *[])
4545
constexpr IndexType startB = { { 14, 14, 14 } };
4646
constexpr IndexType endA = { { 21, 31, 41 } };
4747

48-
RegionType regionA;
49-
RegionType regionB;
50-
51-
regionA = { startA, sizeA };
48+
RegionType regionA = { startA, sizeA };
5249

5350
if (regionA.GetUpperIndex() != endA)
5451
{
@@ -110,7 +107,7 @@ itkImageRegionTest(int, char *[])
110107
std::cout << "Caught expected exception" << err;
111108
}
112109

113-
regionB = { startB, sizeB };
110+
RegionType regionB = { startB, sizeB };
114111

115112
// Test IsInside( integerIndex )
116113
IndexType index = startA;

Modules/Core/Common/test/itkImportImageTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ itkImportImageTest(int, char *[])
4444
ITK_EXERCISE_BASIC_OBJECT_METHODS(basicImport, ImportImageFilter, ImageSource);
4545

4646
ShortImage::Pointer image;
47-
itk::ImageRegion<Dimension> region;
4847
constexpr itk::ImageRegion<Dimension>::IndexType index = { { 0, 0 } };
4948
constexpr itk::ImageRegion<Dimension>::SizeType size = { { 8, 12 } };
50-
region = { index, size };
49+
itk::ImageRegion<Dimension> region = { index, size };
5150
// local scope to make sure that imported data is not deleted with ImportImageFilter
5251
// but with the ImportImageContainer is creates.
5352
{

0 commit comments

Comments
 (0)