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.
- Call other Get methods for ivars that have no Set methods/ivars having
  an informative purpose.
- Remove statements that serialize the values obtained through the Get
  macro and call the Get methods in the context of the quantitative
  testing macros.
  • Loading branch information
jhlegarreta committed Aug 8, 2023
1 parent 90799a2 commit 8dd3730
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "itkTransformFileReader.h"
#include "itkTestingMacros.h"

int
itkTransformFileReaderTemplateTest(int argc, char * argv[])
Expand All @@ -33,14 +34,17 @@ itkTransformFileReaderTemplateTest(int argc, char * argv[])

auto transformReader = TransformReaderType::New();

std::cout << "Reader class = " << transformReader->GetNameOfClass() << "Reader base = "
<< dynamic_cast<TransformReaderType::Superclass *>(transformReader.GetPointer())->GetNameOfClass()
<< std::endl;
ITK_EXERCISE_BASIC_OBJECT_METHODS(transformReader, TransformFileReaderTemplate, LightProcessObject);


// trigger empty read exception
ITK_TRY_EXPECT_EXCEPTION(transformReader->Update());

transformReader->SetFileName("transform.garbage");

const char * fileName = "transform.garbage";
transformReader->SetFileName(fileName);
ITK_TEST_SET_GET_VALUE(fileName, transformReader->GetFileName());

// trigger exception for transformio not found
ITK_TRY_EXPECT_EXCEPTION(transformReader->Update());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "itkTransformFileWriter.h"
#include "itkTestingMacros.h"

int
itkTransformFileWriterTemplateTest(int argc, char * argv[])
Expand All @@ -30,18 +31,21 @@ itkTransformFileWriterTemplateTest(int argc, char * argv[])
}

using TransformWriterType = itk::TransformFileWriterTemplate<double>;
auto transformWriter = TransformWriterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(transformWriter, TransformFileWriterTemplate, LightProcessObject);

auto transformWriter = TransformWriterType::New();

std::cout << "Writer class = " << transformWriter->GetNameOfClass() << "Writer base = "
<< dynamic_cast<TransformWriterType::Superclass *>(transformWriter.GetPointer())->GetNameOfClass()
<< std::endl;
auto useCompression = false;
ITK_SET_GET_BOOLEAN(transformWriter, UseCompression, useCompression);

// trigger empty write exception
ITK_TRY_EXPECT_EXCEPTION(transformWriter->Update());

transformWriter->SetFileName("transform.garbage");
const char * fileName = "transform.garbage";
transformWriter->SetFileName(fileName);
ITK_TEST_SET_GET_VALUE(fileName, transformWriter->GetFileName());

// trigger exception for transformio not found
ITK_TRY_EXPECT_EXCEPTION(transformWriter->Update());

Expand Down
6 changes: 5 additions & 1 deletion Modules/Nonunit/IntegratedTest/test/itkBioRadImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "itkImageFileWriter.h"
#include "itkBioRadImageIO.h"
#include "itkImage.h"
#include "itkTestingMacros.h"

// Specific ImageIO test

Expand All @@ -43,6 +44,10 @@ itkBioRadImageIOTest(int argc, char * argv[])
reader->SetFileName(filename);

auto bioradImageIO = ImageIOType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(bioradImageIO, BioRadImageIO, ImageIOBase);


reader->SetImageIO(bioradImageIO);
bioradImageIO->DebugOn();

Expand Down Expand Up @@ -75,7 +80,6 @@ itkBioRadImageIOTest(int argc, char * argv[])
return EXIT_FAILURE;
}

bioradImageIO->Print(std::cout);

return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,59 @@ itkDemonsRegistrationFilterTest(int, char *[])
using RegistrationType = itk::DemonsRegistrationFilter<ImageType, ImageType, FieldType>;
auto registrator = RegistrationType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(registrator, DemonsRegistrationFilter, PDEDeformableRegistrationFilter);


registrator->SetInitialDisplacementField(caster->GetOutput());
ITK_TEST_SET_GET_VALUE(caster->GetOutput(), registrator->GetInitialDisplacementField());

registrator->SetMovingImage(moving);
ITK_TEST_SET_GET_VALUE(moving, registrator->GetMovingImage());

registrator->SetFixedImage(fixed);
registrator->SetNumberOfIterations(200);
registrator->SetStandardDeviations(1.0);
registrator->SetMaximumError(0.08);
registrator->SetMaximumKernelWidth(10);
registrator->SetIntensityDifferenceThreshold(0.001);
ITK_TEST_SET_GET_VALUE(fixed, registrator->GetFixedImage());

auto numberOfIterations = static_cast<itk::IdentifierType>(200);
registrator->SetNumberOfIterations(numberOfIterations);
ITK_TEST_SET_GET_VALUE(numberOfIterations, registrator->GetNumberOfIterations());

double standardDeviationsVal = 1.0;
RegistrationType::StandardDeviationsType standardDeviations{ standardDeviationsVal };
registrator->SetStandardDeviations(standardDeviationsVal);
ITK_TEST_SET_GET_VALUE(standardDeviations, registrator->GetStandardDeviations());

registrator->SetStandardDeviations(standardDeviations);
ITK_TEST_SET_GET_VALUE(standardDeviations, registrator->GetStandardDeviations());

auto maximumError = 0.08;
registrator->SetMaximumError(maximumError);
ITK_TEST_SET_GET_VALUE(maximumError, registrator->GetMaximumError());

unsigned int maximumKernelWidth = 10;
registrator->SetMaximumKernelWidth(maximumKernelWidth);
ITK_TEST_SET_GET_VALUE(maximumKernelWidth, registrator->GetMaximumKernelWidth());

auto intensityDifferenceThreshold = 0.001;
registrator->SetIntensityDifferenceThreshold(intensityDifferenceThreshold);
ITK_TEST_SET_GET_VALUE(intensityDifferenceThreshold, registrator->GetIntensityDifferenceThreshold());

auto smoothDisplacementField = true;
ITK_TEST_SET_GET_BOOLEAN(registrator, SmoothDisplacementField, smoothDisplacementField);

auto smoothUpdateField = false;
ITK_TEST_SET_GET_BOOLEAN(registrator, SmoothUpdateField, smoothUpdateField);

double updateFieldStandardDeviationsVal = 1.0;
RegistrationType::StandardDeviationsType updateFieldStandardDeviations{ updateFieldStandardDeviationsVal };
registrator->SetUpdateFieldStandardDeviations(updateFieldStandardDeviationsVal);
ITK_TEST_SET_GET_VALUE(updateFieldStandardDeviations, registrator->GetUpdateFieldStandardDeviations());

registrator->SetUpdateFieldStandardDeviations(updateFieldStandardDeviations);
ITK_TEST_SET_GET_VALUE(updateFieldStandardDeviations, registrator->GetUpdateFieldStandardDeviations());

// turn on inplace execution
registrator->InPlaceOn();
auto inPlace = true;
ITK_TEST_SET_GET_BOOLEAN(registrator, InPlace, inPlace);

// turn on/off use moving image gradient
auto useMovingImageGradient = false;
Expand All @@ -205,18 +247,6 @@ itkDemonsRegistrationFilterTest(int, char *[])
fptr->Print(std::cout);
}

// exercise other member variables
std::cout << "No. Iterations: " << registrator->GetNumberOfIterations() << std::endl;
std::cout << "Max. kernel error: " << registrator->GetMaximumError() << std::endl;
std::cout << "Max. kernel width: " << registrator->GetMaximumKernelWidth() << std::endl;

double v[ImageDimension];
for (unsigned int j = 0; j < ImageDimension; ++j)
{
v[j] = registrator->GetStandardDeviations()[j];
}
registrator->SetStandardDeviations(v);

using ProgressType = ShowProgressObject<RegistrationType>;
ProgressType progressWatch(registrator);
itk::SimpleMemberCommand<ProgressType>::Pointer command;
Expand Down Expand Up @@ -272,6 +302,8 @@ itkDemonsRegistrationFilterTest(int, char *[])
return EXIT_FAILURE;
}

std::cout << "IntensityDifferenceThreshold: " << registrator->GetIntensityDifferenceThreshold() << std::endl;

registrator->Print(std::cout);

