Go to the documentation of this file.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 <OGRE/OgreCamera.h>
00031 #include <OGRE/OgreSceneManager.h>
00032 #include <OGRE/OgreSceneNode.h>
00033
00034 #include "rviz/display_context.h"
00035 #include "rviz/frame_manager.h"
00036 #include "rviz/properties/enum_property.h"
00037 #include "rviz/properties/tf_frame_property.h"
00038 #include "rviz/viewport_mouse_event.h"
00039 #include "rviz/view_manager.h"
00040
00041 #include "rviz/frame_position_tracking_view_controller.h"
00042
00043 namespace rviz
00044 {
00045
00046 FramePositionTrackingViewController::FramePositionTrackingViewController()
00047 : target_scene_node_( NULL )
00048 {
00049 target_frame_property_ = new TfFrameProperty( "Target Frame", TfFrameProperty::FIXED_FRAME_STRING,
00050 "TF frame whose motion this view will follow.", this, NULL, true );
00051 }
00052
00053 void FramePositionTrackingViewController::onInitialize()
00054 {
00055 target_frame_property_->setFrameManager( context_->getFrameManager() );
00056
00057 target_scene_node_ = context_->getSceneManager()->getRootSceneNode()->createChildSceneNode();
00058 camera_->detachFromParent();
00059 target_scene_node_->attachObject( camera_ );
00060 }
00061
00062 FramePositionTrackingViewController::~FramePositionTrackingViewController()
00063 {
00064 context_->getSceneManager()->destroySceneNode( target_scene_node_ );
00065 }
00066
00067 void FramePositionTrackingViewController::onActivate()
00068 {
00069 updateTargetSceneNode();
00070
00071
00072
00073
00074
00075
00076
00077 connect( target_frame_property_, SIGNAL( changed() ), this, SLOT( updateTargetFrame() ));
00078 }
00079
00080 void FramePositionTrackingViewController::update(float dt, float ros_dt)
00081 {
00082 updateTargetSceneNode();
00083 }
00084
00085 void FramePositionTrackingViewController::updateTargetFrame()
00086 {
00087 Ogre::Vector3 old_position = target_scene_node_->getPosition();
00088 Ogre::Quaternion old_orientation = target_scene_node_->getOrientation();
00089
00090 updateTargetSceneNode();
00091
00092 onTargetFrameChanged( old_position, old_orientation );
00093 }
00094
00095 void FramePositionTrackingViewController::updateTargetSceneNode()
00096 {
00097 Ogre::Vector3 new_reference_position;
00098 Ogre::Quaternion new_reference_orientation;
00099
00100 if( context_->getFrameManager()->getTransform( target_frame_property_->getFrameStd(), ros::Time(),
00101 new_reference_position, new_reference_orientation ))
00102 {
00103 target_scene_node_->setPosition( new_reference_position );
00104
00105 reference_position_ = new_reference_position;
00106 reference_orientation_ = new_reference_orientation;
00107
00108 context_->queueRender();
00109 }
00110
00111
00122 }
00123
00124 void FramePositionTrackingViewController::mimic( ViewController* source_view )
00125 {
00126 QVariant target_frame = source_view->subProp( "Target Frame" )->getValue();
00127 if( target_frame.isValid() )
00128 {
00129 target_frame_property_->setValue( target_frame );
00130 }
00131 }
00132
00133 }