Main MRPT website > C++ reference for MRPT 1.9.9
TUserOptionsChecker_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 // implementation of the TUserOptionsChecker class template methods
11 namespace mrpt
12 {
13 namespace graphslam
14 {
15 namespace apps
16 {
17 template <class GRAPH_t>
19  : sep_header(40, '='), sep_subheader(20, '-')
20 {
21 }
22 
23 template <class GRAPH_t>
25 {
26  using namespace std;
27 
28  // release the instances holding the descriptions of the available
29  // deciders/optimizers
31  regs_descriptions.begin();
32  it != regs_descriptions.end(); ++it)
33  {
34  delete *it;
35  }
37  optimizers_descriptions.begin();
38  it != optimizers_descriptions.end(); ++it)
39  {
40  delete *it;
41  }
42 }
43 
44 template <class GRAPH_t>
46 {
47  MRPT_START;
48 
49  using namespace mrpt::graphslam::deciders;
50  using namespace mrpt::graphslam::optimizers;
51  using namespace mrpt::graphs;
52  using namespace mrpt::poses;
53 
54  // node registration deciders
55  node_regs_map["CEmptyNRD"] =
56  &createNodeRegistrationDecider<CEmptyNRD<GRAPH_t>>;
57  node_regs_map["CFixedIntervalsNRD"] =
58  &createNodeRegistrationDecider<CFixedIntervalsNRD<GRAPH_t>>;
59  // edge registration deciders
60  edge_regs_map["CEmptyERD"] =
61  &createEdgeRegistrationDecider<CEmptyERD<GRAPH_t>>;
62  // optimizers
63  optimizers_map["CLevMarqGSO"] =
64  &createGraphSlamOptimizer<CLevMarqGSO<GRAPH_t>>;
65  optimizers_map["CEmptyGSO"] =
66  &createGraphSlamOptimizer<CLevMarqGSO<GRAPH_t>>;
67 
68  // create the decider optimizer, specific to the GRAPH_T template type
69  this->_createDeciderOptimizerMappings();
70 
71  MRPT_END;
72 }
73 
74 template <class GRAPH_t>
76 {
77 }
78 
79 // deciders/optpimizers specific to the 2D SLAM cases
80 template <>
81 inline void TUserOptionsChecker<
82  mrpt::graphs::CNetworkOfPoses2DInf>::_createDeciderOptimizerMappings()
83 {
84  using namespace mrpt::graphs;
85 
86  node_regs_map["CICPCriteriaNRD"] =
87  &createNodeRegistrationDecider<CICPCriteriaNRD<CNetworkOfPoses2DInf>>;
88  edge_regs_map["CICPCriteriaERD"] =
89  &createEdgeRegistrationDecider<CICPCriteriaERD<CNetworkOfPoses2DInf>>;
90  edge_regs_map["CLoopCloserERD"] =
91  &createEdgeRegistrationDecider<CLoopCloserERD<CNetworkOfPoses2DInf>>;
92 }
93 template <>
94 inline void TUserOptionsChecker<
95  mrpt::graphs::CNetworkOfPoses2DInf_NA>::_createDeciderOptimizerMappings()
96 {
97  using namespace mrpt::graphs;
98 
99  node_regs_map["CICPCriteriaNRD"] = &createNodeRegistrationDecider<
101  edge_regs_map["CICPCriteriaERD"] = &createEdgeRegistrationDecider<
103  edge_regs_map["CLoopCloserERD"] =
104  &createEdgeRegistrationDecider<CLoopCloserERD<CNetworkOfPoses2DInf_NA>>;
105 }
106 
107 // deciders/optpimizers specific to the 3D SLAM cases
108 template <>
109 inline void TUserOptionsChecker<
110  mrpt::graphs::CNetworkOfPoses3DInf>::_createDeciderOptimizerMappings()
111 {
112 }
113 
114 template <class GRAPH_t>
116  std::string reg_type /*="all"*/) const
117 {
118  MRPT_START;
119  using namespace std;
120  using namespace mrpt;
121 
122  ASSERTMSG_(
123  (system::strCmpI(reg_type, "node") ||
124  system::strCmpI(reg_type, "edge") || system::strCmpI(reg_type, "all")),
125  format(
126  "Registrar string '%s' does not match a known registrar name.\n"
127  "Specify 'node' 'edge' or 'all'",
128  reg_type.c_str()));
129 
130  if (system::strCmpI(reg_type, "node") || system::strCmpI(reg_type, "edge"))
131  {
132  cout << endl
133  << "Available " << system::upperCase(reg_type)
134  << " Registration Deciders: " << endl;
135  cout << sep_header << endl;
136 
138  regs_descriptions.begin();
139  dec_it != regs_descriptions.end(); ++dec_it)
140  {
141  TRegistrationDeciderProps* dec = *dec_it;
142  if (system::strCmpI(dec->type, reg_type))
143  {
144  cout << dec->name << endl;
145  cout << sep_subheader << endl;
146  cout << "\t- "
147  << "Description: " << dec->description << endl;
148  cout << "\t- "
149  << "Rawlog Format: " << dec->rawlog_format << endl;
150  cout << "\t- "
151  << "Observations that can be used: " << endl;
152  cout << "\t- "
153  << "Multi-robot SLAM capable decider: "
154  << (dec->is_mr_slam_class ? "TRUE" : "FALSE") << endl;
155  cout << "\t- "
156  << "SLAM Type: " << endl;
157  if (dec->is_slam_2d)
158  {
159  cout << "\t\t+ "
160  << "2D" << endl;
161  }
162  if (dec->is_slam_3d)
163  {
164  cout << "\t\t+ "
165  << "3D" << endl;
166  }
167  cout << endl;
168  for (vector<string>::const_iterator obs_it =
169  dec->observations_used.begin();
170  obs_it != dec->observations_used.end(); ++obs_it)
171  {
172  cout << "\t\t+ " << *obs_it << endl;
173  }
174  }
175  }
176  }
177  else
178  { // print both
179  dumpRegistrarsToConsole("node");
180  dumpRegistrarsToConsole("edge");
181  }
182 
183  MRPT_END;
184 }
185 
186 template <class GRAPH_t>
188 {
189  MRPT_START;
190 
191  using namespace std;
192 
193  cout << endl << "Available GraphSlam Optimizer classes: " << endl;
194  cout << sep_header << endl;
195 
197  optimizers_descriptions.begin();
198  opt_it != optimizers_descriptions.end(); ++opt_it)
199  {
200  TOptimizerProps* opt = *opt_it;
201  cout << opt->name << endl;
202  cout << sep_subheader << endl;
203  cout << "\t- "
204  << "Description: " << opt->description << endl;
205 
206  cout << "\t- "
207  << "Multi-robot SLAM capable optimizer: "
208  << (opt->is_mr_slam_class ? "TRUE" : "FALSE");
209  cout << "\t- "
210  << "SLAM Type: " << endl;
211  if (opt->is_slam_2d)
212  {
213  cout << "\t\t+ "
214  << "2D" << endl;
215  }
216  if (opt->is_slam_3d)
217  {
218  cout << "\t\t+ "
219  << "3D" << endl;
220  }
221  }
222  MRPT_END;
223 }
224 
225 template <class GRAPH_t>
227  std::string given_reg, std::string reg_type) const
228 {
229  MRPT_START;
230 
231  using namespace std;
232  using namespace mrpt;
233  using namespace mrpt::poses;
234 
235  ASSERTMSG_(
236  (system::strCmpI(reg_type, "node") ||
237  system::strCmpI(reg_type, "edge")),
238  format(
239  "Registrar string \"%s\" does not match a known registrar name.\n"
240  "Specify 'node' or 'edge' ",
241  reg_type.c_str()));
242  bool found = false;
243 
245  regs_descriptions.begin();
246  dec_it != regs_descriptions.end(); ++dec_it)
247  {
248  TRegistrationDeciderProps* dec = *dec_it;
249 
250  // TODO - check this
251  // if decider is not suitable for the selected SLAM type, ignore.
252  pose_t p;
253  if ((!dec->is_slam_2d && IS_CLASS(&p, CPose2D)) ||
254  (!dec->is_slam_3d && IS_CLASS(&p, CPose3D)))
255  {
256  continue;
257  }
258 
259  if (system::strCmpI(dec->type, reg_type))
260  {
261  if (system::strCmpI(dec->name, given_reg))
262  {
263  found = true;
264  return found;
265  }
266  }
267  }
268 
269  return found;
270  MRPT_END;
271 }
272 
273 template <class GRAPH_t>
275  std::string given_opt) const
276 {
277  MRPT_START;
278  using namespace std;
279  using namespace mrpt;
280  using namespace mrpt::poses;
281 
282  bool found = false;
283 
285  optimizers_descriptions.begin();
286  opt_it != optimizers_descriptions.end(); ++opt_it)
287  {
288  TOptimizerProps* opt = *opt_it;
289 
290  // if optimizer is not suitable for the selected SLAM type, ignore.
291  pose_t p;
292  if ((!opt->is_slam_2d && IS_CLASS(&p, CPose2D)) &&
293  (!opt->is_slam_3d && IS_CLASS(&p, CPose3D)))
294  {
295  continue;
296  }
297 
298  if (system::strCmpI(opt->name, given_opt))
299  {
300  found = true;
301  return found;
302  }
303  }
304 
305  return found;
306  MRPT_END;
307 }
308 
309 template <class GRAPH_t>
311 {
312  MRPT_START;
313 
314  // reset the vectors - in case they contain any elements
315  regs_descriptions.clear();
316  optimizers_descriptions.clear();
317 
318  // registering the available deciders
319  { // CFixedIntervalsNRD
321  dec->name = "CFixedIntervalsNRD";
322  dec->description =
323  "Register a new node if the distance from the previous node "
324  "surpasses a predefined distance threshold. Uses odometry "
325  "information for estimating the robot movement";
326  dec->type = "Node";
327  dec->rawlog_format = "Both";
328  dec->observations_used.push_back("CActionRobotMovement2D - Format #1");
329  dec->observations_used.push_back("CObservationOdometry - Format #2");
330  dec->is_slam_2d = true;
331  dec->is_slam_3d = true;
332 
333  regs_descriptions.push_back(dec);
334  }
335  { // CICPCriteriaNRD
337  dec->name = "CICPCriteriaNRD";
338  dec->description =
339  "Register a new node if the distance from the previous node "
340  "surpasses a predefined distance threshold. Uses 2D/3D RangeScans "
341  "alignment for estimating the robot movement";
342  dec->type = "Node";
343  dec->rawlog_format = "#2 - Observation-only";
344  dec->observations_used.push_back("CObservation2DRangeScan - Format #2");
345  dec->observations_used.push_back("CObservation3DRangeScan - Format #2");
346  dec->is_slam_2d = true;
347 
348  regs_descriptions.push_back(dec);
349  }
350  { // CEmptyNRD
352  dec->name = "CEmptyNRD";
353  dec->description =
354  "Empty Decider - does nothing when its class methods are called";
355  dec->type = "Node";
356  dec->rawlog_format = "Both";
357  dec->is_mr_slam_class = true;
358  dec->is_slam_2d = true;
359  dec->is_slam_3d = true;
360 
361  regs_descriptions.push_back(dec);
362  }
363  { // CICPCriteriaERD
365  dec->name = "CICPCriteriaERD";
366  dec->description =
367  "Register a new edge by aligning the provided 2D/3D RangeScans of "
368  "2 nodes. Uses the goodness of the ICP Alignment as the criterium "
369  "for adding a new edge";
370  dec->type = "Edge";
371  dec->rawlog_format = "Both";
372  dec->observations_used.push_back(
373  "CObservation2DRangeScan - Format #1, #2");
374  dec->observations_used.push_back("CObservation3DRangeScan - Format #2");
375  dec->is_slam_2d = true;
376 
377  regs_descriptions.push_back(dec);
378  }
379  { // CEmptyERD
381  dec->name = "CEmptyERD";
382  dec->description =
383  "Empty Decider - does nothing when its class methods are called";
384  dec->type = "Edge";
385  dec->rawlog_format = "Both";
386  dec->is_mr_slam_class = true;
387  dec->is_slam_2d = true;
388  dec->is_slam_3d = true;
389 
390  regs_descriptions.push_back(dec);
391  }
392  { // CLoopCloserERD
394  dec->name = "CLoopCloserERD";
395  dec->description =
396  "Partition the map and register *sets* of edges based on the "
397  "Pairwise consistency matrix of each set.";
398  dec->type = "Edge";
399  dec->rawlog_format = "Both";
400  dec->observations_used.push_back(
401  "CObservation2DRangeScan - Format #1, #2");
402  dec->is_slam_2d = true;
403 
404  regs_descriptions.push_back(dec);
405  }
406 
407  // registering the available optimizers
408  { // CEmptyGSO
409  TOptimizerProps* opt = new TOptimizerProps;
410  opt->name = "CEmptyGSO";
411  opt->description =
412  "Empty Optimizer - does nothing when its class methods are called";
413  opt->is_mr_slam_class = true;
414  opt->is_slam_2d = true;
415  opt->is_slam_3d = true;
416 
417  optimizers_descriptions.push_back(opt);
418  }
419 
420  { // CLevMarqGSO
421  TOptimizerProps* opt = new TOptimizerProps;
422  opt->name = "CLevMarqGSO";
423  opt->description = "Levenberg-Marqurdt non-linear graphSLAM solver";
424  opt->is_mr_slam_class = true;
425  opt->is_slam_2d = true;
426  opt->is_slam_3d = true;
427 
428  optimizers_descriptions.push_back(opt);
429  }
430 
431  MRPT_END
432 }
433 }
434 }
435 } // END OF NAMESPACES
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
Definition: CObject.h:103
A directed graph of pose constraints, with edges being the relative poses between pairs of nodes iden...
ICP-based Fixed Intervals Node Registration.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:41
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
Scalar * iterator
Definition: eigen_plugins.h:26
const Scalar * const_iterator
Definition: eigen_plugins.h:27
GLfloat GLfloat p
Definition: glext.h:6305
GLsizei const GLchar ** string
Definition: glext.h:4101
bool strCmpI(const std::string &s1, const std::string &s2)
Return true if the two strings are equal (case insensitive)
std::string upperCase(const std::string &str)
Returns a upper-case version of a string.
#define MRPT_START
Definition: mrpt_macros.h:425
#define MRPT_END
Definition: mrpt_macros.h:429
#define ASSERTMSG_(f, __ERROR_MSG)
Definition: mrpt_macros.h:306
Abstract graph and tree data structures, plus generic graph algorithms.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:18
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
Properties struct for the Optimizer classes.
std::string name
Name of the decider or optimizer class.
std::string description
General description of the decicder or optimizer class.
bool is_mr_slam_class
Class indicating if the current decider/optimizer class can be used in a multi-robot SLAM operation.
Properties struct for the Registration Decider classes.
std::vector< std::string > observations_used
Measurements that the current decider class can utilize.
std::string rawlog_format
Rawlog formats that the decider can be used in.
Class containing the declarations of supplementary methods that can be used in application-related co...
virtual bool checkOptimizerExists(std::string given_opt) const
Check if the given optimizer exists in the vector of optimizers.
virtual void populateDeciderOptimizerProperties()
Populate the available decider, optimizer classes available in user applications.
virtual void createDeciderOptimizerMappings()
Create the necessary mappings from strings to the corresponding instance creation functors.
virtual void dumpOptimizersToConsole() const
Print the optimizers vector in a formatted manner to the standard output.
GRAPH_t::constraint_t::type_value pose_t
virtual bool checkRegistrationDeciderExists(std::string given_reg, std::string reg_type) const
Check if the given registrator decider exists in the vector of deciders.
virtual void dumpRegistrarsToConsole(std::string reg_type="all") const
Print the registration deciders vector in a formatted manner to the standard output.



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST