21 #ifndef otbMassOfBelief_hxx
22 #define otbMassOfBelief_hxx
34 template <
class TLabel,
class TMass>
38 m_MassesMap[labelSet] = mass;
44 template <
class TLabel,
class TMass>
48 m_MassesMap.erase(labelSet);
55 template <
class TLabel,
class TMass>
59 typename MassMapType::const_iterator it = m_MassesMap.find(labelSet);
61 if (it != m_MassesMap.end())
67 return itk::NumericTraits<MassType>::Zero;
71 template <
class TLabel,
class TMass>
78 typename MassMapType::const_iterator it = m_MassesMap.begin();
81 while (it != m_MassesMap.end())
83 output.insert(it->first);
91 template <
class TLabel,
class TMass>
101 for (
typename LabelSetOfSetType::iterator it = support.begin(); it != support.end(); ++it)
105 std::insert_iterator<LabelSetType> tmpIt(tempSet, tempSet.begin());
108 std::set_union(output.begin(), output.end(), it->begin(), it->end(), tmpIt);
111 output.swap(tempSet);
118 template <
class TLabel,
class TMass>
122 MassType sum = itk::NumericTraits<MassType>::Zero;
125 for (
typename MassMapType::const_iterator it = m_MassesMap.begin(); it != m_MassesMap.end(); ++it)
134 for (
typename MassMapType::iterator it = m_MassesMap.begin(); it != m_MassesMap.end(); ++it)
143 template <
class TLabel,
class TMass>
150 MassType sum = itk::NumericTraits<MassType>::Zero;
153 for (
typename MassMapType::const_iterator it = m_MassesMap.begin(); it != m_MassesMap.end(); ++it)
162 if (uncertaintyMass > 0)
165 this->SetMass(universe, uncertaintyMass);
172 template <
class TLabel,
class TMass>
178 template <
class TLabel,
class TMass>
185 unsigned long nbElements = 1 << universe.size();
189 for (
unsigned long elementId = 1; elementId <= nbElements; ++elementId)
194 unsigned long residu = elementId;
197 for (
typename LabelSetType::const_iterator it = universe.begin(); residu > 0 && it != universe.end(); ++it)
200 unsigned long bit = residu % 2;
205 newElement.insert(*it);
211 this->SetMass(newElement, itk::NumericTraits<MassType>::Zero);
215 template <
class TLabel,
class TMass>
225 for (
typename LabelSetOfSetType::const_iterator it = support.begin(); it != support.end(); ++it)
229 std::insert_iterator<LabelSetType> interIt(intersectionSet, intersectionSet.begin());
232 std::set_intersection(labelSet.begin(), labelSet.end(), it->begin(), it->end(), interIt);
236 if (intersectionSet == (*it))
238 containedSet.insert((*it));
243 return this->GetBelief(containedSet);
246 template <
class TLabel,
class TMass>
256 for (
typename LabelSetOfSetType::const_iterator it = support.begin(); it != support.end(); ++it)
260 std::insert_iterator<LabelSetType> interIt(intersectionSet, intersectionSet.begin());
263 std::set_intersection(labelSet.begin(), labelSet.end(), it->begin(), it->end(), interIt);
266 if (!intersectionSet.empty())
268 intersectedSet.insert((*it));
273 return this->GetPlausibility(intersectedSet);
276 template <
class TLabel,
class TMass>
280 MassType belief = itk::NumericTraits<MassType>::Zero;
283 for (
typename LabelSetOfSetType::const_iterator it = containedLabelSet.begin(); it != containedLabelSet.end(); ++it)
285 belief += this->GetMass((*it));
292 template <
class TLabel,
class TMass>
296 MassType plausibility = itk::NumericTraits<MassType>::Zero;
299 for (
typename LabelSetOfSetType::const_iterator it = intersectedLabelSet.begin(); it != intersectedLabelSet.end(); ++it)
301 plausibility += this->GetMass((*it));
308 template <
class TLabel,
class TMass>
318 template <
class TLabel,
class TMass>
321 return m_MassesMap.empty();
324 template <
class TLabel,
class TMass>
328 Superclass::PrintSelf(os, indent);
331 os << indent <<
"Mass of belief universe: ";
332 PrintLabelSet(os, this->GetUniverse());
336 os << indent <<
"Mass of belief support: ";
337 PrintLabelSetOfSet(os, this->GetSupport());
341 for (
typename MassMapType::const_iterator it = m_MassesMap.begin(); it != m_MassesMap.end(); ++it)
344 PrintLabelSet(os, it->first);
345 os <<
" has mass " << (it->second) << std::endl;
347 os << indent <<
"Other masses are null" << std::endl;
350 template <
class TLabel,
class TMass>
354 typename LabelSetType::const_iterator it = labelSet.begin();
360 while (it != labelSet.end())
364 if (it != labelSet.end())
375 template <
class TLabel,
class TMass>
379 typename LabelSetOfSetType::const_iterator it = labelSet.begin();
385 while (it != labelSet.end())
387 PrintLabelSet(out, *it);
389 if (it != labelSet.end())