1818
1919#include " itkFastChamferDistanceImageFilter.h"
2020#include " itkMath.h"
21- // simple signed distance function
21+ # include < gtest/gtest.h >
2222
2323namespace
2424{
25+ // simple signed distance function
2526template <typename TPoint>
2627double
2728SimpleSignedDistance (const TPoint & p)
@@ -50,14 +51,15 @@ SimpleSignedDistance(const TPoint & p)
5051 }
5152}
5253
53- } // namespace
5454
5555template <unsigned int VDimension>
56- int
56+ void
5757FastChamferDistanceImageFilterTest (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