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.hpp>
31 
32 #include <OgreSceneNode.h>
33 #include <OgreSceneManager.h>
34 
35 #include "rviz/display_context.h"
36 #include "rviz/frame_manager.h"
37 #include "rviz/ogre_helpers/axes.h"
40 
41 #include "axes_display.h"
42 
43 namespace rviz
44 {
45 AxesDisplay::AxesDisplay() : Display(), axes_(nullptr)
46 {
49  "The TF frame these axes will use for their origin.", this, nullptr, true);
50 
52  new FloatProperty("Length", 1.0, "Length of each axis, in meters.", this, SLOT(updateShape()));
53  length_property_->setMin(0.0001);
54 
56  new FloatProperty("Radius", 0.1, "Radius of each axis, in meters.", this, SLOT(updateShape()));
57  radius_property_->setMin(0.0001);
58 }
59 
61 {
62  delete axes_;
63 }
64 
66 {
68 
70  axes_->getSceneNode()->setVisible(isEnabled());
71 }
72 
74 {
75  axes_->getSceneNode()->setVisible(true);
76 }
77 
79 {
80  axes_->getSceneNode()->setVisible(false);
81 }
82 
84 {
87 }
88 
89 void AxesDisplay::update(float /*dt*/, float /*ros_dt*/)
90 {
91  QString qframe = frame_property_->getFrame();
92  std::string frame = qframe.toStdString();
93 
94  Ogre::Vector3 position;
95  Ogre::Quaternion orientation;
96  if (context_->getFrameManager()->getTransform(frame, ros::Time(), position, orientation))
97  {
98  axes_->setPosition(position);
99  axes_->setOrientation(orientation);
100  setStatus(StatusProperty::Ok, "Transform", "Transform OK");
101  }
102  else
103  {
104  std::string error;
105  if (context_->getFrameManager()->transformHasProblems(frame, ros::Time(), error))
106  {
107  setStatus(StatusProperty::Error, "Transform", QString::fromStdString(error));
108  }
109  else
110  {
111  setStatus(StatusProperty::Error, "Transform",
112  "Could not transform from [" + qframe + "] to Fixed Frame [" + fixed_frame_ +
113  "] for an unknown reason");
114  }
115  }
116 }
117 
118 } // namespace rviz
119 
~AxesDisplay() override
void setMin(float min)
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:88
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.
void onEnable() override
Derived classes override this to do the actual work of enabling themselves.
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
Property specialized to enforce floating point max/min.
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
void updateShape()
Update the length and radius of the axes object from property values.
FloatProperty * length_property_
Definition: axes_display.h:73
void update(float dt, float ros_dt) override
Called periodically by the visualization manager.
void onDisable() override
Derived classes override this to do the actual work of disabling themselves.
TfFrameProperty * frame_property_
Definition: axes_display.h:75
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
FloatProperty * radius_property_
Definition: axes_display.h:74
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:59
void onInitialize() override
Override this function to do subclass-specific initialization.
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:83
Axes * axes_
Handles actually drawing the axes.
Definition: axes_display.h:71
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
bool isEnabled() const
Return true if this Display is enabled, false if not.
Definition: display.cpp:268
static const QString FIXED_FRAME_STRING
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.
void setFrameManager(FrameManager *frame_manager)
void set(float length, float radius)
Set the parameters on this object.
Definition: axes.cpp:68
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: axes.h:95
Displays a set of XYZ axes at the origin of a chosen frame.
Definition: axes_display.h:42
#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


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