Skip to content

Commit

Permalink
ENH: Increase coverage for miscellaneous classes
Browse files Browse the repository at this point in the history
Increase coverage for miscellaneous classes:
- Exercise basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro. Remove redundant calls to
  print the filter: rely on the basic method exercising macro call.
- Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro.
- Test the boolean ivars using the `ITK_TEST_SET_GET_BOOLEAN` macro.
- Test exceptions using the `ITK_TRY_EXPECT_EXCEPTION` macro.
  • Loading branch information
jhlegarreta authored and dzenanz committed Aug 24, 2022
1 parent 16d7523 commit b248e0d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ itkFiniteCylinderSpatialFunctionTest(int, char *[])
ITK_EXERCISE_BASIC_OBJECT_METHODS(spatialFunc, FiniteCylinderSpatialFunction, InteriorExteriorSpatialFunction);


// Test exceptions
TCylinderFunctionVectorType orientation;
orientation[0] = 0.0;
orientation[1] = 0.0;
orientation[2] = 0.0;
ITK_TRY_EXPECT_EXCEPTION(spatialFunc->SetOrientation(orientation));

double axis = 40.0;
spatialFunc->SetAxisLength(axis);
ITK_TEST_SET_GET_VALUE(axis, spatialFunc->GetAxisLength());
Expand All @@ -53,7 +60,6 @@ itkFiniteCylinderSpatialFunctionTest(int, char *[])
spatialFunc->SetCenter(center);
ITK_TEST_SET_GET_VALUE(center, spatialFunc->GetCenter());

TCylinderFunctionVectorType orientation;
orientation[0] = .35;
orientation[1] = .35;
orientation[2] = .30;
Expand Down
7 changes: 7 additions & 0 deletions Modules/Core/Mesh/test/itkWarpMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ itkWarpMeshFilterTest(int, char *[])
ITK_EXERCISE_BASIC_OBJECT_METHODS(warpFilter, WarpMeshFilter, MeshToMeshFilter);


// Test exceptions
ITK_TRY_EXPECT_EXCEPTION(warpFilter->Update());

warpFilter->SetInput(sphereMeshSource->GetOutput());

// Test exceptions
ITK_TRY_EXPECT_EXCEPTION(warpFilter->Update());


warpFilter->SetDisplacementField(deformationField);

ITK_TRY_EXPECT_NO_EXCEPTION(warpFilter->Update());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkBilateralImageFilter.h"
#include "itkNullImageToImageFilterDriver.hxx"
#include "itkTestingMacros.h"

