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-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 CLEVMARQGSO_IMPL_H
11 #define CLEVMARQGSO_IMPL_H
12 
14 {
15 // Ctors, Dtors
16 //////////////////////////////////////////////////////////////
17 
18 template <class GRAPH_T>
20  : m_first_time_call(false),
21  m_has_read_config(false),
22  m_autozoom_active(true),
23  m_last_total_num_of_nodes(5),
24  m_optimization_policy(FOP_USE_LC),
25  m_curr_used_consec_lcs(0),
26  m_curr_ignored_consec_lcs(0),
27  m_just_fully_optimized_graph(false),
28  m_min_nodes_for_optimization(3)
29 {
30  MRPT_START;
31  this->initializeLoggers("CLevMarqGSO");
32 
33  MRPT_END;
34 }
35 template <class GRAPH_T>
37 {
38  // JL Removed MRPT_END since it could launch an exception, not allowed in a
39  // dtor
40 }
41 
42 // Member function implementations
43 //////////////////////////////////////////////////////////////
44 template <class GRAPH_T>
47  mrpt::obs::CSensoryFrame::Ptr observations,
48  mrpt::obs::CObservation::Ptr observation)
49 {
50  MRPT_START;
51  MRPT_LOG_DEBUG("In updateOptimizerState... ");
52 
53  if (this->m_graph->nodeCount() > m_last_total_num_of_nodes)
54  {
55  m_last_total_num_of_nodes = this->m_graph->nodeCount();
56  registered_new_node = true;
57 
58  if (m_first_time_call)
59  {
60  opt_params.last_pair_nodes_to_edge = this->m_graph->edges;
61  m_first_time_call = true;
62  }
63 
64  if (opt_params.optimization_on_second_thread)
65  {
66  // join the previous optimization thread
67  m_thread_optimize.join();
68 
69  // optimize the graph - run on a seperate thread
70  m_thread_optimize = std::thread(&CLevMarqGSO::optimizeGraph, this);
71  }
72  else
73  { // single threaded implementation
74  bool is_full_update = this->checkForFullOptimization();
75  this->_optimizeGraph(is_full_update);
76  }
77  }
78 
79  return true;
80  MRPT_END;
81 }
82 
83 template <class GRAPH_T>
85 {
86  MRPT_START;
87  ASSERTDEB_(m_has_read_config);
88  parent::initializeVisuals();
89 
90  this->initGraphVisualization();
91  this->initOptDistanceVisualization();
92 
93  MRPT_END;
94 }
95 
96 template <class GRAPH_T>
98 {
99  MRPT_START;
100  parent::updateVisuals();
101 
102  if (opt_params.optimization_distance > 0)
103  {
104  this->updateOptDistanceVisualization();
105  }
106 
107  this->updateGraphVisualization();
108 
109  MRPT_END;
110 }
111 
112 template <class GRAPH_T>
114  const std::map<std::string, bool>& events_occurred)
115 {
116  MRPT_START;
117  using namespace std;
118  parent::notifyOfWindowEvents(events_occurred);
119 
120  // I know the keys exists - I registered them explicitly
121 
122  // optimization_distance toggling
123  if (opt_params.optimization_distance > 0)
124  {
125  if (events_occurred.find(opt_params.keystroke_optimization_distance)
126  ->second)
127  {
128  this->toggleOptDistanceVisualization();
129  }
130 
131  if (events_occurred.find(opt_params.keystroke_optimize_graph)->second)
132  {
133  this->_optimizeGraph(/*is_full_update=*/true);
134  }
135  }
136 
137  // graph toggling
138  if (events_occurred.find(viz_params.keystroke_graph_toggle)->second)
139  {
140  this->toggleGraphVisualization();
141  }
142 
143  // if mouse event, let the user decide about the camera
144  if (events_occurred.find("mouse_clicked")->second)
145  {
146  MRPT_LOG_DEBUG_STREAM("Mouse was clicked. Disabling autozoom.");
147  m_autozoom_active = false;
148  }
149 
150  // autofit the graph once
151  if (events_occurred.find(viz_params.keystroke_graph_autofit)->second)
152  {
153  MRPT_LOG_DEBUG_STREAM("Autofit button was pressed");
154  this->fitGraphInView();
155  }
156 
157  MRPT_END;
158 } // end of notifyOfWindowEvents
159 
160 template <class GRAPH_T>
162 {
163  MRPT_START;
164  ASSERTDEBMSG_(this->m_win_manager, "No CWindowManager* is given");
165 
166  if (viz_params.visualize_optimized_graph)
167  {
168  this->m_win_observer->registerKeystroke(
169  viz_params.keystroke_graph_toggle, "Toggle Graph visualization");
170  this->m_win_observer->registerKeystroke(
171  viz_params.keystroke_graph_autofit, "Fit Graph in view");
172 
173  this->m_win_manager->assignTextMessageParameters(
174  /* offset_y* = */ &viz_params.offset_y_graph,
175  /* text_index* = */ &viz_params.text_index_graph);
176  }
177 
178  MRPT_END;
179 }
180 template <class GRAPH_T>
182 {
183  MRPT_START;
184  ASSERTDEBMSG_(this->m_win_manager, "No CWindowManager* is given");
185  using namespace mrpt::opengl;
186 
187  this->logFmt(
188  mrpt::system::LVL_DEBUG, "In the updateGraphVisualization function");
189 
190  // update the graph (clear and rewrite..)
191  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
192 
193  // remove previous graph and insert the new instance
194  // TODO - make this an incremental proocecure
195  CRenderizable::Ptr prev_object = scene->getByName("optimized_graph");
196  bool prev_visibility = true;
197  if (prev_object)
198  { // set the visibility of the graph correctly
199  prev_visibility = prev_object->isVisible();
200  }
201  scene->removeObject(prev_object);
202 
203  // CSetOfObjects::Ptr graph_obj =
204  // graph_tools::graph_visualize(*this->m_graph, viz_params.cfg);
205  CSetOfObjects::Ptr graph_obj = mrpt::make_aligned_shared<CSetOfObjects>();
206  this->m_graph->getAs3DObject(graph_obj, viz_params.cfg);
207 
208  graph_obj->setName("optimized_graph");
209  graph_obj->setVisibility(prev_visibility);
210  scene->insert(graph_obj);
211  this->m_win->unlockAccess3DScene();
212 
213  this->m_win_manager->addTextMessage(
214  5, -viz_params.offset_y_graph,
215  format(
216  "Optimized Graph: #nodes %d",
217  static_cast<int>(this->m_graph->nodeCount())),
218  mrpt::img::TColorf(0.0, 0.0, 0.0),
219  /* unique_index = */ viz_params.text_index_graph);
220 
221  this->m_win->forceRepaint();
222 
223  if (m_autozoom_active)
224  {
225  this->fitGraphInView();
226  }
227 
228  MRPT_END;
229 }
230 
231 template <class GRAPH_T>
233 {
234  MRPT_START;
235  using namespace mrpt::opengl;
236 
237  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
238 
239  CRenderizable::Ptr graph_obj = scene->getByName("optimized_graph");
240  graph_obj->setVisibility(!graph_obj->isVisible());
241 
242  this->m_win->unlockAccess3DScene();
243  this->m_win->forceRepaint();
244 
245  MRPT_END;
246 }
247 
248 template <class GRAPH_T>
250 {
251  MRPT_START;
252  using namespace mrpt::opengl;
253 
255  this->m_win,
256  "\nVisualization of data was requested but no CDisplayWindow3D pointer "
257  "was given\n");
258 
259  // first fetch the graph object
260  COpenGLScene::Ptr& scene = this->m_win->get3DSceneAndLock();
261  CRenderizable::Ptr obj = scene->getByName("optimized_graph");
262  CSetOfObjects::Ptr graph_obj =
263  std::dynamic_pointer_cast<CSetOfObjects>(obj);
264  this->m_win->unlockAccess3DScene();
265  this->m_win->forceRepaint();
266 
267  // autofit it based on its grid
268  CGridPlaneXY::Ptr obj_grid =
269  graph_obj->CSetOfObjects::getByClass<CGridPlaneXY>();
270  if (obj_grid)
271  {
272  float x_min, x_max, y_min, y_max;
273  obj_grid->getPlaneLimits(x_min, x_max, y_min, y_max);
274  const float z_min = obj_grid->getPlaneZcoord();
275  this->m_win->setCameraPointingToPoint(
276  0.5 * (x_min + x_max), 0.5 * (y_min + y_max), z_min);
277  this->m_win->setCameraZoom(
278  2.0f * std::max(10.0f, std::max(x_max - x_min, y_max - y_min)));
279  }
280  this->m_win->setCameraAzimuthDeg(60);
281  this->m_win->setCameraElevationDeg(75);
282  this->m_win->setCameraProjective(true);
283 
284  MRPT_END;
285 }
286 
287 template <class GRAPH_T>
289 {
290  MRPT_START;
291  using namespace mrpt::opengl;
292 
293  if (opt_params.optimization_distance > 0)
294  {
295  this->m_win_observer->registerKeystroke(
296  opt_params.keystroke_optimization_distance,
297  "Toggle optimization distance on/off");
298 
299  this->m_win_observer->registerKeystroke(
300  opt_params.keystroke_optimize_graph,
301  "Manually trigger a full graph optimization");
302  }
303 
304  pose_t p;
305  CRenderizable::Ptr obj = this->initOptDistanceVisualizationInternal(p);
306  pose_t initial_pose;
307  obj->setPose(initial_pose);
308  obj->setName("optimization_distance_obj");
309 
310  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
311  scene->insert(obj);
312  this->m_win->unlockAccess3DScene();
313  this->m_win->forceRepaint();
314 
315  // optimization distance disk - textMessage
316  this->m_win_manager->assignTextMessageParameters(
317  &opt_params.offset_y_optimization_distance,
318  &opt_params.text_index_optimization_distance);
319 
320  this->m_win_manager->addTextMessage(
321  5, -opt_params.offset_y_optimization_distance,
322  format("Radius for graph optimization"),
323  mrpt::img::TColorf(opt_params.optimization_distance_color),
324  /* unique_index = */ opt_params.text_index_optimization_distance);
325  MRPT_END;
326 }
327 
328 template <class GRAPH_T>
331  const mrpt::poses::CPose2D& p_unused)
332 {
333  using namespace mrpt::opengl;
334 
335  CDisk::Ptr obj = mrpt::make_aligned_shared<CDisk>();
336  obj->setDiskRadius(
337  opt_params.optimization_distance,
338  opt_params.optimization_distance - 0.1);
339  obj->setColor_u8(opt_params.optimization_distance_color);
340 
341  return obj;
342 }
343 template <class GRAPH_T>
346  const mrpt::poses::CPose3D& p_unused)
347 {
348  using namespace mrpt::opengl;
349 
350  CSphere::Ptr obj = mrpt::make_aligned_shared<CSphere>();
351  obj->setRadius(opt_params.optimization_distance);
352  obj->setColor_u8(
353  opt_params.optimization_distance_color.R,
354  opt_params.optimization_distance_color.G,
355  opt_params.optimization_distance_color.B,
356  /*alpha = */ 60);
357 
358  return obj;
359 }
360 
361 template <class GRAPH_T>
363 {
364  MRPT_START;
365  ASSERTDEBMSG_(this->m_win_manager, "No CWindowManager* is given");
366  using namespace mrpt::opengl;
367 
368  // update ICP_max_distance Disk
369  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
370 
371  CRenderizable::Ptr obj = scene->getByName("optimization_distance_obj");
372  obj->setPose(this->m_graph->nodes.rbegin()->second);
373 
374  this->m_win->unlockAccess3DScene();
375  this->m_win->forceRepaint();
376  MRPT_END;
377 }
378 
379 // TODO - implement this
380 template <class GRAPH_T>
382 {
383  MRPT_START;
384  using namespace mrpt::opengl;
385 
386  COpenGLScene::Ptr scene = this->m_win->get3DSceneAndLock();
387 
388  CRenderizable::Ptr obj = scene->getByName("optimization_distance_obj");
389  obj->setVisibility(!obj->isVisible());
390 
391  this->m_win->unlockAccess3DScene();
392  this->m_win->forceRepaint();
393 
394  MRPT_END;
395 }
396 
397 template <class GRAPH_T>
399 {
400  MRPT_START;
401  using namespace std;
402 
404  "optimizeGraph:: ThreadID:" << endl
405  << "\t" << std::this_thread::get_id()
406  << endl
407  << "\t"
408  << "Trying to grab lock... ");
409 
410  std::lock_guard<std::mutex> graph_lock(*this->m_graph_section);
411  this->_optimizeGraph();
412 
413  this->logFmt(mrpt::system::LVL_DEBUG, "2nd thread grabbed the lock..");
414 
415  MRPT_END;
416 }
417 
418 template <class GRAPH_T>
419 void CLevMarqGSO<GRAPH_T>::_optimizeGraph(bool is_full_update /*=false*/)
420 {
421  MRPT_START;
422  this->m_time_logger.enter("CLevMarqGSO::_optimizeGraph");
423 
424  // if less than X nodes exist overall, do not try optimizing
425  if (m_min_nodes_for_optimization > this->m_graph->nodes.size())
426  {
427  return;
428  }
429 
430  mrpt::system::CTicTac optimization_timer;
431  optimization_timer.Tic();
432 
433  // set of nodes for which the optimization procedure will take place
434  std::set<mrpt::graphs::TNodeID>* nodes_to_optimize;
435 
436  // fill in the nodes in certain distance to the current node, only if
437  // is_full_update is not instructed
438  if (is_full_update)
439  {
440  // nodes_to_optimize: List of nodes to optimize. NULL -> all but the
441  // root
442  // node.
443  nodes_to_optimize = NULL;
444  }
445  else
446  {
447  nodes_to_optimize = new std::set<mrpt::graphs::TNodeID>;
448 
449  // I am certain that this shall not be called when nodeCount = 0, since
450  // the
451  // optimization procedure starts only after certain number of nodes has
452  // been added
453  this->getNearbyNodesOf(
454  nodes_to_optimize, this->m_graph->nodeCount() - 1,
455  opt_params.optimization_distance);
456  nodes_to_optimize->insert(this->m_graph->nodeCount() - 1);
457  }
458 
460 
461  // Execute the optimization
463  *(this->m_graph), levmarq_info, nodes_to_optimize, opt_params.cfg,
464  &CLevMarqGSO<GRAPH_T>::levMarqFeedback); // functor feedback
465 
466  if (is_full_update)
467  {
468  m_just_fully_optimized_graph = true;
469  }
470  else
471  {
472  m_just_fully_optimized_graph = false;
473  }
474 
475  double elapsed_time = optimization_timer.Tac();
476  this->logFmt(
477  mrpt::system::LVL_DEBUG, "Optimization of graph took: %fs",
478  elapsed_time);
479 
480  // deleting the nodes_to_optimize set
481  delete nodes_to_optimize;
482  nodes_to_optimize = nullptr;
483 
484  this->m_time_logger.leave("CLevMarqGSO::_optimizeGraph");
485  MRPT_UNUSED_PARAM(elapsed_time);
486  MRPT_END;
487 } // end of _optimizeGraph
488 
489 template <class GRAPH_T>
491 {
492  MRPT_START;
493 
494  bool is_loop_closure = false;
495  auto curr_pair_nodes_to_edge = this->m_graph->edges;
496 
497  // find the *node pairs* that exist in current but not the last
498  // nodes_to_edge
499  // map If the distance of any of these pairs is greater than
500  // LC_min_nodeid_diff then consider this a loop closure
501  typename GRAPH_T::edges_map_t::const_iterator search;
502  mrpt::graphs::TPairNodeIDs curr_pair;
503 
504  for (typename GRAPH_T::edges_map_t::const_iterator it =
505  curr_pair_nodes_to_edge.begin();
506  it != curr_pair_nodes_to_edge.end(); ++it)
507  {
508  search = opt_params.last_pair_nodes_to_edge.find(it->first);
509  // if current node pair is not found in the last set...
510  if (search == opt_params.last_pair_nodes_to_edge.end())
511  {
512  curr_pair = it->first;
513 
514  if (std::abs(
515  static_cast<int>(curr_pair.first) -
516  static_cast<int>(curr_pair.second)) >
517  opt_params.LC_min_nodeid_diff)
518  {
519  this->logFmt(
520  mrpt::system::LVL_DEBUG, "Registering loop closure... ");
521  is_loop_closure = true;
522  break; // no need for more iterations
523  }
524  }
525  }
526 
527  // update the pair_nodes_to_edge map
528  opt_params.last_pair_nodes_to_edge = curr_pair_nodes_to_edge;
529  return is_loop_closure;
530 
531  MRPT_END;
532 }
533 
534 template <class GRAPH_T>
536 {
537  bool is_full_update = false;
538 
539  if (opt_params.optimization_distance == -1)
540  { // always optimize fully
541  return true;
542  }
543 
544  bool added_lc = this->checkForLoopClosures();
545 
546  // Decide on the LoopClosingAttitude I am in
547  if (!added_lc)
548  { // reset both ignored and used counters
549  if (m_curr_used_consec_lcs != 0 || m_curr_ignored_consec_lcs != 0)
550  {
551  MRPT_LOG_DEBUG_STREAM("No new Loop Closure found.");
552  }
553 
554  m_curr_used_consec_lcs = 0;
555  m_curr_ignored_consec_lcs = 0;
556  m_optimization_policy = FOP_USE_LC;
557 
558  return is_full_update;
559  }
560  else
561  { // lc found.
562  // have I used enough consecutive loop closures?
563  bool use_limit_reached =
564  m_curr_used_consec_lcs == m_max_used_consec_lcs;
565  // have I ignored enough consecutive loop closures?
566  bool ignore_limit_reached =
567  m_curr_ignored_consec_lcs == m_max_ignored_consec_lcs;
568 
569  // Have I reached any of the limits above?
570  if (ignore_limit_reached || use_limit_reached)
571  {
572  m_curr_ignored_consec_lcs = 0;
573  m_curr_used_consec_lcs = 0;
574 
575  // decide of the my policy on full optimization
576  if (ignore_limit_reached)
577  {
578  m_optimization_policy = FOP_USE_LC;
579  }
580  if (use_limit_reached)
581  {
582  m_optimization_policy = FOP_IGNORE_LC;
583  }
584  }
585  else
586  { // no limits reached yet.
587  if (m_optimization_policy == FOP_USE_LC)
588  {
589  m_curr_used_consec_lcs += 1;
590  }
591  else
592  {
593  m_curr_ignored_consec_lcs += 1;
594  }
595  }
596  }
597 
598  // Decide on whether to fully optimize the graph based on the mode I am in
599  if (m_optimization_policy == FOP_IGNORE_LC)
600  {
601  is_full_update = false;
603  "*PARTIAL* graph optimization.. ignoring new loop closure");
604  }
605  else
606  {
607  is_full_update = true;
608  MRPT_LOG_WARN_STREAM("Commencing with *FULL* graph optimization... ");
609  }
610  return is_full_update;
611 
612 } // end of checkForFullOptimization
613 
614 template <class GRAPH_T>
616 {
617  return m_just_fully_optimized_graph;
618 }
619 
620 template <class GRAPH_T>
622  const GRAPH_T& graph, const size_t iter, const size_t max_iter,
623  const double cur_sq_error)
624 {
625 }
626 
627 template <class GRAPH_T>
629  std::set<mrpt::graphs::TNodeID>* nodes_set,
630  const mrpt::graphs::TNodeID& cur_nodeID, double distance)
631 {
632  MRPT_START;
633 
634  if (distance > 0)
635  {
636  // check all but the last node.
637  for (mrpt::graphs::TNodeID nodeID = 0;
638  nodeID < this->m_graph->nodeCount() - 1; ++nodeID)
639  {
640  double curr_distance = this->m_graph->nodes[nodeID].distanceTo(
641  this->m_graph->nodes[cur_nodeID]);
642  if (curr_distance <= distance)
643  {
644  nodes_set->insert(nodeID);
645  }
646  }
647  }
648  else
649  { // check against all nodes
650  this->m_graph->getAllNodes(*nodes_set);
651  }
652 
653  MRPT_END;
654 }
655 
656 template <class GRAPH_T>
658 {
659  parent::printParams();
660 
661  opt_params.dumpToConsole();
662  viz_params.dumpToConsole();
663 }
664 template <class GRAPH_T>
666 {
667  MRPT_START;
668  parent::loadParams(source_fname);
669 
670  opt_params.loadFromConfigFileName(source_fname, "OptimizerParameters");
671  viz_params.loadFromConfigFileName(source_fname, "VisualizationParameters");
672 
673  mrpt::config::CConfigFile source(source_fname);
674 
675  // TODO - check that these work
676  m_max_used_consec_lcs = source.read_int(
677  "OptimizerParameters", "max_used_consecutive_loop_closures", 2, false);
678 
679  m_max_ignored_consec_lcs = source.read_int(
680  "OptimizerParameters", "max_ignored_consecutive_loop_closures", 15,
681  false);
682 
683  // set the logging level if given by the user
684  // Minimum verbosity level of the logger
685  int min_verbosity_level =
686  source.read_int("OptimizerParameters", "class_verbosity", 1, false);
687  this->setMinLoggingLevel(mrpt::system::VerbosityLevel(min_verbosity_level));
688 
689  MRPT_LOG_DEBUG("Successfully loaded Params. ");
690  m_has_read_config = true;
691 
692  MRPT_END;
693 }
694 
695 template <class GRAPH_T>
697 {
698  MRPT_START;
699  using namespace std;
700 
701  const std::string report_sep(2, '\n');
702  const std::string header_sep(80, '#');
703 
704  // Report on graph
705  stringstream class_props_ss;
706  class_props_ss << "Levenberg Marquardt Optimization Summary: " << std::endl;
707  class_props_ss << header_sep << std::endl;
708 
709  // time and output logging
710  const std::string time_res = this->m_time_logger.getStatsAsText();
711  const std::string output_res = this->getLogAsString();
712 
713  // merge the individual reports
714  report_str->clear();
715  parent::getDescriptiveReport(report_str);
716 
717  *report_str += class_props_ss.str();
718  *report_str += report_sep;
719 
720  *report_str += time_res;
721  *report_str += report_sep;
722 
723  *report_str += output_res;
724  *report_str += report_sep;
725 
726  MRPT_END;
727 }
728 
729 // OptimizationParams
730 //////////////////////////////////////////////////////////////
731 template <class GRAPH_T>
733  : optimization_distance_color(0, 201, 87),
734  keystroke_optimization_distance("u"),
735  keystroke_optimize_graph("w")
736 {
737 }
738 template <class GRAPH_T>
740 {
741 }
742 template <class GRAPH_T>
744  std::ostream& out) const
745 {
746  MRPT_START;
747  out << "-----------[ Levenberg-Marquardt Optimization ] -------\n";
748  out << "Optimization on second thread = "
749  << (optimization_on_second_thread ? "TRUE" : "FALSE") << std::endl;
750  out << "Optimize nodes in distance = " << optimization_distance << "\n";
751  out << "Min. node difference for LC = " << LC_min_nodeid_diff << "\n";
752  out << cfg.getAsString() << std::endl;
753  MRPT_END;
754 }
755 template <class GRAPH_T>
757  const mrpt::config::CConfigFileBase& source, const std::string& section)
758 {
759  MRPT_START;
760  optimization_on_second_thread = source.read_bool(
761  section, "optimization_on_second_thread", false, false);
762  LC_min_nodeid_diff = source.read_int(
763  "GeneralConfiguration", "LC_min_nodeid_diff", 30, false);
764  optimization_distance =
765  source.read_double(section, "optimization_distance", 5, false);
766  // asert the previous value
768  optimization_distance == 1 || optimization_distance > 0,
769  format(
770  "Invalid value for optimization distance: %.2f",
771  optimization_distance));
772 
773  // optimization parameters
774  cfg["verbose"] = source.read_bool(section, "verbose", 0, false);
775  cfg["profiler"] = source.read_bool(section, "profiler", 0, false);
776  cfg["max_iterations"] =
777  source.read_double(section, "max_iterations", 100, false);
778  cfg["scale_hessian"] =
779  source.read_double("Optimization", "scale_hessian", 0.2, false);
780  cfg["tau"] = source.read_double(section, "tau", 1e-3, false);
781 
782  MRPT_END;
783 }
784 
785 // GraphVisualizationParams
786 //////////////////////////////////////////////////////////////
787 template <class GRAPH_T>
789  : keystroke_graph_toggle("s"), keystroke_graph_autofit("a")
790 {
791 }
792 template <class GRAPH_T>
794 {
795 }
796 template <class GRAPH_T>
798  std::ostream& out) const
799 {
800  MRPT_START;
801 
802  out << mrpt::format(
803  "-----------[ Graph Visualization Parameters ]-----------\n");
804  out << mrpt::format(
805  "Visualize optimized graph = %s\n",
806  visualize_optimized_graph ? "TRUE" : "FALSE");
807 
808  out << mrpt::format("%s", cfg.getAsString().c_str());
809 
810  std::cout << std::endl;
811 
812  MRPT_END;
813 }
814 template <class GRAPH_T>
816  const mrpt::config::CConfigFileBase& source, const std::string& section)
817 {
818  MRPT_START;
819 
820  visualize_optimized_graph =
821  source.read_bool(section, "visualize_optimized_graph", 1, false);
822 
823  cfg["show_ID_labels"] =
824  source.read_bool(section, "optimized_show_ID_labels", 0, false);
825  cfg["show_ground_grid"] =
826  source.read_double(section, "optimized_show_ground_grid", 1, false);
827  cfg["show_edges"] =
828  source.read_bool(section, "optimized_show_edges", 1, false);
829  cfg["edge_color"] =
830  source.read_int(section, "optimized_edge_color", 4286611456, false);
831  cfg["edge_width"] =
832  source.read_double(section, "optimized_edge_width", 1.5, false);
833  cfg["show_node_corners"] =
834  source.read_bool(section, "optimized_show_node_corners", 1, false);
835  cfg["show_edge_rel_poses"] =
836  source.read_bool(section, "optimized_show_edge_rel_poses", 1, false);
837  cfg["edge_rel_poses_color"] = source.read_int(
838  section, "optimized_edge_rel_poses_color", 1090486272, false);
839  cfg["nodes_edges_corner_scale"] = source.read_double(
840  section, "optimized_nodes_edges_corner_scale", 0.4, false);
841  cfg["nodes_corner_scale"] =
842  source.read_double(section, "optimized_nodes_corner_scale", 0.7, false);
843  cfg["nodes_point_size"] =
844  source.read_int(section, "optimized_nodes_point_size", 5, false);
845  cfg["nodes_point_color"] = source.read_int(
846  section, "optimized_nodes_point_color", 10526880, false);
847 
848  MRPT_END;
849 }
850 } // namespace mrpt
851 
852 #endif /* end of include guard: CLEVMARQGSO_IMPL_H */
853 
854 
void initGraphVisualization()
Initialize objects relateed to the Graph Visualization.
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
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 optimize_graph_spa_levmarq(GRAPH_T &graph, TResultInfoSpaLevMarq &out_info, const std::set< mrpt::graphs::TNodeID > *in_nodes_to_optimize=nullptr, const mrpt::system::TParametersDouble &extra_params=mrpt::system::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:76
#define MRPT_START
Definition: exceptions.h:262
bool checkForFullOptimization()
Decide whether to issue a full graph optimization.
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
void getNearbyNodesOf(std::set< mrpt::graphs::TNodeID > *nodes_set, const mrpt::graphs::TNodeID &cur_nodeID, double distance)
Get a list of the nodeIDs whose position is within a certain distance to the specified nodeID...
VerbosityLevel
Enumeration of available verbosity levels.
A grid of lines over the XY plane.
Definition: CGridPlaneXY.h:30
mrpt::opengl::CRenderizable::Ptr initOptDistanceVisualizationInternal(const mrpt::poses::CPose2D &p_unused)
Setup the corresponding Disk/Sphere instance.
void updateGraphVisualization()
Called internally for updating the visualization scene for the graph building procedure.
void toggleGraphVisualization()
Toggle the graph visualization on and off.
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:26
void optimizeGraph()
Wrapper around _optimizeGraph which first locks the section and then calls the _optimizeGraph method...
This class allows loading and storing values and vectors of different types from ".ini" files easily.
typename GRAPH_T::constraint_t::type_value pose_t
type of underlying poses (2D/3D)
Definition: CLevMarqGSO.h:128
A high-performance stopwatch, with typical resolution of nanoseconds.
STL namespace.
bool justFullyOptimizedGraph() const
Used by the caller to query for possible full graph optimization on the latest optimizer run...
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
#define MRPT_LOG_WARN_STREAM(__CONTENTS)
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.
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.
This class allows loading and storing values and vectors of different types from a configuration text...
void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
void loadParams(const std::string &source_fname)
Load the necessary for the decider/optimizer configuration parameters.
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 initializeLoggers(const std::string &name)
Initialize the COutputLogger, CTimeLogger instances given the name of the decider/optimizer at hand...
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
Use: MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);
GLsizei const GLchar ** string
Definition: glext.h:4101
bool checkForLoopClosures()
Check if a loop closure edge was added in the graph.
#define ASSERTDEBMSG_(f, __ERROR_MSG)
Definition: exceptions.h:208
void updateOptDistanceVisualization()
Update the position of the disk indicating the distance in which Levenberg-Marquardt graph optimizati...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:38
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Definition: exceptions.h:205
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
#define MRPT_END
Definition: exceptions.h:266
A RGB color - floats in the range [0,1].
Definition: TColor.h:77
Output information for mrpt::graphslam::optimize_graph_spa_levmarq()
void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
uint64_t TNodeID
A generic numeric type for unique IDs of nodes or entities.
Definition: TNodeID.h:16
std::pair< TNodeID, TNodeID > TPairNodeIDs
A pair of node IDs.
Definition: TNodeID.h:18
GLenum GLsizei GLenum format
Definition: glext.h:3531
Levenberg-Marquardt non-linear graph slam optimization scheme.
Definition: CLevMarqGSO.h:118
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
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...
GLfloat GLfloat p
Definition: glext.h:6305
void fitGraphInView()
Set the camera parameters of the CDisplayWindow3D so that the whole graph is viewed in the window...
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.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
Definition: geometry.cpp:1891
void updateVisuals()
Update the relevant visual features in CDisplayWindow.
void _optimizeGraph(bool is_full_update=false)
Optimize the given graph.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020