DebugHelper.cpp
Go to the documentation of this file.
1 
20 #include <boost/algorithm/string.hpp>
21 #include <boost/range/irange.hpp>
22 
24 
25 namespace next_best_view {
26 
28 
30  if (!instancePtr)
32  return instancePtr;
33 }
34 
36  mNodeHandle = ros::NodeHandle("/nbv");
37  this->setLevels();
38 }
39 
40 void DebugHelper::write(const char *text, DebugHelper::DebugLevel level)
41 {
42  if (this->checkLevel(level)) {
43  ROS_DEBUG("%s", text);
44  }
45 }
46 
47 void DebugHelper::write(const std::string& text, DebugLevel level) {
48  const char* cText = text.c_str();
49 
50  this->write(cText, level);
51 }
52 
53 void DebugHelper::write(const std::ostream& text, DebugLevel level) {
54  std::stringstream ss;
55  ss << text.rdbuf();
56  std::string s = ss.str();
57 
58  this->write(s, level);
59 }
60 
62 {
63  if (this->checkLevel(level)) {
64  ROS_DEBUG(" ");
65  ROS_DEBUG("%s", text);
66  ROS_DEBUG(" ");
67  }
68 }
69 
70 void DebugHelper::writeNoticeably(const std::string &text, DebugHelper::DebugLevel level)
71 {
72  const char* cText = text.c_str();
73 
74  this->writeNoticeably(cText, level);
75 }
76 
77 void DebugHelper::writeNoticeably(const std::ostream &text, DebugHelper::DebugLevel level)
78 {
79  std::stringstream ss;
80  ss << text.rdbuf();
81  std::string s = ss.str();
82 
83  this->writeNoticeably(s, level);
84 }
85 
86 unsigned int DebugHelper::getLevel()
87 {
88  return mLevels;
89 }
90 
92 {
93  if (mLevels == ALL)
94  return "ALL";
95  if (mLevels == NONE)
96  return "NONE";
97 
98  std::string level = "";
99 
100  if (mLevels & PARAMETERS)
101  level += "PARAMETERS";
102  if (mLevels & SERVICE_CALLS) {
103  addToString(level, "SERVICE_CALLS");
104  }
105  if (mLevels & VISUALIZATION) {
106  addToString(level, "VISUALIZATION");
107  }
108  if (mLevels & CALCULATION) {
109  addToString(level, "CALCULATION");
110  }
111  if (mLevels & RATING) {
112  addToString(level, "RATING");
113  }
114  if (mLevels & ROBOT_MODEL) {
115  addToString(level, "ROBOT_MODEL");
116  }
117  if (mLevels & MAP) {
118  addToString(level, "MAP");
119  }
120  if (mLevels & FILTER) {
121  addToString(level, "FILTER");
122  }
123  if (mLevels & IK_RATING) {
124  addToString(level, "IK_RATING");
125  }
126  if (mLevels & SPACE_SAMPLER) {
127  addToString(level, "SPACE_SAMPLER");
128  }
129  if (mLevels & HYPOTHESIS_UPDATER) {
130  addToString(level, "HYPOTHESIS_UPDATER");
131  }
132  if (mLevels & WORLD) {
133  addToString(level, "WORLD");
134  }
135  if (mLevels & VOXEL_GRID) {
136  addToString(level, "VOXEL_GRID");
137  }
138 
139  return level;
140 }
141 
143  return level & mLevels;
144 }
145 
147  std::string levels;
148  mNodeHandle.getParam("debugLevels", levels);
149  setLevels(levels);
150 }
151 
152 void DebugHelper::setLevels(std::string levelsStr) {
153  std::vector<std::string> levels;
154  boost::trim_if(levelsStr, boost::is_any_of("\"',[]{} "));
155  boost::split(levels, levelsStr, boost::is_any_of(", "), boost::token_compress_on);
156  // trim each split string and to uppercase
157  for (int i : boost::irange(0, (int) levels.size())) {
158  boost::trim_if(levels[i], boost::is_any_of("\"',[]{} "));
159  boost::to_upper(levels[i]);
160  }
161  mLevels = parseLevels(levels);
162 }
163 
164 int DebugHelper::parseLevels(std::vector<std::string> levels) {
165  if (levels.size() == 0)
166  return ALL;
167  if (levels.size() == 1) {
168  if (levels.at(0).compare("ALL") == 0)
169  return ALL;
170  if (levels.at(0).compare("NONE") == 0)
171  return NONE;
172  }
173 
174  int level = 0;
175  for (unsigned int i = 0; i < levels.size(); i++) {
176  if (levels.at(i).compare("PARAMETERS") == 0) {
177  level += PARAMETERS;
178  }
179  else if (levels.at(i).compare("SERVICE_CALLS") == 0) {
180  level += SERVICE_CALLS;
181  }
182  else if (levels.at(i).compare("VISUALIZATION") == 0) {
183  level += VISUALIZATION;
184  }
185  else if (levels.at(i).compare("CALCULATION") == 0) {
186  level += CALCULATION;
187  }
188  else if (levels.at(i).compare("RATING") == 0) {
189  level += RATING;
190  }
191  else if (levels.at(i).compare("ROBOT_MODEL") == 0) {
192  level += ROBOT_MODEL;
193  }
194  else if (levels.at(i).compare("MAP") == 0) {
195  level += MAP;
196  }
197  else if (levels.at(i).compare("FILTER") == 0) {
198  level += FILTER;
199  }
200  else if (levels.at(i).compare("IK_RATING") == 0) {
201  level += IK_RATING;
202  }
203  else if (levels.at(i).compare("SPACE_SAMPLER") == 0) {
204  level += SPACE_SAMPLER;
205  }
206  else if (levels.at(i).compare("HYPOTHESIS_UPDATER") == 0) {
207  level += HYPOTHESIS_UPDATER;
208  }
209  else if (levels.at(i).compare("WORLD") == 0) {
210  level += WORLD;
211  }
212  else if (levels.at(i).compare("VOXEL_GRID") == 0) {
213  level += VOXEL_GRID;
214  }
215  else {
216  ROS_ERROR_STREAM("Invalid debug level: " << levels.at(i));
217  throw "Invalid debug level";
218  }
219  }
220 
221  return level;
222 }
223 
224 void DebugHelper::addToString(std::string& s, const std::string& add)
225 {
226  if (s.size() != 0)
227  s += ", ";
228  s += add;
229 }
230 
231 }
ros::NodeHandle mNodeHandle
Definition: DebugHelper.hpp:60
std::string getLevelString()
returns the debug levels that are set as string
Definition: DebugHelper.cpp:91
XmlRpcServer s
void write(const char *text, DebugLevel level)
writes the text to the console if it has a level that allows it
Definition: DebugHelper.cpp:40
bool checkLevel(DebugLevel level)
checks whether the given level is allowed
this namespace contains all generally usable classes.
void writeNoticeably(const char *text, DebugLevel level)
writes the text noticeably to the console if it has a level that allows it
Definition: DebugHelper.cpp:61
static boost::shared_ptr< DebugHelper > getInstance()
Definition: DebugHelper.cpp:29
void setLevels()
sets the allowed debug levels
static void addToString(std::string &s, const std::string &add)
adds a string to a given string s. Puts a comma between them if the string s has a size bigger than 0...
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_STREAM(args)
static boost::shared_ptr< DebugHelper > instancePtr
Definition: DebugHelper.hpp:54
unsigned int getLevel()
returns the debug level that is set
Definition: DebugHelper.cpp:86
static int parseLevels(std::vector< std::string > levels)
parses the level list to the corresponding integer
#define ROS_DEBUG(...)


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18