polygon_display.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
37 
38 namespace robot_nav_rviz_plugins
39 {
41 {
43  outline_color_property_ = new rviz::ColorProperty("Outline Color", QColor(36, 64, 142), "Color to draw the polygon.",
44  this, SLOT(queueRender()));
45 
46  filler_color_property_ = new rviz::ColorProperty("Fill Color", QColor(165, 188, 255), "Color to fill the polygon.",
47  this, SLOT(queueRender()));
48  filler_alpha_property_ = new rviz::FloatProperty("Alpha", 0.8, "Amount of transparency to apply to the filler.",
49  this, SLOT(queueRender()));
52 
53  zoffset_property_ = new rviz::FloatProperty("Z-Offset", 0.0, "Offset in the Z direction.", this, SLOT(queueRender()));
54 }
55 
57 {
58  if (outline_object_)
59  {
60  delete outline_object_;
61  }
62  if (filler_object_)
63  {
64  delete filler_object_;
65  }
66 }
67 
69 {
73 }
74 
76 {
80 }
81 
82 
84 {
86  {
88  }
89  else
90  {
92  }
93 
95  {
98  }
99  else
100  {
103  }
104  queueRender();
105 }
106 
107 
108 void PolygonDisplay::processMessage(const nav_2d_msgs::Polygon2DStamped::ConstPtr& msg)
109 {
110  if (!validateFloats(msg->polygon))
111  {
112  setStatus(rviz::StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)");
113  return;
114  }
115 
116  Ogre::Vector3 position;
117  Ogre::Quaternion orientation;
118  if (!context_->getFrameManager()->getTransform(msg->header, position, orientation))
119  {
120  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'",
121  msg->header.frame_id.c_str(), qPrintable(fixed_frame_));
122  }
123 
124  scene_node_->setPosition(position);
125  scene_node_->setOrientation(orientation);
126  bool empty = msg->polygon.points.empty();
127 
128  double z_offset = zoffset_property_->getFloat();
129 
131  if (mode_property_->shouldDrawOutlines() && !empty)
132  {
133  Ogre::ColourValue outline_color = rviz::qtToOgre(outline_color_property_->getColor());
134  outline_object_->setPolygon(msg->polygon, outline_color, z_offset);
135  }
136 
137  if (!mode_property_->shouldDrawFiller() || empty)
138  {
140  }
141  else
142  {
144  }
145 }
146 
147 } // namespace robot_nav_rviz_plugins
148 
149 
virtual QColor getColor() const
void setMin(float min)
void setPolygon(const nav_2d_msgs::Polygon2D &polygon, const Ogre::ColourValue &color, double z_offset)
Set the object to display the outline of the given polygon, in a specific color, possibly offset in z...
void setMax(float max)
DisplayContext * context_
Constructs a manual ogre object to display the polygon area as a triangle mesh.
Definition: polygon_parts.h:91
virtual float getFloat() const
Constructs a manual ogre object to display the polygon outline as a line strip.
Definition: polygon_parts.h:65
std_msgs::ColorRGBA getColor(rviz::ColorProperty *color_property, rviz::FloatProperty *alpha_property=nullptr)
Given a Color Property and an optional Float property, return a ROS Color message.
const std::string & getName() const
Ogre::SceneNode * scene_node_
Ogre::ColourValue qtToOgre(const QColor &c)
QString fixed_frame_
PolygonDisplayModeProperty * mode_property_
Several reusable pieces for displaying polygons.
void queueRender()
rviz::ColorProperty * filler_color_property_
virtual FrameManager * getFrameManager() const =0
void setPolygon(const nav_2d_msgs::Polygon2D &polygon, const std_msgs::ColorRGBA &color, double z_offset)
Set the object to display the area of the given polygon, in a specific color, possibly offset in z...
Ogre::SceneManager * scene_manager_
void processMessage(const nav_2d_msgs::Polygon2DStamped::ConstPtr &msg) override
rviz::FloatProperty * filler_alpha_property_
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Wrapper for EnumProperty + enum for whether to display the outline, area, or both.
Displays a nav_2d_msgs::Polygon2DStamped message in Rviz.
bool validateFloats(const nav_grid::NavGridInfo &info)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
rviz::ColorProperty * outline_color_property_
#define ROS_DEBUG(...)


robot_nav_rviz_plugins
Author(s):
autogenerated on Sun Jan 10 2021 04:08:58