MappedProbabilityTable.cpp
Go to the documentation of this file.
1 
19 
21 
23  {
24  // Initialize pointer.
25  mTable.reset(new ProbabilityTable());
26  }
27 
28  MappedProbabilityTable::MappedProbabilityTable(boost::property_tree::ptree& pPt)
29  {
30  // Initialize pointer.
31  mTable.reset(new ProbabilityTable());
32 
33  // Execute the loading of mapping and probability table.
34  load(pPt);
35  }
36 
38  {
39 
40  }
41 
42  void MappedProbabilityTable::load(boost::property_tree::ptree& pPt)
43  {
44  // Load mappings from object types to table indices.
45  BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pPt.get_child("mapping"))
46  {
47  // Only access the 'map' child nodes.
48  if(!std::strcmp(v.first.c_str(), "map"))
49  {
50  // Extract key and value and add them to the mapping.
51  unsigned int value = v.second.get<unsigned int>("<xmlattr>.id");
52  std::string key = v.second.get<std::string>("<xmlattr>.name");
53 
54  // Check, if there is an invalid mapping to type zero (reserved for unknown types).
55  if(value == 0)
56  throw std::invalid_argument("Unable to procees loading. Scene object model: no mapping to type 0 allowed, it is reserved for unknown objects");
57 
58  // Check, if there was a scene object type specified.
59  if(key.size() == 0)
60  throw std::invalid_argument("Unable to procees loading. Scene object model: No name for object mapping specified.");
61 
62  // Add mapping to list.
63  mMappingTypeToIndice.insert(std::pair<std::string, unsigned int>(key, value));
64  }
65  }
66 
67  // Load the probability table.
68  mTable->load(pPt);
69  }
70 
71  void MappedProbabilityTable::save(boost::property_tree::ptree& pPt)
72  {
73  // Create a subtree for the mapping.
74  boost::property_tree::ptree subtreeMapping;
75 
76  // Iterate over the mapping of object types to indices.
77  for(std::map<std::string, unsigned int>::iterator it = mMappingTypeToIndice.begin(); it != mMappingTypeToIndice.end(); ++it)
78  {
79  boost::property_tree::ptree subtreeMap;
80 
81  subtreeMap.add("<xmlattr>.id", it->second);
82  subtreeMap.add("<xmlattr>.name", it->first);
83 
84  subtreeMapping.add_child("map", subtreeMap);
85  }
86 
87  // Add subtree to main tree.
88  pPt.add_child("mapping", subtreeMapping);
89 
90  // Save the probability table.
91  mTable->save(pPt);
92  }
93 
94 
95  void MappedProbabilityTable::initializeTable(unsigned int pRows)
96  {
97  // Add one additional column to handle the unknown object class.
98  mTable.reset(new ProbabilityTable(pRows, mMappingTypeToIndice.size() + 1));
99  }
100 
101  double MappedProbabilityTable::getProbability(unsigned int pRow, std::string pType)
102  {
103  double result = 0;
104 
105  // If object type is known, return the associated probability. Otherwise return the default class probability.
106  if(getIndex(pType) == 0)
107  result = mTable->getProbability(pRow, 0);
108  else
109  result = mTable->getProbability(pRow, mMappingTypeToIndice[pType]);
110 
111  // Return the probability
112  return result;
113  }
114 
115  void MappedProbabilityTable::add(std::string pType)
116  {
117  // If no entry was found, create a new one.
118  if(getIndex(pType) == 0)
119  mMappingTypeToIndice.insert(std::pair<std::string, unsigned int>(pType, mMappingTypeToIndice.size() + 1));
120  }
121 
122  void MappedProbabilityTable::add(unsigned int pRow, std::string pType)
123  {
124  // If object not found (doubt that this will happen), add to unseen objects.
125  // Otherwise add count tto the column associated with the object.
126  if(getIndex(pType) == 0)
127  mTable->add(pRow, 0, 1);
128  else
129  mTable->add(pRow, mMappingTypeToIndice[pType], 1);
130  }
131 
132  void MappedProbabilityTable::setDefaultClassCounter(unsigned int pRow, double pCount)
133  {
134  mTable->add(pRow, 0, pCount);
135  }
136 
138  {
139  mTable->normalize();
140  }
141 
142  unsigned int MappedProbabilityTable::getIndex(std::string pType)
143  {
144  unsigned int index = 0;
145 
146  // Get index, if in list.
147  std::map<std::string, unsigned int>::iterator it = mMappingTypeToIndice.find(pType);
148  if((it) != mMappingTypeToIndice.end())
149  {
150  index = it->second;
151  }
152  return index;
153  }
154 
156  {
157  return mTable->getNumberOfColumns();
158  }
159 
161  {
162  return mTable->getNumberOfRows();
163  }
164 
165 }
std::map< std::string, unsigned int > mMappingTypeToIndice
void setDefaultClassCounter(unsigned int pRow, double pCount)
double getProbability(unsigned int pRow, std::string pType)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54