Skip to content

Commit

Permalink
BUG: Check if calculator is proper type
Browse files Browse the repository at this point in the history
Use the VerifyPreconditions method to check that the calculator is set
( in the base class ) and that it is a OtsuThresholdCalculator is the
OtsuThresholdImageFilter class.
  • Loading branch information
blowekamp committed Mar 26, 2020
1 parent b1237c6 commit 3e73077
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ class ITK_TEMPLATE_EXPORT HistogramThresholdImageFilter : public ImageToImageFil
void
GenerateData() override;


void
VerifyPreconditions() ITKv5_CONST override
{
Superclass::VerifyPreconditions();
if (m_Calculator.IsNull())
{
itkExceptionMacro(<< "No threshold calculator set.");
}
}

private:
OutputPixelType m_InsideValue;
OutputPixelType m_OutsideValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ template <typename TInputImage, typename TOutputImage, typename TMaskImage>
void
HistogramThresholdImageFilter<TInputImage, TOutputImage, TMaskImage>::GenerateData()
{
if (m_Calculator.IsNull())
{
itkExceptionMacro(<< "No threshold calculator set.");
}
typename ProgressAccumulator::Pointer progress = ProgressAccumulator::New();
progress->SetMiniPipelineFilter(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ class OtsuThresholdImageFilter : public HistogramThresholdImageFilter<TInputImag
this->Superclass::GenerateData();
}

void
VerifyPreconditions() ITKv5_CONST override
{
Superclass::VerifyPreconditions();
if (dynamic_cast<const CalculatorType *>(Superclass::GetCalculator()) == nullptr)
{
itkExceptionMacro(<< "Invalid OtsuThresholdCalculator.");
}
}


private:
#if defined(ITKV4_COMPATIBILITY)
bool m_ReturnBinMidpoint{ true };
Expand Down

0 comments on commit 3e73077

Please sign in to comment.