UserCamera.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GAZEBO_RENDERING_USERCAMERA_HH_
18 #define GAZEBO_RENDERING_USERCAMERA_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <ignition/math/Pose3.hh>
23 #include <ignition/math/Vector2.hh>
24 
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  class MouseEvent;
34  }
35 
36  // Forward declare private data
37  class UserCameraPrivate;
38 
39  namespace rendering
40  {
43 
46  class GZ_RENDERING_VISIBLE UserCamera : public Camera
47  {
53  public: UserCamera(const std::string &_name, ScenePtr _scene,
54  bool _stereoEnabled = false);
55 
57  public: virtual ~UserCamera();
58 
61  public: void Load(sdf::ElementPtr _sdf);
62 
63  // Documentation inherited
64  public: virtual void SetClipDist(const float _near, const float _far);
65  using Camera::SetClipDist;
66 
68  public: void Load();
69 
71  public: void Init();
72 
74  public: virtual void Update();
75 
85  public: virtual void Render(const bool _force = false);
86  using Camera::Render;
87 
89  public: virtual void PostRender();
90 
92  public: void Fini();
93 
94  // Documentation inherited.
95  public: virtual void SetWorldPose(const ignition::math::Pose3d &_pose);
96 
100  public: void SetInitialPose(const ignition::math::Pose3d &_pose);
101 
104  public: ignition::math::Pose3d InitialPose() const;
105 
108  public: void HandleMouseEvent(const common::MouseEvent &_evt);
109 
112  public: void HandleKeyPressEvent(const std::string &_key);
113 
116  public: void HandleKeyReleaseEvent(const std::string &_key);
117 
120  public: void SetViewController(const std::string &_type);
121 
125  public: void SetViewController(const std::string &_type,
126  const ignition::math::Vector3d &_pos);
127 
130  public: std::string GetViewControllerTypeString();
131 
135  public: void Resize(unsigned int _w, unsigned int _h);
136 
142  public: void SetViewportDimensions(float _x, float _y,
143  float _w, float _h);
144 
147  public: void MoveToVisual(VisualPtr _visual);
148 
151  public: void MoveToVisual(const std::string &_visualName);
152 
155  public: void SetDevicePixelRatio(const double _ratio);
156 
159  public: double DevicePixelRatio() const;
160 
161  // Documentation Inherited
162  public: virtual void CameraToViewportRay(const int _screenx,
163  const int _screeny,
164  ignition::math::Vector3d &_origin,
165  ignition::math::Vector3d &_dir) const;
166 
171  public: virtual void SetRenderTarget(Ogre::RenderTarget *_target);
172 
178  public: void EnableViewController(bool _value) const;
179 
185  public: VisualPtr Visual(const ignition::math::Vector2i &_mousePos,
186  std::string &_mod) const;
187 
191  public: VisualPtr Visual(
192  const ignition::math::Vector2i &_mousePos) const;
193 
196  public: void SetFocalPoint(const ignition::math::Vector3d &_pt);
197 
198  // Documentation inherited
199  public: virtual unsigned int GetImageWidth() const;
200 
201  // Documentation inherited
202  public: virtual unsigned int GetImageHeight() const;
203 
206  public: bool IsCameraSetInWorldFile();
207 
210  public: void SetUseSDFPose(bool _value);
211 
216  public: void SetJoyTwistControl(bool _value);
217 
222  public: void SetJoyPoseControl(bool _value);
223 
226  public: bool StereoEnabled() const;
227 
235  public: void EnableStereo(bool _enable);
236 
237  // Documentation inherited.
238  public: virtual bool SetProjectionType(const std::string &_type);
239 
240  // Documentation inherited.
241  public: virtual ignition::math::Vector2i Project(
242  const ignition::math::Vector3d &_pt) const;
243 
255  protected: virtual bool AttachToVisualImpl(VisualPtr _visual,
256  const bool _inheritOrientation, const double _minDist = 0,
257  const double _maxDist = 0);
259 
260  // Documentation inherited.
261  protected: virtual void AnimationComplete();
262 
268  protected: virtual bool TrackVisualImpl(VisualPtr _visual);
269 
270  // Documentation inherited.
271  protected: virtual void UpdateFOV();
272 
274  private: void ToggleShowVisual();
275 
279  private: void ShowVisual(bool _show);
280 
283  private: void OnMoveToVisualComplete();
284 
289  private: void OnJoyTwist(ConstJoystickPtr &_msg);
290 
295  private: void OnJoyPose(ConstPosePtr &_msg);
296 
299  private: UserCameraPrivate *dataPtr;
300  };
302  }
303 }
304 #endif
void EnableViewController(bool _value) const
Set whether the view controller is enabled.
void HandleKeyReleaseEvent(const std::string &_key)
Handle a key release.
virtual unsigned int GetImageWidth() const
void SetInitialPose(const ignition::math::Pose3d &_pose)
Set the initial pose in the world coordinate frame and set that as the current camera world pose.
Forward declarations for the common classes.
Definition: Animation.hh:27
void SetFocalPoint(const ignition::math::Vector3d &_pt)
Set the point the camera should orbit around.
virtual bool AttachToVisualImpl(VisualPtr _visual, const bool _inheritOrientation, const double _minDist=0, const double _maxDist=0)
Set the camera to be attached to a visual.
void Init()
Initialize.
void Resize(unsigned int _w, unsigned int _h)
Resize the camera.
void HandleMouseEvent(const common::MouseEvent &_evt)
Handle a mouse event.
common
Definition: FuelModelDatabase.hh:37
VisualPtr Visual(const ignition::math::Vector2i &_mousePos) const
Get a visual at a mouse position.
VisualPtr Visual(const ignition::math::Vector2i &_mousePos, std::string &_mod) const
Get an entity at a pixel location using a camera.
virtual void PostRender()
Post render.
virtual ~UserCamera()
Destructor.
void Load()
Generic load function.
A camera used for user visualization of a scene.
Definition: UserCamera.hh:47
void SetViewportDimensions(float _x, float _y, float _w, float _h)
Set the dimensions of the viewport.
void SetJoyPoseControl(bool _value)
brief Enable or disable camera control through ~/user_camera/joy_pose gz topic.
void HandleKeyPressEvent(const std::string &_key)
Handle a key press.
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
void SetJoyTwistControl(bool _value)
brief Enable or disable camera control through ~/user_camera/joy_twist gz topic.
void SetViewController(const std::string &_type, const ignition::math::Vector3d &_pos)
Set view controller.
virtual void UpdateFOV()
Update the camera's field of view.
virtual bool AttachToVisualImpl(const std::string &_name, const bool _inheritOrientation, const double _minDist=0, const double _maxDist=0)
Attach the camera to a scene node.
rendering
Definition: RenderEngine.hh:31
virtual bool SetProjectionType(const std::string &_type)
Set the type of projection used by the camera.
virtual void Render(const bool _force=false)
Render the camera.
virtual unsigned int GetImageHeight() const
void SetViewController(const std::string &_type)
Set view controller.
virtual void Update()
Render the camera.
virtual void CameraToViewportRay(const int _screenx, const int _screeny, ignition::math::Vector3d &_origin, ignition::math::Vector3d &_dir) const
Get a world space ray as cast from the camera through the viewport.
void MoveToVisual(const std::string &_visualName)
Move the camera to focus on a visual.
bool IsCameraSetInWorldFile()
brief Show if the user camera pose has changed in the world file.
bool StereoEnabled() const
Get whether stereo is enabled.
void MoveToVisual(VisualPtr _visual)
Move the camera to focus on a visual.
virtual void Render(const bool _force=false)
Render the camera.
virtual void SetClipDist(const float _near, const float _far)
Set the clip distances.
virtual void SetClipDist()
Set the clip distance based on stored SDF values.
void Fini()
Finialize.
void EnableStereo(bool _enable)
Turn on/off stereo rendering.
virtual bool TrackVisualImpl(VisualPtr _visual)
Set the camera to track a scene node.
virtual void SetRenderTarget(Ogre::RenderTarget *_target)
Set to true to enable rendering.
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
void Load(sdf::ElementPtr _sdf)
Load the user camera.
virtual ignition::math::Vector2i Project(const ignition::math::Vector3d &_pt) const
Project 3D world coordinates to 2D screen coordinates.
Basic camera sensor.
Definition: Camera.hh:86
virtual void AnimationComplete()
Internal function used to indicate that an animation has completed.
void SetDevicePixelRatio(const double _ratio)
Set the screen point to device pixel ratio.
std::string GetViewControllerTypeString()
Get current view controller type.
ignition::math::Pose3d InitialPose() const
Get the initial pose in the world coordinate frame.
void SetUseSDFPose(bool _value)
brief Set if the user camera pose has changed in the world file.
Generic description of a mouse event.
Definition: MouseEvent.hh:36
virtual void SetWorldPose(const ignition::math::Pose3d &_pose)
Set the global pose of the camera.
double DevicePixelRatio() const
Get the screen point to device pixel ratio.
UserCamera(const std::string &_name, ScenePtr _scene, bool _stereoEnabled=false)
Constructor.