pose_with_covariance_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Ellon Paiva Mendes @ LAAS-CNRS
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 <OgreEntity.h>
31 #include <OgreSceneNode.h>
32 
33 #include "rviz/display_context.h"
34 #include "rviz/frame_manager.h"
36 #include "rviz/ogre_helpers/axes.h"
46 #include "rviz/validate_floats.h"
48 
50 #include "covariance_visual.h"
51 #include "covariance_property.h"
52 
53 #include <Eigen/Dense>
54 
55 namespace rviz
56 {
57 
59 {
60 public:
62  : SelectionHandler( context )
63  , display_( display )
64  {}
65 
66  void createProperties( const Picked& obj, Property* parent_property )
67  {
68  Property* cat = new Property( "Pose " + display_->getName(), QVariant(), "", parent_property );
69  properties_.push_back( cat );
70 
71  frame_property_ = new StringProperty( "Frame", "", "", cat );
73 
74  position_property_ = new VectorProperty( "Position", Ogre::Vector3::ZERO, "", cat );
76 
77  orientation_property_ = new QuaternionProperty( "Orientation", Ogre::Quaternion::IDENTITY, "", cat );
79 
80  covariance_position_property_ = new VectorProperty( "Covariance Position", Ogre::Vector3::ZERO, "", cat );
82 
83  covariance_orientation_property_ = new VectorProperty( "Covariance Orientation", Ogre::Vector3::ZERO, "", cat );
85  }
86 
87  void getAABBs( const Picked& obj, V_AABB& aabbs )
88  {
89  if( display_->pose_valid_ )
90  {
92  {
93  aabbs.push_back( display_->arrow_->getHead()->getEntity()->getWorldBoundingBox() );
94  aabbs.push_back( display_->arrow_->getShaft()->getEntity()->getWorldBoundingBox() );
95  }
96  else
97  {
98  aabbs.push_back( display_->axes_->getXShape()->getEntity()->getWorldBoundingBox() );
99  aabbs.push_back( display_->axes_->getYShape()->getEntity()->getWorldBoundingBox() );
100  aabbs.push_back( display_->axes_->getZShape()->getEntity()->getWorldBoundingBox() );
101  }
102 
104  {
106  {
107  aabbs.push_back( display_->covariance_->getPositionShape()->getEntity()->getWorldBoundingBox() );
108  }
110  {
111  aabbs.push_back( display_->covariance_->getOrientationShape(CovarianceVisual::kRoll)->getEntity()->getWorldBoundingBox() );
112  aabbs.push_back( display_->covariance_->getOrientationShape(CovarianceVisual::kPitch)->getEntity()->getWorldBoundingBox() );
113  aabbs.push_back( display_->covariance_->getOrientationShape(CovarianceVisual::kYaw)->getEntity()->getWorldBoundingBox() );
114  }
115  }
116  }
117  }
118 
119  void setMessage(const geometry_msgs::PoseWithCovarianceStampedConstPtr& message)
120  {
121  // properties_.size() should only be > 0 after createProperties()
122  // and before destroyProperties(), during which frame_property_,
123  // position_property_, and orientation_property_ should be valid
124  // pointers.
125  if( properties_.size() > 0 )
126  {
127  frame_property_->setStdString( message->header.frame_id );
128  position_property_->setVector( Ogre::Vector3( message->pose.pose.position.x,
129  message->pose.pose.position.y,
130  message->pose.pose.position.z ));
131  orientation_property_->setQuaternion( Ogre::Quaternion( message->pose.pose.orientation.w,
132  message->pose.pose.orientation.x,
133  message->pose.pose.orientation.y,
134  message->pose.pose.orientation.z ));
135  covariance_position_property_->setVector( Ogre::Vector3( message->pose.covariance[0+0*6],
136  message->pose.covariance[1+1*6],
137  message->pose.covariance[2+2*6] ));
138 
139  covariance_orientation_property_->setVector( Ogre::Vector3( message->pose.covariance[3+3*6],
140  message->pose.covariance[4+4*6],
141  message->pose.covariance[5+5*6] ));
142  }
143  }
144 
145 private:
152 
153 };
154 
156  : pose_valid_( false )
157 {
158  shape_property_ = new EnumProperty( "Shape", "Arrow", "Shape to display the pose as.",
159  this, SLOT( updateShapeChoice() ));
160  shape_property_->addOption( "Arrow", Arrow );
161  shape_property_->addOption( "Axes", Axes );
162 
163  color_property_ = new ColorProperty( "Color", QColor( 255, 25, 0 ), "Color to draw the arrow.",
164  this, SLOT( updateColorAndAlpha() ));
165 
166  alpha_property_ = new FloatProperty( "Alpha", 1, "Amount of transparency to apply to the arrow.",
167  this, SLOT( updateColorAndAlpha() ));
168  alpha_property_->setMin( 0 );
169  alpha_property_->setMax( 1 );
170 
171  shaft_length_property_ = new FloatProperty( "Shaft Length", 1, "Length of the arrow's shaft, in meters.",
172  this, SLOT( updateArrowGeometry() ));
173 
174  // aleeper: default changed from 0.1 to match change in arrow.cpp
175  shaft_radius_property_ = new FloatProperty( "Shaft Radius", 0.05, "Radius of the arrow's shaft, in meters.",
176  this, SLOT( updateArrowGeometry() ));
177 
178  head_length_property_ = new FloatProperty( "Head Length", 0.3, "Length of the arrow's head, in meters.",
179  this, SLOT( updateArrowGeometry() ));
180 
181  // aleeper: default changed from 0.2 to match change in arrow.cpp
182  head_radius_property_ = new FloatProperty( "Head Radius", 0.1, "Radius of the arrow's head, in meters.",
183  this, SLOT( updateArrowGeometry() ));
184 
185  axes_length_property_ = new FloatProperty( "Axes Length", 1, "Length of each axis, in meters.",
186  this, SLOT( updateAxisGeometry() ));
187 
188  axes_radius_property_ = new FloatProperty( "Axes Radius", 0.1, "Radius of each axis, in meters.",
189  this, SLOT( updateAxisGeometry() ));
190 
191  covariance_property_ = new CovarianceProperty( "Covariance", true, "Whether or not the covariances of the messages should be shown.",
192  this, SLOT( queueRender() ));
193 }
194 
196 {
198 
204  // Arrow points in -Z direction, so rotate the orientation before display.
205  // TODO: is it safe to change Arrow to point in +X direction?
206  arrow_->setOrientation( Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_Y ));
207 
211 
213 
216 
218  coll_handler_->addTrackedObjects( arrow_->getSceneNode() );
219  coll_handler_->addTrackedObjects( axes_->getSceneNode() );
220  coll_handler_->addTrackedObjects( covariance_->getPositionSceneNode() );
221  coll_handler_->addTrackedObjects( covariance_->getOrientationSceneNode() );
222 }
223 
225 {
226  if ( initialized() )
227  {
228  delete arrow_;
229  delete axes_;
230  }
231 }
232 
234 {
237 }
238 
240 {
241  Ogre::ColourValue color = color_property_->getOgreColor();
242  color.a = alpha_property_->getFloat();
243 
244  arrow_->setColor( color );
245 
247 }
248 
250 {
256 }
257 
259 {
263 }
264 
266 {
267  bool use_arrow = ( shape_property_->getOptionInt() == Arrow );
268 
269  color_property_->setHidden( !use_arrow );
270  alpha_property_->setHidden( !use_arrow );
271  shaft_length_property_->setHidden( !use_arrow );
272  shaft_radius_property_->setHidden( !use_arrow );
273  head_length_property_->setHidden( !use_arrow );
274  head_radius_property_->setHidden( !use_arrow );
275 
276  axes_length_property_->setHidden( use_arrow );
277  axes_radius_property_->setHidden( use_arrow );
278 
280 
282 }
283 
285 {
286  if( !pose_valid_ )
287  {
288  arrow_->getSceneNode()->setVisible( false );
289  axes_->getSceneNode()->setVisible( false );
290  covariance_->setVisible( false );
291  }
292  else
293  {
294  bool use_arrow = (shape_property_->getOptionInt() == Arrow);
295  arrow_->getSceneNode()->setVisible( use_arrow );
296  axes_->getSceneNode()->setVisible( !use_arrow );
298  }
299 }
300 
301 void PoseWithCovarianceDisplay::processMessage( const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& message )
302 {
303  if( !validateFloats( message->pose.pose ) || !validateFloats( message->pose.covariance ))
304  {
305  setStatus( StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" );
306  return;
307  }
308 
309  if( !validateQuaternions( message->pose.pose ))
310  {
311  ROS_WARN_ONCE_NAMED( "quaternions", "PoseWithCovariance '%s' contains unnormalized quaternions. "
312  "This warning will only be output once but may be true for others; "
313  "enable DEBUG messages for ros.rviz.quaternions to see more details.",
314  qPrintable( getName() ) );
315  ROS_DEBUG_NAMED( "quaternions", "PoseWithCovariance '%s' contains unnormalized quaternions.",
316  qPrintable( getName() ) );
317  }
318 
319  Ogre::Vector3 position;
320  Ogre::Quaternion orientation;
321  if( !context_->getFrameManager()->transform( message->header, message->pose.pose, position, orientation ))
322  {
323  ROS_ERROR( "Error transforming pose '%s' from frame '%s' to frame '%s'",
324  qPrintable( getName() ), message->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
325  return;
326  }
327 
328  pose_valid_ = true;
330 
331  axes_->setPosition( position );
332  axes_->setOrientation( orientation );
333 
334  arrow_->setPosition( position );
335  arrow_->setOrientation( orientation * Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_Y ) );
336 
337  covariance_->setPosition( position );
338  covariance_->setOrientation( orientation );
339  covariance_->setCovariance( message->pose );
340 
341  coll_handler_->setMessage( message );
342 
344 }
345 
347 {
348  MFDClass::reset();
349  pose_valid_ = false;
351 }
352 
353 } // namespace rviz
354 
Shape * getYShape()
Definition: axes.h:98
void setMin(float min)
Displays the pose from a geometry_msgs::PoseWithCovarianceStamped message.
void setMax(float max)
Ogre::ColourValue getOgreColor() const
virtual void processMessage(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr &message)
virtual bool setVector(const Ogre::Vector3 &vector)
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:256
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual float getFloat() const
virtual void setReadOnly(bool read_only)
Overridden from Property to propagate read-only-ness to children.
Property specialized to enforce floating point max/min.
void set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
Set the parameters for this arrow.
Definition: arrow.cpp:71
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:264
Shape * getHead()
Definition: arrow.h:151
CovarianceVisualPtr createAndPushBackVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this arrow.
Definition: arrow.h:143
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of this object.
Definition: axes.cpp:84
virtual bool getBool() const
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:281
#define ROS_DEBUG_NAMED(name,...)
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of the base of the arrow.
Definition: arrow.cpp:111
Pure-virtual base class for objects which give Display subclasses context in which to work...
std::vector< Ogre::AxisAlignedBox > V_AABB
bool validateFloats(const sensor_msgs::CameraInfo &msg)
virtual void addOption(const QString &option, int value=0)
boost::shared_ptr< CovarianceVisual > covariance_
void queueRender()
Convenience function which calls context_->queueRender().
Definition: display.cpp:99
virtual void setReadOnly(bool read_only)
Overridden from Property to propagate read-only-ness to children.
virtual void setColor(float r, float g, float b, float a)
Set the color of this arrow. Sets both the head and shaft color to the same value. Values are in the range [0, 1].
Definition: arrow.cpp:86
virtual bool setQuaternion(const Ogre::Quaternion &quaternion)
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Transform a pose from a frame into the fixed frame.
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
virtual void setOrientation(const Ogre::Quaternion &orientation)
Set the orientation.
Definition: arrow.cpp:116
Shape * getXShape()
Definition: axes.h:97
PoseWithCovarianceDisplaySelectionHandler(PoseWithCovarianceDisplay *display, DisplayContext *context)
void setMessage(const geometry_msgs::PoseWithCovarianceStampedConstPtr &message)
virtual void reset()
Called to tell the display to clear its state.
#define ROS_WARN_ONCE_NAMED(name,...)
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:58
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:261
PoseWithCovarianceDisplaySelectionHandlerPtr coll_handler_
virtual void onInitialize()
Override this function to do subclass-specific initialization.
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
Definition: property.cpp:530
Property specialized for string values.
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
bool validateQuaternions(const visualization_msgs::InteractiveMarker &marker)
Property specialized to provide getter for booleans.
void createProperties(const Picked &obj, Property *parent_property)
Override to create properties of the given picked object(s).
QList< Property * > properties_
An arrow consisting of a cylinder and a cone.
Definition: arrow.h:59
void set(float length, float radius)
Set the parameters on this object.
Definition: axes.cpp:69
virtual void setOrientation(const Ogre::Quaternion &orientation)
Set the orientation of the object.
Definition: axes.cpp:89
Shape * getShaft()
Definition: arrow.h:150
virtual void onEnable()
Overridden from MessageFilterDisplay to get Arrow/Axes visibility correct.
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:247
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: axes.h:90
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:397
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
bool setStdString(const std::string &std_str)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
Enum property.
Definition: enum_property.h:47
#define ROS_ERROR(...)
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
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:159
Shape * getZShape()
Definition: axes.h:99
Ogre::Entity * getEntity()
Definition: shape.h:104


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51