Main MRPT website > C++ reference for 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-2017, 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 
13 // Implementattion file for TUncertaintyPath struct
14 
15 namespace mrpt
16 {
17 namespace graphslam
18 {
19 template <class GRAPH_T>
21 {
22  this->clear();
23 }
24 template <class GRAPH_T>
26  const mrpt::utils::TNodeID& starting_node)
27 {
28  this->clear();
29  nodes_traversed.push_back(starting_node);
30 }
31 template <class GRAPH_T>
33  const mrpt::utils::TNodeID& starting_node,
34  const mrpt::utils::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::utils::TNodeID& from, const mrpt::utils::TNodeID& to) const
80 {
81  ASSERTMSG_(
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()));
86  ASSERTMSG_(
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
103  ASSERTMSG_(
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.");
107  ASSERTMSG_(
108  other.nodes_traversed.size(),
109  "\"other\" instance doesn't have an initialized list of traversed "
110  "nodes");
111  ASSERTMSG_(
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::utils::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::utils::CConfigFileBase& source, const std::string& section)
176 {
177 }
178 
179 template <class GRAPH_T>
181  mrpt::utils::CStream& out) const
182 {
183  out.printf("%s\n", this->getAsString().c_str());
184 }
185 
186 template <class GRAPH_T>
188 {
189  using namespace mrpt;
190  using namespace mrpt::poses;
191  using namespace std;
192  using namespace mrpt::utils;
193  using namespace mrpt::math;
194 
195  stringstream ss;
196  string header_sep(30, '=');
197 
198  ss << "Path properties: " << endl;
199  ss << header_sep << endl << endl;
200 
201  ss << "- CPosePDFGaussianInf: "
202  << (curr_pose_pdf.isInfType() ? "TRUE" : "FALSE") << endl;
203  ss << "- Nodes list: \n\t< " << getSTLContainerAsString(nodes_traversed)
204  << "\b\b>" << endl;
205 
206  ss << endl;
207  ss << curr_pose_pdf << endl;
208  ss << endl;
209 
210  CMatrixDouble33 mat;
211  if (curr_pose_pdf.isInfType())
212  {
213  curr_pose_pdf.getInformationMatrix(mat);
214  }
215  else
216  {
217  curr_pose_pdf.getCovariance(mat);
218  }
219  ss << "Determinant: " << mat.det();
220 
221  *str = ss.str();
222 }
223 template <class GRAPH_T>
225 {
226  std::string s;
227  this->getAsString(&s);
228  return s;
229 }
230 
231 template <class GRAPH_T>
233 {
234  return nodes_traversed.at(0);
235 }
236 template <class GRAPH_T>
238 {
239  return nodes_traversed.back();
240 }
241 
242 template <class GRAPH_T>
244 {
245  using namespace mrpt;
246  using namespace mrpt::math;
247  using namespace mrpt::poses;
248  using namespace std;
249 
250  // if determinant is up-to-date then return the cached version...
251  if (determinant_is_updated) return determinant_cached;
252 
253  // update the cached version and return it.
254  CMatrixDouble33 mat;
255  if (curr_pose_pdf.isInfType())
256  {
257  curr_pose_pdf.getInformationMatrix(mat);
258  }
259  else
260  {
261  curr_pose_pdf.getCovariance(mat);
262  }
263  double determinant = mat.det();
264 
265  determinant_cached = determinant;
266  determinant_is_updated = true;
267 
268  return determinant;
269 }
270 
271 template <class GRAPH_T>
273  const self_t& other) const
274 {
275  using namespace mrpt;
276  using namespace mrpt::math;
277  using namespace mrpt::poses;
278  using namespace std;
279 
280  ASSERTMSG_(
281  (curr_pose_pdf.isInfType() && other.curr_pose_pdf.isInfType()) ||
282  (!curr_pose_pdf.isInfType() && !other.curr_pose_pdf.isInfType()),
283  mrpt::format(
284  "Constraints of given paths don't have the same "
285  "representation of uncertainty"));
286 
287  // If we are talking about information form matrices, the *higher* the
288  // determinant the more confident we are.
289  // if we are talking about covariances then the *lower*.
290  bool has_lower = false;
291  if (curr_pose_pdf.isInfType())
292  {
293  has_lower = this->getDeterminant() > other.getDeterminant();
294  }
295  else
296  {
297  has_lower = this->getDeterminant() < other.getDeterminant();
298  }
299 
300  return has_lower;
301 }
302 }
303 } // end of namespaces
304 
305 #endif /* end of include guard: TUNCERTAINTYPATH_IMPL_H */
std::vector< mrpt::utils::TNodeID > nodes_traversed
Nodes that the Path comprises of.
Holds the data of an information path.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void addToPath(const mrpt::utils::TNodeID &node, const constraint_t &edge)
add a new link in the current path.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::string getSTLContainerAsString(const T &t)
Return a STL container in std::string form.
STL namespace.
GLdouble s
Definition: glext.h:3676
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:189
This class allows loading and storing values and vectors of different types from a configuration text...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
uint64_t TNodeID
The type for node IDs in graphs of different types.
constraint_t curr_pose_pdf
Current path position + corresponding covariance.
constraint_t::type_value pose_t
type of underlying poses (2D/3D).
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
GLsizei const GLchar ** string
Definition: glext.h:4101
bool hasLowerUncertaintyThan(const self_t &other) const
Test if the current path has a lower uncertainty than the other path.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void assertIsBetweenNodeIDs(const mrpt::utils::TNodeID &from, const mrpt::utils::TNodeID &to) const
Assert that the current path is between the given nodeIDs.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
This method load the options from a ".ini"-like file or memory-stored string list.
bool operator==(const self_t &other) const
bool operator!=(const self_t &other) const
const mrpt::utils::TNodeID & getSource() const
Return the source node of this path.
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
self_t & operator+=(const self_t &other)
GRAPH_T::constraint_t constraint_t
Handy typedefs.
#define ASSERTMSG_(f, __ERROR_MSG)
const mrpt::utils::TNodeID & getDestination() const
Return the Destination node of this path.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019