// -----------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,61 @@ itkFastSymmetricForcesDemonsRegistrationFilterTest(int, char *[])


registrator->SetInitialDisplacementField(caster->GetOutput());
ITK_TEST_SET_GET_VALUE(caster->GetOutput(), registrator->GetInitialDisplacementField());

registrator->SetMovingImage(moving);
ITK_TEST_SET_GET_VALUE(moving, registrator->GetMovingImage());

registrator->SetFixedImage(fixed);
registrator->SetNumberOfIterations(200);
registrator->SetStandardDeviations(1.0);
registrator->SetMaximumError(0.08);
registrator->SetMaximumKernelWidth(10);
registrator->SetIntensityDifferenceThreshold(0.001);
ITK_TEST_SET_GET_VALUE(fixed, registrator->GetFixedImage());

auto numberOfIterations = static_cast<itk::IdentifierType>(200);
registrator->SetNumberOfIterations(numberOfIterations);
ITK_TEST_SET_GET_VALUE(numberOfIterations, registrator->GetNumberOfIterations());

double standardDeviationsVal = 1.0;
RegistrationType::StandardDeviationsType standardDeviations{ standardDeviationsVal };
registrator->SetStandardDeviations(standardDeviationsVal);
ITK_TEST_SET_GET_VALUE(standardDeviations, registrator->GetStandardDeviations());

registrator->SetStandardDeviations(standardDeviations);
ITK_TEST_SET_GET_VALUE(standardDeviations, registrator->GetStandardDeviations());

auto maximumError = 0.08;
registrator->SetMaximumError(maximumError);
ITK_TEST_SET_GET_VALUE(maximumError, registrator->GetMaximumError());

unsigned int maximumKernelWidth = 10;
registrator->SetMaximumKernelWidth(maximumKernelWidth);
ITK_TEST_SET_GET_VALUE(maximumKernelWidth, registrator->GetMaximumKernelWidth());

auto intensityDifferenceThreshold = 0.001;
registrator->SetIntensityDifferenceThreshold(intensityDifferenceThreshold);
ITK_TEST_SET_GET_VALUE(intensityDifferenceThreshold, registrator->GetIntensityDifferenceThreshold());

auto smoothDisplacementField = true;
ITK_TEST_SET_GET_BOOLEAN(registrator, SmoothDisplacementField, smoothDisplacementField);

auto smoothUpdateField = false;
ITK_TEST_SET_GET_BOOLEAN(registrator, SmoothUpdateField, smoothUpdateField);

double updateFieldStandardDeviationsVal = 1.0;
RegistrationType::StandardDeviationsType updateFieldStandardDeviations{ updateFieldStandardDeviationsVal };
registrator->SetUpdateFieldStandardDeviations(updateFieldStandardDeviationsVal);
ITK_TEST_SET_GET_VALUE(updateFieldStandardDeviations, registrator->GetUpdateFieldStandardDeviations());

registrator->SetUpdateFieldStandardDeviations(updateFieldStandardDeviations);
ITK_TEST_SET_GET_VALUE(updateFieldStandardDeviations, registrator->GetUpdateFieldStandardDeviations());

// turn on inplace execution
registrator->InPlaceOn();
auto inPlace = true;
ITK_TEST_SET_GET_BOOLEAN(registrator, InPlace, inPlace);

using FunctionType = RegistrationType::DemonsRegistrationFunctionType;
FunctionType * fptr;
fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
fptr->Print(std::cout);

// exercise other member variables
std::cout << "No. Iterations: " << registrator->GetNumberOfIterations() << std::endl;
std::cout << "Max. kernel error: " << registrator->GetMaximumError() << std::endl;
std::cout << "Max. kernel width: " << registrator->GetMaximumKernelWidth() << std::endl;

double v[ImageDimension];
for (unsigned int j = 0; j < ImageDimension; ++j)
{
v[j] = registrator->GetStandardDeviations()[j];
}
registrator->SetStandardDeviations(v);

using ProgressType = ShowProgressObject<RegistrationType>;
ProgressType progressWatch(registrator);
itk::SimpleMemberCommand<ProgressType>::Pointer command;
Expand Down

0 comments on commit 8dd3730

Please sign in to comment.