Skip to content

Commit

Permalink
BUG: Restore setting TargetPoints after ReachMode
Browse files Browse the repository at this point in the history
Check that the target reach mode and expected number of target point
are correct in VerifyPreconditions, instead of when setting expected
number of targets.

This restores prior behavior of being able to set the target reach mode
before setting the target points.
  • Loading branch information
blowekamp committed Jan 12, 2023
1 parent f187319 commit bb0f6e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,21 @@ class ITK_TEMPLATE_EXPORT FastMarchingUpwindGradientImageFilter : public FastMar
void
SetTargetReachedModeToOneTarget()
{
this->VerifyTargetReachedModeConditions();

this->SetTargetReachedMode(OneTarget);
m_NumberOfTargets = 1;
}
void
SetTargetReachedModeToSomeTargets(SizeValueType numberOfTargets)
{
this->VerifyTargetReachedModeConditions(numberOfTargets);

this->SetTargetReachedMode(SomeTargets);
m_NumberOfTargets = numberOfTargets;
}

void
SetTargetReachedModeToAllTargets()
{
this->VerifyTargetReachedModeConditions();

this->SetTargetReachedMode(AllTargets);
m_NumberOfTargets = m_TargetPoints->Size();
// m_NumberOfTargets is not used for this case
}

/** Get the number of targets. */
Expand Down Expand Up @@ -221,6 +215,9 @@ class ITK_TEMPLATE_EXPORT FastMarchingUpwindGradientImageFilter : public FastMar
void
PrintSelf(std::ostream & os, Indent indent) const override;

virtual void
VerifyPreconditions() ITKv5_CONST override;

void
Initialize(LevelSetImageType *) override;

Expand All @@ -240,7 +237,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingUpwindGradientImageFilter : public FastMar
* Returns true if at least a target point exists; returns false otherwise.
*/
bool
IsTargetPointsExistenceConditionSatisfied()
IsTargetPointsExistenceConditionSatisfied() const
{
if (!m_TargetPoints || m_TargetPoints->Size() == 0)
{
Expand All @@ -258,7 +255,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingUpwindGradientImageFilter : public FastMar
* Raises an exception if the conditions are not satisfied.
*/
void
VerifyTargetReachedModeConditions(unsigned int targetModeMinPoints = 1)
VerifyTargetReachedModeConditions(unsigned int targetModeMinPoints = 1) const
{
bool targetPointsExist = this->IsTargetPointsExistenceConditionSatisfied();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ FastMarchingUpwindGradientImageFilter<TLevelSet, TSpeedImage>::PrintSelf(std::os
os << indent << "Target value: " << m_TargetValue << std::endl;
}

template <typename TLevelSet, typename TSpeedImage>
void
FastMarchingUpwindGradientImageFilter<TLevelSet, TSpeedImage>::VerifyPreconditions() ITKv5_CONST
{
Superclass::VerifyPreconditions();

switch (this->m_TargetReachedMode)
{
case AllTargets:
this->VerifyTargetReachedModeConditions(this->m_NumberOfTargets);
break;
case OneTarget:
this->VerifyTargetReachedModeConditions(1);
break;
case SomeTargets:
this->VerifyTargetReachedModeConditions(this->m_NumberOfTargets);
break;
}
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ itkFastMarchingUpwindGradientTest(int, char *[])
ITK_EXERCISE_BASIC_OBJECT_METHODS(marcher, FastMarchingUpwindGradientImageFilter, FastMarchingImageFilter);


// Test exceptions
ITK_TRY_EXPECT_EXCEPTION(marcher->SetTargetReachedModeToOneTarget());

itk::SizeValueType numberOfTargets = 0;
ITK_TRY_EXPECT_EXCEPTION(marcher->SetTargetReachedModeToSomeTargets(numberOfTargets));

ITK_TRY_EXPECT_EXCEPTION(marcher->SetTargetReachedModeToAllTargets());


// ShowProgressObject progressWatch(marcher);
// itk::SimpleMemberCommand<ShowProgressObject>::Pointer command;
// command = itk::SimpleMemberCommand<ShowProgressObject>::New();
Expand Down Expand Up @@ -165,6 +156,20 @@ itkFastMarchingUpwindGradientTest(int, char *[])
ITK_TEST_SET_GET_VALUE(targetOffset, marcher->GetTargetOffset());


// Test exceptions
ITK_TRY_EXPECT_NO_EXCEPTION(marcher->SetTargetReachedModeToOneTarget());
ITK_TRY_EXPECT_EXCEPTION(marcher->Update());

itk::SizeValueType numberOfTargets = 0;
ITK_TRY_EXPECT_NO_EXCEPTION(marcher->SetTargetReachedModeToSomeTargets(numberOfTargets));
ITK_TEST_SET_GET_VALUE(numberOfTargets, marcher->GetNumberOfTargets());
ITK_TRY_EXPECT_EXCEPTION(marcher->Update());

ITK_TRY_EXPECT_NO_EXCEPTION(marcher->SetTargetReachedModeToAllTargets());
ITK_TRY_EXPECT_EXCEPTION(marcher->Update());

ITK_TRY_EXPECT_NO_EXCEPTION(marcher->SetTargetReachedModeToNoTargets());

// turn on debugging
// marcher->DebugOn();

Expand Down Expand Up @@ -285,7 +290,8 @@ itkFastMarchingUpwindGradientTest(int, char *[])

// Now stop the algorithm once SOME of the targets have been reached.
numberOfTargets = targetPoints->Size() + 1;
ITK_TRY_EXPECT_EXCEPTION(marcher->SetTargetReachedModeToSomeTargets(numberOfTargets));
ITK_TRY_EXPECT_NO_EXCEPTION(marcher->SetTargetReachedModeToSomeTargets(numberOfTargets))
ITK_TRY_EXPECT_EXCEPTION(marcher->Update());

numberOfTargets = targetPoints->Size() - 1;
marcher->SetTargetReachedModeToSomeTargets(numberOfTargets);
Expand All @@ -303,7 +309,6 @@ itkFastMarchingUpwindGradientTest(int, char *[])
ITK_TEST_SET_GET_VALUE(FloatFMType::AllTargets, marcher->GetTargetReachedMode());

numberOfTargets = targetPoints->Size();
ITK_TEST_EXPECT_EQUAL(numberOfTargets, marcher->GetNumberOfTargets());

ITK_TRY_EXPECT_NO_EXCEPTION(marcher->Update());

Expand Down

0 comments on commit bb0f6e8

Please sign in to comment.