marker_base.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, 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 "marker_base.h"
00031 #include "rviz/default_plugin/marker_display.h"
00032 #include "rviz/display_context.h"
00033 #include "rviz/selection/selection_manager.h"
00034 #include "marker_selection_handler.h"
00035 #include "rviz/frame_manager.h"
00036 
00037 #include <OGRE/OgreSceneNode.h>
00038 #include <OGRE/OgreSceneManager.h>
00039 #include <OGRE/OgreEntity.h>
00040 #include <OGRE/OgreSubEntity.h>
00041 
00042 #include <tf/tf.h>
00043 #include <tf/transform_listener.h>
00044 
00045 namespace rviz
00046 {
00047 
00048 MarkerBase::MarkerBase( MarkerDisplay* owner, DisplayContext* context, Ogre::SceneNode* parent_node )
00049   : owner_( owner )
00050   , context_( context )
00051   , scene_node_( parent_node->createChildSceneNode() )
00052 {}
00053 
00054 MarkerBase::~MarkerBase()
00055 {
00056   context_->getSceneManager()->destroySceneNode(scene_node_);
00057 }
00058 
00059 void MarkerBase::setMessage(const Marker& message)
00060 {
00061   // copy and save to shared pointer
00062   MarkerConstPtr message_ptr( new Marker(message) );
00063   setMessage( message_ptr );
00064 }
00065 
00066 void MarkerBase::setMessage(const MarkerConstPtr& message)
00067 {
00068   MarkerConstPtr old = message_;
00069   message_ = message;
00070 
00071   expiration_ = ros::Time::now() + message->lifetime;
00072 
00073   onNewMessage(old, message);
00074 }
00075 
00076 void MarkerBase::updateFrameLocked()
00077 {
00078   ROS_ASSERT(message_ && message_->frame_locked);
00079   onNewMessage(message_, message_);
00080 }
00081 
00082 bool MarkerBase::expired()
00083 {
00084   return ros::Time::now() >= expiration_;
00085 }
00086 
00087 bool MarkerBase::transform(const MarkerConstPtr& message, Ogre::Vector3& pos, Ogre::Quaternion& orient, Ogre::Vector3& scale)
00088 {
00089   ros::Time stamp = message->header.stamp;
00090   if (message->frame_locked)
00091   {
00092     stamp = ros::Time();
00093   }
00094 
00095   if (!context_->getFrameManager()->transform(message->header.frame_id, stamp, message->pose, pos, orient))
00096   {
00097     std::string error;
00098     context_->getFrameManager()->transformHasProblems(message->header.frame_id, message->header.stamp, error);
00099     if ( owner_ )
00100     {
00101       owner_->setMarkerStatus(getID(), StatusProperty::Error, error);
00102     }
00103     return false;
00104   }
00105 
00106   scale = Ogre::Vector3(message->scale.x, message->scale.y, message->scale.z);
00107 
00108   return true;
00109 }
00110 
00111 void MarkerBase::setInteractiveObject( InteractiveObjectWPtr control )
00112 {
00113   if( handler_ )
00114   {
00115     handler_->setInteractiveObject( control );
00116   }
00117 }
00118 
00119 void MarkerBase::setPosition( const Ogre::Vector3& position )
00120 {
00121   scene_node_->setPosition( position );
00122 }
00123 
00124 void MarkerBase::setOrientation( const Ogre::Quaternion& orientation )
00125 {
00126   scene_node_->setOrientation( orientation );
00127 }
00128 
00129 const Ogre::Vector3& MarkerBase::getPosition()
00130 {
00131   return scene_node_->getPosition();
00132 }
00133 
00134 const Ogre::Quaternion& MarkerBase::getOrientation()
00135 {
00136   return scene_node_->getOrientation();
00137 }
00138 
00139 void MarkerBase::extractMaterials( Ogre::Entity *entity, S_MaterialPtr &materials )
00140 {
00141   uint32_t num_sub_entities = entity->getNumSubEntities();
00142   for (uint32_t i = 0; i < num_sub_entities; ++i)
00143   {
00144     Ogre::SubEntity* sub = entity->getSubEntity(i);
00145     Ogre::MaterialPtr material = sub->getMaterial();
00146     materials.insert( material );
00147   }
00148 }
00149 
00150 
00151 
00152 } // namespace rviz


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