visualization.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2016,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the institute nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Author: Christoph Rösmann
37  *********************************************************************/
38 
40 #include <boost/utility.hpp>
41 
42 
43 namespace teb_local_planner
44 {
45 
46 
47 template <typename GraphType>
48 void TebVisualization::publishGraph(const GraphType& graph, const std::string& ns_prefix)
49 {
51  return;
52 
53  typedef typename boost::graph_traits<GraphType>::vertex_iterator GraphVertexIterator;
54  typedef typename boost::graph_traits<GraphType>::edge_iterator GraphEdgeIterator;
55 
56  // Visualize Edges
57  visualization_msgs::Marker marker;
58  marker.header.frame_id = cfg_->map_frame;
59  marker.header.stamp = ros::Time::now();
60  marker.ns = ns_prefix + "Edges";
61  marker.id = 0;
62 // #define TRIANGLE
63 #ifdef TRIANGLE
64  marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
65 #else
66  marker.type = visualization_msgs::Marker::LINE_LIST;
67 #endif
68  marker.action = visualization_msgs::Marker::ADD;
69 
70  GraphEdgeIterator it_edge, end_edges;
71  for (boost::tie(it_edge,end_edges) = boost::edges(graph); it_edge!=end_edges; ++it_edge)
72  {
73 #ifdef TRIANGLE
74  geometry_msgs::Point point_start1;
75  point_start1.x = graph[boost::source(*it_edge,graph)].pos[0]+0.05;
76  point_start1.y = graph[boost::source(*it_edge,graph)].pos[1]-0.05;
77  point_start1.z = 0;
78  marker.points.push_back(point_start1);
79  geometry_msgs::Point point_start2;
80  point_start2.x = graph[boost::source(*it_edge,graph)].pos[0]-0.05;
81  point_start2.y = graph[boost::source(*it_edge,graph)].pos[1]+0.05;
82  point_start2.z = 0;
83  marker.points.push_back(point_start2);
84 
85 #else
86  geometry_msgs::Point point_start;
87  point_start.x = graph[boost::source(*it_edge,graph)].pos[0];
88  point_start.y = graph[boost::source(*it_edge,graph)].pos[1];
89  point_start.z = 0;
90  marker.points.push_back(point_start);
91 #endif
92  geometry_msgs::Point point_end;
93  point_end.x = graph[boost::target(*it_edge,graph)].pos[0];
94  point_end.y = graph[boost::target(*it_edge,graph)].pos[1];
95  point_end.z = 0;
96  marker.points.push_back(point_end);
97 
98  // add color
99  std_msgs::ColorRGBA color;
100  color.a = 1.0;
101  color.r = 0;
102  color.g = 0;
103  color.b = 1;
104  marker.colors.push_back(color);
105  marker.colors.push_back(color);
106 #ifdef TRIANGLE
107  marker.colors.push_back(color);
108 #endif
109  }
110 
111 #ifdef TRIANGLE
112  marker.scale.x = 1;
113  marker.scale.y = 1;
114  marker.scale.z = 1;
115 #else
116  marker.scale.x = 0.01;
117 #endif
118  marker.color.a = 1.0;
119  marker.color.r = 0.0;
120  marker.color.g = 1.0;
121  marker.color.b = 0.0;
122 
123  // Now publish edge markers
124  teb_marker_pub_.publish( marker );
125 
126  // Visualize vertices
127  marker.header.frame_id = cfg_->map_frame;
128  marker.header.stamp = ros::Time::now();
129  marker.ns = ns_prefix + "Vertices";
130  marker.id = 0;
131  marker.type = visualization_msgs::Marker::POINTS;
132  marker.action = visualization_msgs::Marker::ADD;
133 
134  GraphVertexIterator it_vert, end_vert;
135  for (boost::tie(it_vert,end_vert) = boost::vertices(graph); it_vert!=end_vert; ++it_vert)
136  {
137  geometry_msgs::Point point;
138  point.x = graph[*it_vert].pos[0];
139  point.y = graph[*it_vert].pos[1];
140  point.z = 0;
141  marker.points.push_back(point);
142  // add color
143 
144  std_msgs::ColorRGBA color;
145  color.a = 1.0;
146  if (it_vert==end_vert-1)
147  {
148  color.r = 1;
149  color.g = 0;
150  color.b = 0;
151  }
152  else
153  {
154  color.r = 0;
155  color.g = 1;
156  color.b = 0;
157  }
158  marker.colors.push_back(color);
159  }
160  // set first color (start vertix) to blue
161  if (!marker.colors.empty())
162  {
163  marker.colors.front().b = 1;
164  marker.colors.front().g = 0;
165  }
166 
167  marker.scale.x = 0.1;
168  marker.scale.y = 0.1;
169  marker.color.a = 1.0;
170  marker.color.r = 0.0;
171  marker.color.g = 1.0;
172  marker.color.b = 0.0;
173 
174  // Now publish vertex markers
175  teb_marker_pub_.publish( marker );
176 }
177 
178 template <typename BidirIter>
179 void TebVisualization::publishPathContainer(BidirIter first, BidirIter last, const std::string& ns)
180 {
182  return;
183 
184  visualization_msgs::Marker marker;
185  marker.header.frame_id = cfg_->map_frame;
186  marker.header.stamp = ros::Time::now();
187  marker.ns = ns;
188  marker.id = 0;
189  marker.type = visualization_msgs::Marker::LINE_LIST;
190  marker.action = visualization_msgs::Marker::ADD;
191 
192  typedef typename std::iterator_traits<BidirIter>::value_type PathType; // Get type of the path (point container)
193 
194  // Iterate through path container
195  while(first != last)
196  {
197  // iterate single path points
198  typename PathType::const_iterator it_point, end_point;
199  for (it_point = first->begin(), end_point = boost::prior(first->end()); it_point != end_point; ++it_point)
200  {
201  geometry_msgs::Point point_start;
202  point_start.x = get_const_reference(*it_point).x();
203  point_start.y = get_const_reference(*it_point).y();
204  point_start.z = 0;
205  marker.points.push_back(point_start);
206 
207  geometry_msgs::Point point_end;
208  point_end.x = get_const_reference(*boost::next(it_point)).x();
209  point_end.y = get_const_reference(*boost::next(it_point)).y();
210  point_end.z = 0;
211  marker.points.push_back(point_end);
212  }
213  ++first;
214  }
215  marker.scale.x = 0.01;
216  marker.color.a = 1.0;
217  marker.color.r = 0.0;
218  marker.color.g = 1.0;
219  marker.color.b = 0.0;
220 
221  teb_marker_pub_.publish( marker );
222 }
223 
224 
225 } // namespace teb_local_planner
std::string map_frame
Global planning frame.
Definition: teb_config.h:66
const TebConfig * cfg_
Config class that stores and manages all related parameters.
void publish(const boost::shared_ptr< M > &message) const
void publishPathContainer(BidirIter first, BidirIter last, const std::string &ns="PathContainer")
Publish multiple 2D paths (each path given as a point sequence) from a container class.
const T & get_const_reference(const T *ptr)
Helper function that returns the const reference to a value defined by either its raw pointer type or...
Definition: misc.h:135
bool printErrorWhenNotInitialized() const
Small helper function that checks if initialize() has been called and prints an error message if not...
void publishGraph(const GraphType &graph, const std::string &ns_prefix="Graph")
Publish a boost::adjacency_list (boost&#39;s graph datatype) via markers.
ros::Publisher teb_marker_pub_
Publisher for visualization markers.
static Time now()


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Wed Jun 3 2020 04:03:08