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