rapid
A ROS robotics library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
markers.h
Go to the documentation of this file.
1 #ifndef _RAPID_VIZ_MARKERS_H_
2 #define _RAPID_VIZ_MARKERS_H_
3 
4 #include <string>
5 #include <vector>
6 
7 #include "geometry_msgs/Point.h"
8 #include "geometry_msgs/PoseStamped.h"
9 #include "geometry_msgs/Vector3.h"
10 #include "std_msgs/ColorRGBA.h"
11 #include "visualization_msgs/Marker.h"
12 #include "ros/ros.h"
13 
14 #include "rapid_ros/publisher.h"
15 
16 namespace rapid {
17 namespace viz {
18 visualization_msgs::Marker OutlineBox(const geometry_msgs::PoseStamped& pose,
19  const geometry_msgs::Vector3& scale);
20 
22 
23 // A resource-managing marker that deletes itself from rviz when the object goes
24 // out of scope or is destroyed.
25 //
26 // Usage:
27 // Marker m = Marker::Box(marker_pub, pose, scale);
28 // m.SetId("object", 0);
29 // m.SetColor(1, 0, 0);
30 // m.Publish(); // Publishes the marker
31 // // When m goes out of scope, the rviz marker is deleted.
32 class Marker {
33  public:
34  ~Marker();
35 
36  // Custom copy constructor, generates a new random ID.
37  Marker(const Marker& rhs);
38  Marker& operator=(const Marker& rhs);
39 
40  // Create a box marker with the given pose and scale.
41  static Marker Box(const MarkerPub* pub,
42  const geometry_msgs::PoseStamped& pose,
43  const geometry_msgs::Vector3& scale);
44 
45  // Like a box marker, but only draws the edges of the box.
46  static Marker OutlineBox(const MarkerPub* pub,
47  const geometry_msgs::PoseStamped& pose,
48  const geometry_msgs::Vector3& scale);
49 
50  // Creates a mesh marker.
51  // uri is the URI-form used by the resource_retriever ROS package.
52  // E.g., package://pr2_description/meshes/base_v0/base.dae
53  // color is a color to use, if desired. Leave it as all zeros to use the
54  // mesh's color, or specify a non-zero value to override the mesh's color.
55  static Marker Mesh(const MarkerPub* pub, const geometry_msgs::PoseStamped& ps,
56  const std::string& uri);
57  static Marker Mesh(const MarkerPub* pub, const geometry_msgs::PoseStamped& ps,
58  const std::string& uri, const std_msgs::ColorRGBA& color);
59 
60  // Create a text marker with the given pose. The size is the size of a capital
61  // 'A,' in meters.
62  static Marker Text(const MarkerPub* pub,
63  const geometry_msgs::PoseStamped& pose,
64  const std::string& text, double size);
65 
66  // Create an arrow marker with origin at ps and direction vec. Both are
67  // expected to be in the frame of frame_id.
68  static Marker Vector(const MarkerPub* pub, const std::string& frame_id,
69  const geometry_msgs::Point& origin,
70  const geometry_msgs::Vector3& vector);
71 
72  // Null marker, for initialization purposes.
73  static Marker Null();
74 
75  // Publish the marker to the publisher that was passed in.
76  void Publish();
77  void Delete();
78 
79  // Set properties of the marker.
80  void SetColor(double r, double g, double b, double a = 0.9);
81  void SetFrame(const std::string& frame_id);
82  void SetNamespace(const std::string& ns);
83  void SetPoints(const std::vector<geometry_msgs::Point>& points);
84  void SetPose(const geometry_msgs::PoseStamped& ps);
85  void SetScale(const geometry_msgs::Vector3& scale);
86  void SetText(const std::string& text);
87  void SetType(uint8_t type);
88 
89  visualization_msgs::Marker marker() const; // Returns the marker.
90 
91  private:
92  explicit Marker(const MarkerPub* pub);
93  const MarkerPub* pub_;
94  visualization_msgs::Marker marker_;
95 };
96 } // namespace viz
97 } // namespace rapid
98 #endif // _RAPID_VIZ_MARKERS_H_
Marker(const Marker &rhs)
void SetFrame(const std::string &frame_id)
visualization_msgs::Marker marker() const
void SetText(const std::string &text)
void SetPose(const geometry_msgs::PoseStamped &ps)
visualization_msgs::Marker OutlineBox(const geometry_msgs::PoseStamped &pose, const geometry_msgs::Vector3 &scale)
static Marker Text(const MarkerPub *pub, const geometry_msgs::PoseStamped &pose, const std::string &text, double size)
void SetNamespace(const std::string &ns)
rapid_ros::PublisherInterface< visualization_msgs::Marker > MarkerPub
Definition: markers.h:21
static Marker Box(const MarkerPub *pub, const geometry_msgs::PoseStamped &pose, const geometry_msgs::Vector3 &scale)
void SetColor(double r, double g, double b, double a=0.9)
static Marker Null()
void SetType(uint8_t type)
static Marker OutlineBox(const MarkerPub *pub, const geometry_msgs::PoseStamped &pose, const geometry_msgs::Vector3 &scale)
Marker & operator=(const Marker &rhs)
void SetScale(const geometry_msgs::Vector3 &scale)
static Marker Vector(const MarkerPub *pub, const std::string &frame_id, const geometry_msgs::Point &origin, const geometry_msgs::Vector3 &vector)
static Marker Mesh(const MarkerPub *pub, const geometry_msgs::PoseStamped &ps, const std::string &uri)
void SetPoints(const std::vector< geometry_msgs::Point > &points)