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 
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_
Several reusable pieces for displaying polygons.
void queueRender()
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_
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
PolygonDisplayModeProperty * mode_property_
Wrapper for EnumProperty + enum for whether to display the outline, area, or both.
nav_2d_msgs::Polygon2D polygon3Dto2D(const geometry_msgs::Polygon &polygon_3d)
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)
void processMessage(const geometry_msgs::PolygonStamped::ConstPtr &msg) override
Displays a geometry_msgs::PolygonStamped message in Rviz.
#define ROS_DEBUG(...)


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