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 or its class name.
- Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro.
- Make the tests quantitative: compare the compute threshold to the
  expected one.
- Refactor the tests to accept (more) input parameters to check the
  classes under a broader range of conditions.
- Add the `itkQuadEdgeMeshEulerOperatorSplitFaceTest` test.
  • Loading branch information
jhlegarreta authored and hjmjohnson committed Mar 22, 2022
1 parent ca84de0 commit 7866523
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "itkBSplineInterpolationWeightFunction.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkTestingMacros.h"

// Test template instantiation for TCoordRep = float and VSplineOrder = 1.
// Note that this particular template instantiation would take forever to
Expand Down Expand Up @@ -58,6 +59,19 @@ itkBSplineInterpolationWeightFunctionTest(int, char *[])

auto function = FunctionType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(function, BSplineInterpolationWeightFunction, FunctionBase);


#if !defined(ITK_LEGACY_REMOVE)
# if defined(ITK_LEGACY_SILENT)
typename FunctionType::SizeType supportSize = FunctionType::SizeType::Filled(SplineOrder + 1);
ITK_TEST_EXPECT_EQUAL(supportSize, function->GetSupportSize());

unsigned int numberOfWeights = WeightsType::Length;
ITK_TEST_EXPECT_EQUAL(numberOfWeights, function->GetNumberOfWeights());
# endif
#endif

WeightsType weights1;
WeightsType weights2;

Expand Down
13 changes: 13 additions & 0 deletions Modules/Core/Common/test/itkPointSetTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ itkPointSetTest(int, char *[])
*/
PointSet::Pointer pset(PointSet::New());

ITK_EXERCISE_BASIC_OBJECT_METHODS(pset, PointSet, DataObject);


// Test point container existence exception
auto pId = static_cast<PointSet::PointIdentifier>(numOfPoints + 1);
ITK_TRY_EXPECT_EXCEPTION(pset->GetPoint(pId));