/**
* Test the class instance by driving it with a null input and output.
Expand All @@ -29,14 +30,50 @@ itkBilateralImageFilterTest(int, char *[])
{
try
{
using ImageType = itk::Image<float, 2>;
constexpr unsigned int Dimension = 2;

using ImageType = itk::Image<float, Dimension>;

// Set up filter
using FilterType = itk::BilateralImageFilter<ImageType, ImageType>;
itk::BilateralImageFilter<ImageType, ImageType>::Pointer filter =
itk::BilateralImageFilter<ImageType, ImageType>::New();
filter->SetDomainSigma(2.0);
filter->SetDomainMu(2.5);
filter->SetRangeSigma(35.0f);

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, BilateralImageFilter, ImageToImageFilter);


double domainSigmaVal = 2.0;
typename FilterType::ArrayType domainSigma = FilterType::ArrayType::Filled(domainSigmaVal);
filter->SetDomainSigma(domainSigmaVal);
ITK_TEST_SET_GET_VALUE(domainSigma, filter->GetDomainSigma());

domainSigmaVal = 2.5;
domainSigma.Fill(domainSigmaVal);
filter->SetDomainSigma(domainSigma);
ITK_TEST_SET_GET_VALUE(domainSigma, filter->GetDomainSigma());

double domainMu = 2.5;
filter->SetDomainMu(domainMu);
ITK_TEST_SET_GET_VALUE(domainMu, filter->GetDomainMu());

double rangeSigma = 35.0f;
filter->SetRangeSigma(rangeSigma);
ITK_TEST_SET_GET_VALUE(rangeSigma, filter->GetRangeSigma());

filter->SetFilterDimensionality(Dimension);
ITK_TEST_SET_GET_VALUE(Dimension, filter->GetFilterDimensionality());

bool automaticKernelSize = true;
ITK_TEST_SET_GET_BOOLEAN(filter, AutomaticKernelSize, automaticKernelSize);

typename FilterType::SizeType::SizeValueType radiusVal = 2;
typename FilterType::SizeType radius = FilterType::SizeType::Filled(radiusVal);
filter->SetRadius(radius);
ITK_TEST_SET_GET_VALUE(radius, filter->GetRadius());

unsigned long numberOfRangeGaussianSamples = 150;
filter->SetNumberOfRangeGaussianSamples(numberOfRangeGaussianSamples);
ITK_TEST_SET_GET_VALUE(numberOfRangeGaussianSamples, filter->GetNumberOfRangeGaussianSamples());

// Run Test
itk::Size<2> sz;
Expand Down
3 changes: 3 additions & 0 deletions Modules/IO/RAW/test/itkRawImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ itkRawImageIOTest(int argc, char * argv[])

io->CanReadFile(filename.c_str());

// Not used; empty method body; called for coverage purposes
io->ReadHeader();

// Compare pixel by pixel in memory


Expand Down
2 changes: 2 additions & 0 deletions Modules/Registration/Common/test/itkPointsLocatorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ testPointsLocatorTest()
}

pointsLocator->SetPoints(points);
ITK_TEST_SET_GET_VALUE(points, pointsLocator->GetPoints());

pointsLocator->Initialize();

/**
Expand Down
16 changes: 16 additions & 0 deletions Modules/Segmentation/KLMRegionGrowing/test/itkRegionGrow2DTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ test_regiongrowKLM1D()
KLMFilter->SetMaximumLambda(maximumLambda);
ITK_TEST_SET_GET_VALUE(maximumLambda, KLMFilter->GetMaximumLambda());

unsigned int numberOfRegions = 0;
KLMFilter->SetNumberOfRegions(numberOfRegions);
ITK_TEST_SET_GET_VALUE(numberOfRegions, KLMFilter->GetNumberOfRegions());

int nregions = 2;
KLMFilter->SetMaximumNumberOfRegions(nregions);

Expand Down Expand Up @@ -412,6 +416,10 @@ test_regiongrowKLM1D()
KLMFilter->SetMaximumLambda(maximumLambda);
ITK_TEST_SET_GET_VALUE(maximumLambda, KLMFilter->GetMaximumLambda());

KLMFilter->SetNumberOfRegions(numberOfRegions);
ITK_TEST_SET_GET_VALUE(numberOfRegions, KLMFilter->GetNumberOfRegions());


LOCAL_TEST_EXCEPTION_MACRO(KLMFilter);

if (KLMFilter->GetNumberOfRegions() != KLMFilter->GetMaximumNumberOfRegions())
Expand Down Expand Up @@ -1138,6 +1146,10 @@ test_regiongrowKLM2D()
KLMFilter->SetMaximumLambda(maximumLambda);
ITK_TEST_SET_GET_VALUE(maximumLambda, KLMFilter->GetMaximumLambda());

unsigned int numberOfRegions = 0;
KLMFilter->SetNumberOfRegions(numberOfRegions);
ITK_TEST_SET_GET_VALUE(numberOfRegions, KLMFilter->GetNumberOfRegions());

// Kick off the Region grow function

LOCAL_TEST_EXCEPTION_MACRO(KLMFilter);
Expand Down Expand Up @@ -1424,6 +1436,10 @@ test_regiongrowKLM3D()

KLMFilter->SetMaximumLambda(-1);

unsigned int numberOfRegions = 0;
KLMFilter->SetNumberOfRegions(numberOfRegions);
ITK_TEST_SET_GET_VALUE(numberOfRegions, KLMFilter->GetNumberOfRegions());

// Kick off the Region grow function

LOCAL_TEST_EXCEPTION_MACRO(KLMFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,48 @@ itkSparseFieldFourthOrderLevelSetImageFilterTest(int, char *[])
using FilterType = itk::IsotropicDiffusionLevelSetFilter<ImageType, ImageType>;
auto filter = FilterType::New();

filter->SetInput(image);
std::cout << "MaxRefitIteration = " << (filter->GetMaxRefitIteration()) << "\n";
std::cout << "MaxNormalIteration = " << (filter->GetMaxNormalIteration()) << "\n";
filter->SetCurvatureBandWidth(4);
std::cout << "CurvatureBandWidth= " << (filter->GetCurvatureBandWidth()) << "\n";
filter->SetRMSChangeNormalProcessTrigger(0.001);
std::cout << "RMS change trigger = " << (filter->GetRMSChangeNormalProcessTrigger()) << "\n";
std::cout << "Normal process type = " << (filter->GetNormalProcessType()) << "\n";
std::cout << "Conductance = " << (filter->GetNormalProcessConductance()) << "\n";
std::cout << "Unsharp flag = " << (filter->GetNormalProcessUnsharpFlag()) << "\n";
std::cout << "Unsharp weight = " << (filter->GetNormalProcessUnsharpWeight()) << "\n";
ITK_EXERCISE_BASIC_OBJECT_METHODS(
filter, IsotropicDiffusionLevelSetFilter, SparseFieldFourthOrderLevelSetImageFilter);


unsigned int maxRefitIteration = 0;
filter->SetMaxRefitIteration(maxRefitIteration);
ITK_TEST_SET_GET_VALUE(maxRefitIteration, filter->GetMaxRefitIteration());

unsigned int maxNormalIteration = 100;
filter->SetMaxNormalIteration(maxNormalIteration);
ITK_TEST_SET_GET_VALUE(maxNormalIteration, filter->GetMaxNormalIteration());

typename FilterType::ValueType curvatureBandWidth = 4;
filter->SetCurvatureBandWidth(curvatureBandWidth);
ITK_TEST_SET_GET_VALUE(curvatureBandWidth, filter->GetCurvatureBandWidth());

typename FilterType::ValueType rmsChangeNormalProcessTrigger = 0.001;
filter->SetRMSChangeNormalProcessTrigger(rmsChangeNormalProcessTrigger);
ITK_TEST_SET_GET_VALUE(rmsChangeNormalProcessTrigger, filter->GetRMSChangeNormalProcessTrigger());

int normalProcessType = 0;
filter->SetNormalProcessType(normalProcessType);
ITK_TEST_SET_GET_VALUE(normalProcessType, filter->GetNormalProcessType());

typename FilterType::ValueType normalProcessConductance =
itk::NumericTraits<typename FilterType::ValueType>::ZeroValue();
filter->SetNormalProcessConductance(normalProcessConductance);
ITK_TEST_SET_GET_VALUE(normalProcessConductance, filter->GetNormalProcessConductance());

bool normalProcessUnsharpFlag = false;
filter->SetNormalProcessUnsharpFlag(normalProcessUnsharpFlag);
ITK_TEST_SET_GET_BOOLEAN(filter, NormalProcessUnsharpFlag, normalProcessUnsharpFlag);

ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());
typename FilterType::ValueType normalProcessUnsharpWeight =
itk::NumericTraits<typename FilterType::ValueType>::ZeroValue();
filter->SetNormalProcessUnsharpWeight(normalProcessUnsharpWeight);
ITK_TEST_SET_GET_VALUE(normalProcessUnsharpWeight, filter->GetNormalProcessUnsharpWeight());

filter->SetInput(image);

ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

filter->Print(std::cout);

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

0 comments on commit b248e0d

Please sign in to comment.