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 {
58 {
59 public:
61  : SelectionHandler(context), display_(display)
62  {
63  }
64 
65  void createProperties(const Picked& /*obj*/, Property* parent_property) override
66  {
67  Property* cat = new Property("Pose " + display_->getName(), QVariant(), "", parent_property);
68  properties_.push_back(cat);
69 
70  frame_property_ = new StringProperty("Frame", "", "", cat);
72 
73  position_property_ = new VectorProperty("Position", Ogre::Vector3::ZERO, "", cat);
75 
76  orientation_property_ = new QuaternionProperty("Orientation", Ogre::Quaternion::IDENTITY, "", cat);
78 
80  new VectorProperty("Covariance Position", Ogre::Vector3::ZERO, "", cat);
82 
84  new VectorProperty("Covariance Orientation", Ogre::Vector3::ZERO, "", cat);
86  }
87 
88  void getAABBs(const Picked& /*obj*/, V_AABB& aabbs) override
89  {
90  if (display_->pose_valid_)
91  {
93  {
94  aabbs.push_back(display_->arrow_->getHead()->getEntity()->getWorldBoundingBox());
95  aabbs.push_back(display_->arrow_->getShaft()->getEntity()->getWorldBoundingBox());
96  }
97  else
98  {
99  aabbs.push_back(display_->axes_->getXShape()->getEntity()->getWorldBoundingBox());
100  aabbs.push_back(display_->axes_->getYShape()->getEntity()->getWorldBoundingBox());
101  aabbs.push_back(display_->axes_->getZShape()->getEntity()->getWorldBoundingBox());
102  }
103 
105  {
107  {
108  aabbs.push_back(display_->covariance_->getPositionShape()->getEntity()->getWorldBoundingBox());
109  }
111  {
112  aabbs.push_back(display_->covariance_->getOrientationShape(CovarianceVisual::kRoll)
113  ->getEntity()
114  ->getWorldBoundingBox());
115  aabbs.push_back(display_->covariance_->getOrientationShape(CovarianceVisual::kPitch)
116  ->getEntity()
117  ->getWorldBoundingBox());
118  aabbs.push_back(display_->covariance_->getOrientationShape(CovarianceVisual::kYaw)
119  ->getEntity()
120  ->getWorldBoundingBox());
121  }
122  }
123  }
124  }
125 
126  void setMessage(const geometry_msgs::PoseWithCovarianceStampedConstPtr& message)
127  {
128  // properties_.size() should only be > 0 after createProperties()
129  // and before destroyProperties(), during which frame_property_,
130  // position_property_, and orientation_property_ should be valid
131  // pointers.
132  if (!properties_.empty())
133  {
134  frame_property_->setStdString(message->header.frame_id);
135  position_property_->setVector(Ogre::Vector3(
136  message->pose.pose.position.x, message->pose.pose.position.y, message->pose.pose.position.z));
138  Ogre::Quaternion(message->pose.pose.orientation.w, message->pose.pose.orientation.x,
139  message->pose.pose.orientation.y, message->pose.pose.orientation.z));
140  covariance_position_property_->setVector(Ogre::Vector3(message->pose.covariance[0 + 0 * 6],
141  message->pose.covariance[1 + 1 * 6],
142  message->pose.covariance[2 + 2 * 6]));
143 
144  covariance_orientation_property_->setVector(Ogre::Vector3(message->pose.covariance[3 + 3 * 6],
145  message->pose.covariance[4 + 4 * 6],
146  message->pose.covariance[5 + 5 * 6]));
147  }
148  }
149 
150 private:
157 };
158 
160 {
161  shape_property_ = new EnumProperty("Shape", "Arrow", "Shape to display the pose as.", this,
162  SLOT(updateShapeChoice()));
163  shape_property_->addOption("Arrow", Arrow);
164  shape_property_->addOption("Axes", Axes);
165 
166  color_property_ = new ColorProperty("Color", QColor(255, 25, 0), "Color to draw the arrow.", this,
167  SLOT(updateColorAndAlpha()));
168 
169  alpha_property_ = new FloatProperty("Alpha", 1, "Amount of transparency to apply to the arrow.", this,
170  SLOT(updateColorAndAlpha()));
173 
175  "Shaft Length", 1, "Length of the arrow's shaft, in meters.", this, SLOT(updateArrowGeometry()));
176 
177  // aleeper: default changed from 0.1 to match change in arrow.cpp
179  new FloatProperty("Shaft Radius", 0.05, "Radius of the arrow's shaft, in meters.", this,
180  SLOT(updateArrowGeometry()));
181 
182  head_length_property_ = new FloatProperty("Head Length", 0.3, "Length of the arrow's head, in meters.",
183  this, SLOT(updateArrowGeometry()));
184 
185  // aleeper: default changed from 0.2 to match change in arrow.cpp
186  head_radius_property_ = new FloatProperty("Head Radius", 0.1, "Radius of the arrow's head, in meters.",
187  this, SLOT(updateArrowGeometry()));
188 
189  axes_length_property_ = new FloatProperty("Axes Length", 1, "Length of each axis, in meters.", this,
190  SLOT(updateAxisGeometry()));
191 
192  axes_radius_property_ = new FloatProperty("Axes Radius", 0.1, "Radius of each axis, in meters.", this,
193  SLOT(updateAxisGeometry()));
194 
196  new CovarianceProperty("Covariance", true,
197  "Whether or not the covariances of the messages should be shown.", this,
198  SLOT(queueRender()));
199 }
200 
202 {
204 
208  // Arrow points in -Z direction, so rotate the orientation before display.
209  // TODO: is it safe to change Arrow to point in +X direction?
210  arrow_->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_Y));
211 
214 
216 
219 
221  coll_handler_->addTrackedObjects(arrow_->getSceneNode());
222  coll_handler_->addTrackedObjects(axes_->getSceneNode());
223  coll_handler_->addTrackedObjects(covariance_->getPositionSceneNode());
224  coll_handler_->addTrackedObjects(covariance_->getOrientationSceneNode());
225 }
226 
228 {
229  if (initialized())
230  {
231  delete arrow_;
232  delete axes_;
233  }
234 }
235 
237 {
240 }
241 
243 {
244  Ogre::ColourValue color = color_property_->getOgreColor();
245  color.a = alpha_property_->getFloat();
246 
247  arrow_->setColor(color);
248 
250 }
251 
253 {
257 }
258 
260 {
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 
302  const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& message)
303 {
304  if (!validateFloats(message->pose.pose) || !validateFloats(message->pose.covariance))
305  {
307  "Message contained invalid floating point values (nans or infs)");
308  return;
309  }
310 
311  if (!validateQuaternions(message->pose.pose))
312  {
313  ROS_WARN_ONCE_NAMED("quaternions",
314  "PoseWithCovariance '%s' contains unnormalized quaternions. "
315  "This warning will only be output once but may be true for others; "
316  "enable DEBUG messages for ros.rviz.quaternions to see more details.",
317  qPrintable(getName()));
318  ROS_DEBUG_NAMED("quaternions", "PoseWithCovariance '%s' contains unnormalized quaternions.",
319  qPrintable(getName()));
320  }
321 
322  Ogre::Vector3 position;
323  Ogre::Quaternion orientation;
324  if (!context_->getFrameManager()->transform(message->header, message->pose.pose, position, orientation))
325  {
326  ROS_ERROR("Error transforming pose '%s' from frame '%s' to frame '%s'", qPrintable(getName()),
327  message->header.frame_id.c_str(), qPrintable(fixed_frame_));
328  return;
329  }
330 
331  pose_valid_ = true;
333 
334  axes_->setPosition(position);
335  axes_->setOrientation(orientation);
336 
337  arrow_->setPosition(position);
338  arrow_->setOrientation(orientation * Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_Y));
339 
340  covariance_->setPosition(position);
341  covariance_->setOrientation(orientation);
342  covariance_->setCovariance(message->pose);
343 
344  coll_handler_->setMessage(message);
345 
347 }
348 
350 {
351  MFDClass::reset();
352  pose_valid_ = false;
354 }
355 
356 } // namespace rviz
357 
Shape * getYShape()
Definition: axes.h:109
void setMin(float min)
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:88
Displays the pose from a geometry_msgs::PoseWithCovarianceStamped message.
void setMax(float max)
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:287
void setPosition(const Ogre::Vector3 &position) override
Set the position of the base of the arrow.
Definition: arrow.cpp:114
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
void reset() override
Called to tell the display to clear its state.
Ogre::ColourValue getOgreColor() const
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:74
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
void createProperties(const Picked &, Property *parent_property) override
Override to create properties of the given picked object(s).
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
Shape * getHead()
Definition: arrow.h:163
CovarianceVisualPtr createAndPushBackVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this arrow.
Definition: arrow.h:149
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
#define ROS_DEBUG_NAMED(name,...)
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:98
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
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.
Shape * getXShape()
Definition: axes.h:105
PoseWithCovarianceDisplaySelectionHandler(PoseWithCovarianceDisplay *display, DisplayContext *context)
void setMessage(const geometry_msgs::PoseWithCovarianceStampedConstPtr &message)
void getAABBs(const Picked &, V_AABB &aabbs) override
#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:59
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
PoseWithCovarianceDisplaySelectionHandlerPtr coll_handler_
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:83
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
Definition: property.cpp:543
Property specialized for string values.
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
void onInitialize() override
Override this function to do subclass-specific initialization.
bool validateQuaternions(const visualization_msgs::InteractiveMarker &marker)
virtual float getFloat() const
Property specialized to provide getter for booleans.
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:68
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation.
Definition: arrow.cpp:119
Shape * getShaft()
Definition: arrow.h:159
void setColor(float r, float g, float b, float a) override
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:89
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: axes.h:95
void processMessage(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr &message) override
virtual bool getBool() const
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:433
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:46
#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:175
void onEnable() override
Overridden from MessageFilterDisplay to get Arrow/Axes visibility correct.
Shape * getZShape()
Definition: axes.h:113
Ogre::Entity * getEntity()
Definition: shape.h:110


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Jan 9 2023 03:07:20