axes_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 <boost/bind/bind.hpp>
31 
32 #include <OgreSceneNode.h>
33 #include <OgreSceneManager.h>
34 #include <OgreRibbonTrail.h>
35 
36 #include <rviz/display_context.h>
37 #include <rviz/frame_manager.h>
38 #include <rviz/ogre_helpers/axes.h>
41 
42 #include "axes_display.h"
43 
44 namespace rviz
45 {
46 AxesDisplay::AxesDisplay() : Display(), axes_(nullptr), trail_(nullptr)
47 {
49  "The TF frame these axes will use for their origin.", this,
50  nullptr, true, [this] { resetTrail(); });
51 
52  length_property_ = new FloatProperty("Length", 1.0, "Length of each axis, in meters.", this,
54  length_property_->setMin(0.0001);
55 
56  radius_property_ = new FloatProperty("Radius", 0.1, "Radius of each axis, in meters.", this,
58  radius_property_->setMin(0.0001);
59 
61  new Property("Show Trail", false, "Enable/disable a 2 meter \"ribbon\" which follows this frame.",
63 
64  alpha_property_ = new FloatProperty("Alpha", 1.0, "Alpha channel value of each axis.", this,
66  alpha_property_->setMin(0.0);
67  alpha_property_->setMax(1.0);
68 }
69 
71 {
72  if (trail_)
73  {
74  scene_manager_->destroyRibbonTrail(trail_);
75  }
76 
77  delete axes_;
78 }
79 
81 {
83 
86  axes_->getSceneNode()->setVisible(isEnabled());
87 }
88 
90 {
92  resetTrail(false);
93 }
94 
95 void AxesDisplay::resetTrail(bool update)
96 {
97  if (!trail_)
98  return;
99  if (update)
100  this->update(0.0, 0.0);
101  trail_->nodeUpdated(axes_->getSceneNode());
102  trail_->clearAllChains();
103 }
104 
106 {
107  axes_->getSceneNode()->setVisible(true);
108  if (trail_)
109  trail_->setVisible(true);
110 }
111 
113 {
114  axes_->getSceneNode()->setVisible(false);
115  if (trail_)
116  trail_->setVisible(false);
117 }
118 
120 {
123 }
124 
126 {
127  if (trail_property_->getValue().toBool())
128  {
129  if (!trail_)
130  {
131  static int count = 0;
132  std::stringstream ss;
133  ss << "Trail for frame " << frame_property_->getFrame().toStdString() << count++;
134  trail_ = scene_manager_->createRibbonTrail(ss.str());
135  trail_->setMaxChainElements(100);
136  trail_->setInitialWidth(0, 0.01f);
137  trail_->setInitialColour(0, 1, 0, 0);
138  trail_->addNode(axes_->getSceneNode());
139  trail_->setTrailLength(2.0f);
140  trail_->setVisible(isEnabled());
141  axes_->getSceneNode()->getParentSceneNode()->attachObject(trail_);
142  }
143  }
144  else
145  {
146  if (trail_)
147  {
148  scene_manager_->destroyRibbonTrail(trail_);
149  trail_ = nullptr;
150  }
151  }
152 }
153 
154 void AxesDisplay::update(float /*dt*/, float /*ros_dt*/)
155 {
156  QString qframe = frame_property_->getFrame();
157  std::string frame = qframe.toStdString();
158 
159  Ogre::Vector3 position;
160  Ogre::Quaternion orientation;
161  if (context_->getFrameManager()->getTransform(frame, ros::Time(), position, orientation))
162  {
163  axes_->setPosition(position);
164  axes_->setOrientation(orientation);
165  setStatus(StatusProperty::Ok, "Transform", "Transform OK");
166  }
167  else
168  {
169  std::string error;
170  if (context_->getFrameManager()->transformHasProblems(frame, ros::Time(), error))
171  {
172  setStatus(StatusProperty::Error, "Transform", QString::fromStdString(error));
173  }
174  else
175  {
176  setStatus(StatusProperty::Error, "Transform",
177  "Could not transform from [" + qframe + "] to Fixed Frame [" + fixed_frame_ +
178  "] for an unknown reason");
179  }
180  }
181 }
182 
183 } // namespace rviz
184 
axes.h
rviz::Axes::getSceneNode
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: axes.h:96
rviz::Display::isEnabled
bool isEnabled() const
Return true if this Display is enabled, false if not.
Definition: display.cpp:271
frame_manager.h
rviz::DisplayContext::queueRender
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
rviz::StatusProperty::Error
@ Error
Definition: status_property.h:46
rviz::AxesDisplay::~AxesDisplay
~AxesDisplay() override
Definition: axes_display.cpp:70
rviz::FloatProperty::setMax
void setMax(float max)
Definition: float_property.cpp:57
rviz::AxesDisplay::length_property_
FloatProperty * length_property_
Definition: axes_display.h:83
float_property.h
rviz::Display::fixed_frame_
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
rviz::AxesDisplay::AxesDisplay
AxesDisplay()
Definition: axes_display.cpp:46
axes_display.h
rviz::Property::getValue
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
Definition: property.cpp:150
rviz::Property::Property
Property(const QString &name=QString(), const QVariant &default_value=QVariant(), const QString &description=QString(), Property *parent=nullptr)
Constructor.
Definition: property.cpp:59
rviz::AxesDisplay
Displays a set of XYZ axes at the origin of a chosen frame.
Definition: axes_display.h:47
rviz::FloatProperty::setMin
void setMin(float min)
Definition: float_property.cpp:51
f
f
rviz::Display
Definition: display.h:63
rviz::FloatProperty
Property specialized to enforce floating point max/min.
Definition: float_property.h:37
rviz::AxesDisplay::alpha_property_
FloatProperty * alpha_property_
Definition: axes_display.h:86
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
rviz
Definition: add_display_dialog.cpp:54
rviz::StatusProperty::Ok
@ Ok
Definition: status_property.h:44
rviz::AxesDisplay::onInitialize
void onInitialize() override
Override this function to do subclass-specific initialization.
Definition: axes_display.cpp:80
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
rviz::AxesDisplay::onEnable
void onEnable() override
Derived classes override this to do the actual work of enabling themselves.
Definition: axes_display.cpp:105
rviz::AxesDisplay::updateTrail
void updateTrail()
Create or Destroy trail based on boolean property.
Definition: axes_display.cpp:125
rviz::AxesDisplay::updateShape
void updateShape()
Update the length and radius of the axes object from property values.
Definition: axes_display.cpp:119
rviz::AxesDisplay::update
void update(float dt, float ros_dt) override
Called periodically by the visualization manager.
Definition: axes_display.cpp:154
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::Axes
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:57
rviz::AxesDisplay::trail_property_
Property * trail_property_
Definition: axes_display.h:85
rviz::TfFrameProperty
Definition: tf_frame_property.h:41
tf_frame_property.h
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::AxesDisplay::resetTrail
void resetTrail(bool update=true)
Definition: axes_display.cpp:95
rviz::TfFrameProperty::FIXED_FRAME_STRING
static const QString FIXED_FRAME_STRING
Definition: tf_frame_property.h:92
rviz::Display::context_
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz....
Definition: display.h:287
ros::Time
rviz::TfFrameProperty::getFrame
QString getFrame() const
Definition: tf_frame_property.cpp:99
rviz::AxesDisplay::frame_property_
TfFrameProperty * frame_property_
Definition: axes_display.h:87
class_list_macros.hpp
rviz::Display::reset
virtual void reset()
Called to tell the display to clear its state.
Definition: display.cpp:290
rviz::Axes::set
void set(float length, float radius, float alpha=1.0f)
Set the parameters on this object.
Definition: axes.cpp:76
rviz::AxesDisplay::reset
void reset() override
Called to tell the display to clear its state.
Definition: axes_display.cpp:89
rviz::TfFrameProperty::setFrameManager
void setFrameManager(FrameManager *frame_manager)
Definition: tf_frame_property.cpp:67
rviz::Axes::setPosition
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:92
rviz::AxesDisplay::trail_
Ogre::RibbonTrail * trail_
Definition: axes_display.h:81
display_context.h
rviz::Axes::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:97
rviz::AxesDisplay::onDisable
void onDisable() override
Derived classes override this to do the actual work of disabling themselves.
Definition: axes_display.cpp:112
rviz::AxesDisplay::axes_
Axes * axes_
Handles actually drawing the axes.
Definition: axes_display.h:80
rviz::FrameManager::transformHasProblems
bool transformHasProblems(const std::string &frame, ros::Time time, std::string &error)
Check to see if a transform is known between a given frame and the fixed frame.
Definition: frame_manager.cpp:272
rviz::AxesDisplay::radius_property_
FloatProperty * radius_property_
Definition: axes_display.h:84


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:52