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 #include <OgreBillboardSet.h>
34 
35 #include "rviz/display_context.h"
36 #include "rviz/frame_manager.h"
40 #include "rviz/validate_floats.h"
41 
42 #include "polygon_display.h"
43 
44 namespace rviz
45 {
46 
48 {
49  color_property_ = new ColorProperty( "Color", QColor( 25, 255, 0 ),
50  "Color to draw the polygon.", this, SLOT( queueRender() ));
51  alpha_property_ = new FloatProperty( "Alpha", 1.0,
52  "Amount of transparency to apply to the polygon.", this, SLOT( queueRender() ));
53  alpha_property_->setMin( 0 );
54  alpha_property_->setMax( 1 );
55 }
56 
58 {
59  if ( initialized() )
60  {
61  scene_manager_->destroyManualObject( manual_object_ );
62  }
63 }
64 
66 {
68 
69  manual_object_ = scene_manager_->createManualObject();
70  manual_object_->setDynamic( true );
71  scene_node_->attachObject( manual_object_ );
72 }
73 
75 {
77  manual_object_->clear();
78 }
79 
80 bool validateFloats( const geometry_msgs::PolygonStamped& msg )
81 {
82  return validateFloats(msg.polygon.points);
83 }
84 
85 void PolygonDisplay::processMessage(const geometry_msgs::PolygonStamped::ConstPtr& msg)
86 {
87  if( !validateFloats( *msg ))
88  {
89  setStatus( StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" );
90  return;
91  }
92 
93  Ogre::Vector3 position;
94  Ogre::Quaternion orientation;
95  if( !context_->getFrameManager()->getTransform( msg->header, position, orientation ))
96  {
97  ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'",
98  msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
99  }
100 
101  scene_node_->setPosition( position );
102  scene_node_->setOrientation( orientation );
103 
104  manual_object_->clear();
105 
106  Ogre::ColourValue color = qtToOgre( color_property_->getColor() );
107  color.a = alpha_property_->getFloat();
108  // TODO: this does not actually support alpha as-is. The
109  // "BaseWhiteNoLighting" material ends up ignoring the alpha
110  // component of the color values we set at each point. Need to make
111  // a material and do the whole setSceneBlending() rigamarole.
112 
113  uint32_t num_points = msg->polygon.points.size();
114  if( num_points > 0 )
115  {
116  manual_object_->estimateVertexCount( num_points );
117  manual_object_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP );
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 
virtual QColor getColor() const
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:256
FloatProperty * alpha_property_
virtual float getFloat() const
Displays a geometry_msgs::PolygonStamped message.
virtual void onInitialize()
Overridden from MessageFilterDisplay.
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:264
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:87
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:281
bool validateFloats(const sensor_msgs::CameraInfo &msg)
void queueRender()
Convenience function which calls context_->queueRender().
Definition: display.cpp:99
virtual void reset()
Overridden from MessageFilterDisplay.
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
Ogre::ManualObject * manual_object_
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:261
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_
virtual void processMessage(const geometry_msgs::PolygonStamped::ConstPtr &msg)
Overridden from MessageFilterDisplay.
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:247
#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:186
#define ROS_DEBUG(...)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42