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,
48  SLOT(queueRender()));
49  alpha_property_ = new FloatProperty("Alpha", 1.0, "Amount of transparency to apply to the polygon.",
50  this, SLOT(queueRender()));
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  for (uint32_t i = 0; i < num_points + 1; ++i)
118  {
119  const geometry_msgs::Point32& msg_point = msg->polygon.points[i % num_points];
120  manual_object_->position(msg_point.x, msg_point.y, msg_point.z);
121  manual_object_->colour(color);
122  }
123 
124  manual_object_->end();
125  }
126 }
127 
128 } // namespace rviz
129 
void setMin(float min)
void setMax(float max)
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
virtual QColor getColor() const
FloatProperty * alpha_property_
Displays a geometry_msgs::PolygonStamped message.
Property specialized to enforce floating point max/min.
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:83
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
bool validateFloats(const sensor_msgs::CameraInfo &msg)
void reset() override
Overridden from MessageFilterDisplay.
void queueRender()
Convenience function which calls context_->queueRender().
Definition: display.cpp:98
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
Ogre::ManualObject * manual_object_
void processMessage(const geometry_msgs::PolygonStamped::ConstPtr &msg) override
Overridden from MessageFilterDisplay.
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
void onInitialize() override
Overridden from MessageFilterDisplay.
virtual float getFloat() const
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.
ColorProperty * color_property_
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:175
#define ROS_DEBUG(...)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25