Skip to content

Commit 6dc4948

Browse files
committed
BUG: Use one calculator in ItermodesThresholder
Use the parent class's calculator and override GenerateDate method to update the derived calculators ivars. Store the calculator parameters as filter ivar, with correct filter modified time management. Closes #1720. Co-Authored: Jon Haitz Legarreta Gorroño <jon.haitz.legarreta@gmail.com>
1 parent b1237c6 commit 6dc4948

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

Modules/Filtering/Thresholding/include/itkIntermodesThresholdImageFilter.h

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,15 @@ class IntermodesThresholdImageFilter : public HistogramThresholdImageFilter<TInp
9393
using HistogramType = typename Superclass::HistogramType;
9494
using CalculatorType = IntermodesThresholdCalculator<HistogramType, InputPixelType>;
9595

96-
void
97-
SetMaximumSmoothingIterations(SizeValueType maxSmoothingIterations)
98-
{
99-
m_IntermodesCalculator->SetMaximumSmoothingIterations(maxSmoothingIterations);
100-
}
10196

102-
SizeValueType
103-
GetMaximumSmoothingIterations()
104-
{
105-
return (m_IntermodesCalculator->GetMaximumSmoothingIterations());
106-
}
97+
itkSetMacro(MaxSmoothingIterations, SizeValueType);
98+
itkGetMacro(MaxSmoothingIterations, SizeValueType);
10799

108100
/** Select whether midpoint (intermode=true) or minimum between
109101
peaks is used. */
110-
void
111-
SetUseInterMode(bool useIntermode)
112-
{
113-
m_IntermodesCalculator->SetUseInterMode(useIntermode);
114-
}
115-
116-
bool
117-
GetUseInterMode()
118-
{
119-
return (m_IntermodesCalculator->GetUseInterMode());
120-
}
102+
itkSetMacro(UseInterMode, bool);
103+
itkGetConstReferenceMacro(UseInterMode, bool);
104+
itkBooleanMacro(UseInterMode);
121105

122106
/** Image related type alias. */
123107
static constexpr unsigned int InputImageDimension = InputImageType::ImageDimension;
@@ -126,23 +110,44 @@ class IntermodesThresholdImageFilter : public HistogramThresholdImageFilter<TInp
126110
protected:
127111
IntermodesThresholdImageFilter()
128112
{
129-
m_IntermodesCalculator = CalculatorType::New();
130-
this->SetCalculator(m_IntermodesCalculator);
131-
m_IntermodesCalculator->SetMaximumSmoothingIterations(10000);
132-
m_IntermodesCalculator->SetUseInterMode(true);
113+
auto calculator = CalculatorType::New();
114+
calculator->SetMaximumSmoothingIterations(m_MaxSmoothingIterations);
115+
calculator->SetUseInterMode(m_UseInterMode);
116+
Superclass::SetCalculator(calculator);
133117
}
134118
~IntermodesThresholdImageFilter() override = default;
135119

120+
void
121+
VerifyPreconditions() ITKv5_CONST override
122+
{
123+
Superclass::VerifyPreconditions();
124+
if (dynamic_cast<const CalculatorType *>(Superclass::GetCalculator()) == nullptr)
125+
{
126+
itkExceptionMacro(<< "Invalid IntermodesCalculator.");
127+
}
128+
}
129+
130+
void
131+
GenerateData() override
132+
{
133+
auto calculator = static_cast<CalculatorType *>(this->Superclass::GetModifiableCalculator());
134+
calculator->SetMaximumSmoothingIterations(m_MaxSmoothingIterations);
135+
calculator->SetUseInterMode(m_UseInterMode);
136+
this->Superclass::GenerateData();
137+
}
138+
139+
136140
void
137141
PrintSelf(std::ostream & os, Indent indent) const override
138142
{
139143
Superclass::PrintSelf(os, indent);
140-
141-
itkPrintSelfObjectMacro(IntermodesCalculator);
144+
os << indent << "MaxSmoothingIterations: " << m_MaxSmoothingIterations << std::endl;
145+
os << indent << "UseIterMode: " << m_UseInterMode << std::endl;
142146
}
143147

144148
private:
145-
typename CalculatorType::Pointer m_IntermodesCalculator;
149+
SizeValueType m_MaxSmoothingIterations{ 1000 };
150+
bool m_UseInterMode{ true };
146151
};
147152

148153
} // end namespace itk

0 commit comments

Comments
 (0)