/usr/include/OTB-5.8/otbMassOfBelief.txx is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbMassOfBelief_txx
#define otbMassOfBelief_txx
#include "otbMassOfBelief.h"
#include <algorithm>
#include <iterator>
#include "otbMath.h"
namespace otb
{
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::SetMass(const LabelSetType & labelSet, const MassType & mass)
{
// Insert into the mass map
m_MassesMap[labelSet] = mass;
// Call modified
this->Modified();
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::RemoveMass(const LabelSetType & labelSet)
{
// Insert into the mass map
m_MassesMap.erase(labelSet);
// Call modified
this->Modified();
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::MassType
MassOfBelief<TLabel, TMass>
::GetMass(const LabelSetType & labelSet) const
{
// Look for mass in the table
typename MassMapType::const_iterator it = m_MassesMap.find(labelSet);
if(it!=m_MassesMap.end())
{
return it->second;
}
else
{
return itk::NumericTraits<MassType>::Zero;
}
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::LabelSetOfSetType
MassOfBelief<TLabel, TMass>
::GetSupport() const
{
// Build the output
LabelSetOfSetType output;
// Define an iterator on the mass map
typename MassMapType::const_iterator it = m_MassesMap.begin();
// Walk the mass map, gathering the element of the power set
while(it != m_MassesMap.end())
{
output.insert(it->first);
++it;
}
// Return
return output;
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::LabelSetType
MassOfBelief<TLabel, TMass>
::GetUniverse() const
{
// Build the output
LabelSetType output;
// Retrieve support set
LabelSetOfSetType support = this->GetSupport();
// Walk the support and perform union
for(typename LabelSetOfSetType::iterator it = support.begin();
it != support.end(); ++it)
{
// Temporary set
LabelSetType tempSet;
std::insert_iterator<LabelSetType> tmpIt(tempSet, tempSet.begin());
// Perform set union
std::set_union(output.begin(), output.end(), it->begin(), it->end(), tmpIt);
// swap output and tempSet
output.swap(tempSet);
}
// Return
return output;
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::Normalize()
{
// Sum of masses
MassType sum = itk::NumericTraits<MassType>::Zero;
// Compute normalization factor
for(typename MassMapType::const_iterator it = m_MassesMap.begin();
it != m_MassesMap.end(); ++it)
{
sum+=it->second;
}
// check if sum is not null (maybe use and 1e-xxx)
if(sum > 0.0)
{
// Apply normalization factor
for(typename MassMapType::iterator it = m_MassesMap.begin();
it != m_MassesMap.end(); ++it)
{
it->second/=sum;
}
// Call modified
this->Modified();
}
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::EstimateUncertainty()
{
// Retrieve the universe of the mass of belief
LabelSetType universe = this->GetUniverse();
// Compute the sum of available masses
MassType sum = itk::NumericTraits<MassType>::Zero;
// Compute normalization factor
for(typename MassMapType::const_iterator it = m_MassesMap.begin();
it != m_MassesMap.end(); ++it)
{
sum+=it->second;
}
// Compute uncertainty mass
MassType uncertaintyMass = 1 - sum;
// Check if uncertainty mass is not negative
if(uncertaintyMass > 0)
{
// Associate uncertainty mass
this->SetMass(universe, uncertaintyMass);
// Call modified
this->Modified();
}
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::Clear()
{
m_MassesMap.clear();
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::InitializePowerSetMasses(const LabelSetType & universe)
{
// Clear any previous mass
this->Clear();
// Compute number of elements
unsigned long nbElements = 1 << universe.size(); // 2^universe.size()
// Build each element
for(unsigned long elementId = 1; elementId <= nbElements; ++elementId)
{
// Instantiate a new element
LabelSetType newElement;
unsigned long residu = elementId;
// Walk the universe set
for(typename LabelSetType::const_iterator it = universe.begin();
residu >0 && it!=universe.end(); ++it)
{
// Retrieve the current bit
unsigned long bit = residu%2;
// If bit is 1, add the current element from universe to the new set
if(bit)
{
newElement.insert(*it);
}
// Compute residu
residu/=2;
}
this->SetMass(newElement, itk::NumericTraits<MassType>::Zero);
}
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::MassType
MassOfBelief<TLabel, TMass>
::GetBelief(const LabelSetType & labelSet) const
{
// Retrieve support of mass function
LabelSetOfSetType support = this->GetSupport();
// Define an empty set which will contain contained elements of the power-set
LabelSetOfSetType containedSet;
// Look for elements in the support which are contained in labelSet
for(typename LabelSetOfSetType::const_iterator it = support.begin();
it!=support.end(); ++it)
{
// Temporary set containing intersection
LabelSetType intersectionSet;
std::insert_iterator<LabelSetType> interIt(intersectionSet, intersectionSet.begin());
// Perform set union
std::set_intersection(labelSet.begin(), labelSet.end(), it->begin(), it->end(), interIt);
// If labelSet inter (*it) == (*it), then (*it) is contained
// inside labelSet
if(intersectionSet == (*it))
{
containedSet.insert((*it));
}
}
// Call the generic implementation
return this->GetBelief(containedSet);
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::MassType
MassOfBelief<TLabel, TMass>
::GetPlausibility(const LabelSetType & labelSet) const
{
// Retrieve support of mass function
LabelSetOfSetType support = this->GetSupport();
// Define an empty set which will contain contained elements of the power-set
LabelSetOfSetType intersectedSet;
// Look for elements in the support which are contained in labelSet
for(typename LabelSetOfSetType::const_iterator it = support.begin();
it!=support.end(); ++it)
{
// Temporary set containing intersection
LabelSetType intersectionSet;
std::insert_iterator<LabelSetType> interIt(intersectionSet, intersectionSet.begin());
// Perform set intersection
std::set_intersection(labelSet.begin(), labelSet.end(), it->begin(), it->end(), interIt);
// If labelSet inter (*it) != {}, then (*it) intersects labelSet
if(!intersectionSet.empty())
{
intersectedSet.insert((*it));
}
}
// Call the generic implementation
return this->GetPlausibility(intersectedSet);
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::MassType
MassOfBelief<TLabel, TMass>
::GetBelief(const LabelSetOfSetType & containedLabelSet) const
{
// Define output
MassType belief = itk::NumericTraits<MassType>::Zero;
// Sum masses of contained set
for(typename LabelSetOfSetType::const_iterator it = containedLabelSet.begin();
it!=containedLabelSet.end(); ++it)
{
belief+=this->GetMass((*it));
}
// return belief
return belief;
}
template <class TLabel, class TMass>
typename MassOfBelief<TLabel, TMass>
::MassType
MassOfBelief<TLabel, TMass>
::GetPlausibility(const LabelSetOfSetType & intersectedLabelSet) const
{
// Define output
MassType plausibility = itk::NumericTraits<MassType>::Zero;
// Sum masses of contained set
for(typename LabelSetOfSetType::const_iterator it = intersectedLabelSet.begin();
it!=intersectedLabelSet.end(); ++it)
{
plausibility+=this->GetMass((*it));
}
// return belief
return plausibility;
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::Copy(const Self * massOfBelief)
{
// Swap content of masses maps
m_MassesMap = massOfBelief->m_MassesMap;
// Call to Modified()
this->Modified();
}
template <class TLabel, class TMass>
bool
MassOfBelief<TLabel, TMass>
::IsEmpty() const
{
return m_MassesMap.empty();
}
template <class TLabel, class TMass>
void
MassOfBelief<TLabel, TMass>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
// Call superclass implementation
Superclass::PrintSelf(os, indent);
// Display mass of belief universe
os << indent << "Mass of belief universe: ";
PrintLabelSet(os, this->GetUniverse());
os << std::endl;
// Display mass of belief support
os << indent << "Mass of belief support: ";
PrintLabelSetOfSet(os, this->GetSupport());
os << std::endl;
// Display individual masses
for(typename MassMapType::const_iterator it = m_MassesMap.begin();
it!=m_MassesMap.end(); ++it)
{
os<< indent;
PrintLabelSet(os, it->first);
os << " has mass " << (it->second) << std::endl;
}
os << indent << "Other masses are null" << std::endl;
}
template <class TLabel, class TMass>
std::ostream &
MassOfBelief<TLabel, TMass>
::PrintLabelSet(std::ostream & out,
const LabelSetType & labelSet)
{
// Define an iterator on the label set
typename LabelSetType::const_iterator it = labelSet.begin();
// Open the set
out<<"{";
// Append the set elements
while(it != labelSet.end())
{
out<<(*it);
++it;
if(it != labelSet.end())
out<<", ";
}
// close the set
out<<"}";
// Return
return out;
}
template <class TLabel, class TMass>
std::ostream &
MassOfBelief<TLabel, TMass>
::PrintLabelSetOfSet(std::ostream & out,
const LabelSetOfSetType & labelSet)
{
// Define an iterator on the label set
typename LabelSetOfSetType::const_iterator it = labelSet.begin();
// Open the set
out<<"{";
// Append the set elements
while(it != labelSet.end())
{
PrintLabelSet(out, *it);
++it;
if(it != labelSet.end())
out<<", ";
}
// close the set
out<<"}";
// Return
return out;
}
} // end namespace otb
/** Define the << operator for label sets */
/*
template <class TLabel>
std::ostream &
operator<<(std::ostream & out,
const std::set<TLabel> & labelSet)*/
#endif
|