Skip to content

Commit

Permalink
ENH: Improve the DTI module classes coverage
Browse files Browse the repository at this point in the history
Improve the DTI module classes 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.
- Increase the ability of the testing for the
  `itk::DiffusionTensor3DReconstructionImageFilterTest` class by adding an
  input argument to the test.
  • Loading branch information
jhlegarreta authored and dzenanz committed Sep 8, 2020
1 parent d37d8b3 commit b60c3c6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Modules/Filtering/DiffusionTensorImage/test/CMakeLists.txt
Expand Up @@ -11,7 +11,7 @@ CreateTestDriver(ITKDiffusionTensorImage "${ITKDiffusionTensorImage-Test_LIBRAR
itk_add_test(NAME itkDiffusionTensor3DTest
COMMAND ITKDiffusionTensorImageTestDriver itkDiffusionTensor3DTest)
itk_add_test(NAME itkDiffusionTensor3DReconstructionImageFilterTest
COMMAND ITKDiffusionTensorImageTestDriver itkDiffusionTensor3DReconstructionImageFilterTest)
COMMAND ITKDiffusionTensorImageTestDriver itkDiffusionTensor3DReconstructionImageFilterTest 1.0)
itk_add_test(NAME itkTensorRelativeAnisotropyImageFilterTest
COMMAND ITKDiffusionTensorImageTestDriver itkTensorRelativeAnisotropyImageFilterTest)
itk_add_test(NAME itkTensorFractionalAnisotropyImageFilterTest
Expand Down
Expand Up @@ -18,11 +18,21 @@
#include "itkDiffusionTensor3DReconstructionImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"
#include <iostream>

int
itkDiffusionTensor3DReconstructionImageFilterTest(int, char *[])
itkDiffusionTensor3DReconstructionImageFilterTest(int argc, char * argv[])
{
// Check parameters
if (argc != 2)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << itkNameOfTestExecutableMacro(argv) << " bValue" << std::endl;
return EXIT_FAILURE;
}

using ReferencePixelType = short int;
using GradientPixelType = short int;
using TensorPrecisionType = double;
Expand All @@ -37,6 +47,17 @@ itkDiffusionTensor3DReconstructionImageFilterTest(int, char *[])
TensorReconstructionImageFilterType::Pointer tensorReconstructionFilter =
TensorReconstructionImageFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(
tensorReconstructionFilter, DiffusionTensor3DReconstructionImageFilter, ImageToImageFilter);

auto threshold = itk::NumericTraits<TensorReconstructionImageFilterType::ReferencePixelType>::min();
tensorReconstructionFilter->SetThreshold(threshold);
ITK_TEST_SET_GET_VALUE(threshold, tensorReconstructionFilter->GetThreshold());

auto bValue = static_cast<TensorPrecisionType>(std::stod(argv[1]));
tensorReconstructionFilter->SetBValue(bValue);
ITK_TEST_SET_GET_VALUE(bValue, tensorReconstructionFilter->GetBValue());

// Create a reference image
//
using ReferenceImageType = TensorReconstructionImageFilterType::ReferenceImageType;
Expand Down Expand Up @@ -119,6 +140,8 @@ itkDiffusionTensor3DReconstructionImageFilterTest(int, char *[])
tensorReconstructionFilter->SetMaskSpatialObject(maskSpatialObject);
}
tensorReconstructionFilter->SetReferenceImage(referenceImage);
ITK_TEST_SET_GET_VALUE(referenceImage, tensorReconstructionFilter->GetReferenceImage());

// TODO: remove this when netlib is made thread safe
tensorReconstructionFilter->SetNumberOfWorkUnits(1);

Expand Down Expand Up @@ -201,5 +224,7 @@ itkDiffusionTensor3DReconstructionImageFilterTest(int, char *[])
<< std::endl;
}


std::cout << "Test finished" << std::endl;
return result;
}
Expand Up @@ -19,6 +19,7 @@
#include "itkHessianRecursiveGaussianImageFilter.h"
#include "itkTensorFractionalAnisotropyImageFilter.h"
#include "itkDiffusionTensor3D.h"
#include "itkTestingMacros.h"


int
Expand Down Expand Up @@ -122,6 +123,9 @@ itkTensorFractionalAnisotropyImageFilterTest(int, char *[])

FAFilterType::Pointer fractionalAnisotropyFilter = FAFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(
fractionalAnisotropyFilter, TensorFractionalAnisotropyImageFilter, UnaryFunctorImageFilter);

fractionalAnisotropyFilter->SetInput(filter->GetOutput());

// Execute the filter
Expand Down Expand Up @@ -150,6 +154,6 @@ itkTensorFractionalAnisotropyImageFilterTest(int, char *[])
}


// All objects should be automatically destroyed at this point
std::cout << "Test finished" << std::endl;
return EXIT_SUCCESS;
}
Expand Up @@ -19,6 +19,7 @@
#include "itkHessianRecursiveGaussianImageFilter.h"
#include "itkTensorRelativeAnisotropyImageFilter.h"
#include "itkDiffusionTensor3D.h"
#include "itkTestingMacros.h"


int
Expand Down Expand Up @@ -122,6 +123,9 @@ itkTensorRelativeAnisotropyImageFilterTest(int, char *[])

FAFilterType::Pointer relativeAnisotropyFilter = FAFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(
relativeAnisotropyFilter, TensorRelativeAnisotropyImageFilter, UnaryFunctorImageFilter);

relativeAnisotropyFilter->SetInput(filter->GetOutput());

// Execute the filter
Expand Down Expand Up @@ -150,6 +154,6 @@ itkTensorRelativeAnisotropyImageFilterTest(int, char *[])
}


// All objects should be automatically destroyed at this point
std::cout << "Test finished" << std::endl;
return EXIT_SUCCESS;
}

0 comments on commit b60c3c6

Please sign in to comment.