polygon3d_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 
38 
39 namespace robot_nav_rviz_plugins
40 {
42 {
44  outline_color_property_ = new rviz::ColorProperty("Outline Color", QColor(36, 64, 142), "Color to draw the polygon.",
45  this, SLOT(queueRender()));
46 
47  filler_color_property_ = new rviz::ColorProperty("Fill Color", QColor(165, 188, 255), "Color to fill the polygon.",
48  this, SLOT(queueRender()));
49  filler_alpha_property_ = new rviz::FloatProperty("Alpha", 0.8, "Amount of transparency to apply to the filler.",
50  this, SLOT(queueRender()));
53 
54  zoffset_property_ = new rviz::FloatProperty("Z-Offset", 0.0, "Offset in the Z direction.", this, SLOT(queueRender()));
55 }
56 
58 {
59  if (outline_object_)
60  {
61  delete outline_object_;
62  }
63  if (filler_object_)
64  {
65  delete filler_object_;
66  }
67 }
68 
70 {
74 }
75 
77 {
81 }
82 
83 
85 {
87  {
89  }
90  else
91  {
93  }
94 
96  {
99  }
100  else
101  {
104  }
105  queueRender();
106 }
107 
108 
109 void Polygon3DDisplay::processMessage(const geometry_msgs::PolygonStamped::ConstPtr& msg)
110 {
111  nav_2d_msgs::Polygon2DStamped polygon2d = nav_2d_utils::polygon3Dto2D(*msg);
112 
113  if (!validateFloats(polygon2d.polygon))
114  {
115  setStatus(rviz::StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)");
116  return;
117  }
118 
119  Ogre::Vector3 position;
120  Ogre::Quaternion orientation;
121  if (!context_->getFrameManager()->getTransform(polygon2d.header, position, orientation))
122  {
123  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'",
124  polygon2d.header.frame_id.c_str(), qPrintable(fixed_frame_));
125  }
126 
127  scene_node_->setPosition(position);
128  scene_node_->setOrientation(orientation);
129  bool empty = polygon2d.polygon.points.empty();
130 
131  double z_offset = zoffset_property_->getFloat();
132 
134  if (mode_property_->shouldDrawOutlines() && !empty)
135  {
136  Ogre::ColourValue outline_color = rviz::qtToOgre(outline_color_property_->getColor());
137  outline_object_->setPolygon(polygon2d.polygon, outline_color, z_offset);
138  }
139 
140  if (!mode_property_->shouldDrawFiller() || empty)
141  {
143  }
144  else
145  {
147  }
148 }
149 
150 } // namespace robot_nav_rviz_plugins
151 
152 
robot_nav_rviz_plugins::Polygon3DDisplay
Displays a geometry_msgs::PolygonStamped message in Rviz.
Definition: polygon3d_display.h:53
rviz::ColorProperty::getColor
virtual QColor getColor() const
rviz::MessageFilterDisplay::reset
void reset() override
validate_floats.h
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::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::Polygon3DDisplay::mode_property_
PolygonDisplayModeProperty * mode_property_
Definition: polygon3d_display.h:73
polygon3d_display.h
nav_2d_utils::polygon3Dto2D
nav_2d_msgs::Polygon2D polygon3Dto2D(const geometry_msgs::Polygon &polygon_3d)
robot_nav_rviz_plugins::validateFloats
bool validateFloats(const nav_grid::NavGridInfo &info)
Definition: validate_floats.h:49
rviz::Property::show
void show()
robot_nav_rviz_plugins::Polygon3DDisplay::Polygon3DDisplay
Polygon3DDisplay()
Definition: polygon3d_display.cpp:41
rviz::FloatProperty::setMax
void setMax(float max)
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::Polygon3DDisplay::onInitialize
void onInitialize() override
Definition: polygon3d_display.cpp:69
robot_nav_rviz_plugins::Polygon3DDisplay::filler_color_property_
rviz::ColorProperty * filler_color_property_
Definition: polygon3d_display.h:76
robot_nav_rviz_plugins::PolygonMaterial::getName
const std::string & getName() const
Definition: polygon_parts.h:131
rviz::FloatProperty::setMin
void setMin(float min)
rviz::ColorProperty
rviz::Display
robot_nav_rviz_plugins::Polygon3DDisplay::reset
void reset() override
Definition: polygon3d_display.cpp:76
rviz::FloatProperty
rviz::Property::hide
void hide()
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
robot_nav_rviz_plugins::Polygon3DDisplay::outline_color_property_
rviz::ColorProperty * outline_color_property_
Definition: polygon3d_display.h:75
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_
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
robot_nav_rviz_plugins::Polygon3DDisplay::filler_object_
PolygonFill * filler_object_
Definition: polygon3d_display.h:70
robot_nav_rviz_plugins::Polygon3DDisplay::updateStyle
void updateStyle()
Definition: polygon3d_display.cpp:84
rviz::MessageFilterDisplay::onInitialize
void onInitialize() override
robot_nav_rviz_plugins::PolygonOutline::reset
void reset()
Definition: polygon_parts.cpp:67
robot_nav_rviz_plugins::Polygon3DDisplay::polygon_material_
PolygonMaterial polygon_material_
Definition: polygon3d_display.h:71
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
robot_nav_rviz_plugins::Polygon3DDisplay::processMessage
void processMessage(const geometry_msgs::PolygonStamped::ConstPtr &msg) override
Definition: polygon3d_display.cpp:109
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::Polygon3DDisplay::filler_alpha_property_
rviz::FloatProperty * filler_alpha_property_
Definition: polygon3d_display.h:77
conversions.h
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::PolygonOutline
Constructs a manual ogre object to display the polygon outline as a line strip.
Definition: polygon_parts.h:65
robot_nav_rviz_plugins::Polygon3DDisplay::zoffset_property_
rviz::FloatProperty * zoffset_property_
Definition: polygon3d_display.h:74
robot_nav_rviz_plugins::Polygon3DDisplay::outline_object_
PolygonOutline * outline_object_
Definition: polygon3d_display.h:69
robot_nav_rviz_plugins::Polygon3DDisplay::~Polygon3DDisplay
virtual ~Polygon3DDisplay()
Definition: polygon3d_display.cpp:57


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