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 "marker_base.h"
00031 #include "rviz/default_plugin/marker_display.h"
00032 #include "rviz/common.h"
00033 #include "rviz/visualization_manager.h"
00034 #include "rviz/selection/selection_manager.h"
00035 #include "rviz/frame_manager.h"
00036
00037 #include <OGRE/OgreSceneNode.h>
00038 #include <OGRE/OgreSceneManager.h>
00039
00040 #include <tf/tf.h>
00041 #include <tf/transform_listener.h>
00042
00043 namespace rviz
00044 {
00045
00046 MarkerBase::MarkerBase(MarkerDisplay* owner, VisualizationManager* manager, Ogre::SceneNode* parent_node)
00047 : owner_(owner)
00048 , vis_manager_(manager)
00049 , parent_node_(parent_node->createChildSceneNode())
00050 , coll_(0)
00051 {}
00052
00053 MarkerBase::~MarkerBase()
00054 {
00055 vis_manager_->getSelectionManager()->removeObject(coll_);
00056 vis_manager_->getSceneManager()->destroySceneNode(parent_node_);
00057 }
00058
00059 void MarkerBase::setMessage(const MarkerConstPtr& message)
00060 {
00061 MarkerConstPtr old = message_;
00062 message_ = message;
00063
00064 expiration_ = ros::Time::now() + message->lifetime;
00065
00066 onNewMessage(old, message);
00067 }
00068
00069 void MarkerBase::updateFrameLocked()
00070 {
00071 ROS_ASSERT(message_ && message_->frame_locked);
00072 onNewMessage(message_, message_);
00073 }
00074
00075 bool MarkerBase::expired()
00076 {
00077 return ros::Time::now() >= expiration_;
00078 }
00079
00080 bool MarkerBase::transform(const MarkerConstPtr& message, Ogre::Vector3& pos, Ogre::Quaternion& orient, Ogre::Vector3& scale, bool relative_orientation)
00081 {
00082 ros::Time stamp = message->header.stamp;
00083 if (message->frame_locked)
00084 {
00085 stamp = ros::Time();
00086 }
00087
00088 if (!FrameManager::instance()->transform(message->header.frame_id, stamp, message->pose, pos, orient, relative_orientation))
00089 {
00090 std::string error;
00091 FrameManager::instance()->transformHasProblems(message->header.frame_id, message->header.stamp, error);
00092 owner_->setMarkerStatus(getID(), status_levels::Error, error);
00093 return false;
00094 }
00095
00096 scale = Ogre::Vector3(message->scale.x, message->scale.y, message->scale.z);
00097 scaleRobotToOgre( scale );
00098
00099 return true;
00100 }
00101
00102 }