00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "axes_display.h"
00031 #include "rviz/visualization_manager.h"
00032 #include "rviz/properties/property.h"
00033 #include "rviz/properties/property_manager.h"
00034 #include "rviz/common.h"
00035 #include "rviz/frame_manager.h"
00036
00037 #include "ogre_tools/axes.h"
00038
00039 #include <boost/bind.hpp>
00040
00041 #include <OGRE/OgreSceneNode.h>
00042 #include <OGRE/OgreSceneManager.h>
00043
00044 namespace rviz
00045 {
00046
00047 AxesDisplay::AxesDisplay( const std::string& name, VisualizationManager* manager )
00048 : Display( name, manager )
00049 , length_( 1.0 )
00050 , radius_( 0.1 )
00051 {
00052 axes_ = new ogre_tools::Axes( scene_manager_, 0, length_, radius_ );
00053
00054 axes_->getSceneNode()->setVisible( isEnabled() );
00055
00056 setFrame(FIXED_FRAME_STRING);
00057 }
00058
00059 AxesDisplay::~AxesDisplay()
00060 {
00061 delete axes_;
00062 }
00063
00064 void AxesDisplay::onEnable()
00065 {
00066 axes_->getSceneNode()->setVisible( true );
00067 }
00068
00069 void AxesDisplay::onDisable()
00070 {
00071 axes_->getSceneNode()->setVisible( false );
00072 }
00073
00074 void AxesDisplay::create()
00075 {
00076 axes_->set( length_, radius_ );
00077
00078 causeRender();
00079 }
00080
00081 void AxesDisplay::set( float length, float radius )
00082 {
00083 length_ = length;
00084 radius_ = radius;
00085
00086 create();
00087
00088 propertyChanged(length_property_);
00089 propertyChanged(radius_property_);
00090 }
00091
00092 void AxesDisplay::setFrame(const std::string& frame)
00093 {
00094 frame_ = frame;
00095 propertyChanged(frame_property_);
00096 }
00097
00098 void AxesDisplay::setLength( float length )
00099 {
00100 set( length, radius_ );
00101 }
00102
00103 void AxesDisplay::setRadius( float radius )
00104 {
00105 set( length_, radius );
00106 }
00107
00108 void AxesDisplay::update(float dt, float ros_dt)
00109 {
00110 std::string frame = frame_;
00111 if (frame == FIXED_FRAME_STRING)
00112 {
00113 frame = fixed_frame_;
00114 }
00115
00116 Ogre::Vector3 position;
00117 Ogre::Quaternion orientation;
00118 if (vis_manager_->getFrameManager()->getTransform(frame, ros::Time(), position, orientation, false))
00119 {
00120 axes_->setPosition(position);
00121 axes_->setOrientation(orientation);
00122 setStatus(status_levels::Ok, "Transform", "Transform OK");
00123 }
00124 else
00125 {
00126 std::string error;
00127 if (vis_manager_->getFrameManager()->transformHasProblems(frame, ros::Time(), error))
00128 {
00129 setStatus(status_levels::Error, "Transform", error);
00130 }
00131 else
00132 {
00133 std::stringstream ss;
00134 ss << "Could not transform from [" << frame << "] to Fixed Frame [" << fixed_frame_ << "] for an unknown reason";
00135 setStatus(status_levels::Error, "Transform", ss.str());
00136 }
00137 }
00138 }
00139
00140 void AxesDisplay::createProperties()
00141 {
00142 frame_property_ = property_manager_->createProperty<TFFrameProperty>("Reference Frame", property_prefix_, boost::bind(&AxesDisplay::getFrame, this),
00143 boost::bind(&AxesDisplay::setFrame, this, _1), parent_category_, this);
00144 setPropertyHelpText(frame_property_, "The TF frame these axes will use for their origin.");
00145 length_property_ = property_manager_->createProperty<FloatProperty>( "Length", property_prefix_, boost::bind( &AxesDisplay::getLength, this ),
00146 boost::bind( &AxesDisplay::setLength, this, _1 ), parent_category_, this );
00147 FloatPropertyPtr float_prop = length_property_.lock();
00148 float_prop->setMin( 0.0001 );
00149 setPropertyHelpText(length_property_, "Length of each axis, in meters.");
00150
00151 radius_property_ = property_manager_->createProperty<FloatProperty>( "Radius", property_prefix_, boost::bind( &AxesDisplay::getRadius, this ),
00152 boost::bind( &AxesDisplay::setRadius, this, _1 ), parent_category_, this );
00153 float_prop = radius_property_.lock();
00154 float_prop->setMin( 0.0001 );
00155 setPropertyHelpText(radius_property_, "Width of each axis, in meters.");
00156 }
00157
00158 }