Skip to content

Commit

Permalink
ENH: Increase code coverage
Browse files Browse the repository at this point in the history
Increase the code coverage:
- Exercise the basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro.
- Remove explicit calls to the `Print` method and rely on the
  basic method exercising macro call.

Take advantage of the commit to:
- Define as a constant expression the image dimensionality.
- Capitalize comment sentences.
in the `itkHausdorffDistanceImageFilterTest.cxx` file
  • Loading branch information
jhlegarreta authored and dzenanz committed Mar 29, 2021
1 parent b2c3042 commit f704b5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

#include "itkHausdorffDistanceImageFilter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkHausdorffDistanceImageFilterTest(int, char *[])
{

constexpr unsigned int ImageDimension = 3;

using Pixel1Type = unsigned int;
using Pixel2Type = float;
enum
{
ImageDimension = 3
};

using Image1Type = itk::Image<Pixel1Type, ImageDimension>;
using Image2Type = itk::Image<Pixel2Type, ImageDimension>;
Expand Down Expand Up @@ -80,8 +79,10 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
++it2;
}

int exit_status = EXIT_SUCCESS; // If no failures detected, then EXIT_SUCCESS
// compute the directed Hausdorff distance h(image1,image2)
// If no failures detected, then EXIT_SUCCESS
int exit_status = EXIT_SUCCESS;

// Compute the directed Hausdorff distance h(image1,image2)
{
using FilterType = itk::DirectedHausdorffDistanceImageFilter<Image1Type, Image2Type>;
FilterType::Pointer filter = FilterType::New();
Expand All @@ -90,9 +91,8 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
filter->SetInput1(image1);
filter->SetInput2(image2);
filter->Update();
filter->Print(std::cout);

// check results
// Check results
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
const FilterType::RealType distance = filter->GetDirectedHausdorffDistance();

Expand All @@ -111,7 +111,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
}
}

// compute the directed Hausdorff distance h(image2,image1)
// Compute the directed Hausdorff distance h(image2,image1)
{
using FilterType = itk::DirectedHausdorffDistanceImageFilter<Image2Type, Image1Type>;
FilterType::Pointer filter = FilterType::New();
Expand All @@ -120,7 +120,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
filter->SetInput2(image1);
filter->Update();

// check results
// Check results
const FilterType::RealType trueDistance = 5 * std::sqrt(static_cast<double>(ImageDimension));
const FilterType::RealType distance = filter->GetDirectedHausdorffDistance();

Expand All @@ -140,16 +140,19 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
}
}

// compute the Hausdorff distance H(image1,image2)
// Compute the Hausdorff distance H(image1,image2)
{
using FilterType = itk::HausdorffDistanceImageFilter<Image1Type, Image2Type>;
FilterType::Pointer filter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, HausdorffDistanceImageFilter, ImageToImageFilter);


filter->SetInput1(image1);
filter->SetInput2(image2);
filter->Update();

// check results
// Check results
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
const FilterType::RealType distance = filter->GetHausdorffDistance();

Expand All @@ -169,7 +172,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
}
}

// compute the Hausdorff distance H(image2,image1)
// Compute the Hausdorff distance H(image2,image1)
{
using FilterType = itk::HausdorffDistanceImageFilter<Image2Type, Image1Type>;
FilterType::Pointer filter = FilterType::New();
Expand All @@ -178,7 +181,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
filter->SetInput2(image1);
filter->Update();

// check results
// Check results
const FilterType::RealType trueDistance = 10 * std::sqrt(static_cast<double>(ImageDimension));
const FilterType::RealType distance = filter->GetHausdorffDistance();

Expand All @@ -198,7 +201,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
}
}

// compute the Hausdorff distance H(image2,image1)
// Compute the Hausdorff distance H(image2,image1)
{
Image1Type::SpacingType spacing1 = image1->GetSpacing();
spacing1[0] = spacing1[0] / 2;
Expand All @@ -210,6 +213,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
spacing2[1] = spacing2[1] / 2;
spacing2[2] = spacing2[2] / 2;
image2->SetSpacing(spacing2);

using FilterType = itk::HausdorffDistanceImageFilter<Image2Type, Image1Type>;
FilterType::Pointer filter = FilterType::New();

Expand All @@ -218,7 +222,7 @@ itkHausdorffDistanceImageFilterTest(int, char *[])
filter->SetUseImageSpacing(true);
filter->Update();

// check results
// Check results
const FilterType::RealType trueDistance =
10 * std::sqrt(spacing1[0] * spacing1[0] + spacing1[1] * spacing1[1] + spacing1[2] * spacing1[2]);
const FilterType::RealType trueAverageDistance = 4.5 * spacing1[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/

#include "itkScalarChanAndVeseSparseLevelSetImageFilter.h"
#include "itkTestingMacros.h"

int
itkScalarChanAndVeseSparseLevelSetImageFilterTest1(int, char *[])
Expand Down Expand Up @@ -50,8 +51,10 @@ itkScalarChanAndVeseSparseLevelSetImageFilterTest1(int, char *[])

FilterType::Pointer filter = FilterType::New();

std::cout << "GetNameOfClass() = " << filter->GetNameOfClass() << std::endl;
filter->Print(std::cout);
ITK_EXERCISE_BASIC_OBJECT_METHODS(
filter, ScalarChanAndVeseSparseLevelSetImageFilter, MultiphaseSparseFiniteDifferenceImageFilter);


std::cout << "Test finished. " << std::endl;
return EXIT_SUCCESS;
}

0 comments on commit f704b5f

Please sign in to comment.