asrVisualizer.cpp
Go to the documentation of this file.
1 
18 #include "asrVisualizer.h"
19 #include <Eigen/Geometry>
20 
21 namespace ASR
22 {
23 
24 asrVisualizer::asrVisualizer(int max_number_of_published_vis_msgs)
25 {
26  ros::NodeHandle n("~");
27  hypothesis3dPublisher = n.advertise<visualization_msgs::Marker>("hypothesis3d_markers", max_number_of_published_vis_msgs);
28  publisher = n.advertise<visualization_msgs::MarkerArray>("/recognizer_prediction_psm/visualization_marker_array", 1);
29 
30  if(!n.getParam("/recognizer_prediction_psm/marker_lifetime", marker_lifetime))
31  marker_lifetime = 20;
32 }
33 
37 void asrVisualizer::addPointToFoundBuffer(Eigen::Vector2f point)
38 {
39  mFoundBuffer.push_back(std::make_pair(point.x(), point.y()));
40 }
41 
45 void asrVisualizer::addPointToUnfoundBuffer(Eigen::Vector2f point)
46 {
47  mUnfoundBuffer.push_back(std::make_pair(point.x(), point.y()));
48 }
49 
56 void asrVisualizer::addAttributedPoints(std::vector<AttributedPoint> hypotheses, std::vector<AttributedPoint> found_poses)
57 {
58  for(AttributedPoint p : hypotheses)
59  {
60  geometry_msgs::Pose pose = p.pose;
61  mUnfoundBuffer.push_back(std::make_pair(pose.position.x, pose.position.y));
62  }
63 
64  for(AttributedPoint p : found_poses)
65  {
66  geometry_msgs::Pose pose = p.pose;
67  mFoundBuffer.push_back(std::make_pair(pose.position.x, pose.position.y));
68  }
69 }
70 
71 
83 void asrVisualizer::publishRVizMarker(std::vector<AttributedPoint> hypotheses, std::vector<AttributedPoint> found_poses,
84  const std::string target_frame, const int id)
85 {
86  float scale_hyp = 0.1f;
87  float scale_found = 0.2f;
88 
89  visualization_msgs::Marker sample3dList;
90  sample3dList.header.frame_id = target_frame;
91  sample3dList.header.stamp = ros::Time::now();
92  sample3dList.ns = "hypothesis";
93  sample3dList.action = visualization_msgs::Marker::ADD;
94  sample3dList.type = visualization_msgs::Marker::SPHERE_LIST;
95  sample3dList.lifetime = ros::Duration(1.0f);
96  sample3dList.id = id;
97 
98  sample3dList.scale.x = scale_hyp;
99  sample3dList.scale.y = scale_hyp;
100  sample3dList.scale.z = scale_hyp;
101  sample3dList.color.r = 1;
102  sample3dList.color.g = 0;
103  sample3dList.color.b = 0;
104  sample3dList.color.a = 1.0;
105 
106  for(AttributedPoint hyp : hypotheses)
107  {
108  sample3dList.points.push_back(hyp.pose.position);
109  }
110 
111  visualization_msgs::Marker found3dList;
112  found3dList.header.frame_id = target_frame;
113  found3dList.header.stamp = ros::Time::now();
114  found3dList.ns = "observed_objects";
115  found3dList.action = visualization_msgs::Marker::ADD;
116  found3dList.type = visualization_msgs::Marker::CUBE_LIST;
117  found3dList.lifetime = ros::Duration(1.0f);
118  found3dList.id = id + 1;
119 
120  found3dList.scale.x = scale_found;
121  found3dList.scale.y = scale_found;
122  found3dList.scale.z = scale_found;
123  found3dList.color.r = 0;
124  found3dList.color.g = 0;
125  found3dList.color.b = 1;
126  found3dList.color.a = 1.0;
127 
128  for(AttributedPoint p : found_poses)
129  {
130  found3dList.points.push_back(p.pose.position);
131  }
132 
133  if(!sample3dList.points.empty()) hypothesis3dPublisher.publish(sample3dList);
134  if(!found3dList.points.empty()) hypothesis3dPublisher.publish(found3dList);
135 }
136 
146 void asrVisualizer::initAnimatedPlot(const std::string& pPlotTitle,
147  const std::string& pXLabel, const std::string& pYLabel,
148  const std::pair<float, float>& pXRange, const std::pair<float, float>& pYRange,
149  const std::pair<float, float>& pDelta) {
150 
151  //Create a clean interface to gnuplot.
152  mGnuplotHandler.reset(new Gnuplot);
153 
154  //Empty buffers with data for gnuplot.
155  //mUnfoundBuffer.clear();
156  //mFoundBuffer.clear();
157 
158  //Set bar chart title
159  *(mGnuplotHandler) << "set title \"" << pPlotTitle << "\"\n";
160 
161  //Unit length in plot of both x and y axis are equal.
162  *(mGnuplotHandler) << "set size ratio -1\n";
163 
164  //Style for points
165  *(mGnuplotHandler) << "set border linewidth 0.5\n";
166  *(mGnuplotHandler) << "set pointsize .2\n";
167  *(mGnuplotHandler) << "set style line 1 lc rgb '#00008b' pt 5\n";
168  *(mGnuplotHandler) << "set style line 2 lc rgb '#00ced1' pt 7\n";
169 
170  //Set labels for axes
171  *(mGnuplotHandler) << "set xlabel \"" << pXLabel << "\"\n";
172  *(mGnuplotHandler) << "set ylabel \"" << pYLabel << "\"\n";
173 
174  //Set range in both x and y direction
175  *(mGnuplotHandler) << "set xrange [" << pXRange.second << ":" << pXRange.first << "]\n";
176  *(mGnuplotHandler) << "set yrange [" << pYRange.first << ":" << pYRange.second << "]\n";
177 
178  //Ask for a grid for highres ticks
179  *(mGnuplotHandler) << "set grid x2tics lc rgb \"#bbbbbb\"\n";
180  *(mGnuplotHandler) << "set grid y2tics lc rgb \"#bbbbbb\"\n";
181 
182  //Lowres ticks
183  *(mGnuplotHandler) << "set xtics " << pXRange.first << "," << pDelta.first * 4 << "," << pXRange.second <<"rotate\n";
184  *(mGnuplotHandler) << "set ytics " << pYRange.first << "," << pDelta.second * 4 << "," << pYRange.second <<"\n";
185 
186  //Highres tics
187  *(mGnuplotHandler) << "set x2tics " << pXRange.first << "," << pDelta.first << "," << pXRange.second <<" scale 0\n";
188  *(mGnuplotHandler) << "set y2tics " << pYRange.first << "," << pDelta.second << "," << pYRange.second <<" scale 0\n";
189 
190  //Highres ticks with labels please
191  *(mGnuplotHandler) << "set format y2 \"\"\n";
192  *(mGnuplotHandler) << "set format x2 \"\"\n";
193 }
194 
195 
201 {
203  //Prevent system from trying to send data to non-initialized gnuplot handler
204  if(!mGnuplotHandler)
205  throw std::runtime_error("Cannot show non-existing gnuplot visualization.");
206 
207  //*(mGnuplotHandler) << "set object 1 ellipse center 4.,2. size 2.,1.\n";
208 
209 
210  //Every data combination has in common it wants to be plotted.
211  *(mGnuplotHandler) << "plot ";
212 
213  //This should be later called in a loop with type and id as parameters
214  *(mGnuplotHandler) << "'-' with points ls 1 title \"Poses\"";
215  //This should be later called in a loop with type and id as parameters
216  *(mGnuplotHandler) << ", '-' with points ls 2 title \"Object Hypotheses\"";
217  //if(mVisitedViews.size() > 0) *(mGnuplotHandler) << ", '-' with linespoints ls 3 title \"Camera Movement\" ";
218 
219  //End of gnuplot instructions for defining how bars are to be plotted
220  *(mGnuplotHandler) << "\n";
221 
222  //Later I should call .send(mUnfoundBuffer), on the gnuplothandler handler it returns, as often as the number of objects that I search for.
223 
224  //Push bar chart data to gnuplot.
226  //if(mVisitedViews.size() > 0) mGnuplotHandler->send(mVisitedViews);
227  mGnuplotHandler->flush();
228 }
229 
230 
238 void asrVisualizer::generateMarkerArray(std::vector<AttributedPoint> hypotheses,
239  std::vector<AttributedPoint> found_poses)
240 
241 {
242  int i = 0;
243 /*
244  // Standart markers (points)
245  for (ASR::AttributedPoint p : hypotheses)
246  {
247  visualization_msgs::Marker marker;
248  marker.header.frame_id = "\map";
249  marker.type = marker.SPHERE;
250  marker.action = marker.ADD;
251  marker.id = i;
252  marker.lifetime = ros::Duration(marker_lifetime);
253  marker.ns = p.objectType;
254  marker.scale.x = 0.05;
255  marker.scale.y = 0.05;
256  marker.scale.z = 0.05;
257  marker.color.a = 0.7;
258  marker.color.r = 1.0;
259  marker.color.g = 1.0;
260  marker.color.b = 0.0;
261  if(p.objectType.compare("Cup") == 0)
262  {
263  marker.color.r = 0.0;
264  marker.color.g = 150/255.0;
265  marker.color.b = 130/255.0;
266  } else if(p.objectType.compare("CeylonTea") == 0)
267  {
268  marker.color.r = 252/255.0;
269  marker.color.g = 229/255.0;
270  marker.color.b = 0;
271  } else if(p.objectType.compare("PlateDeep") == 0)
272  {
273  marker.color.r = 140/255.0;
274  marker.color.g = 182/255.0;
275  marker.color.b = 60/255.0;
276  } else if(p.objectType.compare("Marker_1") == 0)
277  {
278  marker.color.r = 162/255.0;
279  marker.color.g = 34/255.0;
280  marker.color.b = 35/255.0;
281  }
282 
283  marker.pose.orientation.w = 1.0;
284  marker.pose.position.x = p.pose.position.x;
285  marker.pose.position.y = p.pose.position.y;
286  marker.pose.position.z = p.pose.position.z;
287  markerArray.markers.push_back(marker);
288  i = i+1;
289  }
290 */
291 
292  // 3D Markers
293  for (ASR::AttributedPoint p : hypotheses)
294  {
295  std::string object_path = "";
296 
297  if(p.objectType.compare("PlateDeep") == 0)
298  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/PlateDeep/object.dae";
299  else if(p.objectType.compare("Cup") == 0)
300  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/Cup/object.dae";
301  else if(p.objectType.compare("Smacks") == 0)
302  object_path = "package://asr_object_database/rsc/databases/textured_objects/Smacks/Smacks.dae";
303  else if(p.objectType.compare(("VitalisSchoko")) == 0)
304  object_path = "package://asr_object_database/rsc/databases/textured_objects/VitalisSchoko/VitalisSchoko.dae";
305  else if(p.objectType.compare("CeylonTea") == 0)
306  object_path = "package://asr_object_database/rsc/databases/textured_objects/CeylonTea/CeylonTea.dae";
307  else if(p.objectType.compare("Marker_1") == 0)
308  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/SpoonBig/object_rotated.dae";
309 
310  visualization_msgs::Marker marker;
311  marker.header.frame_id = "/map";
312  marker.type = visualization_msgs::Marker::MESH_RESOURCE;
313  marker.mesh_resource = object_path;
314  marker.mesh_use_embedded_materials = true;
315  marker.action = marker.ADD;
316  marker.id = i;
317  marker.lifetime = ros::Duration(marker_lifetime);
318  marker.ns = p.objectType;
319  marker.scale.x = 0.001;
320  marker.scale.y = 0.001;
321  marker.scale.z = 0.001;
322  marker.pose.orientation.w = p.pose.orientation.w;
323  marker.pose.orientation.x = p.pose.orientation.x;
324  marker.pose.orientation.y = p.pose.orientation.y;
325  marker.pose.orientation.z = p.pose.orientation.z;
326  marker.pose.position.x = p.pose.position.x;
327  marker.pose.position.y = p.pose.position.y;
328  marker.pose.position.z = p.pose.position.z;
329 
330  markerArray.markers.push_back(marker);
331  i = i+1;
332  }
333 
334  for (ASR::AttributedPoint p : found_poses)
335  {
336  std::string object_path = "";
337 
338  if(p.objectType.compare("PlateDeep") == 0)
339  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/PlateDeep/object.dae";
340  else if(p.objectType.compare("Cup") == 0)
341  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/Cup/object.dae";
342  else if(p.objectType.compare("Smacks") == 0)
343  object_path = "package://asr_object_database/rsc/databases/textured_objects/Smacks/Smacks.dae";
344  else if(p.objectType.compare(("VitalisSchoko")) == 0)
345  object_path = "package://asr_object_database/rsc/databases/textured_objects/VitalisSchoko/VitalisSchoko.dae";
346  else if(p.objectType.compare("CeylonTea") == 0)
347  object_path = "package://asr_object_database/rsc/databases/textured_objects/CeylonTea/CeylonTea.dae";
348  else if(p.objectType.compare("Marker_1") == 0)
349  object_path = "package://asr_object_database/rsc/databases/segmentable_objects/SpoonBig/object_rotated.dae";
350 
351  visualization_msgs::Marker marker;
352  marker.header.frame_id = "/map";
353  marker.type = visualization_msgs::Marker::MESH_RESOURCE;
354  marker.mesh_resource = object_path;
355  marker.mesh_use_embedded_materials = true;
356  marker.action = marker.ADD;
357  marker.id = i;
358  marker.lifetime = ros::Duration(marker_lifetime);
359  marker.ns = p.objectType;
360  marker.scale.x = 0.001;
361  marker.scale.y = 0.001;
362  marker.scale.z = 0.001;
363  marker.pose.orientation.w = p.pose.orientation.w;
364  marker.pose.orientation.x = p.pose.orientation.x;
365  marker.pose.orientation.y = p.pose.orientation.y;
366  marker.pose.orientation.z = p.pose.orientation.z;
367  marker.pose.position.x = p.pose.position.x;
368  marker.pose.position.y = p.pose.position.y;
369  marker.pose.position.z = p.pose.position.z;
370 
371  markerArray.markers.push_back(marker);
372  i = i+1;
373  }
374 }
375 
383 {
384  if(!markerArray.markers.empty()) publisher.publish(markerArray);
385 }
386 
387 }
asrVisualizer(int max_number_of_published_vis_msgs=100)
void publish(const boost::shared_ptr< M > &message) const
f
std::vector< std::pair< double, double > > mUnfoundBuffer
void addPointToFoundBuffer(float x, float y)
Definition: asrVisualizer.h:68
ros::Publisher publisher
void addPointToUnfoundBuffer(Eigen::Vector2f point)
void generateMarkerArray(std::vector< AttributedPoint > hypotheses, std::vector< AttributedPoint > found_poses)
asrVisualizer::generateMarkerArray generates a MarkerArray for RViz visualization ...
ros::Publisher hypothesis3dPublisher
visualization_msgs::MarkerArray markerArray
void addAttributedPoints(std::vector< AttributedPoint > hypotheses, std::vector< AttributedPoint > found_poses)
void publishRVizMarker(std::vector< AttributedPoint > hypotheses, std::vector< AttributedPoint > found_poses, const std::string target_frame="/map", const int id=1)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void initAnimatedPlot(const std::string &pPlotTitle, const std::string &pXLabel, const std::string &pYLabel, const std::pair< float, float > &pXRange, const std::pair< float, float > &pYRange, const std::pair< float, float > &pDelta)
bool getParam(const std::string &key, std::string &s) const
static Time now()
std::vector< std::pair< double, double > > mFoundBuffer
#define ROS_ASSERT(cond)
void publishMarkerArray()
asrVisualizer::publishMarkerArray publishs the MarkerArray
boost::shared_ptr< Gnuplot > mGnuplotHandler


asr_recognizer_prediction_psm
Author(s): Braun Kai, Meißner Pascal
autogenerated on Wed Feb 19 2020 03:31:28