Skip to content

Commit 3e73077

Browse files
committed
BUG: Check if calculator is proper type
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.
1 parent b1237c6 commit 3e73077

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Modules/Filtering/Thresholding/include/itkHistogramThresholdImageFilter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ class ITK_TEMPLATE_EXPORT HistogramThresholdImageFilter : public ImageToImageFil
197197
void
198198
GenerateData() override;
199199

200+
201+
void
202+
VerifyPreconditions() ITKv5_CONST override
203+
{
204+
Superclass::VerifyPreconditions();
205+
if (m_Calculator.IsNull())
206+
{
207+
itkExceptionMacro(<< "No threshold calculator set.");
208+
}
209+
}
210+
200211
private:
201212
OutputPixelType m_InsideValue;
202213
OutputPixelType m_OutsideValue;

Modules/Filtering/Thresholding/include/itkHistogramThresholdImageFilter.hxx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ template <typename TInputImage, typename TOutputImage, typename TMaskImage>
5959
void
6060
HistogramThresholdImageFilter<TInputImage, TOutputImage, TMaskImage>::GenerateData()
6161
{
62-
if (m_Calculator.IsNull())
63-
{
64-
itkExceptionMacro(<< "No threshold calculator set.");
65-
}
6662
typename ProgressAccumulator::Pointer progress = ProgressAccumulator::New();
6763
progress->SetMiniPipelineFilter(this);
6864

Modules/Filtering/Thresholding/include/itkOtsuThresholdImageFilter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ class OtsuThresholdImageFilter : public HistogramThresholdImageFilter<TInputImag
118118
this->Superclass::GenerateData();
119119
}
120120

121+
void
122+
VerifyPreconditions() ITKv5_CONST override
123+
{
124+
Superclass::VerifyPreconditions();
125+
if (dynamic_cast<const CalculatorType *>(Superclass::GetCalculator()) == nullptr)
126+
{
127+
itkExceptionMacro(<< "Invalid OtsuThresholdCalculator.");
128+
}
129+
}
130+
131+
121132
private:
122133
#if defined(ITKV4_COMPATIBILITY)
123134
bool m_ReturnBinMidpoint{ true };

0 commit comments

Comments
 (0)