Main MRPT website > C++ reference for MRPT 1.9.9
CLevMarqGSO_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 CLEVMARQGSO_IMPL_H
11 #define CLEVMARQGSO_IMPL_H
12 
13 namespace mrpt
14 {
15 namespace graphslam
16 {
17 namespace optimizers
18 {
19 // Ctors, Dtors
20 //////////////////////////////////////////////////////////////
21 
22 template <class GRAPH_T>
24  : m_first_time_call(false),
25  m_has_read_config(false),
26  m_autozoom_active(true),
27  m_last_total_num_of_nodes(5),
28  m_optimization_policy(FOP_USE_LC),
29  m_curr_used_consec_lcs(0),
30  m_curr_ignored_consec_lcs(0),
31  m_just_fully_optimized_graph(false),
32  m_min_nodes_for_optimization(3)
33 {
34  MRPT_START;
35  using namespace mrpt::utils;
36  this->initializeLoggers("CLevMarqGSO");
37 
38  MRPT_END;
39 }
40 template <class GRAPH_T>
42 {
43  // JL Removed MRPT_END since it could launch an exception, not allowed in a
44  // dtor
45 }
46 
47 // Member function implementations
48 //////////////////////////////////////////////////////////////
49 template <class GRAPH_T>
52  mrpt::obs::CSensoryFrame::Ptr observations,
53  mrpt::obs::CObservation::Ptr observation)
54 {
55  MRPT_START;
56  using namespace mrpt::utils;
57  this->logFmt(LVL_DEBUG, "In updateOptimizerState... ");
58 
60  {
62  registered_new_node = true;
63 
65  {
67  m_first_time_call = true;
68  }
69 
71  {
72  // join the previous optimization thread
73  m_thread_optimize.join();
74 
75  // optimize the graph - run on a seperate thread
76  m_thread_optimize = std::thread(&CLevMarqGSO::optimizeGraph, this);
77  }
78  else
79  { // single threaded implementation
80  bool is_full_update = this->checkForFullOptimization();
81  this->_optimizeGraph(is_full_update);
82  }
83  }
84 
85  return true;
86  MRPT_END;
87 }
88 
89 template <class GRAPH_T>
91 {
92  MRPT_START;
95 
96  this->initGraphVisualization();
98 
99  MRPT_END;
100 }
101 
102 template <class GRAPH_T>
104 {
105  MRPT_START;
107 
109  {
111  }
112 
113  this->updateGraphVisualization();
114 
115  MRPT_END;
116 }
117 
118 template <class GRAPH_T>
120  const std::map<std::string, bool>& events_occurred)
121 {
122  MRPT_START;
123  using namespace std;
124  parent::notifyOfWindowEvents(events_occurred);
125 
126  // I know the keys exists - I registered them explicitly
127 
128  // optimization_distance toggling
130  {
131  if (events_occurred.find(opt_params.keystroke_optimization_distance)
132  ->second)
133  {
135  }
136 
137  if (events_occurred.find(opt_params.keystroke_optimize_graph)->second)
138  {
139  this->_optimizeGraph(/*is_full_update=*/true);
140  }
141  }
142 
143  // graph toggling
144  if (events_occurred.find(viz_params.keystroke_graph_toggle)->second)
145  {
146  this->toggleGraphVisualization();
147  }
148 
149  // if mouse event, let the user decide about the camera
150  if (events_occurred.find("mouse_clicked")->second)
151  {
152  MRPT_LOG_DEBUG_STREAM("Mouse was clicked. Disabling autozoom.");
153  m_autozoom_active = false;
154  }
155 
156  // autofit the graph once
157  if (events_occurred.find(viz_params.keystroke_graph_autofit)->second)
158  {
159  MRPT_LOG_DEBUG_STREAM("Autofit button was pressed");
160  this->fitGraphInView();
161  }
162 
163  MRPT_END;
164 } // end of notifyOfWindowEvents
165 
166 template <class GRAPH_T>
168 {
169  MRPT_START;
170  ASSERTMSG_(this->m_win_manager, "No CWindowManager* is given");
171 
173  {
175  viz_params.keystroke_graph_toggle, "Toggle Graph visualization");
177  viz_params.keystroke_graph_autofit, "Fit Graph in view");
178 
180  /* offset_y* = */ &viz_params.offset_y_graph,
181  /* text_index* = */ &viz_params.text_index_graph);
182  }
183 
184  MRPT_END;
185 }
186 template <class GRAPH_T>
188 {
189  MRPT_START;
190  ASSERTMSG_(this->m_win_manager, "No CWindowManager* is given");
191  using namespace mrpt::opengl;
192  using namespace mrpt::utils;
193 
194  this->logFmt(
195  mrpt::utils::LVL_DEBUG, "In the updateGraphVisualization function");
196 
197  // update the graph (clear and rewrite..)
198  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
199 
200  // remove previous graph and insert the new instance
201  // TODO - make this an incremental proocecure
202  CRenderizable::Ptr prev_object = scene->getByName("optimized_graph");
203  bool prev_visibility = true;
204  if (prev_object)
205  { // set the visibility of the graph correctly
206  prev_visibility = prev_object->isVisible();
207  }
208  scene->removeObject(prev_object);
209 
210  // CSetOfObjects::Ptr graph_obj =
211  // graph_tools::graph_visualize(*this->m_graph, viz_params.cfg);
212  CSetOfObjects::Ptr graph_obj = mrpt::make_aligned_shared<CSetOfObjects>();
213  this->m_graph->getAs3DObject(graph_obj, viz_params.cfg);
214 
215  graph_obj->setName("optimized_graph");
216  graph_obj->setVisibility(prev_visibility);
217  scene->insert(graph_obj);
218  this->m_win->unlockAccess3DScene();
219 
222  format(
223  "Optimized Graph: #nodes %d",
224  static_cast<int>(this->m_graph->nodeCount())),
225  TColorf(0.0, 0.0, 0.0),
226  /* unique_index = */ viz_params.text_index_graph);
227 
228  this->m_win->forceRepaint();
229 
230  if (m_autozoom_active)
231  {
232  this->fitGraphInView();
233  }
234 
235  MRPT_END;
236 }
237 
238 template <class GRAPH_T>
240 {
241  MRPT_START;
242  using namespace mrpt::opengl;
243 
244  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
245 
246  CRenderizable::Ptr graph_obj = scene->getByName("optimized_graph");
247  graph_obj->setVisibility(!graph_obj->isVisible());
248 
249  this->m_win->unlockAccess3DScene();
250  this->m_win->forceRepaint();
251 
252  MRPT_END;
253 }
254 
255 template <class GRAPH_T>
257 {
258  MRPT_START;
259  using namespace mrpt::opengl;
260 
261  ASSERTMSG_(
262  this->m_win,
263  "\nVisualization of data was requested but no CDisplayWindow3D pointer "
264  "was given\n");
265 
266  // first fetch the graph object
267  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
268  CRenderizable::Ptr obj = scene->getByName("optimized_graph");
269  CSetOfObjects::Ptr graph_obj =
270  std::dynamic_pointer_cast<CSetOfObjects>(obj);
271  this->m_win->unlockAccess3DScene();
272  this->m_win->forceRepaint();
273 
274  // autofit it based on its grid
275  CGridPlaneXY::Ptr obj_grid =
276  graph_obj->CSetOfObjects::getByClass<CGridPlaneXY>();
277  if (obj_grid)
278  {
279  float x_min, x_max, y_min, y_max;
280  obj_grid->getPlaneLimits(x_min, x_max, y_min, y_max);
281  const float z_min = obj_grid->getPlaneZcoord();
283  0.5 * (x_min + x_max), 0.5 * (y_min + y_max), z_min);
284  this->m_win->setCameraZoom(
285  2.0f * std::max(10.0f, std::max(x_max - x_min, y_max - y_min)));
286  }
287  this->m_win->setCameraAzimuthDeg(60);
288  this->m_win->setCameraElevationDeg(75);
289  this->m_win->setCameraProjective(true);
290 
291  MRPT_END;
292 }
293 
294 template <class GRAPH_T>
296 {
297  MRPT_START;
298  using namespace mrpt::opengl;
299 
301  {
304  "Toggle optimization distance on/off");
305 
308  "Manually trigger a full graph optimization");
309  }
310 
311  pose_t p;
313  pose_t initial_pose;
314  obj->setPose(initial_pose);
315  obj->setName("optimization_distance_obj");
316 
317  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
318  scene->insert(obj);
319  this->m_win->unlockAccess3DScene();
320  this->m_win->forceRepaint();
321 
322  // optimization distance disk - textMessage
326 
329  format("Radius for graph optimization"),
331  /* unique_index = */ opt_params.text_index_optimization_distance);
332  MRPT_END;
333 }
334 
335 template <class GRAPH_T>
338  const mrpt::poses::CPose2D& p_unused)
339 {
340  using namespace mrpt::opengl;
341 
342  CDisk::Ptr obj = mrpt::make_aligned_shared<CDisk>();
343  obj->setDiskRadius(
347 
348  return obj;
349 }
350 template <class GRAPH_T>
353  const mrpt::poses::CPose3D& p_unused)
354 {
355  using namespace mrpt::opengl;
356 
357  CSphere::Ptr obj = mrpt::make_aligned_shared<CSphere>();
359  obj->setColor_u8(
363  /*alpha = */ 60);
364 
365  return obj;
366 }
367 
368 template <class GRAPH_T>
370 {
371  MRPT_START;
372  ASSERTMSG_(this->m_win_manager, "No CWindowManager* is given");
373  using namespace mrpt::opengl;
374 
375  // update ICP_max_distance Disk
376  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
377 
378  CRenderizable::Ptr obj = scene->getByName("optimization_distance_obj");
379  obj->setPose(this->m_graph->nodes.rbegin()->second);
380 
381  this->m_win->unlockAccess3DScene();
382  this->m_win->forceRepaint();
383  MRPT_END;
384 }
385 
386 // TODO - implement this
387 template <class GRAPH_T>
389 {
390  MRPT_START;
391  using namespace mrpt::opengl;
392 
393  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
394 
395  CRenderizable::Ptr obj = scene->getByName("optimization_distance_obj");
396  obj->setVisibility(!obj->isVisible());
397 
398  this->m_win->unlockAccess3DScene();
399  this->m_win->forceRepaint();
400 
401  MRPT_END;
402 }
403 
404 template <class GRAPH_T>
406 {
407  MRPT_START;
408  using namespace std;
409 
411  "optimizeGraph:: ThreadID:" << endl
412  << "\t" << std::this_thread::get_id()
413  << endl
414  << "\t"
415  << "Trying to grab lock... ");
416 
417  std::lock_guard<std::mutex> m_graph_lock(*this->m_graph_section);
418  this->_optimizeGraph();
419 
420  this->logFmt(mrpt::utils::LVL_DEBUG, "2nd thread grabbed the lock..");
421 
422  MRPT_END;
423 }
424 
425 template <class GRAPH_T>
426 void CLevMarqGSO<GRAPH_T>::_optimizeGraph(bool is_full_update /*=false*/)
427 {
428  MRPT_START;
429  this->m_time_logger.enter("CLevMarqGSO::_optimizeGraph");
430 
431  using namespace mrpt::utils;
432 
433  // if less than X nodes exist overall, do not try optimizing
434  if (m_min_nodes_for_optimization > this->m_graph->nodes.size())
435  {
436  return;
437  }
438 
439  CTicTac optimization_timer;
440  optimization_timer.Tic();
441 
442  // set of nodes for which the optimization procedure will take place
443  std::set<mrpt::utils::TNodeID>* nodes_to_optimize;
444 
445  // fill in the nodes in certain distance to the current node, only if
446  // is_full_update is not instructed
447  if (is_full_update)
448  {
449  // nodes_to_optimize: List of nodes to optimize. NULL -> all but the
450  // root
451  // node.
452  nodes_to_optimize = NULL;
453  }
454  else
455  {
456  nodes_to_optimize = new std::set<mrpt::utils::TNodeID>;
457 
458  // I am certain that this shall not be called when nodeCount = 0, since
459  // the
460  // optimization procedure starts only after certain number of nodes has
461  // been added
462  this->getNearbyNodesOf(
463  nodes_to_optimize, this->m_graph->nodeCount() - 1,
465  nodes_to_optimize->insert(this->m_graph->nodeCount() - 1);
466  }
467 
469 
470  // Execute the optimization
472  *(this->m_graph), levmarq_info, nodes_to_optimize, opt_params.cfg,
473  &CLevMarqGSO<GRAPH_T>::levMarqFeedback); // functor feedback
474 
475  if (is_full_update)
476  {
478  }
479  else
480  {
482  }
483 
484  double elapsed_time = optimization_timer.Tac();
485  this->logFmt(
486  mrpt::utils::LVL_DEBUG, "Optimization of graph took: %fs",
487  elapsed_time);
488 
489  // deleting the nodes_to_optimize set
490  delete nodes_to_optimize;
491  nodes_to_optimize = nullptr;
492 
493  this->m_time_logger.leave("CLevMarqGSO::_optimizeGraph");
494  MRPT_UNUSED_PARAM(elapsed_time);
495  MRPT_END;
496 } // end of _optimizeGraph
497 
498 template <class GRAPH_T>
500 {
501  MRPT_START;
502 
503  bool is_loop_closure = false;
504  typename GRAPH_T::edges_map_t curr_pair_nodes_to_edge =
505  this->m_graph->edges;
506 
507  // find the *node pairs* that exist in current but not the last
508  // nodes_to_edge
509  // map If the distance of any of these pairs is greater than
510  // LC_min_nodeid_diff then consider this a loop closure
511  typename GRAPH_T::edges_map_t::const_iterator search;
512  mrpt::utils::TPairNodeIDs curr_pair;
513 
514  for (typename GRAPH_T::edges_map_t::const_iterator it =
515  curr_pair_nodes_to_edge.begin();
516  it != curr_pair_nodes_to_edge.end(); ++it)
517  {
518  search = opt_params.last_pair_nodes_to_edge.find(it->first);
519  // if current node pair is not found in the last set...
520  if (search == opt_params.last_pair_nodes_to_edge.end())
521  {
522  curr_pair = it->first;
523 
524  if (std::abs(
525  static_cast<int>(curr_pair.first) -
526  static_cast<int>(curr_pair.second)) >
528  {
529  this->logFmt(
530  mrpt::utils::LVL_DEBUG, "Registering loop closure... ");
531  is_loop_closure = true;
532  break; // no need for more iterations
533  }
534  }
535  }
536 
537  // update the pair_nodes_to_edge map
538  opt_params.last_pair_nodes_to_edge = curr_pair_nodes_to_edge;
539  return is_loop_closure;
540 
541  MRPT_END;
542 }
543 
544 template <class GRAPH_T>
546 {
547  bool is_full_update = false;
548 
550  { // always optimize fully
551  return true;
552  }
553 
554  bool added_lc = this->checkForLoopClosures();
555 
556  // Decide on the LoopClosingAttitude I am in
557  if (!added_lc)
558  { // reset both ignored and used counters
560  {
561  MRPT_LOG_DEBUG_STREAM("No new Loop Closure found.");
562  }
563 
567 
568  return is_full_update;
569  }
570  else
571  { // lc found.
572  // have I used enough consecutive loop closures?
573  bool use_limit_reached =
575  // have I ignored enough consecutive loop closures?
576  bool ignore_limit_reached =
578 
579  // Have I reached any of the limits above?
580  if (ignore_limit_reached || use_limit_reached)
581  {
584 
585  // decide of the my policy on full optimization
586  if (ignore_limit_reached)
587  {
589  }
590  if (use_limit_reached)
591  {
593  }
594  }
595  else
596  { // no limits reached yet.
598  {
600  }
601  else
602  {
604  }
605  }
606  }
607 
608  // Decide on whether to fully optimize the graph based on the mode I am in
610  {
611  is_full_update = false;
613  "*PARTIAL* graph optimization.. ignoring new loop closure");
614  }
615  else
616  {
617  is_full_update = true;
618  MRPT_LOG_WARN_STREAM("Commencing with *FULL* graph optimization... ");
619  }
620  return is_full_update;
621 
622 } // end of checkForFullOptimization
623 
624 template <class GRAPH_T>
626 {
628 }
629 
630 template <class GRAPH_T>
632  const GRAPH_T& graph, const size_t iter, const size_t max_iter,
633  const double cur_sq_error)
634 {
635 }
636 
637 template <class GRAPH_T>
639  std::set<mrpt::utils::TNodeID>* nodes_set,
640  const mrpt::utils::TNodeID& cur_nodeID, double distance)
641 {
642  MRPT_START;
643 
644  if (distance > 0)
645  {
646  // check all but the last node.
647  for (mrpt::utils::TNodeID nodeID = 0;
648  nodeID < this->m_graph->nodeCount() - 1; ++nodeID)
649  {
650  double curr_distance = this->m_graph->nodes[nodeID].distanceTo(
651  this->m_graph->nodes[cur_nodeID]);
652  if (curr_distance <= distance)
653  {
654  nodes_set->insert(nodeID);
655  }
656  }
657  }
658  else
659  { // check against all nodes
660  this->m_graph->getAllNodes(*nodes_set);
661  }
662 
663  MRPT_END;
664 }
665 
666 template <class GRAPH_T>
668 {
670 
673 }
674 template <class GRAPH_T>
676 {
677  MRPT_START;
678  using namespace mrpt::utils;
679  parent::loadParams(source_fname);
680 
681  opt_params.loadFromConfigFileName(source_fname, "OptimizerParameters");
682  viz_params.loadFromConfigFileName(source_fname, "VisualizationParameters");
683 
684  CConfigFile source(source_fname);
685 
686  // TODO - check that these work
687  m_max_used_consec_lcs = source.read_int(
688  "OptimizerParameters", "max_used_consecutive_loop_closures", 2, false);
689 
690  m_max_ignored_consec_lcs = source.read_int(
691  "OptimizerParameters", "max_ignored_consecutive_loop_closures", 15,
692  false);
693 
694  // set the logging level if given by the user
695  // Minimum verbosity level of the logger
696  int min_verbosity_level =
697  source.read_int("OptimizerParameters", "class_verbosity", 1, false);
698  this->setMinLoggingLevel(VerbosityLevel(min_verbosity_level));
699 
700  this->logFmt(mrpt::utils::LVL_DEBUG, "Successfully loaded Params. ");
701  m_has_read_config = true;
702 
703  MRPT_END;
704 }
705 
706 template <class GRAPH_T>
708 {
709  MRPT_START;
710  using namespace std;
711 
712  const std::string report_sep(2, '\n');
713  const std::string header_sep(80, '#');
714 
715  // Report on graph
716  stringstream class_props_ss;
717  class_props_ss << "Levenberg Marquardt Optimization Summary: " << std::endl;
718  class_props_ss << header_sep << std::endl;
719 
720  // time and output logging
721  const std::string time_res = this->m_time_logger.getStatsAsText();
722  const std::string output_res = this->getLogAsString();
723 
724  // merge the individual reports
725  report_str->clear();
726  parent::getDescriptiveReport(report_str);
727 
728  *report_str += class_props_ss.str();
729  *report_str += report_sep;
730 
731  *report_str += time_res;
732  *report_str += report_sep;
733 
734  *report_str += output_res;
735  *report_str += report_sep;
736 
737  MRPT_END;
738 }
739 
740 // OptimizationParams
741 //////////////////////////////////////////////////////////////
742 template <class GRAPH_T>
744  : optimization_distance_color(0, 201, 87),
745  keystroke_optimization_distance("u"),
746  keystroke_optimize_graph("w")
747 {
748 }
749 template <class GRAPH_T>
751 {
752 }
753 template <class GRAPH_T>
755  mrpt::utils::CStream& out) const
756 {
757  MRPT_START;
758 
759  out.printf(
760  "------------------[ Levenberg-Marquardt Optimization "
761  "]------------------\n");
762  out.printf(
763  "Optimization on second thread = %s\n",
764  optimization_on_second_thread ? "TRUE" : "FALSE");
765  out.printf(
766  "Optimize nodes in distance = %.2f\n", optimization_distance);
767  out.printf("Min. node difference for LC = %d\n", LC_min_nodeid_diff);
768 
769  out.printf("%s", cfg.getAsString().c_str());
770  std::cout << std::endl;
771 
772  MRPT_END;
773 }
774 template <class GRAPH_T>
776  const mrpt::utils::CConfigFileBase& source, const std::string& section)
777 {
778  MRPT_START;
779  optimization_on_second_thread = source.read_bool(
780  section, "optimization_on_second_thread", false, false);
781  LC_min_nodeid_diff = source.read_int(
782  "GeneralConfiguration", "LC_min_nodeid_diff", 30, false);
783  optimization_distance =
784  source.read_double(section, "optimization_distance", 5, false);
785  // asert the previous value
786  ASSERTMSG_(
787  optimization_distance == -1 || optimization_distance > 0,
788  format(
789  "Invalid value for optimization distance: %.2f",
790  optimization_distance));
791 
792  // optimization parameters
793  cfg["verbose"] = source.read_bool(section, "verbose", 0, false);
794  cfg["profiler"] = source.read_bool(section, "profiler", 0, false);
795  cfg["max_iterations"] =
796  source.read_double(section, "max_iterations", 100, false);
797  cfg["scale_hessian"] =
798  source.read_double("Optimization", "scale_hessian", 0.2, false);
799  cfg["tau"] = source.read_double(section, "tau", 1e-3, false);
800 
801  MRPT_END;
802 }
803 
804 // GraphVisualizationParams
805 //////////////////////////////////////////////////////////////
806 template <class GRAPH_T>
808  : keystroke_graph_toggle("s"), keystroke_graph_autofit("a")
809 {
810 }
811 template <class GRAPH_T>
813 {
814 }
815 template <class GRAPH_T>
817  mrpt::utils::CStream& out) const
818 {
819  MRPT_START;
820 
821  out.printf("-----------[ Graph Visualization Parameters ]-----------\n");
822  out.printf(
823  "Visualize optimized graph = %s\n",
824  visualize_optimized_graph ? "TRUE" : "FALSE");
825 
826  out.printf("%s", cfg.getAsString().c_str());
827 
828  std::cout << std::endl;
829 
830  MRPT_END;
831 }
832 template <class GRAPH_T>
834  const mrpt::utils::CConfigFileBase& source, const std::string& section)
835 {
836  MRPT_START;
837  using namespace utils;
838 
839  visualize_optimized_graph =
840  source.read_bool(section, "visualize_optimized_graph", 1, false);
841 
842  cfg["show_ID_labels"] =
843  source.read_bool(section, "optimized_show_ID_labels", 0, false);
844  cfg["show_ground_grid"] =
845  source.read_double(section, "optimized_show_ground_grid", 1, false);
846  cfg["show_edges"] =
847  source.read_bool(section, "optimized_show_edges", 1, false);
848  cfg["edge_color"] =
849  source.read_int(section, "optimized_edge_color", 4286611456, false);
850  cfg["edge_width"] =
851  source.read_double(section, "optimized_edge_width", 1.5, false);
852  cfg["show_node_corners"] =
853  source.read_bool(section, "optimized_show_node_corners", 1, false);
854  cfg["show_edge_rel_poses"] =
855  source.read_bool(section, "optimized_show_edge_rel_poses", 1, false);
856  cfg["edge_rel_poses_color"] = source.read_int(
857  section, "optimized_edge_rel_poses_color", 1090486272, false);
858  cfg["nodes_edges_corner_scale"] = source.read_double(
859  section, "optimized_nodes_edges_corner_scale", 0.4, false);
860  cfg["nodes_corner_scale"] =
861  source.read_double(section, "optimized_nodes_corner_scale", 0.7, false);
862  cfg["nodes_point_size"] =
863  source.read_int(section, "optimized_nodes_point_size", 5, false);
864  cfg["nodes_point_color"] = source.read_int(
865  section, "optimized_nodes_point_color", 10526880, false);
866 
867  MRPT_END;
868 }
869 }
870 }
871 } // end of namespaces
872 
873 #endif /* end of include guard: CLEVMARQGSO_IMPL_H */
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
#define MRPT_LOG_WARN_STREAM(__CONTENTS)
void getAllNodes(std::set< TNodeID > &lstNode_IDs) const
Return a list of all the node_ID's of the graph, generated from all the nodes that appear in the list...
edges_map_t edges
The public member with the directed edges in the graph.
global_poses_t nodes
The nodes (vertices) of the graph, with their estimated "global" (with respect to root) position,...
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr object, const mrpt::utils::TParametersDouble &viz_params) const
Return 3D Visual Representation of the edges and nodes in the network of poses.
size_t nodeCount() const
Return number of nodes in the list nodes of global coordinates (may be different that all nodes appea...
mrpt::graphslam::CWindowObserver * m_win_observer
CWindowObserver object for monitoring various visual-oriented events.
mrpt::graphslam::CWindowManager * m_win_manager
Pointer to the CWindowManager object used to store visuals-related instances.
virtual void initializeLoggers(const std::string &name)
Initialize the COutputLogger, CTimeLogger instances given the name of the decider/optimizer at hand.
virtual void loadParams(const std::string &source_fname)
Load the necessary for the decider/optimizer configuration parameters.
virtual void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
virtual void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
static const std::string header_sep
Separator string to be used in debugging messages.
virtual void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
typename mrpt::graphs::CNetworkOfPoses2DInf * m_graph
Pointer to the graph that is under construction.
void addTextMessage(const double x, const double y, const std::string &text, const mrpt::utils::TColorf &color=mrpt::utils::TColorf(1.0, 1.0, 1.0), const size_t unique_index=0)
Wrapper around the CDisplayWindow3D::addTextMessage method, so that the user does not have to specify...
void assignTextMessageParameters(double *offset_y, int *text_index)
Assign the next available offset_y and text_index for the textMessage under construction.
void registerKeystroke(const std::string key_str, const std::string key_desc)
Make new keystrokes available in the help message box.
Levenberg-Marquardt non-linear graph slam optimization scheme.
Definition: CLevMarqGSO.h:134
bool checkForLoopClosures()
Check if a loop closure edge was added in the graph.
void updateOptDistanceVisualization()
Update the position of the disk indicating the distance in which Levenberg-Marquardt graph optimizati...
void _optimizeGraph(bool is_full_update=false)
Optimize the given graph.
void fitGraphInView()
Set the camera parameters of the CDisplayWindow3D so that the whole graph is viewed in the window.
void getNearbyNodesOf(std::set< mrpt::utils::TNodeID > *nodes_set, const mrpt::utils::TNodeID &cur_nodeID, double distance)
Get a list of the nodeIDs whose position is within a certain distance to the specified nodeID.
void updateGraphVisualization()
Called internally for updating the visualization scene for the graph building procedure.
void initGraphVisualization()
Initialize objects relateed to the Graph Visualization.
size_t m_curr_used_consec_lcs
Number of consecutive loop closures that are currently registered.
Definition: CLevMarqGSO.h:390
void toggleGraphVisualization()
Toggle the graph visualization on and off.
GraphVisualizationParams viz_params
Parameters relevant to the visualization of the graph.
Definition: CLevMarqGSO.h:237
size_t m_max_used_consec_lcs
Number of maximum cosecutive loop closures that are allowed to be issued.
Definition: CLevMarqGSO.h:385
void updateVisuals()
Update the relevant visual features in CDisplayWindow.
void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
bool updateState(mrpt::obs::CActionCollection::Ptr action, mrpt::obs::CSensoryFrame::Ptr observations, mrpt::obs::CObservation::Ptr observation)
Generic method for fetching the incremental action/observation readings from the calling function.
void loadParams(const std::string &source_fname)
Load the necessary for the decider/optimizer configuration parameters.
static void levMarqFeedback(const GRAPH_T &graph, const size_t iter, const size_t max_iter, const double cur_sq_error)
Feedback of the Levenberg-Marquardt graph optimization procedure.
void optimizeGraph()
Wrapper around _optimizeGraph which first locks the section and then calls the _optimizeGraph method.
void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
bool m_just_fully_optimized_graph
Indicates whether a full graph optimization was just issued.
Definition: CLevMarqGSO.h:407
FullOptimizationPolicy m_optimization_policy
Should I fully optimize the graph on loop closure?
Definition: CLevMarqGSO.h:369
mrpt::opengl::CRenderizable::Ptr initOptDistanceVisualizationInternal(const mrpt::poses::CPose2D &p_unused)
Setup the corresponding Disk/Sphere instance.
OptimizationParams opt_params
Parameters relevant to the optimizatio nfo the graph.
Definition: CLevMarqGSO.h:235
GRAPH_T::constraint_t::type_value pose_t
Definition: CLevMarqGSO.h:142
void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
bool checkForFullOptimization()
Decide whether to issue a full graph optimization.
void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
void toggleOptDistanceVisualization()
toggle the optimization distance object on and off
void initOptDistanceVisualization()
Initialize the Disk/Sphere used for visualizing the optimization distance.
size_t m_min_nodes_for_optimization
Minimum number of nodes before we try optimizing the graph.
Definition: CLevMarqGSO.h:410
size_t m_curr_ignored_consec_lcs
Consecutive Loop Closures that have currently been ignored.
Definition: CLevMarqGSO.h:401
bool justFullyOptimizedGraph() const
Used by the caller to query for possible full graph optimization on the latest optimizer run.
size_t m_max_ignored_consec_lcs
Number of consecutive loop closures to ignore after m_max_used_consec_lcs have already been issued.
Definition: CLevMarqGSO.h:396
void setCameraPointingToPoint(float x, float y, float z)
Changes the camera parameters programmatically.
void forceRepaint()
Repaints the window.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
void setCameraZoom(float zoom)
Changes the camera parameters programmatically.
void setCameraProjective(bool isProjective)
Sets the camera as projective, or orthogonal.
mrpt::opengl::COpenGLScene::Ptr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
void setCameraAzimuthDeg(float deg)
Changes the camera parameters programmatically.
void setCameraElevationDeg(float deg)
Changes the camera parameters programmatically.
std::shared_ptr< CActionCollection > Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:43
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
std::shared_ptr< CDisk > Ptr
Definition: CDisk.h:35
A grid of lines over the XY plane.
Definition: CGridPlaneXY.h:33
void getPlaneLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CGridPlaneXY.h:66
std::shared_ptr< CGridPlaneXY > Ptr
Definition: CGridPlaneXY.h:34
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:62
std::shared_ptr< CRenderizable > Ptr
Definition: CRenderizable.h:45
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
std::shared_ptr< CSphere > Ptr
Definition: CSphere.h:33
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
This class allows loading and storing values and vectors of different types from a configuration text...
This class allows loading and storing values and vectors of different types from "....
Definition: CConfigFile.h:36
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
void loadFromConfigFileName(const std::string &config_file, const std::string &section)
Behaves like loadFromConfigFile, but you can pass directly a file name and a temporary CConfigFile ob...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:42
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
This class implements a high-performance stopwatch.
Definition: CTicTac.h:24
double Tac()
Stops the stopwatch.
Definition: CTicTac.cpp:97
void Tic()
Starts the stopwatch.
Definition: CTicTac.cpp:82
std::string getStatsAsText(const size_t column_width=80) const
Dump all stats to a multi-line text string.
void enter(const char *func_name)
Start of a named section.
Definition: CTimeLogger.h:117
double leave(const char *func_name)
End of a named section.
Definition: CTimeLogger.h:123
const Scalar * const_iterator
Definition: eigen_plugins.h:27
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
GLfloat GLfloat p
Definition: glext.h:6305
GLenum GLsizei GLenum format
Definition: glext.h:3531
GLsizei const GLchar ** string
Definition: glext.h:4101
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
Definition: geometry.cpp:1885
void optimize_graph_spa_levmarq(GRAPH_T &graph, TResultInfoSpaLevMarq &out_info, const std::set< mrpt::utils::TNodeID > *in_nodes_to_optimize=nullptr, const mrpt::utils::TParametersDouble &extra_params=mrpt::utils::TParametersDouble(), typename graphslam_traits< GRAPH_T >::TFunctorFeedback functor_feedback=typename graphslam_traits< GRAPH_T >::TFunctorFeedback())
Optimize a graph of pose constraints using the Sparse Pose Adjustment (SPA) sparse representation and...
Definition: levmarq.h:79
uint64_t TNodeID
The type for node IDs in graphs of different types.
Definition: types_simple.h:49
std::pair< TNodeID, TNodeID > TPairNodeIDs
A pair of node IDs.
Definition: types_simple.h:51
#define MRPT_START
Definition: mrpt_macros.h:425
#define ASSERT_(f)
Definition: mrpt_macros.h:309
#define MRPT_END
Definition: mrpt_macros.h:429
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:365
#define ASSERTMSG_(f, __ERROR_MSG)
Definition: mrpt_macros.h:306
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:16
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
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
Output information for mrpt::graphslam::optimize_graph_spa_levmarq()
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form,...
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.
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form,...
double optimization_distance
optimize only for the nodes found in a certain distance from the current position.
Definition: CLevMarqGSO.h:186
std::string keystroke_optimization_distance
Keystroke to toggle the optimization distance on/off.
Definition: CLevMarqGSO.h:191
std::string keystroke_optimize_graph
Keystroke to manually trigger a full graph optimization.
Definition: CLevMarqGSO.h:193
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.
A RGB color - floats in the range [0,1].
Definition: TColor.h:79



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