mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
batch_visualizer.h
Go to the documentation of this file.
1 
6 #ifndef BATCH_VISUALIZER_H
7 #define BATCH_VISUALIZER_H
8 
9 #include <vector>
10 #include <ros/ros.h>
11 #include <visualization_msgs/MarkerArray.h>
13 #include <mrs_msgs/Path.h>
14 #include <mrs_msgs/TrajectoryReference.h>
15 #include <mrs_lib/visual_object.h>
16 #include <set>
17 
18 #define DEFAULT_ELLIPSE_POINTS 64
19 
20 namespace mrs_lib
21 {
22 
27 
28 public:
44  BatchVisualizer(ros::NodeHandle &nh, std::string marker_topic_name, std::string parent_frame);
45 
56  void addPoint(const Eigen::Vector3d &point, const double r = 0.0, const double g = 1.0, const double b = 0.3, const double a = 1.0,
57  const ros::Duration &timeout = ros::Duration(0));
58 
69  void addRay(const mrs_lib::geometry::Ray &ray, const double r = 1.0, const double g = 0.0, const double b = 0.0, const double a = 1.0,
70  const ros::Duration &timeout = ros::Duration(0));
71 
83  void addTriangle(const mrs_lib::geometry::Triangle &tri, const double r = 0.5, const double g = 0.5, const double b = 0.0, const double a = 1.0,
84  const bool filled = true, const ros::Duration &timeout = ros::Duration(0));
85 
97  void addRectangle(const mrs_lib::geometry::Rectangle &rect, const double r = 0.5, const double g = 0.5, const double b = 0.0, const double a = 1.0,
98  const bool filled = true, const ros::Duration &timeout = ros::Duration(0));
99 
111  void addCuboid(const mrs_lib::geometry::Cuboid &cuboid, const double r = 0.5, const double g = 0.5, const double b = 0.0, const double a = 1.0,
112  const bool filled = true, const ros::Duration &timeout = ros::Duration(0));
113 
126  void addEllipse(const mrs_lib::geometry::Ellipse &ellipse, const double r = 0.0, const double g = 1.0, const double b = 1.0, const double a = 1.0,
127  const bool filled = true, const int num_points = DEFAULT_ELLIPSE_POINTS, const ros::Duration &timeout = ros::Duration(0));
128 
142  void addCylinder(const mrs_lib::geometry::Cylinder &cylinder, const double r = 0.7, const double g = 0.8, const double b = 0.3, const double a = 1.0,
143  const bool filled = true, const bool capped = true, const int sides = DEFAULT_ELLIPSE_POINTS,
144  const ros::Duration &timeout = ros::Duration(0));
158  void addCone(const mrs_lib::geometry::Cone &cone, const double r = 0.7, const double g = 0.8, const double b = 0.3, const double a = 1.0,
159  const bool filled = true, const bool capped = true, const int sides = DEFAULT_ELLIPSE_POINTS, const ros::Duration &timeout = ros::Duration(0));
160 
172  void addPath(const mrs_msgs::Path &p, const double r = 0.3, const double g = 1.0, const double b = 0.3, const double a = 1.0, const bool filled = true,
173  const ros::Duration &timeout = ros::Duration(0));
174 
186  void addTrajectory(const mrs_msgs::TrajectoryReference &traj, const double r = 0.3, const double g = 1.0, const double b = 0.3, const double a = 1.0,
187  const bool filled = true, const ros::Duration &timeout = ros::Duration(0));
188 
192  void addNullPoint();
193 
197  void addNullLine();
198 
202  void addNullTriangle();
203 
209  void setPointsScale(const double scale);
210 
216  void setParentFrame(const std::string parent_frame);
217 
223  void setLinesScale(const double scale);
224 
228  void clearBuffers();
229 
233  void clearVisuals();
234 
238  void publish();
239 
240 private:
241  ros::Publisher visual_pub;
242  visualization_msgs::MarkerArray msg;
243 
244  std::string parent_frame; // coordinate frame id
245  std::string marker_topic_name;
246 
247  std::set<VisualObject> visual_objects; // buffer for objects to be visualized
248 
249  visualization_msgs::Marker points_marker;
250  visualization_msgs::Marker lines_marker;
251  visualization_msgs::Marker triangles_marker;
252 
253  bool initialized = false;
254  void initialize();
255 
256  double points_scale = 0.02;
257  double lines_scale = 0.04;
258 
259  unsigned long uuid = 0; // create unique ID for items in object buffer
260 };
261 
262 } // namespace mrs_lib
263 
264 #endif
mrs_lib::BatchVisualizer::publish
void publish()
publish the visual markers ROS message and populates it with buffer content
Definition: batch_visualizer.cpp:278
mrs_lib::BatchVisualizer::addEllipse
void addEllipse(const mrs_lib::geometry::Ellipse &ellipse, const double r=0.0, const double g=1.0, const double b=1.0, const double a=1.0, const bool filled=true, const int num_points=DEFAULT_ELLIPSE_POINTS, const ros::Duration &timeout=ros::Duration(0))
add an ellipse to the buffer
Definition: batch_visualizer.cpp:136
mrs_lib::BatchVisualizer::addPath
void addPath(const mrs_msgs::Path &p, const double r=0.3, const double g=1.0, const double b=0.3, const double a=1.0, const bool filled=true, const ros::Duration &timeout=ros::Duration(0))
add a path to the buffer
Definition: batch_visualizer.cpp:161
mrs_lib::BatchVisualizer::addNullTriangle
void addNullTriangle()
helper function for adding an invisible triangle to the buffer
Definition: batch_visualizer.cpp:219
mrs_lib::BatchVisualizer::addPoint
void addPoint(const Eigen::Vector3d &point, const double r=0.0, const double g=1.0, const double b=0.3, const double a=1.0, const ros::Duration &timeout=ros::Duration(0))
add a point to the buffer
Definition: batch_visualizer.cpp:93
mrs_lib::BatchVisualizer::~BatchVisualizer
~BatchVisualizer()
destructor
Definition: batch_visualizer.cpp:12
mrs_lib::BatchVisualizer::setLinesScale
void setLinesScale(const double scale)
set the thickness of all lines
Definition: batch_visualizer.cpp:254
mrs_lib::BatchVisualizer::clearBuffers
void clearBuffers()
remove all objects from the buffer
Definition: batch_visualizer.cpp:260
visual_object.h
Object abstraction for the Batch Visualizer.
mrs_lib::geometry::Ray
geometric representation of a ray. Instantiate it by two input Vector3. Use static methods for from-t...
Definition: shapes.h:26
mrs_lib::BatchVisualizer::clearVisuals
void clearVisuals()
publishes an empty message. Removes all objects drawn onto the scene, but keeps them in buffer
Definition: batch_visualizer.cpp:266
mrs_lib::geometry::Cuboid
geometric representation of a cuboid
Definition: shapes.h:319
mrs_lib::BatchVisualizer::setParentFrame
void setParentFrame(const std::string parent_frame)
set the parent frame_id
Definition: batch_visualizer.cpp:27
mrs_lib::BatchVisualizer::addCuboid
void addCuboid(const mrs_lib::geometry::Cuboid &cuboid, const double r=0.5, const double g=0.5, const double b=0.0, const double a=1.0, const bool filled=true, const ros::Duration &timeout=ros::Duration(0))
add a cuboid to the buffer
Definition: batch_visualizer.cpp:127
mrs_lib::BatchVisualizer::setPointsScale
void setPointsScale(const double scale)
set the scale of all points
Definition: batch_visualizer.cpp:248
mrs_lib::BatchVisualizer::addCylinder
void addCylinder(const mrs_lib::geometry::Cylinder &cylinder, const double r=0.7, const double g=0.8, const double b=0.3, const double a=1.0, const bool filled=true, const bool capped=true, const int sides=DEFAULT_ELLIPSE_POINTS, const ros::Duration &timeout=ros::Duration(0))
add a cylinder to the buffer
Definition: batch_visualizer.cpp:145
mrs_lib::BatchVisualizer::addCone
void addCone(const mrs_lib::geometry::Cone &cone, const double r=0.7, const double g=0.8, const double b=0.3, const double a=1.0, const bool filled=true, const bool capped=true, const int sides=DEFAULT_ELLIPSE_POINTS, const ros::Duration &timeout=ros::Duration(0))
add a cone to the buffer
Definition: batch_visualizer.cpp:153
mrs_lib::BatchVisualizer::addTriangle
void addTriangle(const mrs_lib::geometry::Triangle &tri, const double r=0.5, const double g=0.5, const double b=0.0, const double a=1.0, const bool filled=true, const ros::Duration &timeout=ros::Duration(0))
add a triangle to the buffer
Definition: batch_visualizer.cpp:109
mrs_lib::geometry::Ellipse
geometric representation of an ellipse
Definition: shapes.h:428
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
mrs_lib::BatchVisualizer::addNullPoint
void addNullPoint()
helper function for adding an invisible point to the object buffer
Definition: batch_visualizer.cpp:177
mrs_lib::geometry::Rectangle
geometric representation of a rectangle (can represent any quadrilateral)
Definition: shapes.h:189
shapes.h
Defines various geometrical shapes and their relations.
mrs_lib::BatchVisualizer::addRectangle
void addRectangle(const mrs_lib::geometry::Rectangle &rect, const double r=0.5, const double g=0.5, const double b=0.0, const double a=1.0, const bool filled=true, const ros::Duration &timeout=ros::Duration(0))
add a rectangle to the buffer
Definition: batch_visualizer.cpp:118
mrs_lib::BatchVisualizer::addRay
void addRay(const mrs_lib::geometry::Ray &ray, const double r=1.0, const double g=0.0, const double b=0.0, const double a=1.0, const ros::Duration &timeout=ros::Duration(0))
add a ray to the buffer
Definition: batch_visualizer.cpp:101
mrs_lib::geometry::Triangle
geometric representation of a triangle. Instantiate a new triangle by providing three vertices
Definition: shapes.h:100
mrs_lib::BatchVisualizer::addNullLine
void addNullLine()
helper function for adding an invisible line to the object buffer
Definition: batch_visualizer.cpp:195
mrs_lib::BatchVisualizer::BatchVisualizer
BatchVisualizer()
dummy constructor
Definition: batch_visualizer.cpp:9
mrs_lib::geometry::Cylinder
geometric representation of a cylinder
Definition: shapes.h:492
mrs_lib::geometry::Cone
geometric representaiton of a cone
Definition: shapes.h:575
mrs_lib::BatchVisualizer::addTrajectory
void addTrajectory(const mrs_msgs::TrajectoryReference &traj, const double r=0.3, const double g=1.0, const double b=0.3, const double a=1.0, const bool filled=true, const ros::Duration &timeout=ros::Duration(0))
add a trajectory to the buffer
Definition: batch_visualizer.cpp:169
mrs_lib::BatchVisualizer
library for drawing large amounts of geometric objects in RVIZ at the same time
Definition: batch_visualizer.h:26