Skip to content

Commit cce8680

Browse files
authored
Merge pull request InsightSoftwareConsortium#5901 from hjmjohnson/convert-itkfloodfilliteratortest-to-gtest
ENH: Convert itkFloodFillIteratorTest to GTest
2 parents 9ffeeae + 8312123 commit cce8680

2 files changed

Lines changed: 7 additions & 40 deletions

File tree

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(
77
itkExtractImage3Dto2DTest.cxx
88
itkExtractImageTest.cxx
99
itkFloodFilledSpatialFunctionTest.cxx
10-
itkFloodFillIteratorTest.cxx
1110
itkGaussianDerivativeOperatorTest.cxx
1211
itkMapContainerTest.cxx
1312
itkVectorContainerTest.cxx
@@ -270,12 +269,6 @@ itk_add_test(
270269
ITKCommon1TestDriver
271270
itkFloodFilledSpatialFunctionTest
272271
)
273-
itk_add_test(
274-
NAME itkFloodFillIteratorTest
275-
COMMAND
276-
ITKCommon1TestDriver
277-
itkFloodFillIteratorTest
278-
)
279272

280273
itk_add_test(
281274
NAME itkColorTableTest1
@@ -1688,6 +1681,7 @@ set(
16881681
itkAnnulusOperatorGTest.cxx
16891682
itkCrossHelperGTest.cxx
16901683
itkAdaptorComparisonGTest.cxx
1684+
itkFloodFillIteratorGTest.cxx
16911685
)
16921686
creategoogletestdriver(ITKCommon "${ITKCommon-Test_LIBRARIES}" "${ITKCommonGTests}")
16931687
# If `-static` was passed to CMAKE_EXE_LINKER_FLAGS, compilation fails. No need to

Modules/Core/Common/test/itkFloodFillIteratorTest.cxx renamed to Modules/Core/Common/test/itkFloodFillIteratorGTest.cxx

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,40 @@
1616
*
1717
*=========================================================================*/
1818

19-
#include <iostream>
20-
21-
// Native ITK stuff
2219
#include "itkImageRegionIterator.h"
23-
24-
// Spatial function stuff
2520
#include "itkSphereSpatialFunction.h"
2621
#include "itkFloodFilledSpatialFunctionConditionalIterator.h"
22+
#include "itkGTest.h"
23+
24+
#include <iostream>
25+
2726

28-
int
29-
itkFloodFillIteratorTest(int, char *[])
27+
TEST(FloodFillIterator, SphereFloodFill)
3028
{
3129
constexpr unsigned int dim{ 3 };
3230

33-
// Image type alias
3431
using TImageType = itk::Image<int, dim>;
3532

36-
//-----------------Create a new input image--------------------
37-
// Image size and spacing parameters
3833
TImageType::SizeValueType sourceImageSize[] = { 20, 20, 20 };
3934
TImageType::SpacingValueType sourceImageSpacing[] = { 1.0, 1.0, 1.0 };
4035
TImageType::PointValueType sourceImageOrigin[] = { 0, 0, 0 };
4136

42-
// Creates the sourceImage (but doesn't set the size or allocate memory)
4337
auto sourceImage = TImageType::New();
4438
sourceImage->SetOrigin(sourceImageOrigin);
4539
sourceImage->SetSpacing(sourceImageSpacing);
4640

47-
std::cout << "New sourceImage created" << std::endl;
48-
49-
//-----The following block allocates the sourceImage-----
50-
51-
// Create a size object native to the sourceImage type
5241
TImageType::SizeType sourceImageSizeObject;
53-
// Set the size object to the array defined earlier
5442
sourceImageSizeObject.SetSize(sourceImageSize);
55-
// Create a region object native to the sourceImage type
5643
TImageType::RegionType largestPossibleRegion;
57-
// Resize the region
5844
largestPossibleRegion.SetSize(sourceImageSizeObject);
59-
// Set the largest legal region size (i.e. the size of the whole sourceImage), the buffered, and
60-
// the requested region to what we just defined.
6145
sourceImage->SetRegions(largestPossibleRegion);
62-
// Now allocate memory for the sourceImage
6346
sourceImage->AllocateInitialized();
6447

65-
std::cout << "New sourceImage allocated" << std::endl;
66-
67-
//---------Create and initialize a spatial function-----------
48+
std::cout << "New sourceImage created and allocated" << std::endl;
6849

6950
using TFunctionType = itk::SphereSpatialFunction<dim>;
7051
using TFunctionPositionType = TFunctionType::InputType;
7152

72-
// Create and initialize a new sphere function
73-
7453
auto spatialFunc = TFunctionType::New();
7554
spatialFunc->SetRadius(5);
7655

@@ -80,17 +59,13 @@ itkFloodFillIteratorTest(int, char *[])
8059
center[2] = 10;
8160
spatialFunc->SetCenter(center);
8261

83-
std::cout << "Sphere spatial function created" << std::endl;
84-
85-
//---------Create and initialize a spatial function iterator-----------
8662
TImageType::IndexType seedPos;
8763
constexpr TImageType::IndexValueType pos[]{ 10, 10, 10 };
8864
seedPos.SetIndex(pos);
8965

9066
using TItType = itk::FloodFilledSpatialFunctionConditionalIterator<TImageType, TFunctionType>;
9167
TItType sfi(sourceImage, spatialFunc, seedPos);
9268

93-
// Iterate through the entire image and set interior pixels to 255
9469
for (; !(sfi.IsAtEnd()); ++sfi)
9570
{
9671

@@ -99,6 +74,4 @@ itkFloodFillIteratorTest(int, char *[])
9974
}
10075

10176
std::cout << "Spatial function iterator created, sphere drawn" << std::endl;
102-
103-
return EXIT_SUCCESS;
10477
}

0 commit comments

Comments
 (0)