axes_display.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <boost/bind.hpp>
00031 
00032 #include <OGRE/OgreSceneNode.h>
00033 #include <OGRE/OgreSceneManager.h>
00034 
00035 #include "rviz/display_context.h"
00036 #include "rviz/frame_manager.h"
00037 #include "rviz/ogre_helpers/axes.h"
00038 #include "rviz/properties/float_property.h"
00039 #include "rviz/properties/tf_frame_property.h"
00040 
00041 #include "axes_display.h"
00042 
00043 namespace rviz
00044 {
00045 
00046 AxesDisplay::AxesDisplay()
00047   : Display()
00048   , axes_( 0 )
00049 {
00050   frame_property_ = new TfFrameProperty( "Reference Frame", TfFrameProperty::FIXED_FRAME_STRING,
00051                                          "The TF frame these axes will use for their origin.",
00052                                          this, NULL, true );
00053 
00054   length_property_ = new FloatProperty( "Length", 1.0,
00055                                         "Length of each axis, in meters.",
00056                                         this, SLOT( updateShape() ));
00057   length_property_->setMin( 0.0001 );
00058 
00059   radius_property_ = new FloatProperty( "Radius", 0.1,
00060                                         "Radius of each axis, in meters.",
00061                                         this, SLOT( updateShape() ));
00062   radius_property_->setMin( 0.0001 );
00063 }
00064 
00065 AxesDisplay::~AxesDisplay()
00066 {
00067   delete axes_;
00068 }
00069 
00070 void AxesDisplay::onInitialize()
00071 {
00072   frame_property_->setFrameManager( context_->getFrameManager() );
00073 
00074   axes_ = new Axes( scene_manager_, 0, length_property_->getFloat(), radius_property_->getFloat() );
00075   axes_->getSceneNode()->setVisible( isEnabled() );
00076 }
00077 
00078 void AxesDisplay::onEnable()
00079 {
00080   axes_->getSceneNode()->setVisible( true );
00081 }
00082 
00083 void AxesDisplay::onDisable()
00084 {
00085   axes_->getSceneNode()->setVisible( false );
00086 }
00087 
00088 void AxesDisplay::updateShape()
00089 {
00090   axes_->set( length_property_->getFloat(), radius_property_->getFloat() );
00091   context_->queueRender();
00092 }
00093 
00094 void AxesDisplay::update( float dt, float ros_dt )
00095 {
00096   QString qframe = frame_property_->getFrame();
00097   std::string frame = qframe.toStdString();
00098 
00099   Ogre::Vector3 position;
00100   Ogre::Quaternion orientation;
00101   if( context_->getFrameManager()->getTransform( frame, ros::Time(), position, orientation ))
00102   {
00103     axes_->setPosition( position );
00104     axes_->setOrientation( orientation );
00105     setStatus( StatusProperty::Ok, "Transform", "Transform OK" );
00106   }
00107   else
00108   {
00109     std::string error;
00110     if( context_->getFrameManager()->transformHasProblems( frame, ros::Time(), error ))
00111     {
00112       setStatus( StatusProperty::Error, "Transform", QString::fromStdString( error ));
00113     }
00114     else
00115     {
00116       setStatus( StatusProperty::Error,
00117                  "Transform",
00118                  "Could not transform from [" + qframe + "] to Fixed Frame [" + fixed_frame_ + "] for an unknown reason" );
00119     }
00120   }
00121 }
00122 
00123 } // namespace rviz
00124 
00125 #include <pluginlib/class_list_macros.h>
00126 PLUGINLIB_EXPORT_CLASS( rviz::AxesDisplay, rviz::Display )


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35