rviz_markers.hpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #ifndef _RVIZ_MARKERS_HPP_
33 #define _RVIZ_MARKERS_HPP_
34 
36 
39 template <class T>
40 std::string to_string (const T& t)
41 {
42  std::stringstream ss;
43  ss << t;
44  return ss.str();
45 };
47 
48 template <class T>
49 visualization_msgs::Marker markers<T>::unmark(std::string frame_id, std::string ns, int id)
50 {
51  uint32_t shape = visualization_msgs::Marker::CUBE;
52  visualization_msgs::Marker marker;
53  marker.header.frame_id = frame_id;
54  marker.header.stamp = ros::Time::now();
55 
56  marker.pose.position.x = 100;
57  marker.pose.position.y = 100;
58  marker.pose.position.z = 100;
59  marker.pose.orientation.x = 0.0;
60  marker.pose.orientation.y = 0.0;
61  marker.pose.orientation.z = 0.0;
62  marker.pose.orientation.w = 1.0;
63 
64  marker.scale.x = 0.1;
65  marker.scale.y = 0.1;
66  marker.scale.z = 0.1;
67 
68  marker.color.r = 1.0f;
69  marker.color.g = 0.0f;
70  marker.color.b = 0.0f;
71  marker.color.a = 0.5;
72 
73  marker.ns = ns;
74  marker.id = id;
75  marker.type = shape;
76  marker.action = visualization_msgs::Marker::ADD;
77  marker.lifetime = ros::Duration();
78  return marker;
79 };
81 
82 template <class T>
83 visualization_msgs::Marker markers<T>::mark(typename PointCloud<T>::Ptr cloud_cluster, string ns ,int id, float r, float g, float b)
84 {
85  Eigen::Vector4f centroid;
86  Eigen::Vector4f min;
87  Eigen::Vector4f max;
88 
89  compute3DCentroid (*cloud_cluster, centroid);
90  getMinMax3D (*cloud_cluster, min, max);
91 
92  uint32_t shape = visualization_msgs::Marker::CUBE;
93  visualization_msgs::Marker marker;
94  marker.header.frame_id = cloud_cluster->header.frame_id;
95  marker.header.stamp = ros::Time::now();
96 
97  marker.ns = ns;
98  marker.id = id;
99  marker.type = shape;
100  marker.action = visualization_msgs::Marker::ADD;
101 
102  marker.pose.position.x = centroid[0];
103  marker.pose.position.y = centroid[1];
104  marker.pose.position.z = centroid[2];
105  marker.pose.orientation.x = 0.0;
106  marker.pose.orientation.y = 0.0;
107  marker.pose.orientation.z = 0.0;
108  marker.pose.orientation.w = 1.0;
109 
110  marker.scale.x = (max[0]-min[0]);
111  marker.scale.y = (max[1]-min[1]);
112  marker.scale.z = (max[2]-min[2]);
113 
114  if (marker.scale.x ==0)
115  marker.scale.x=0.1;
116 
117  if (marker.scale.y ==0)
118  marker.scale.y=0.1;
119 
120  if (marker.scale.z ==0)
121  marker.scale.z=0.1;
122 
123  marker.color.r = r;
124  marker.color.g = g;
125  marker.color.b = b;
126  marker.color.a = 0.3;
127 
128  marker.lifetime = ros::Duration();
129  // marker.lifetime = ros::Duration(0.5);
130  return marker;
131 };
133 
134 template<class T>
135 visualization_msgs::Marker markers<T>::mark_text(typename PointCloud<T>::Ptr cloud_cluster, string ns ,int id, float r, float g, float b)
136 {
137  Eigen::Vector4f centroid;
138  Eigen::Vector4f min;
139  Eigen::Vector4f max;
140 
141  compute3DCentroid (*cloud_cluster, centroid);
142  pcl::getMinMax3D (*cloud_cluster, min, max);
143 
144  uint32_t shape = visualization_msgs::Marker::TEXT_VIEW_FACING;
145  visualization_msgs::Marker marker;
146  marker.header.frame_id = cloud_cluster->header.frame_id;
147  marker.header.stamp = ros::Time::now();
148 
149  marker.ns = ns;
150  marker.id = id;
151  marker.type = shape;
152  marker.action = visualization_msgs::Marker::ADD;
153 
154  marker.pose.position.x = centroid[0];
155  marker.pose.position.y = centroid[1];
156  marker.pose.position.z = max[2]+0.2;
157 
158  marker.scale.z = 0.4;
159  marker.color.r = r;
160  marker.color.g = g;
161  marker.color.b = b;
162  marker.color.a = 1.0;
163 
164  // Setup the text to show
165  string text;
166  text = "Cluster" + to_string(id) + "\n X=" + to_string(round(centroid[0])) + ", Y=" + to_string(round(centroid[1])) + ", Z=" + to_string(round(centroid[2])) ;
167  marker.text=text;
168  marker.lifetime = ros::Duration();
169  return marker;
170 };
172 
173 #endif
visualization_msgs::Marker mark_text(typename PointCloud< T >::Ptr cloud_cluster, string ns, int id, float r, float g, float b)
function to create a marker with some text info about a pointcloud (cluster)
markers class main declaration
std::string to_string(const T &t)
convert numeric type to string This function should work for all numeric c++ types: int...
visualization_msgs::Marker unmark(std::string frame_id, std::string ns, int id)
function to estimate a marker arround the cluster to show on rviz This function will set a marker ver...
visualization_msgs::Marker mark(typename PointCloud< T >::Ptr cloud_cluster, string ns, int id, float r, float g, float b)
function to estimate a marker arround the cluster to show on rviz


pointcloud_segmentation
Author(s): Tiago Talhada
autogenerated on Mon Mar 2 2015 01:32:39