Skip to content

Commit 1cb6591

Browse files
N-Dekkerhjmjohnson
authored andcommitted
ENH: Convert FastChamferDistanceImageFilter test to GoogleTest
Follow-up to pull request #5612 "Convert three more Filtering/DistanceMap tests to GoogleTest"
1 parent cbe6fbb commit 1cb6591

File tree

2 files changed

+21
-99
lines changed

2 files changed

+21
-99
lines changed

Modules/Filtering/DistanceMap/test/CMakeLists.txt

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(
77
itkSignedDanielssonDistanceMapImageFilterTest.cxx
88
itkSignedDanielssonDistanceMapImageFilterTest1.cxx
99
itkSignedDanielssonDistanceMapImageFilterTest2.cxx
10-
itkFastChamferDistanceImageFilterTest.cxx
1110
itkSignedMaurerDistanceMapImageFilterTest.cxx
1211
itkApproximateSignedDistanceMapImageFilterTest.cxx
1312
itkIsoContourDistanceImageFilterTest.cxx
@@ -108,34 +107,6 @@ itk_add_test(
108107
4
109108
)
110109

111-
itk_add_test(
112-
NAME itkFastChamferDistanceImageFilterTest1
113-
COMMAND
114-
ITKDistanceMapTestDriver
115-
itkFastChamferDistanceImageFilterTest
116-
1
117-
)
118-
itk_add_test(
119-
NAME itkFastChamferDistanceImageFilterTest2
120-
COMMAND
121-
ITKDistanceMapTestDriver
122-
itkFastChamferDistanceImageFilterTest
123-
2
124-
)
125-
itk_add_test(
126-
NAME itkFastChamferDistanceImageFilterTest3
127-
COMMAND
128-
ITKDistanceMapTestDriver
129-
itkFastChamferDistanceImageFilterTest
130-
3
131-
)
132-
itk_add_test(
133-
NAME itkFastChamferDistanceImageFilterTest4
134-
COMMAND
135-
ITKDistanceMapTestDriver
136-
itkFastChamferDistanceImageFilterTest
137-
4
138-
)
139110
itk_add_test(
140111
NAME itkSignedMaurerDistanceMapImageFilterTest1
141112
COMMAND
@@ -238,6 +209,7 @@ set(
238209
itkContourMeanDistanceImageFilterGTest.cxx
239210
itkDanielssonDistanceMapImageFilterGTest.cxx
240211
itkDirectedHausdorffDistanceImageFilterGTest.cxx
212+
itkFastChamferDistanceImageFilterGTest.cxx
241213
itkHausdorffDistanceImageFilterGTest.cxx
242214
itkReflectiveImageRegionIteratorGTest.cxx
243215
itkSignedDanielssonDistanceMapImageFilterGTest.cxx

Modules/Filtering/DistanceMap/test/itkFastChamferDistanceImageFilterTest.cxx renamed to Modules/Filtering/DistanceMap/test/itkFastChamferDistanceImageFilterGTest.cxx

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
#include "itkFastChamferDistanceImageFilter.h"
2020
#include "itkMath.h"
21-
// simple signed distance function
21+
#include <gtest/gtest.h>
2222

2323
namespace
2424
{
25+
// simple signed distance function
2526
template <typename TPoint>
2627
double
2728
SimpleSignedDistance(const TPoint & p)
@@ -50,14 +51,15 @@ SimpleSignedDistance(const TPoint & p)
5051
}
5152
}
5253

53-
} // namespace
5454

5555
template <unsigned int VDimension>
56-
int
56+
void
5757
FastChamferDistanceImageFilterTest(unsigned int iPositive, unsigned int iNegative, unsigned int iOther)
5858
{
59-
std::cout << "Test ITK Chamfer Distance Image Filter" << std::endl;
60-
std::cout << "Compute the distance map of a 32^d image" << std::endl;
59+
// Test ITK Chamfer Distance Image Filter
60+
// Compute the distance map of a 32^d image
61+
62+
SCOPED_TRACE("Dimension = " + std::to_string(VDimension));
6163

6264
using PixelType = float;
6365

@@ -92,16 +94,7 @@ FastChamferDistanceImageFilterTest(unsigned int iPositive, unsigned int iNegativ
9294

9395
const typename ImageType::Pointer outputImage = filter->GetOutput();
9496

95-
try
96-
{
97-
filter->Update();
98-
}
99-
catch (const itk::ExceptionObject & err)
100-
{
101-
std::cout << "ExceptionObject caught !" << std::endl;
102-
std::cout << err << std::endl;
103-
return EXIT_FAILURE;
104-
}
97+
EXPECT_NO_THROW(filter->Update());
10598

10699
filter->Print(std::cout);
107100

@@ -142,24 +135,10 @@ FastChamferDistanceImageFilterTest(unsigned int iPositive, unsigned int iNegativ
142135
}
143136
++itNB;
144137
}
145-
int returnVal(EXIT_SUCCESS);
146-
if (innerpositive != iPositive)
147-
{
148-
std::cout << "Inner positive points: " << innerpositive << " != " << iPositive << std::endl;
149-
returnVal = EXIT_FAILURE;
150-
}
151-
152-
if (innernegative != iNegative)
153-
{
154-
std::cout << "Inner negative points: " << innernegative << " != " << iNegative << std::endl;
155-
returnVal = EXIT_FAILURE;
156-
}
157138

158-
if (otherpoints != iOther)
159-
{
160-
std::cout << "Rest of points: " << otherpoints << " != " << iOther << std::endl;
161-
returnVal = EXIT_FAILURE;
162-
}
139+
EXPECT_EQ(innerpositive, iPositive);
140+
EXPECT_EQ(innernegative, iNegative);
141+
EXPECT_EQ(otherpoints, iOther);
163142

164143
// Exercising filter methods
165144
float inweights[VDimension];
@@ -183,11 +162,8 @@ FastChamferDistanceImageFilterTest(unsigned int iPositive, unsigned int iNegativ
183162

184163
std::cout << "outweights = " << outweights << std::endl;
185164

186-
if (itk::Math::NotAlmostEquals(filter->GetMaximumDistance(), 5))
187-
{
188-
std::cout << "filter->GetMaximumDistance() != 5" << std::endl;
189-
returnVal = EXIT_FAILURE;
190-
}
165+
EXPECT_FLOAT_EQ(filter->GetMaximumDistance(), 5);
166+
191167
/* For debugging write the result
192168
using WriterType = itk::ImageFileWriter< ImageType >;
193169
auto writer = WriterType::New();
@@ -196,41 +172,15 @@ FastChamferDistanceImageFilterTest(unsigned int iPositive, unsigned int iNegativ
196172
writer->SetInput(filter->GetOutput());
197173
writer->Update();
198174
*/
199-
200-
if (returnVal == EXIT_SUCCESS)
201-
{
202-
std::cout << "Test passed" << std::endl;
203-
}
204-
return returnVal;
205175
}
206176

207-
int
208-
itkFastChamferDistanceImageFilterTest(int argc, char * argv[])
209-
{
210-
if (argc != 2)
211-
{
212-
std::cout << "This test requires at least one argument (the image dimension)" << std::endl;
213-
return EXIT_FAILURE;
214-
}
177+
} // namespace
215178

216-
const int Dimension = std::stoi(argv[1]);
217179

218-
std::cout << "Dimension = " << Dimension << std::endl;
219-
if (Dimension == 1)
220-
{
221-
return FastChamferDistanceImageFilterTest<1>(4, 6, 8);
222-
}
223-
if (Dimension == 2)
224-
{
225-
return FastChamferDistanceImageFilterTest<2>(144, 124, 256);
226-
}
227-
if (Dimension == 3)
228-
{
229-
return FastChamferDistanceImageFilterTest<3>(3068, 2066, 5520);
230-
}
231-
if (Dimension == 4)
232-
{
233-
return FastChamferDistanceImageFilterTest<4>(49472, 28928, 93136);
234-
}
235-
return EXIT_FAILURE;
180+
TEST(FastChamferDistanceImageFilter, Test)
181+
{
182+
FastChamferDistanceImageFilterTest<1>(4, 6, 8);
183+
FastChamferDistanceImageFilterTest<2>(144, 124, 256);
184+
FastChamferDistanceImageFilterTest<3>(3068, 2066, 5520);
185+
FastChamferDistanceImageFilterTest<4>(49472, 28928, 93136);
236186
}

0 commit comments

Comments
 (0)