/**
* Add our test points to the mesh.
* pset->SetPoint(pointId, point)
Expand All @@ -72,6 +79,12 @@ itkPointSetTest(int, char *[])
return EXIT_FAILURE;
}

// Test non-existing point id exception
ITK_TRY_EXPECT_EXCEPTION(pset->GetPoint(pId));

PointSet::RegionType region = 0;
pset->SetRequestedRegion(region);

// Clear the point set
pset->Initialize();

Expand Down
11 changes: 9 additions & 2 deletions Modules/Core/ImageFunction/test/itkMedianImageFunctionTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "itkMedianImageFunction.h"
#include "itkTestingMacros.h"

int
itkMedianImageFunctionTest(int, char *[])
Expand Down Expand Up @@ -53,6 +54,9 @@ itkMedianImageFunctionTest(int, char *[])

auto function = FunctionType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(function, MedianImageFunction, ImageFunction);


function->SetInputImage(image);

ImageType::IndexType index;
Expand Down Expand Up @@ -136,9 +140,12 @@ itkMedianImageFunctionTest(int, char *[])
}

// now set the radius
function->SetNeighborhoodRadius(2);
unsigned int neighborhoodRadius = 2;
function->SetNeighborhoodRadius(neighborhoodRadius);
ITK_TEST_SET_GET_VALUE(neighborhoodRadius, function->GetNeighborhoodRadius());

median = function->EvaluateAtIndex(index);
std::cout << "function->EvaluateAtIndex( index ), neighborhood radius 2: "
std::cout << "function->EvaluateAtIndex( index ), neighborhood radius " << neighborhoodRadius << ": "
<< static_cast<itk::NumericTraits<FunctionType::OutputType>::PrintType>(median) << std::endl;
// Since we've changed the image outside the default neighborhood
// for the MedianImageFunction, it would be an error for the median
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ itkRayCastInterpolateImageFunctionTest(int itkNotUsed(argc), char * itkNotUsed(a
ITK_EXERCISE_BASIC_OBJECT_METHODS(interp, RayCastInterpolateImageFunction, InterpolateImageFunction);


// Test exceptions
ITK_TRY_EXPECT_EXCEPTION(interp->GetRadius());

interp->SetInputImage(image);

PointType focus;
Expand Down
6 changes: 4 additions & 2 deletions Modules/Core/Mesh/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ itk_add_test(NAME itkSimplexMeshTest
COMMAND ITKMeshTestDriver itkSimplexMeshTest)
itk_add_test(NAME itkAutomaticTopologyMeshSourceTest
COMMAND ITKMeshTestDriver itkAutomaticTopologyMeshSourceTest)
itk_add_test(NAME itkBinaryMask3DMeshSourceTest
COMMAND ITKMeshTestDriver itkBinaryMask3DMeshSourceTest)
itk_add_test(NAME itkBinaryMask3DMeshSourceTestRegionOff
COMMAND ITKMeshTestDriver itkBinaryMask3DMeshSourceTest 0)
itk_add_test(NAME itkBinaryMask3DMeshSourceTestRegionOn
COMMAND ITKMeshTestDriver itkBinaryMask3DMeshSourceTest 1)
itk_add_test(NAME itkImageToParametricSpaceFilterTest
COMMAND ITKMeshTestDriver itkImageToParametricSpaceFilterTest)
itk_add_test(NAME itkInteriorExteriorMeshFilterTest
Expand Down
30 changes: 19 additions & 11 deletions Modules/Core/Mesh/test/itkBinaryMask3DMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ Create16CubeConfig(ImagePointerType image,
int
itkBinaryMask3DMeshSourceTest(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " useRegion" << std::endl;
return EXIT_FAILURE;
}

// Declare the type of the Mesh
using MeshType = itk::Mesh<double>;
using MeshSourceType = itk::BinaryMask3DMeshSource<ImageType, MeshType>;
Expand Down Expand Up @@ -97,27 +104,28 @@ itkBinaryMask3DMeshSourceTest(int argc, char * argv[])
}

auto meshSource = MeshSourceType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(meshSource, BinaryMask3DMeshSource, ImageToMeshFilter);


meshSource->SetInput(image);
meshSource->SetObjectValue(internalValue);

if (argc == 2)
auto useRegion = static_cast<bool>(std::stoi(argv[1]));
if (useRegion)
{
if (std::stoi(argv[1]) == 1)
{
size[0] = 9;
size[1] = 9;
size[2] = 9;
region.SetSize(size);
meshSource->SetRegionOfInterest(region);
}
size[0] = 9;
size[1] = 9;
size[2] = 9;
region.SetSize(size);
meshSource->SetRegionOfInterest(region);
ITK_TEST_SET_GET_VALUE(region, meshSource->GetRegionOfInterest());
}

ITK_TRY_EXPECT_NO_EXCEPTION(meshSource->Update());

std::cout << meshSource->GetNameOfClass() << std::endl;
std::cout << "NumberOfNodes: " << meshSource->GetNumberOfNodes() << std::endl;
std::cout << "NumberOfCells: " << meshSource->GetNumberOfCells() << std::endl;
std::cout << meshSource << std::endl;

return EXIT_SUCCESS;
}
Expand Down
4 changes: 4 additions & 0 deletions Modules/Core/Mesh/test/itkMeshTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ itkMeshTest(int, char *[])
* Create the mesh through its object factory.
*/
auto mesh = MeshType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(mesh, Mesh, PointSet);


mesh->DebugOn();


Expand Down
12 changes: 10 additions & 2 deletions Modules/Core/Mesh/test/itkRegularSphereMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ itkRegularSphereMeshSourceTest(int, char *[])

auto mySphereMeshSource = SphereMeshSourceType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(mySphereMeshSource, RegularSphereMeshSource, MeshSource);


using PointType = SphereMeshSourceType::PointType;
using VectorType = SphereMeshSourceType::VectorType;

Expand All @@ -44,14 +47,19 @@ itkRegularSphereMeshSourceTest(int, char *[])
scale.Fill(radius);

mySphereMeshSource->SetCenter(center);
mySphereMeshSource->SetResolution(1);
ITK_TEST_SET_GET_VALUE(center, mySphereMeshSource->GetCenter());

