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 
robot_nav_rviz_plugins::PolygonDisplay::~PolygonDisplay
virtual ~PolygonDisplay()
Definition: polygon_display.cpp:56
rviz::ColorProperty::getColor
virtual QColor getColor() const
polygon_display.h
rviz::MessageFilterDisplay::reset
void reset() override
validate_floats.h
robot_nav_rviz_plugins::PolygonDisplay::filler_color_property_
rviz::ColorProperty * filler_color_property_
Definition: polygon_display.h:76
rviz::qtToOgre
Ogre::ColourValue qtToOgre(const QColor &c)
robot_nav_rviz_plugins
Several reusable pieces for displaying polygons.
Definition: nav_grid_display.h:60
rviz::Display::queueRender
void queueRender()
robot_nav_rviz_plugins::PolygonDisplay::mode_property_
PolygonDisplayModeProperty * mode_property_
Definition: polygon_display.h:73
robot_nav_rviz_plugins::PolygonDisplay::zoffset_property_
rviz::FloatProperty * zoffset_property_
Definition: polygon_display.h:74
robot_nav_rviz_plugins::getColor
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.
Definition: polygon_parts.cpp:43
rviz::StatusProperty::Error
Error
robot_nav_rviz_plugins::PolygonDisplay::updateStyle
void updateStyle()
Definition: polygon_display.cpp:83
robot_nav_rviz_plugins::validateFloats
bool validateFloats(const nav_grid::NavGridInfo &info)
Definition: validate_floats.h:49
rviz::Property::show
void show()
rviz::FloatProperty::setMax
void setMax(float max)
robot_nav_rviz_plugins::PolygonDisplay::outline_color_property_
rviz::ColorProperty * outline_color_property_
Definition: polygon_display.h:75
robot_nav_rviz_plugins::PolygonDisplayModeProperty::shouldDrawFiller
bool shouldDrawFiller() const
Definition: polygon_parts.h:146
robot_nav_rviz_plugins::PolygonOutline::setPolygon
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...
Definition: polygon_parts.cpp:72
rviz::Display::fixed_frame_
QString fixed_frame_
robot_nav_rviz_plugins::PolygonMaterial::getName
const std::string & getName() const
Definition: polygon_parts.h:131
robot_nav_rviz_plugins::PolygonDisplay::reset
void reset() override
Definition: polygon_display.cpp:75
rviz::FloatProperty::setMin
void setMin(float min)
rviz::ColorProperty
rviz::Display
rviz::FloatProperty
rviz::Property::hide
void hide()
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FloatProperty::getFloat
virtual float getFloat() const
ROS_DEBUG
#define ROS_DEBUG(...)
robot_nav_rviz_plugins::PolygonDisplayModeProperty::shouldDrawOutlines
bool shouldDrawOutlines() const
Definition: polygon_parts.h:145
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
robot_nav_rviz_plugins::PolygonDisplay::filler_alpha_property_
rviz::FloatProperty * filler_alpha_property_
Definition: polygon_display.h:77
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
robot_nav_rviz_plugins::PolygonDisplay::onInitialize
void onInitialize() override
Definition: polygon_display.cpp:68
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
robot_nav_rviz_plugins::PolygonDisplay::PolygonDisplay
PolygonDisplay()
Definition: polygon_display.cpp:40
rviz::MessageFilterDisplay::onInitialize
void onInitialize() override
robot_nav_rviz_plugins::PolygonOutline::reset
void reset()
Definition: polygon_parts.cpp:67
rviz::FrameManager::getTransform
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
rviz::Display::context_
DisplayContext * context_
robot_nav_rviz_plugins::PolygonFill::reset
void reset()
Definition: polygon_parts.cpp:98
class_list_macros.hpp
robot_nav_rviz_plugins::PolygonFill::setPolygon
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.
Definition: polygon_parts.cpp:105
robot_nav_rviz_plugins::PolygonDisplay::filler_object_
PolygonFill * filler_object_
Definition: polygon_display.h:70
robot_nav_rviz_plugins::PolygonDisplay::outline_object_
PolygonOutline * outline_object_
Definition: polygon_display.h:69
robot_nav_rviz_plugins::PolygonFill
Constructs a manual ogre object to display the polygon area as a triangle mesh.
Definition: polygon_parts.h:91
robot_nav_rviz_plugins::PolygonDisplayModeProperty
Wrapper for EnumProperty + enum for whether to display the outline, area, or both.
Definition: polygon_parts.h:140
robot_nav_rviz_plugins::PolygonDisplay::processMessage
void processMessage(const nav_2d_msgs::Polygon2DStamped::ConstPtr &msg) override
Definition: polygon_display.cpp:108
robot_nav_rviz_plugins::PolygonOutline
Constructs a manual ogre object to display the polygon outline as a line strip.
Definition: polygon_parts.h:65
robot_nav_rviz_plugins::PolygonDisplay::polygon_material_
PolygonMaterial polygon_material_
Definition: polygon_display.h:71
robot_nav_rviz_plugins::PolygonDisplay
Displays a nav_2d_msgs::Polygon2DStamped message in Rviz.
Definition: polygon_display.h:53


robot_nav_rviz_plugins
Author(s):
autogenerated on Sun May 18 2025 02:47:50