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


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