unsigned int resolution = 1;
mySphereMeshSource->SetResolution(resolution);
ITK_TEST_SET_GET_VALUE(resolution, mySphereMeshSource->GetResolution());

mySphereMeshSource->SetScale(scale);
ITK_TEST_SET_GET_VALUE(scale, mySphereMeshSource->GetScale());

mySphereMeshSource->Modified();

ITK_TRY_EXPECT_NO_EXCEPTION(mySphereMeshSource->Update());

std::cout << "mySphereMeshSource: " << mySphereMeshSource;

MeshType::Pointer myMesh = mySphereMeshSource->GetOutput();

Expand Down
6 changes: 6 additions & 0 deletions Modules/Core/Mesh/test/itkTransformMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "itkMesh.h"
#include "itkAffineTransform.h"
#include "itkStdStreamStateSave.h"
#include "itkTestingMacros.h"

int
itkTransformMeshFilterTest(int, char *[])
Expand Down Expand Up @@ -99,6 +100,10 @@ itkTransformMeshFilterTest(int, char *[])

// Create a Filter
auto filter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, TransformMeshFilter, MeshToMeshFilter);


auto filterwithbasetrfs = FilterWithBaseTransformType::New();

// Create a Transform
Expand All @@ -111,6 +116,7 @@ itkTransformMeshFilterTest(int, char *[])
// Connect the inputs
filter->SetInput(inputMesh);
filter->SetTransform(affineTransform);
ITK_TEST_SET_GET_VALUE(affineTransform, filter->GetTransform());

filterwithbasetrfs->SetInput(inputMesh);
filterwithbasetrfs->SetTransform(affineTransform);
Expand Down
11 changes: 8 additions & 3 deletions Modules/Core/Mesh/test/itkVTKPolyDataReaderTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ itkVTKPolyDataReaderTest(int argc, char * argv[])

auto polyDataReader = ReaderType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(polyDataReader, VTKPolyDataReader, MeshSource);


using PointType = ReaderType::PointType;

polyDataReader->SetFileName(argv[1]);
std::string filename = argv[1];
polyDataReader->SetFileName(filename);
ITK_TEST_SET_GET_VALUE(filename, polyDataReader->GetFileName());

ITK_TRY_EXPECT_NO_EXCEPTION(polyDataReader->Update());


std::cout << "polyDataReader:" << std::endl;
std::cout << polyDataReader << std::endl;
std::cout << "Version: " << polyDataReader->GetVersion() << std::endl;
std::cout << "Header: " << polyDataReader->GetHeader() << std::endl;

MeshType::Pointer mesh = polyDataReader->GetOutput();

Expand Down
10 changes: 8 additions & 2 deletions Modules/Core/Mesh/test/itkVTKPolyDataWriterTest01.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ itkVTKPolyDataWriterTest01(int argc, char * argv[])
}

auto writer = WriterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(writer, VTKPolyDataWriter, Object);


writer->SetInput(mesh);
writer->SetFileName(argv[1]);
std::string inputFileName = argv[1];
writer->SetFileName(inputFileName);
ITK_TEST_SET_GET_VALUE(inputFileName, writer->GetFileName());

writer->Write();

std::cout << __LINE__ << " PrintSelf\n" << writer;

return EXIT_SUCCESS;
}
2 changes: 2 additions & 0 deletions Modules/Core/QuadEdgeMesh/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ itk_add_test(NAME itkQuadEdgeMeshEulerOperatorJoinVertexTest4
4)
itk_add_test(NAME itkQuadEdgeMeshEulerOperatorSplitEdgeTest
COMMAND ITKQuadEdgeMeshTestDriver itkQuadEdgeMeshEulerOperatorSplitEdgeTest)
itk_add_test(NAME itkQuadEdgeMeshEulerOperatorSplitFaceTest
COMMAND ITKQuadEdgeMeshTestDriver itkQuadEdgeMeshEulerOperatorSplitFaceTest)
itk_add_test(NAME itkQuadEdgeMeshEulerOperatorSplitVertexTest
COMMAND ITKQuadEdgeMeshTestDriver itkQuadEdgeMeshEulerOperatorSplitVertexTest)
itk_add_test(NAME itkQuadEdgeMeshIteratorTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ itkQuadEdgeMeshEulerOperatorSplitFaceTest(int, char *[])
}
std::cout << "OK" << std::endl;

