Skip to content

Commit

Permalink
ENH: Increase itk::FastMarchingBase class coverage
Browse files Browse the repository at this point in the history
Increase `itk::FastMarchingBase` class coverage.
  • Loading branch information
jhlegarreta authored and dzenanz committed Apr 4, 2022
1 parent 23a216d commit 3a7a6f6
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Modules/Filtering/FastMarching/test/itkFastMarchingBaseTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/

#include "itkFastMarchingBase.h"
#include "itkFastMarchingThresholdStoppingCriterion.h"
#include "itkTestingMacros.h"

namespace itk
Expand Down Expand Up @@ -122,6 +123,67 @@ itkFastMarchingBaseTest(int argc, char * argv[])

using ImageFastMarching = itk::FastMarchingBaseTestHelper<ImageType, ImageType>;
auto fmm = ImageFastMarching::New();

// Check default values
auto topologyCheck = ImageFastMarching::TopologyCheckEnum::Nothing;
ITK_TEST_SET_GET_VALUE(topologyCheck, fmm->GetTopologyCheck());

ITK_TEST_SET_GET_NULL_VALUE(fmm->GetTrialPoints());

ITK_TEST_SET_GET_NULL_VALUE(fmm->GetAlivePoints());

ITK_TEST_SET_GET_NULL_VALUE(fmm->GetProcessedPoints());

ITK_TEST_SET_GET_NULL_VALUE(fmm->GetForbiddenPoints());

ITK_TEST_SET_GET_NULL_VALUE(fmm->GetStoppingCriterion());

double speedConstant = 1.0;
ITK_TEST_SET_GET_VALUE(speedConstant, fmm->GetSpeedConstant());

double normalizationFactor = 1.0;
ITK_TEST_SET_GET_VALUE(normalizationFactor, fmm->GetNormalizationFactor());

auto targetReachedValue = itk::NumericTraits<typename ImageFastMarching::OutputPixelType>::ZeroValue();
ITK_TEST_EXPECT_EQUAL(targetReachedValue, fmm->GetTargetReachedValue());

bool collectPoints = false;
ITK_TEST_EXPECT_EQUAL(collectPoints, fmm->GetCollectPoints());

// Check other values
topologyCheck = ImageFastMarching::TopologyCheckEnum::Strict;
fmm->SetTopologyCheck(topologyCheck);
ITK_TEST_SET_GET_VALUE(topologyCheck, fmm->GetTopologyCheck());

auto processedPoints = ImageFastMarching::NodePairContainerType::New();
typename ImageFastMarching::NodePairType node_pair;
ImageType::OffsetType offset = { { 28, 35 } };

itk::Index<Dimension> index;
index.Fill(0);

node_pair.SetValue(0.0);
node_pair.SetNode(index + offset);
processedPoints->push_back(node_pair);

fmm->SetProcessedPoints(processedPoints);
ITK_TEST_SET_GET_VALUE(processedPoints, fmm->GetProcessedPoints());

auto stoppingCriterion = itk::FastMarchingThresholdStoppingCriterion<ImageType, ImageType>::New();
fmm->SetStoppingCriterion(stoppingCriterion);
ITK_TEST_SET_GET_VALUE(stoppingCriterion, fmm->GetStoppingCriterion());

speedConstant = 2.0;
fmm->SetSpeedConstant(speedConstant);
ITK_TEST_SET_GET_VALUE(speedConstant, fmm->GetSpeedConstant());

normalizationFactor = 2.0;
fmm->SetNormalizationFactor(normalizationFactor);
ITK_TEST_SET_GET_VALUE(normalizationFactor, fmm->GetNormalizationFactor());

collectPoints = true;
ITK_TEST_SET_GET_BOOLEAN(fmm, CollectPoints, collectPoints);

fmm->SetInput(input);

ITK_TRY_EXPECT_EXCEPTION(fmm->Update());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ itkFastMarchingImageFilterRealTest1(int itkNotUsed(argc), char * itkNotUsed(argv


marcher->SetStoppingCriterion(criterion);
ITK_TEST_SET_GET_VALUE(criterion, marcher->GetStoppingCriterion());

ShowProgressObject progressWatch(marcher);
itk::SimpleMemberCommand<ShowProgressObject>::Pointer command = itk::SimpleMemberCommand<ShowProgressObject>::New();
Expand Down Expand Up @@ -96,6 +97,7 @@ itkFastMarchingImageFilterRealTest1(int itkNotUsed(argc), char * itkNotUsed(argv
alive->push_back(node_pair);

marcher->SetAlivePoints(alive);
ITK_TEST_SET_GET_VALUE(alive, marcher->GetAlivePoints());

// Set up trial points
auto trial = NodePairContainerType::New();
Expand Down Expand Up @@ -129,6 +131,7 @@ itkFastMarchingImageFilterRealTest1(int itkNotUsed(argc), char * itkNotUsed(argv
trial->push_back(node_pair);

marcher->SetTrialPoints(trial);
ITK_TEST_SET_GET_VALUE(trial, marcher->GetTrialPoints());

// Specify the size of the output image
FloatImageType::SizeType size = { { 64, 64 } };
Expand Down Expand Up @@ -158,6 +161,9 @@ itkFastMarchingImageFilterRealTest1(int itkNotUsed(argc), char * itkNotUsed(argv
ITK_TRY_EXPECT_NO_EXCEPTION(marcher->Update());


std::cout << "TargetReachedValue: " << marcher->GetTargetReachedValue() << std::endl;
std::cout << "ProcessedPoints: " << marcher->GetProcessedPoints() << std::endl;

// Check the results
FloatImageType::Pointer output = marcher->GetOutput();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ itkFastMarchingImageFilterRealTest2(int itkNotUsed(argc), char * itkNotUsed(argv
adaptor->Update();

marcher->SetForbiddenPoints(adaptor->GetForbiddenPoints());
ITK_TEST_SET_GET_VALUE(adaptor->GetForbiddenPoints(), marcher->GetForbiddenPoints());

marcher->SetAlivePoints(adaptor->GetAlivePoints());
marcher->SetTrialPoints(adaptor->GetTrialPoints());

Expand Down

0 comments on commit 3a7a6f6

Please sign in to comment.