tablet_view_controller.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, JSK Lab, 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 JSK Lab, 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  * Author: Adam Leeper
00030  * Author: Ryohei Ueda
00031  */
00032 
00033 #ifndef JSK_RVIZ_PLUGINS_TABLET_VIEW_CONTROLLER_H_
00034 #define JSK_RVIZ_PLUGINS_TABLET_VIEW_CONTROLLER_H_
00035 
00036 #include "rviz/view_controller.h"
00037 
00038 #include <ros/subscriber.h>
00039 #include <ros/ros.h>
00040 
00041 #include "view_controller_msgs/CameraPlacement.h"
00042 
00043 #include <OGRE/OgreVector3.h>
00044 #include <OGRE/OgreQuaternion.h>
00045 
00046 namespace rviz {
00047   class SceneNode;
00048   class Shape;
00049   class BoolProperty;
00050   class FloatProperty;
00051   class VectorProperty;
00052   class QuaternionProperty;
00053   class TfFrameProperty;
00054   class EditableEnumProperty;
00055   class RosTopicProperty;
00056 }
00057 
00058 namespace jsk_rviz_plugins
00059 {
00060 
00062 class TabletViewController : public rviz::ViewController
00063 {
00064 Q_OBJECT
00065 public:
00066 
00067   enum { TRANSITION_LINEAR = 0,
00068          TRANSITION_SPHERICAL};
00069 
00070   TabletViewController();
00071   virtual ~TabletViewController();
00072 
00077   virtual void onInitialize();
00078 
00082   virtual void onActivate();
00083 
00084 
00086   void move_focus_and_eye( float x, float y, float z );
00087 
00089   void move_eye( float x, float y, float z );
00090 
00091 
00094   void yaw_pitch_roll( float yaw, float pitch, float roll );
00095 
00096 
00097   virtual void handleMouseEvent(rviz::ViewportMouseEvent& evt);
00098 
00099 
00102   virtual void lookAt( const Ogre::Vector3& point );
00103 
00104 
00106   void orbitCameraTo( const Ogre::Vector3& point);
00107 
00109   void moveEyeWithFocusTo( const Ogre::Vector3& point);
00110 
00112   virtual void reset();
00113 
00119   virtual void mimic( ViewController* source_view );
00120 
00128   virtual void transitionFrom( ViewController* previous_view );
00129 
00130 
00131 protected Q_SLOTS:
00137   virtual void updateAttachedFrame();
00138   
00140   virtual void onDistancePropertyChanged();
00141 
00143   virtual void onFocusPropertyChanged();
00144   
00146   virtual void onEyePropertyChanged();
00147 
00149   virtual void onUpPropertyChanged();
00150 
00151 protected:  //methods
00152 
00155   virtual void update(float dt, float ros_dt);
00156 
00158   void connectPositionProperties();
00159 
00161   void disconnectPositionProperties();
00162 
00166   virtual void onAttachedFrameChanged( const Ogre::Vector3& old_reference_position, const Ogre::Quaternion& old_reference_orientation );
00167 
00170   void updateAttachedSceneNode();
00171 
00172   void cameraPlacementCallback(const view_controller_msgs::CameraPlacementConstPtr &cp_ptr);
00173   //void cameraPlacementTrajectoryCallback(const view_controller_msgs::CameraPlacementTrajectoryConstPtr &cptptr);
00174   void transformCameraPlacementToAttachedFrame(view_controller_msgs::CameraPlacement &cp);
00175 
00176   //void setUpVectorPropertyModeDependent( const Ogre::Vector3 &vector );
00177 
00178   void setPropertiesFromCamera( Ogre::Camera* source_camera );
00179 
00181   void beginNewTransition(const Ogre::Vector3 &eye, const Ogre::Vector3 &focus, const Ogre::Vector3 &up,
00182                           const ros::Duration &transition_time);
00183 
00185   void cancelTransition();
00186 
00188   void updateCamera();
00189 
00190   Ogre::Vector3 fixedFrameToAttachedLocal(const Ogre::Vector3 &v) { return reference_orientation_.Inverse()*(v - reference_position_); }
00191   Ogre::Vector3 attachedLocalToFixedFrame(const Ogre::Vector3 &v) { return reference_position_ + (reference_orientation_*v); }
00192 
00193   float getDistanceFromCameraToFocalPoint(); 
00194 
00195   void publishCurrentPlacement();
00196   void publishMouseEvent(rviz::ViewportMouseEvent& event);
00197   Ogre::Quaternion getOrientation(); 
00198 
00199 protected Q_SLOTS:
00200   void updateTopics();
00201   void updatePublishTopics();
00202   void updateMousePointPublishTopics();
00203 protected:    //members
00204 
00205   ros::NodeHandle nh_;
00206 
00207   rviz::BoolProperty* mouse_enabled_property_;            
00208   rviz::EditableEnumProperty* interaction_mode_property_; 
00209   rviz::BoolProperty* fixed_up_property_;                 
00210 
00211   rviz::FloatProperty* distance_property_;                
00212   rviz::VectorProperty* eye_point_property_;              
00213   rviz::VectorProperty* focus_point_property_;            
00214   rviz::VectorProperty* up_vector_property_;              
00215   rviz::FloatProperty* default_transition_time_property_; 
00216 
00217   rviz::RosTopicProperty* camera_placement_topic_property_;
00218   rviz::RosTopicProperty* camera_placement_publish_topic_property_;
00219   rviz::RosTopicProperty* mouse_point_publish_topic_property_;
00220 //  rviz::RosTopicProperty* camera_placement_trajectory_topic_property_;
00221 
00222   rviz::TfFrameProperty* attached_frame_property_;
00223   Ogre::SceneNode* attached_scene_node_;
00224 
00225   Ogre::Quaternion reference_orientation_;    
00226   Ogre::Vector3 reference_position_;          
00227 
00228   // Variables used during animation
00229   bool animate_;
00230   Ogre::Vector3 start_position_, goal_position_;
00231   Ogre::Vector3 start_focus_, goal_focus_;
00232   Ogre::Vector3 start_up_, goal_up_;
00233   ros::Time trajectory_start_time_;
00234   ros::Time transition_start_time_;
00235   ros::Duration current_transition_duration_;
00236 
00237   rviz::Shape* focal_shape_;    
00238   bool dragging_;         
00239 
00240   QCursor interaction_disabled_cursor_;         
00241   
00242 //  ros::Subscriber trajectory_subscriber_;
00243   ros::Subscriber placement_subscriber_;
00244 
00245   ros::Publisher placement_publisher_;
00246   
00247   ros::Publisher mouse_point_publisher_;
00248 };
00249 
00250 }  // namespace rviz_animated_view_controller
00251 
00252 #endif // RVIZ_ANIMATED_VIEW_CONTROLLER_H


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sun Sep 13 2015 22:29:03