(void)splitFacet->GetNameOfClass();

MeshPointer mesh = MeshType::New();
CreateSquareTriangularMesh<MeshType>(mesh);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ itkMRIBiasFieldCorrectionFilterTest(int, char *[])
int interSliceCorrectionMaximumIteration = 100;
double optimizerInitialRadius = 0.02;
double optimizerGrowthFactor = 1.01;
double optimizerShrinkFactor = std::pow(optimizerGrowthFactor, -0.25);
bool usingInterSliceIntensityCorrection = true;


filter->SetSlabNumberOfSamples(slabNumberOfSamples);
filter->SetSlabBackgroundMinimumThreshold(slabBackgroundMinimumThreshold);
filter->SetSlabTolerance(slabTolerance);
Expand All @@ -209,6 +211,7 @@ itkMRIBiasFieldCorrectionFilterTest(int, char *[])
filter->SetInterSliceCorrectionMaximumIteration(interSliceCorrectionMaximumIteration);
filter->SetOptimizerInitialRadius(optimizerInitialRadius);
filter->SetOptimizerGrowthFactor(optimizerGrowthFactor);
filter->SetOptimizerShrinkFactor(optimizerShrinkFactor);

ITK_TEST_SET_GET_BOOLEAN(filter, BiasFieldMultiplicative, isBiasFieldMultiplicative);
ITK_TEST_SET_GET_BOOLEAN(filter, UsingSlabIdentification, usingSlabIdentification);
Expand All @@ -222,6 +225,7 @@ itkMRIBiasFieldCorrectionFilterTest(int, char *[])
ITK_TEST_SET_GET_VALUE(interSliceCorrectionMaximumIteration, filter->GetInterSliceCorrectionMaximumIteration());
ITK_TEST_SET_GET_VALUE(optimizerInitialRadius, filter->GetOptimizerInitialRadius());
ITK_TEST_SET_GET_VALUE(optimizerGrowthFactor, filter->GetOptimizerGrowthFactor());
ITK_TEST_SET_GET_VALUE(optimizerShrinkFactor, filter->GetOptimizerShrinkFactor());
ITK_TEST_SET_GET_BOOLEAN(filter, UsingInterSliceIntensityCorrection, usingInterSliceIntensityCorrection);

filter->SetBiasFieldDegree(biasDegree); // default value = 3
Expand Down
20 changes: 18 additions & 2 deletions Modules/IO/XML/test/itkDOMTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ itkDOMTest2(int argc, char * argv[])
{
// read a DOM object from an XML file
itk::DOMNodeXMLReader::Pointer reader = itk::DOMNodeXMLReader::New();
reader->SetFileName(argv[1]);

ITK_EXERCISE_BASIC_OBJECT_METHODS(reader, DOMNodeXMLReader, Object);


std::string inputFileName = argv[1];
reader->SetFileName(inputFileName);
ITK_TEST_SET_GET_VALUE(inputFileName, reader->GetFileName());

reader->Update();
itk::DOMNode::Pointer dom = reader->GetOutput();

// write a DOM object to an XML file
itk::DOMNodeXMLWriter::Pointer writer = itk::DOMNodeXMLWriter::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(writer, DOMNodeXMLWriter, Object);


writer->SetInput(dom);
writer->SetFileName(argv[2]);
ITK_TEST_SET_GET_VALUE(dom, writer->GetInput());

std::string outputFileName = argv[2];
writer->SetFileName(outputFileName);
ITK_TEST_SET_GET_VALUE(outputFileName, writer->GetFileName());

writer->Update();

// write a DOM object to an XML stream
Expand Down

0 comments on commit 7866523

Please sign in to comment.