Skip to content
Snippets Groups Projects
Commit d0b90635 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: clamp values given to any Sampler

parent 67b9ceeb
Branches
Tags
No related merge requests found
...@@ -33,14 +33,16 @@ void ...@@ -33,14 +33,16 @@ void
SamplerBase::SetNumberOfElements(unsigned long needed, unsigned long total) SamplerBase::SetNumberOfElements(unsigned long needed, unsigned long total)
{ {
bool modified = false; bool modified = false;
unsigned long neededChecked = needed;
if (needed > total) if (needed > total)
{ {
itkExceptionMacro(<< "Needed elements (" << needed << itkWarningMacro(<< "Needed elements (" << needed <<
") greater than total elements" << total << ")." << std::endl); ") will be clamped to total elements (" << total << ")" << std::endl);
neededChecked = total;
} }
if (m_NeededElements != needed) if (m_NeededElements != neededChecked)
{ {
m_NeededElements = needed; m_NeededElements = neededChecked;
modified = true; modified = true;
} }
if (m_TotalElements != total) if (m_TotalElements != total)
...@@ -66,9 +68,22 @@ void ...@@ -66,9 +68,22 @@ void
SamplerBase::SetRate(double rate, unsigned long total) SamplerBase::SetRate(double rate, unsigned long total)
{ {
bool modified = false; bool modified = false;
if (m_Rate != rate) double rateChecked = rate;
if (rate > 1.0)
{ {
m_Rate = rate; itkWarningMacro(<< "Rate (" << rate <<
") will be clamped to 1.0" << std::endl);
rateChecked = 1.0;
}
if (rate < 0.0)
{
itkWarningMacro(<< "Rate (" << rate <<
") will be clamped to 0.0" << std::endl);
rateChecked = 0.0;
}
if (m_Rate != rateChecked)
{
m_Rate = rateChecked;
modified = true; modified = true;
} }
if (m_TotalElements != total) if (m_TotalElements != total)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment