Skip to content

Commit

Permalink
ENH: Increase itk::ObjectByObjectLabelMapFilter class coverage
Browse files Browse the repository at this point in the history
Increase `itk::ObjectByObjectLabelMapFilter` class coverage:
- Exercise the basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro.
- 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.
- Add the corresponding test arguments to the appropriate
  `CMakeLists.txt`test driver command.
- Use the `ITK_TRY_EXPECT_NO_EXCEPTION` macro to avoid boilerplate code.
- Improve slightly the test style to make them more consistent (e.g.
  input argument checking or test finishing message).
  • Loading branch information
jhlegarreta authored and dzenanz committed Jan 4, 2021
1 parent 904a440 commit 2b1806a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Modules/Filtering/LabelMap/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@ itk_add_test(NAME itkObjectByObjectLabelMapFilterTest0
COMMAND ITKLabelMapTestDriver
--compare DATA{Baseline/itkObjectByObjectLabelMapFilterTest0.png}
${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest0.png
itkObjectByObjectLabelMapFilterTest DATA{${ITK_DATA_ROOT}/Input/SpotsLabeled.png} ${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest0.png 0)
itkObjectByObjectLabelMapFilterTest DATA{${ITK_DATA_ROOT}/Input/SpotsLabeled.png} ${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest0.png 0 0 1)
itk_add_test(NAME itkObjectByObjectLabelMapFilterTest1
COMMAND ITKLabelMapTestDriver
--compare DATA{Baseline/itkObjectByObjectLabelMapFilterTest1.png}
${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest1.png
itkObjectByObjectLabelMapFilterTest DATA{${ITK_DATA_ROOT}/Input/SpotsLabeled.png} ${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest1.png 1)
itkObjectByObjectLabelMapFilterTest DATA{${ITK_DATA_ROOT}/Input/SpotsLabeled.png} ${ITK_TEST_OUTPUT_DIR}/itkObjectByObjectLabelMapFilterTest1.png 1 0 1)
itk_add_test(NAME itkPadLabelMapFilterTest1
COMMAND ITKLabelMapTestDriver
--compare DATA{Baseline/cthead1-label-pad.mha}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ int
itkObjectByObjectLabelMapFilterTest(int argc, char * argv[])
{

if (argc != 4)
if (argc != 6)
{
std::cerr << "usage: " << itkNameOfTestExecutableMacro(argv) << " input output keepLabel" << std::endl;
// std::cerr << " : " << std::endl;
exit(1);
std::cerr << "Missing Parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv)
<< " input output keepLabel binaryInternalOutput constrainPaddingToImage" << std::endl;
return EXIT_FAILURE;
}

constexpr int dim = 2;
Expand All @@ -60,11 +61,30 @@ itkObjectByObjectLabelMapFilterTest(int argc, char * argv[])

using ObOType = itk::ObjectByObjectLabelMapFilter<LabelMapType>;
ObOType::Pointer obo = ObOType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(obo, ObjectByObjectLabelMapFilter, LabelMapFilter);


obo->SetInput(i2l->GetOutput());
obo->SetFilter(dilate);

obo->SetPadSize(rad);
obo->SetKeepLabels(std::stoi(argv[3]));
// obo->SetBinaryInternalOutput( false );
ITK_TEST_SET_GET_VALUE(rad, obo->GetPadSize());

auto keepLabels = static_cast<bool>(std::stoi(argv[3]));
ITK_TEST_SET_GET_BOOLEAN(obo, KeepLabels, keepLabels);

bool binaryInternalOutput = static_cast<bool>(std::stoi(argv[4]));
ITK_TEST_SET_GET_BOOLEAN(obo, BinaryInternalOutput, binaryInternalOutput);

bool constrainPaddingToImage = static_cast<bool>(std::stoi(argv[5]));
ITK_TEST_SET_GET_BOOLEAN(obo, ConstrainPaddingToImage, constrainPaddingToImage);

ObOType::InternalOutputPixelType internalForegroundValue =
itk::NumericTraits<ObOType::InternalOutputPixelType>::max();
obo->SetInternalForegroundValue(internalForegroundValue);
ITK_TEST_SET_GET_VALUE(internalForegroundValue, obo->GetInternalForegroundValue());

itk::SimpleFilterWatcher watcher(obo, "filter");

using L2IType = itk::LabelMapToLabelImageFilter<LabelMapType, ImageType>;
Expand All @@ -75,7 +95,10 @@ itkObjectByObjectLabelMapFilterTest(int argc, char * argv[])
WriterType::Pointer writer = WriterType::New();
writer->SetInput(l2i->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();

return 0;
ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update());


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

0 comments on commit 2b1806a

Please sign in to comment.