MRPT  2.0.0
CEdgeCounter.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 
14 #include "CWindowManager.h"
15 
16 #include <map>
17 #include <string>
18 
20 {
21 /**\brief Generic class for tracking the total number of edges for different
22  * tpes of edges and for storing visualization-related information for each
23  * type
24  *
25  * \ingroup mrpt_graphslam_grp
26  */
28 {
29  public:
30  using iterator = std::map<std::string, int>::iterator;
31  using const_iterator = std::map<std::string, int>::const_iterator;
32 
33  CEdgeCounter();
34  ~CEdgeCounter() = default;
35  /**\brief Provide the instance with a CWindowManager.
36  */
38  /**\brief State how many of the existing edges have been removed.
39  *
40  * Method is to be called after CNetworkOfPoses::collapseDuplicatedEdges
41  * method has been executed.
42  */
43  void setRemovedEdges(int removed_edges);
44  /**\brief Method for manually setting the number of loop closures
45  * registered so far.
46  */
47  void setLoopClosureEdgesManually(int num_loop_closures);
48  /**\brief Returns the edges that form loop closures in the current graph.
49  */
50  int getLoopClosureEdges() const;
51  /**\brief Return the total amount of registered edges.
52  * \sa getNumForEdgeType, getLoopClosureEdges
53  */
54  int getTotalNumOfEdges() const;
55  /**\brief Return the total amount of registered edges.
56  *
57  * \sa getNumForEdgeType, getLoopClosureEdges
58  */
59  void getTotalNumOfEdges(int* total_num_edges) const;
60  /**\brief Return the number of edges for the specified type.
61  *
62  * \exception std::exception If edge is not found
63  * \sa getTotalNumOfEdges
64  */
65  int getNumForEdgeType(const std::string& name) const;
66  /** Return the number of edges for the specified type.
67  *
68  * \exception std::exception If edge is not found
69  * \sa getTotalNumOfEdges
70  */
71  void getNumForEdgeType(const std::string& name, int* total_num);
72  /**\brief Set number of a specific edge type manually.
73  *
74  * Handy for not having to call addEdge multiple times in a row.
75  *
76  * \sa addEdge
77  */
78  void setEdgesManually(const std::string& name, int num_of_edges);
79  /**\brief Increment the number of edges for the specified type.
80  *
81  * \exception std::exception If edge exists and \b is_new is True
82  *
83  * \sa setEdgesManually
84  */
85  void addEdge(
86  const std::string& name, bool is_loop_closure = false,
87  bool is_new = false);
88  /**\brief Explicitly register a new edge type.
89  */
90  void addEdgeType(const std::string& name);
91  /**\brief Reset the state of the CEdgeCounter instance.
92  */
93  void clearAllEdges();
94  /**\brief Dump a report of the registered, so far, edges to the console.
95  *
96  * \sa getAsString
97  */
98  void dumpToConsole() const;
99  /**\brief Fill the provided string with a detailed report of the
100  * registered, so far, edges.
101  */
102  void getAsString(std::string* str_out) const;
103  /**\brief Return a detailed report of the registered, so far, edges in a
104  * string representation.
105  */
106  std::string getAsString() const;
107 
108  // VISUALIZATION RELATED METHODS
109  // ////////////////////////////
110 
111  /**\brief Add the textMessage parameters to the object
112  * All the names in the given std::maps have to be already
113  * specified and added in the object via addEdge with is_new=true or
114  * addEdgeType
115  *
116  * \exception std::exception If a name in the provided std::map doesn't
117  * already exist
118  */
120  const std::map<std::string, double>& name_to_offset_y,
121  const std::map<std::string, int>& name_to_text_index);
122 
123  /**\brief Handle the extra visualization parameters for the total number of
124  * edges and for loop closures and then passes execution to the other
125  * setTextMessageParams function.
126  */
128  const std::map<std::string, double>& name_to_offset_y,
129  const std::map<std::string, int>& name_to_text_index,
130  double offset_y_total_edges, int text_index_total_edges,
131  double offset_y_loop_closures, int text_index_loop_closures);
132 
133  /**\brief Instance Iterators */
134  inline iterator begin() { return m_name_to_edges_num.begin(); }
135  inline const_iterator cbegin() const
136  {
137  return m_name_to_edges_num.cbegin();
138  }
139  inline iterator end() { return m_name_to_edges_num.end(); }
140  inline const_iterator cend() const { return m_name_to_edges_num.cend(); }
141 
142  private:
143  /**\brief Update the given CDisplayWindow3D with the edges registered so
144  * far.
145  */
146  void updateTextMessages() const;
147 
150 
151  /**\brief Map edge name <=> num of edges
152  *
153  * Tracking number of edges
154  */
155  std::map<std::string, int> m_name_to_edges_num;
157  int m_unique_edges = 0;
158 
159  // visualization std::maps
160  std::map<std::string, double> m_name_to_offset_y;
161  std::map<std::string, int> m_name_to_text_index;
162 
164 
165  // specifics to loop closures, total edges
166  bool m_display_total_edges = false;
172 };
173 } // namespace mrpt::graphslam::detail
int getNumForEdgeType(const std::string &name) const
Return the number of edges for the specified type.
void addEdgeType(const std::string &name)
Explicitly register a new edge type.
iterator begin()
Instance Iterators.
Definition: CEdgeCounter.h:134
mrpt::gui::CDisplayWindow3D * m_win
Definition: CEdgeCounter.h:148
std::map< std::string, int >::const_iterator const_iterator
Definition: CEdgeCounter.h:31
std::map< std::string, double > m_name_to_offset_y
Definition: CEdgeCounter.h:160
mrpt::graphslam::CWindowManager * m_win_manager
Definition: CEdgeCounter.h:149
void setLoopClosureEdgesManually(int num_loop_closures)
Method for manually setting the number of loop closures registered so far.
int getLoopClosureEdges() const
Returns the edges that form loop closures in the current graph.
void setRemovedEdges(int removed_edges)
State how many of the existing edges have been removed.
void setWindowManagerPtr(mrpt::graphslam::CWindowManager *win_manager)
Provide the instance with a CWindowManager.
Generic class for tracking the total number of edges for different tpes of edges and for storing visu...
Definition: CEdgeCounter.h:27
int getTotalNumOfEdges() const
Return the total amount of registered edges.
void clearAllEdges()
Reset the state of the CEdgeCounter instance.
std::map< std::string, int > m_name_to_edges_num
Map edge name <=> num of edges.
Definition: CEdgeCounter.h:155
std::map< std::string, int > m_name_to_text_index
Definition: CEdgeCounter.h:161
void dumpToConsole() const
Dump a report of the registered, so far, edges to the console.
void setTextMessageParams(const std::map< std::string, double > &name_to_offset_y, const std::map< std::string, int > &name_to_text_index)
Add the textMessage parameters to the object All the names in the given std::maps have to be already ...
void setEdgesManually(const std::string &name, int num_of_edges)
Set number of a specific edge type manually.
void updateTextMessages() const
Update the given CDisplayWindow3D with the edges registered so far.
std::string getAsString() const
Return a detailed report of the registered, so far, edges in a string representation.
void addEdge(const std::string &name, bool is_loop_closure=false, bool is_new=false)
Increment the number of edges for the specified type.
std::map< std::string, int >::iterator iterator
Definition: CEdgeCounter.h:30
Internal auxiliary classes.
Definition: levmarq_impl.h:19
Class acts as a container for storing pointers to mrpt::gui::CDisplayWindow3D, mrpt::graphslam::CWind...
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020