rviz_animated_view_controller.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Author: Adam Leeper
30  */
31 
32 #ifndef RVIZ_ANIMATED_VIEW_CONTROLLER_H
33 #define RVIZ_ANIMATED_VIEW_CONTROLLER_H
34 
35 #include <boost/circular_buffer.hpp>
36 
37 #include <cv_bridge/cv_bridge.h>
38 
40 
41 #include "rviz/view_controller.h"
42 #include "rviz/view_manager.h"
43 #include "rviz/render_panel.h"
44 
45 #include <ros/subscriber.h>
46 #include <ros/ros.h>
47 
48 #include <geometry_msgs/Pose.h>
49 
50 #include <std_msgs/Bool.h>
51 #include <std_msgs/Duration.h>
52 
53 #include <view_controller_msgs/CameraMovement.h>
54 #include <view_controller_msgs/CameraPlacement.h>
55 #include <view_controller_msgs/CameraTrajectory.h>
56 
57 #include <OGRE/OgreRenderWindow.h>
58 #include <OGRE/OgreVector3.h>
59 #include <OGRE/OgreQuaternion.h>
60 
61 namespace rviz {
62  class SceneNode;
63  class Shape;
64  class BoolProperty;
65  class FloatProperty;
66  class VectorProperty;
67  class QuaternionProperty;
68  class TfFrameProperty;
69  class EditableEnumProperty;
70  class RosTopicProperty;
71 }
72 
74 {
75 
78 {
79 Q_OBJECT
80 public:
81 
82  enum { TRANSITION_LINEAR = 0,
83  TRANSITION_SPHERICAL};
84 
86  {
88 
89  OgreCameraMovement(const Ogre::Vector3& eye,
90  const Ogre::Vector3& focus,
91  const Ogre::Vector3& up,
92  const ros::Duration& transition_duration,
93  const uint8_t interpolation_speed)
94  : eye(eye)
95  , focus(focus)
96  , up(up)
97  , transition_duration(transition_duration)
98  , interpolation_speed(interpolation_speed)
99  {
100  }
101 
102  Ogre::Vector3 eye;
103  Ogre::Vector3 focus;
104  Ogre::Vector3 up;
105 
108  };
109 
110  typedef boost::circular_buffer<OgreCameraMovement> BufferCamMovements;
111 
113  virtual ~AnimatedViewController();
114 
115  void initializePublishers();
116  void initializeSubscribers();
117 
122  virtual void onInitialize();
123 
127  virtual void onActivate();
128 
129 
131  void move_focus_and_eye( float x, float y, float z );
132 
134  void move_eye( float x, float y, float z );
135 
136 
139  void yaw_pitch_roll( float yaw, float pitch, float roll );
140 
141 
142  virtual void handleMouseEvent(rviz::ViewportMouseEvent& evt);
143 
145  void publishCameraPose();
146 
149  virtual void lookAt( const Ogre::Vector3& point );
150 
151 
153  void orbitCameraTo( const Ogre::Vector3& point);
154 
156  void moveEyeWithFocusTo( const Ogre::Vector3& point);
157 
159  virtual void reset();
160 
166  virtual void mimic( ViewController* source_view );
167 
175  virtual void transitionFrom( ViewController* previous_view );
176 
177 
178 protected Q_SLOTS:
184  virtual void updateAttachedFrame();
185 
187  virtual void onDistancePropertyChanged();
188 
190  virtual void onFocusPropertyChanged();
191 
193  virtual void onEyePropertyChanged();
194 
196  virtual void onUpPropertyChanged();
197 
198 protected: //methods
199  void updateWindowSizeProperties();
200 
203  virtual void update(float dt, float ros_dt);
204 
210  void pauseAnimationOnRequest();
211 
213  bool isMovementAvailable(){ return cam_movements_buffer_.size() >= 2; };
214 
224  double computeRelativeProgressInTime(const ros::Duration& transition_duration);
225 
247  float computeRelativeProgressInSpace(double relative_progress_in_time,
248  uint8_t interpolation_speed);
249 
251  void publishViewImage();
252 
254  void getViewImage(std::shared_ptr<Ogre::PixelBox>& pixel_box);
255 
256  void convertImage(std::shared_ptr<Ogre::PixelBox> input_image,
257  sensor_msgs::ImagePtr output_image);
258 
260  void prepareNextMovement(const ros::Duration& previous_transition_duration);
261 
263  void connectPositionProperties();
264 
266  void disconnectPositionProperties();
267 
271  virtual void onAttachedFrameChanged( const Ogre::Vector3& old_reference_position, const Ogre::Quaternion& old_reference_orientation );
272 
275  void updateAttachedSceneNode();
276 
277  void cameraPlacementCallback(const view_controller_msgs::CameraPlacementConstPtr &cp_ptr);
278 
283  void cameraTrajectoryCallback(const view_controller_msgs::CameraTrajectoryConstPtr& ct_ptr);
284 
289  void pauseAnimationCallback(const std_msgs::Duration::ConstPtr& pause_duration_msg);
290 
297  void transformCameraToAttachedFrame(geometry_msgs::PointStamped& eye,
298  geometry_msgs::PointStamped& focus,
299  geometry_msgs::Vector3Stamped& up);
300 
301  //void setUpVectorPropertyModeDependent( const Ogre::Vector3 &vector );
302 
303  void setPropertiesFromCamera( Ogre::Camera* source_camera );
304 
313  void beginNewTransition(const Ogre::Vector3& eye,
314  const Ogre::Vector3& focus,
315  const Ogre::Vector3& up,
316  ros::Duration transition_duration,
317  uint8_t interpolation_speed = view_controller_msgs::CameraMovement::WAVE);
318 
320  void cancelTransition();
321 
323  void updateCamera();
324 
325  Ogre::Vector3 fixedFrameToAttachedLocal(const Ogre::Vector3 &v) { return reference_orientation_.Inverse()*(v - reference_position_); }
326  Ogre::Vector3 attachedLocalToFixedFrame(const Ogre::Vector3 &v) { return reference_position_ + (reference_orientation_*v); }
327 
328  float getDistanceFromCameraToFocalPoint();
329 
330  Ogre::Quaternion getOrientation();
331 
332 protected Q_SLOTS:
333  void updateTopics();
334 
335 
336 protected: //members
337 
339 
343 
349 
352 
355 
357 
359  Ogre::SceneNode* attached_scene_node_;
360 
361  Ogre::Quaternion reference_orientation_;
362  Ogre::Vector3 reference_position_;
363 
364  // Variables used during animation
365  bool animate_;
367  BufferCamMovements cam_movements_buffer_;
368 
370  bool dragging_;
371 
373 
377 
381 
385 
387 };
388 
389 } // namespace rviz_animated_view_controller
390 
391 #endif // RVIZ_ANIMATED_VIEW_CONTROLLER_H
Ogre::Quaternion reference_orientation_
Used to store the orientation of the attached frame relative to <Fixed frame>=""> ...
Ogre::Vector3 reference_position_
Used to store the position of the attached frame relative to <Fixed frame>="">
rviz::BoolProperty * mouse_enabled_property_
If True, most user changes to camera state are disabled.
rviz::FloatProperty * distance_property_
The camera&#39;s distance from the focal point.
bool isMovementAvailable()
Returns true if buffer contains at least one start and end pose needed for one movement.
OgreCameraMovement(const Ogre::Vector3 &eye, const Ogre::Vector3 &focus, const Ogre::Vector3 &up, const ros::Duration &transition_duration, const uint8_t interpolation_speed)
rviz::FloatProperty * window_width_property_
The width of the rviz visualization window in pixels.
rviz::BoolProperty * fixed_up_property_
If True, "up" is fixed to ... up.
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
bool dragging_
A flag indicating the dragging state of the mouse.
rviz::BoolProperty * publish_view_images_property_
If True, the camera view is published as images.
rviz::FloatProperty * window_height_property_
The height of the rviz visualization window in pixels.
rviz::EditableEnumProperty * interaction_mode_property_
Select between Orbit or FPS control style.
QCursor interaction_disabled_cursor_
A cursor for indicating mouse interaction is disabled.
rviz::FloatProperty * default_transition_time_property_
A default time for any animation requests.
rviz::VectorProperty * eye_point_property_
The position of the camera.
rviz::Shape * focal_shape_
A small ellipsoid to show the focus point.
rviz::VectorProperty * up_vector_property_
The up vector for the camera.
boost::circular_buffer< OgreCameraMovement > BufferCamMovements
An un-constrained "flying" camera, specified by an eye point, focus point, and up vector...
rviz::VectorProperty * focus_point_property_
The point around which the camera "orbits".


rviz_animated_view_controller
Author(s): Adam Leeper
autogenerated on Mon Feb 28 2022 23:43:34