21 #ifndef otbFuzzyVariable_hxx
22 #define otbFuzzyVariable_hxx
31 template <
class TLabel,
class TPrecision>
36 template <
class TLabel,
class TPrecision>
41 if (v1 > v2 || v2 > v3 || v3 > v4)
42 itkExceptionMacro(<<
"Values have to be v1<=v2<=v3<=v4");
50 parameters[4] =
static_cast<TPrecision
>(0);
51 parameters[5] =
static_cast<TPrecision
>(1);
54 m_MembershipFunctions[
var] = parameters;
60 template <
class TLabel,
class TPrecision>
65 if (v1 > v2 || v2 > v3 || v3 > v4)
66 itkExceptionMacro(<<
"Values have to be v1<=v2<=v3<=v4");
68 itkExceptionMacro(<<
"Values have to be min<max");
80 m_MembershipFunctions[
var] = parameters;
86 template <
class TLabel,
class TPrecision>
90 m_MembershipFunctions.erase(
var);
96 template <
class TLabel,
class TPrecision>
100 m_MembershipFunctions.clear();
107 template <
class TLabel,
class TPrecision>
112 PrecisionType output = itk::NumericTraits<PrecisionType>::Zero;
115 typename ParametersMapType::const_iterator mapIt = m_MembershipFunctions.find(
var);
118 if (mapIt != m_MembershipFunctions.end())
124 if (value < parameters[0] || value >= parameters[3])
126 output = parameters[4];
128 else if (value >= parameters[0] && value < parameters[1])
130 if (parameters[1] > parameters[0])
132 output =
static_cast<TPrecision
>(parameters[4] + (value - parameters[0]) / (parameters[1] - parameters[0]) * (parameters[5] - parameters[4]));
136 output = parameters[5];
140 if (value >= parameters[1] && value < parameters[2])
142 output = parameters[5];
145 if (value >= parameters[2] && value < parameters[3])
147 if (parameters[3] > parameters[2])
149 output =
static_cast<TPrecision
>(parameters[4] + (parameters[3] - value) / (parameters[3] - parameters[2]) * (parameters[5] - parameters[4]));
153 output = parameters[5];
162 template <
class TLabel,
class TPrecision>
169 for (
typename ParametersMapType::const_iterator mapIt = m_MembershipFunctions.begin(); mapIt != m_MembershipFunctions.end(); ++mapIt)
172 output[mapIt->first] = this->GetMembership(mapIt->first, value);
179 template <
class TLabel,
class TPrecision>
183 if (m_MembershipFunctions.empty())
185 itkExceptionMacro(<<
"Membership parameters map is empty");
192 typename MembershipValueType::const_iterator mapIt = memberships.begin();
199 while (mapIt != memberships.end())
201 if (mapIt->second > higherVal)
203 higherVal = mapIt->second;
204 higherVar = mapIt->first;
213 template <
class TLabel,
class TPrecision>
216 Superclass::PrintSelf(os, indent);
219 template <
class TLabel,
class TPrecision>
223 typedef std::map<TLabel, TPrecision> LabelMapType;
224 typename LabelMapType::const_iterator it = labelMap.begin();
230 while (it != labelMap.end())
232 out << it->first <<
" : " << it->second;
234 if (it != labelMap.end())