polygon_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreSceneNode.h>
31 #include <OgreSceneManager.h>
32 #include <OgreManualObject.h>
33 
34 #include <rviz/display_context.h>
35 #include <rviz/frame_manager.h>
39 #include <rviz/validate_floats.h>
40 
41 #include "polygon_display.h"
42 
43 namespace rviz
44 {
46 {
47  color_property_ = new ColorProperty("Color", QColor(25, 255, 0), "Color to draw the polygon.", this,
49  alpha_property_ = new FloatProperty("Alpha", 1.0, "Amount of transparency to apply to the polygon.",
53 }
54 
56 {
57  if (initialized())
58  {
59  scene_manager_->destroyManualObject(manual_object_);
60  }
61 }
62 
64 {
66 
67  manual_object_ = scene_manager_->createManualObject();
68  manual_object_->setDynamic(true);
69  scene_node_->attachObject(manual_object_);
70 }
71 
73 {
75  manual_object_->clear();
76 }
77 
78 bool validateFloats(const geometry_msgs::PolygonStamped& msg)
79 {
80  return validateFloats(msg.polygon.points);
81 }
82 
83 void PolygonDisplay::processMessage(const geometry_msgs::PolygonStamped::ConstPtr& msg)
84 {
85  if (!validateFloats(*msg))
86  {
88  "Message contained invalid floating point values (nans or infs)");
89  return;
90  }
91 
92  Ogre::Vector3 position;
93  Ogre::Quaternion orientation;
94  if (!context_->getFrameManager()->getTransform(msg->header, position, orientation))
95  {
96  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(),
97  qPrintable(fixed_frame_));
98  }
99 
100  scene_node_->setPosition(position);
101  scene_node_->setOrientation(orientation);
102 
103  manual_object_->clear();
104 
105  Ogre::ColourValue color = qtToOgre(color_property_->getColor());
106  color.a = alpha_property_->getFloat();
107  // TODO: this does not actually support alpha as-is. The
108  // "BaseWhiteNoLighting" material ends up ignoring the alpha
109  // component of the color values we set at each point. Need to make
110  // a material and do the whole setSceneBlending() rigamarole.
111 
112  uint32_t num_points = msg->polygon.points.size();
113  if (num_points > 0)
114  {
115  manual_object_->estimateVertexCount(num_points);
116  manual_object_->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP,
117  Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
118  for (uint32_t i = 0; i < num_points + 1; ++i)
119  {
120  const geometry_msgs::Point32& msg_point = msg->polygon.points[i % num_points];
121  manual_object_->position(msg_point.x, msg_point.y, msg_point.z);
122  manual_object_->colour(color);
123  }
124 
125  manual_object_->end();
126  }
127 }
128 
129 } // namespace rviz
130 
rviz::ColorProperty::getColor
virtual QColor getColor() const
Definition: color_property.h:79
polygon_display.h
rviz::PolygonDisplay::manual_object_
Ogre::ManualObject * manual_object_
Definition: polygon_display.h:69
rviz::MessageFilterDisplay< geometry_msgs::PolygonStamped >::reset
void reset() override
Definition: message_filter_display.h:125
validate_floats.h
rviz::qtToOgre
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:83
frame_manager.h
rviz::Display::queueRender
void queueRender()
Convenience function which calls context_->queueRender().
Definition: display.cpp:99
rviz::PolygonDisplay::onInitialize
void onInitialize() override
Overridden from MessageFilterDisplay.
Definition: polygon_display.cpp:63
rviz::Display::initialized
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
rviz::StatusProperty::Error
@ Error
Definition: status_property.h:46
rviz::PolygonDisplay
Displays a geometry_msgs::PolygonStamped message.
Definition: polygon_display.h:52
rviz::PolygonDisplay::color_property_
ColorProperty * color_property_
Definition: polygon_display.h:71
rviz::FloatProperty::setMax
void setMax(float max)
Definition: float_property.cpp:57
rviz::validateFloats
bool validateFloats(const sensor_msgs::CameraInfo &msg)
Definition: camera_display.cpp:72
float_property.h
rviz::Display::fixed_frame_
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
rviz::FloatProperty::setMin
void setMin(float min)
Definition: float_property.cpp:51
rviz::PolygonDisplay::PolygonDisplay
PolygonDisplay()
Definition: polygon_display.cpp:45
rviz::ColorProperty
Definition: color_property.h:40
rviz::Display
Definition: display.h:63
rviz::FloatProperty
Property specialized to enforce floating point max/min.
Definition: float_property.h:37
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:176
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FloatProperty::getFloat
virtual float getFloat() const
Definition: float_property.h:79
ROS_DEBUG
#define ROS_DEBUG(...)
rviz
Definition: add_display_dialog.cpp:54
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
color_property.h
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
rviz::PolygonDisplay::alpha_property_
FloatProperty * alpha_property_
Definition: polygon_display.h:72
rviz::PolygonDisplay::~PolygonDisplay
~PolygonDisplay() override
Definition: polygon_display.cpp:55
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::MessageFilterDisplay< geometry_msgs::PolygonStamped >::onInitialize
void onInitialize() override
Definition: message_filter_display.h:105
rviz::FrameManager::getTransform
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
Definition: frame_manager.h:125
rviz::Display::context_
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz....
Definition: display.h:287
class_list_macros.hpp
display_context.h
rviz::PolygonDisplay::processMessage
void processMessage(const geometry_msgs::PolygonStamped::ConstPtr &msg) override
Overridden from MessageFilterDisplay.
Definition: polygon_display.cpp:83
rviz::PolygonDisplay::reset
void reset() override
Overridden from MessageFilterDisplay.
Definition: polygon_display.cpp:72
parse_color.h


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02