Main MRPT website > C++ reference for MRPT 1.5.7
CEdgeCounter.cpp
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 #include "graphslam-precomp.h" // Precompiled headers
12 
13 // implementation file of CEdgeCounter class
14 using namespace mrpt::graphslam::detail;
15 
16 
18  this->initCEdgeCounter();
19 
20 }
21 
23 
25 
26  this->clearAllEdges();
28 
29  // visualization parameters for total edges / loop closures
30  m_display_total_edges = false;
32 
35 
38 
39  m_unique_edges = 0;
40 
41  m_win = NULL;
42  m_win_manager = NULL;
43 
44 }
45 
47  mrpt::graphslam::CWindowManager* win_manager) {
48  MRPT_START;
49  ASSERT_(win_manager);
50  ASSERT_(win_manager->win);
51 
52  m_win_manager = win_manager;
54 
55  MRPT_END;
56 }
57 
58 void CEdgeCounter::setRemovedEdges(int removed_edges) {
59  m_unique_edges = this->getTotalNumOfEdges() - removed_edges;
60 }
61 
62 void CEdgeCounter::setLoopClosureEdgesManually(int num_loop_closures) {
63  m_num_loop_closures = num_loop_closures;
64 }
65 
67  return m_num_loop_closures;
68 }
69 
71  int sum;
72  this->getTotalNumOfEdges(&sum);
73 
74  return sum;
75 }
76 
77 void CEdgeCounter::getTotalNumOfEdges(int* total_num_edges) const {
78  ASSERT_(total_num_edges);
79  int sum = 0;
80 
82  m_name_to_edges_num.begin(); it != m_name_to_edges_num.end(); ++it) {
83  sum += it->second;
84  }
85  *total_num_edges = sum;
86 }
87 
91  if ( search != m_name_to_edges_num.end() ) {
92  return search->second;
93  }
94  else {
95  THROW_EXCEPTION("No edge with such name exists")
96  }
97 }
98 
99 void CEdgeCounter::getNumForEdgeType(const std::string& name, int* total_num) {
100 
103  if ( search != m_name_to_edges_num.end() ) {
104  *total_num = search->second;
105  }
106  else {
107  THROW_EXCEPTION("No edge with such name exists")
108  }
109 }
110 
111 void CEdgeCounter::setEdgesManually(const std::string& name, int num_of_edges) {
113  if ( search != m_name_to_edges_num.end() ) {
114  search->second = num_of_edges;
115  }
116  else {
117  std::string str_err = "No edge with such name exists.";
118  THROW_EXCEPTION(str_err)
119  }
120  // Update the visualization if the user has already set the vizualization
121  // parameters
123  this->updateTextMessages();
124  }
125 }
126 
128  bool is_loop_closure /* =false */,
129  bool is_new /* =false */) {
131  if ( search != m_name_to_edges_num.end() ) {
132  (search->second)++; // increment to the found element
133 
134  // specify warning if is_new = true
135  if (is_new) {
136  std::string str_err = mrpt::format(
137  "Specified edge type [%s] already exists but is_new is also specified!",
138  name.c_str());
139  THROW_EXCEPTION(str_err)
140  //std::stringstream ss_warn;
141  //ss_warn << "Commencing with the increment normally" << std::endl;
142  }
143  if (is_loop_closure) {
144  // throw if user has also specified the is new boolean flag
145  if (is_new) {
146  std::string str_err = "Both is_new and is_loop_closure flags are true. Exiting...";
147  THROW_EXCEPTION(str_err)
148  }
150  }
151  }
152  else {
153  if (is_new) {
155  }
156  else {
157  std::string str_err = "No edge with such name exists. Specify is_new parameter if you want to add it";
158  THROW_EXCEPTION(str_err)
159  }
160  }
161 
162  // Update the visualization if the user has already set the vizualization
163  // parameters
166  }
167 }
168 
172 
173  if ( search != m_name_to_edges_num.end() ) {
175  mrpt::format("Specified edge type [%s] already exists", name.c_str()))
176  }
177  else {
179  }
180 }
181 
184 
185  m_name_to_edges_num.clear();
186  m_name_to_offset_y.clear();
187  m_name_to_text_index.clear();
188 
190  m_display_total_edges = false;
191  m_display_loop_closures = false;
192 }
193 
195  std::string str(getAsString());
196  std::cout << str << std::endl;
197 }
198 
200  std::stringstream ss_out;
201  std::string sep(80, '#');
202  ss_out << "Summary of Edges: " << std::endl;
203  ss_out << sep << std::endl;
204 
205  ss_out << "\tTotal registered edges: "
206  << this->getTotalNumOfEdges() << std::endl;
207  ss_out << "\tUnique edges (after removal of multiple edges connecting the same nodes): "
208  << m_unique_edges << std::endl;
209 
211  m_name_to_edges_num.begin(); it != m_name_to_edges_num.end(); ++it) {
212  ss_out << "\t" << it->first << " edges: " << it->second << std::endl;
213  }
214  ss_out << "\tLoop closure edges: " << this->getLoopClosureEdges() << std::endl;
215 
216  // dump the contents to the provided string
217  *str_out = ss_out.str();
218 }
219 
221  std::string str;
222  this->getAsString(&str);
223  return str;
224 }
225 
226 // VISUALIZATION RELATED METHODS
227 // ////////////////////////////
228 
230  const std::map<std::string, double>& name_to_offset_y,
231  const std::map<std::string, int>& name_to_text_index) {
233  "Visualization of data was requested but no CWindowManager pointer was provided");
234  ASSERT_EQUAL_(name_to_offset_y.size(), name_to_text_index.size());
235 
237  name_to_offset_y.begin(); it != name_to_offset_y.end(); ++it) {
238  std::string name = it->first;
239 
240  // check if name already exist, otherwise throw exception
243  if ( search == m_name_to_edges_num.end() ) {
244  std::stringstream ss_err;
245  ss_err << "Name " << name << " is not recognized as an Edge type."
246  << std::endl;
247  THROW_EXCEPTION(ss_err.str())
248  }
249  // name exists ...
250 
251  double offset_y = it->second;
252  int text_index = name_to_text_index.find(name)->second;
253 
254  m_name_to_offset_y[name] = offset_y;
255  m_name_to_text_index[name] = text_index;
256 
257  }
258 
260 }
261 
263  const std::map<std::string, double>& name_to_offset_y,
264  const std::map<std::string, int>& name_to_text_index,
265  const double& offset_y_total_edges,
266  const int& text_index_total_edges,
267  const double& offset_y_loop_closures,
268  const int& text_index_loop_closures) {
269 
270  // set the parameters for total edges / loop closures
271  m_display_total_edges = true;
273 
274  m_offset_y_total_edges = offset_y_total_edges;
275  m_offset_y_loop_closures = offset_y_loop_closures;
276 
277  m_text_index_total_edges = text_index_total_edges;
278  m_text_index_loop_closures = text_index_loop_closures;
279 
280  // pass execution to the other setTextMessageParams
281  this->setTextMessageParams(name_to_offset_y, name_to_text_index);
282 
283 }
284 
289 
290  //Add text message for the total amount of edges
291  std::stringstream title;
292  title << "Total edges: " << this->getTotalNumOfEdges();
293  //if (m_unique_edges) {
294  //title << " |Unique: " << m_unique_edges << std::endl;
295  //}
298  title.str(),
299  mrpt::utils::TColorf(1.0, 1.0, 1.0),
300  /* unique_index = */ m_text_index_total_edges);
301  }
302 
303  // add a textMessage for every stored edge type
305  it != m_name_to_offset_y.end(); ++it) {
306 
307  std::string name = it->first;
308  double offset_y = it->second;
309  int text_index = m_name_to_text_index.find(name)->second;
310  int edges_num = m_name_to_edges_num.find(name)->second;
311 
312  std::stringstream title;
313  title << " " << name << ": " << edges_num << std::endl;
314  m_win_manager->addTextMessage(5,-offset_y,
315  title.str(),
316  mrpt::utils::TColorf(1.0, 1.0, 1.0),
317  /* unique_index = */ text_index);
318  }
319 
320 
321  // add text message for the loop closures
323  std::stringstream title;
324  title << " " << "Loop closures: " << m_num_loop_closures << std::endl;
326  title.str(),
327  mrpt::utils::TColorf(1.0, 1.0, 1.0),
328  /* unique_index = */ m_text_index_loop_closures);
329  }
330 
331  m_win->forceRepaint();
332 }
#define ASSERT_EQUAL_(__A, __B)
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.
#define THROW_EXCEPTION(msg)
Scalar * iterator
Definition: eigen_plugins.h:23
mrpt::gui::CDisplayWindow3D * m_win
Definition: CEdgeCounter.h:166
std::map< std::string, double > m_name_to_offset_y
Definition: CEdgeCounter.h:178
const Scalar * const_iterator
Definition: eigen_plugins.h:24
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...
mrpt::graphslam::CWindowManager * m_win_manager
Definition: CEdgeCounter.h:167
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.
mrpt::gui::CDisplayWindow3D * win
CDisplayWindow instance.
#define MRPT_END
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
int getTotalNumOfEdges() const
Return the total amount of registered edges.
GLsizei const GLchar ** string
Definition: glext.h:3919
void forceRepaint()
Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method...
void clearAllEdges()
Reset the state of the CEdgeCounter instance.
#define MRPT_START
std::map< std::string, int > m_name_to_edges_num
Map edge name <=> num of edges.
Definition: CEdgeCounter.h:173
std::map< std::string, int > m_name_to_text_index
Definition: CEdgeCounter.h:179
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 initCEdgeCounter()
Initialization method to be called from the various Constructors.
GLuint const GLchar * name
Definition: glext.h:3891
#define ASSERT_(f)
A RGB color - floats in the range [0,1].
Definition: TColor.h:80
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.
#define ASSERTMSG_(f, __ERROR_MSG)
Internal auxiliary classes.
Definition: levmarq_impl.h:23
Class acts as a container for storing pointers to mrpt::gui::CDisplayWindow3D, mrpt::graphslam::CWind...



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019