MRPT  1.9.9
TUncertaintyPath_impl.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef TUNCERTAINTYPATH_IMPL_H
11 #define TUNCERTAINTYPATH_IMPL_H
12 
14 
15 // Implementattion file for TUncertaintyPath struct
16 
17 namespace mrpt::graphslam
18 {
19 template <class GRAPH_T>
21 {
22  this->clear();
23 }
24 template <class GRAPH_T>
26  const mrpt::graphs::TNodeID& starting_node)
27 {
28  this->clear();
29  nodes_traversed.push_back(starting_node);
30 }
31 template <class GRAPH_T>
33  const mrpt::graphs::TNodeID& starting_node,
34  const mrpt::graphs::TNodeID& ending_node, const constraint_t& edge)
35 {
36  this->clear();
37  nodes_traversed.push_back(starting_node);
38  this->addToPath(ending_node, edge);
39 }
40 
41 template <class GRAPH_T>
43 {
44 }
45 
46 template <class GRAPH_T>
48 {
49  using namespace mrpt;
50  using namespace mrpt::math;
51  using namespace mrpt::poses;
52  using namespace std;
53 
54  // clear the vector of traversed nodes
55  nodes_traversed.clear();
56 
57  // clear the relative edge
58  curr_pose_pdf.mean = pose_t();
59  // by default the information matrix is set to the unit matrix
60  CMatrixDouble33 init_path_mat;
61  init_path_mat.unit();
62  // put a really large number - we are certain of this position
63  init_path_mat *= 10000; // TODO - justify this..
64  curr_pose_pdf.cov_inv = init_path_mat;
65 
66  determinant_is_updated = false;
67  determinant_cached = 0;
68 
69 } // end of clear
70 
71 template <class GRAPH_T>
73 {
74  return *this == self_t();
75 }
76 
77 template <class GRAPH_T>
79  const mrpt::graphs::TNodeID& from, const mrpt::graphs::TNodeID& to) const
80 {
82  this->getSource() == from,
83  format(
84  "\nnodeID %lu is not the source of the path\n%s\n\n",
85  static_cast<unsigned long>(from), this->getAsString().c_str()));
87  this->getDestination() == to,
88  format(
89  "\nnodeID %lu is not the destination of the path\n%s\n\n",
90  static_cast<unsigned long>(to), this->getAsString().c_str()));
91 }
92 
93 template <class GRAPH_T>
95  const self_t& other)
96 {
97  using namespace mrpt;
98  using namespace mrpt::math;
99  using namespace mrpt::poses;
100  using namespace std;
101 
102  // other path should start where this ends
104  other.nodes_traversed.begin()[0] == this->nodes_traversed.rbegin()[0],
105  "\"other\" instance must start from the nodeID that this "
106  "TUncertaintyPath has ended.");
108  other.nodes_traversed.size(),
109  "\"other\" instance doesn't have an initialized list of traversed "
110  "nodes");
112  this->nodes_traversed.size(),
113  "\"this\" instance doesn't have an initialized list of traversed "
114  "nodes");
115 
116  //////// TODO Remove these - >>>>>>>>>>>>>>>>>>>>>
117  // cout << string(20, '-') << "Aggregating 2 paths.."
118  //<< string(20, '-') << endl;
119  // this->dumpToConsole(); other.dumpToConsole();
120  ////// TODO Remove these - <<<<<<<<<<<<<<<<<<<<<
121 
122  // aggregate the two gaussian - mean & information matrix
123  this->curr_pose_pdf += other.curr_pose_pdf;
124 
125  // add the traversed nodes
126  this->nodes_traversed.insert(
127  this->nodes_traversed.end(), other.nodes_traversed.begin() + 1,
128  other.nodes_traversed.end());
129 
130  ////// TODO Remove these - >>>>>>>>>>>>>>>>>>>>>
131  // cout << std::string(10, '%') << endl << "AFTER Aggregation..." << endl;
132  // this->dumpToConsole();
133  // cout << string(50, '-') << endl;
134  // mrpt::system::pause();
135  ////// TODO Remove these - <<<<<<<<<<<<<<<<<<<<<
136 
137  determinant_is_updated = false;
138  return *this;
139 }
140 template <class GRAPH_T>
142 {
143  using namespace mrpt;
144  using namespace mrpt::math;
145  using namespace mrpt::poses;
146  using namespace std;
147 
148  // check if the traversed nodes are the same as well as the
149  // CPoseGaussianInfs are the same..
150  return (
151  this->nodes_traversed == other.nodes_traversed &&
152  this->curr_pose_pdf == other.curr_pose_pdf);
153 }
154 template <class GRAPH_T>
156 {
157  return !(*this == other);
158 }
159 
160 template <class GRAPH_T>
162  const mrpt::graphs::TNodeID& node, const constraint_t& edge)
163 {
164  // update the path
165  curr_pose_pdf += edge;
166 
167  // update the traversed nodes
168  nodes_traversed.push_back(node);
169 
170  determinant_is_updated = false;
171 }
172 
173 template <class GRAPH_T>
175  const mrpt::config::CConfigFileBase& source, const std::string& section)
176 {
177 }
178 
179 template <class GRAPH_T>
180 void TUncertaintyPath<GRAPH_T>::dumpToTextStream(std::ostream& out) const
181 {
182  out << mrpt::format("%s\n", this->getAsString().c_str());
183 }
184 
185 template <class GRAPH_T>
187 {
188  using namespace mrpt;
189  using namespace mrpt::poses;
190  using namespace std;
191  using namespace mrpt::math;
192  using namespace mrpt::containers;
193 
194  stringstream ss;
195  string header_sep(30, '=');
196 
197  ss << "Path properties: " << endl;
198  ss << header_sep << endl << endl;
199 
200  ss << "- CPosePDFGaussianInf: "
201  << (curr_pose_pdf.isInfType() ? "TRUE" : "FALSE") << endl;
202  ss << "- Nodes list: \n\t< " << getSTLContainerAsString(nodes_traversed)
203  << "\b\b>" << endl;
204 
205  ss << endl;
206  ss << curr_pose_pdf << endl;
207  ss << endl;
208 
209  CMatrixDouble33 mat;
210  if (curr_pose_pdf.isInfType())
211  {
212  curr_pose_pdf.getInformationMatrix(mat);
213  }
214  else
215  {
216  curr_pose_pdf.getCovariance(mat);
217  }
218  ss << "Determinant: " << mat.det();
219 
220  *str = ss.str();
221 }
222 template <class GRAPH_T>
224 {
225  std::string s;
226  this->getAsString(&s);
227  return s;
228 }
229 
230 template <class GRAPH_T>
232 {
233  return nodes_traversed.at(0);
234 }
235 template <class GRAPH_T>
237 {
238  return nodes_traversed.back();
239 }
240 
241 template <class GRAPH_T>
243 {
244  using namespace mrpt;
245  using namespace mrpt::math;
246  using namespace mrpt::poses;
247  using namespace std;
248 
249  // if determinant is up-to-date then return the cached version...
250  if (determinant_is_updated) return determinant_cached;
251 
252  // update the cached version and return it.
253  CMatrixDouble33 mat;
254  if (curr_pose_pdf.isInfType())
255  {
256  curr_pose_pdf.getInformationMatrix(mat);
257  }
258  else
259  {
260  curr_pose_pdf.getCovariance(mat);
261  }
262  double determinant = mat.det();
263 
264  determinant_cached = determinant;
265  determinant_is_updated = true;
266 
267  return determinant;
268 }
269 
270 template <class GRAPH_T>
272  const self_t& other) const
273 {
274  using namespace mrpt;
275  using namespace mrpt::math;
276  using namespace mrpt::poses;
277  using namespace std;
278 
280  (curr_pose_pdf.isInfType() && other.curr_pose_pdf.isInfType()) ||
281  (!curr_pose_pdf.isInfType() && !other.curr_pose_pdf.isInfType()),
282  mrpt::format(
283  "Constraints of given paths don't have the same "
284  "representation of uncertainty"));
285 
286  // If we are talking about information form matrices, the *higher* the
287  // determinant the more confident we are.
288  // if we are talking about covariances then the *lower*.
289  bool has_lower = false;
290  if (curr_pose_pdf.isInfType())
291  {
292  has_lower = this->getDeterminant() > other.getDeterminant();
293  }
294  else
295  {
296  has_lower = this->getDeterminant() < other.getDeterminant();
297  }
298 
299  return has_lower;
300 }
301 } // end of namespaces
302 
303 #endif /* end of include guard: TUNCERTAINTYPATH_IMPL_H */
304 
305 
This class allows loading and storing values and vectors of different types from a configuration text...
#define ASSERTDEBMSG_(f, __ERROR_MSG)
Definition: exceptions.h:208
GLdouble s
Definition: glext.h:3676
GLsizei const GLchar ** string
Definition: glext.h:4101
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
std::string getSTLContainerAsString(const T &t)
Return a STL container in std::string form.
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:186
uint64_t TNodeID
A generic numeric type for unique IDs of nodes or entities.
Definition: TNodeID.h:16
SLAM methods related to graphs of pose constraints.
This base provides a set of functions for maths stuff.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Holds the data of an information path.
void addToPath(const mrpt::graphs::TNodeID &node, const constraint_t &edge)
add a new link in the current path.
void assertIsBetweenNodeIDs(const mrpt::graphs::TNodeID &from, const mrpt::graphs::TNodeID &to) const
Assert that the current path is between the given nodeIDs.
bool operator==(const self_t &other) const
const mrpt::graphs::TNodeID & getDestination() const
Return the Destination node of this path.
self_t & operator+=(const self_t &other)
void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form,...
bool operator!=(const self_t &other) const
typename constraint_t::type_value pose_t
type of underlying poses (2D/3D).
typename GRAPH_T::constraint_t constraint_t
Handy typedefs.
std::vector< mrpt::graphs::TNodeID > nodes_traversed
Nodes that the Path comprises of.
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section)
This method load the options from a ".ini"-like file or memory-stored string list.
constraint_t curr_pose_pdf
Current path position + corresponding covariance.
bool hasLowerUncertaintyThan(const self_t &other) const
Test if the current path has a lower uncertainty than the other path.
const mrpt::graphs::TNodeID & getSource() const
Return the source node of this path.



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST