view_controller.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 "view_controller.h"
00031 #include "viewport_mouse_event.h"
00032 #include "visualization_manager.h"
00033 #include "frame_manager.h"
00034 
00035 #include <OGRE/OgreCamera.h>
00036 #include <OGRE/OgreSceneNode.h>
00037 #include <OGRE/OgreSceneManager.h>
00038 
00039 namespace rviz
00040 {
00041 
00042 ViewController::ViewController(VisualizationManager* manager, const std::string& name, Ogre::SceneNode* target_scene_node)
00043 : manager_(manager)
00044 , camera_(0)
00045 , target_scene_node_(target_scene_node)
00046 , name_(name)
00047 {
00048 }
00049 
00050 ViewController::~ViewController()
00051 {
00052 //  manager_->getSceneManager()->destroySceneNode(target_scene_node_);
00053 }
00054 
00055 void ViewController::activate(Ogre::Camera* camera, const std::string& reference_frame)
00056 {
00057   camera_ = camera;
00058   reference_frame_ = reference_frame;
00059   updateTargetSceneNode();
00060   target_scene_node_->attachObject(camera_);
00061 
00062   onActivate();
00063 }
00064 
00065 void ViewController::deactivate()
00066 {
00067   onDeactivate();
00068 
00069   target_scene_node_->detachObject(camera_);
00070   camera_ = 0;
00071 }
00072 
00073 void ViewController::update(float dt, float ros_dt)
00074 {
00075   updateTargetSceneNode();
00076   onUpdate(dt, ros_dt);
00077 }
00078 
00079 void ViewController::emitConfigChanged()
00080 {
00081   Q_EMIT configChanged();
00082 }
00083 
00084 void ViewController::setTargetFrame(const std::string& reference_frame)
00085 {
00086   Ogre::Vector3 old_position;
00087   Ogre::Quaternion old_orientation;
00088   FrameManager::instance()->getTransform(reference_frame_, ros::Time(), old_position, old_orientation);
00089 
00090   reference_frame_ = reference_frame;
00091 
00092   Ogre::Vector3 position;
00093   Ogre::Quaternion orientation;
00094   FrameManager::instance()->getTransform(reference_frame_, ros::Time(), position, orientation);
00095 
00096   reference_position_ = position;
00097   reference_orientation_ = orientation;
00098 
00099   onTargetFrameChanged( old_position, old_orientation );
00100 }
00101 
00102 void ViewController::updateTargetSceneNode()
00103 {
00104   Ogre::Vector3 new_reference_position;
00105   Ogre::Quaternion new_reference_orientation;
00106 
00107   if (FrameManager::instance()->getTransform(reference_frame_, ros::Time(), new_reference_position, new_reference_orientation) )
00108   {
00109     target_scene_node_->setPosition( new_reference_position );
00110 
00111     reference_position_ = new_reference_position;
00112     reference_orientation_ = new_reference_orientation;
00113 
00114     manager_->queueRender();
00115   }
00116 }
00117 
00118 }


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:33