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 
25 #include "gazebo/math/Pose.hh"
26 #include "gazebo/math/Vector2i.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class MouseEvent;
36  }
37 
38  // Forward declare private data
39  class UserCameraPrivate;
40 
41  namespace rendering
42  {
45 
48  class GZ_RENDERING_VISIBLE UserCamera : public Camera
49  {
55  public: UserCamera(const std::string &_name, ScenePtr _scene,
56  bool _stereoEnabled = false);
57 
59  public: virtual ~UserCamera();
60 
63  public: void Load(sdf::ElementPtr _sdf);
64 
65  // Documentation inherited
66  public: virtual void SetClipDist(const float _near, const float _far);
67  using Camera::SetClipDist;
68 
70  public: void Load();
71 
73  public: void Init();
74 
76  public: virtual void Update();
77 
87  public: virtual void Render(const bool _force = false);
88  using Camera::Render;
89 
91  public: virtual void PostRender();
92 
94  public: void Fini();
95 
96  // Documentation inherited.
99  public: virtual void SetWorldPose(const math::Pose &_pose)
100  GAZEBO_DEPRECATED(8.0);
101 
102  // Documentation inherited.
103  public: virtual void SetWorldPose(const ignition::math::Pose3d &_pose);
104 
109  public: void SetDefaultPose(const math::Pose &_pose)
110  GAZEBO_DEPRECATED(8.0);
111 
115  public: void SetInitialPose(const ignition::math::Pose3d &_pose);
116 
120  public: math::Pose DefaultPose() const GAZEBO_DEPRECATED(8.0);
121 
124  public: ignition::math::Pose3d InitialPose() const;
125 
128  public: void HandleMouseEvent(const common::MouseEvent &_evt);
129 
132  public: void HandleKeyPressEvent(const std::string &_key);
133 
136  public: void HandleKeyReleaseEvent(const std::string &_key);
137 
140  public: void SetViewController(const std::string &_type);
141 
145  public: void SetViewController(const std::string &_type,
146  const ignition::math::Vector3d &_pos);
147 
148 
153  public: void SetViewController(const std::string &_type,
154  const math::Vector3 &_pos) GAZEBO_DEPRECATED(8.0);
155 
158  public: std::string GetViewControllerTypeString();
159 
163  public: void Resize(unsigned int _w, unsigned int _h);
164 
170  public: void SetViewportDimensions(float _x, float _y,
171  float _w, float _h);
172 
175  public: void MoveToVisual(VisualPtr _visual);
176 
179  public: void MoveToVisual(const std::string &_visualName);
180 
183  public: void SetDevicePixelRatio(const double _ratio);
184 
187  public: double DevicePixelRatio() const;
188 
189  // Documentation Inherited
190  public: virtual void CameraToViewportRay(const int _screenx,
191  const int _screeny,
192  ignition::math::Vector3d &_origin,
193  ignition::math::Vector3d &_dir) const;
194 
199  public: virtual void SetRenderTarget(Ogre::RenderTarget *_target);
200 
206  public: void EnableViewController(bool _value) const;
207 
215  public: VisualPtr GetVisual(const math::Vector2i &_mousePos,
216  std::string &_mod) GAZEBO_DEPRECATED(8.0);
217 
222  public: VisualPtr GetVisual(const math::Vector2i &_mousePos) const
223  GAZEBO_DEPRECATED(8.0);
224 
229  public: void SetFocalPoint(const math::Vector3 &_pt)
230  GAZEBO_DEPRECATED(8.0);
231 
237  public: VisualPtr Visual(const ignition::math::Vector2i &_mousePos,
238  std::string &_mod) const;
239 
243  public: VisualPtr Visual(
244  const ignition::math::Vector2i &_mousePos) const;
245 
248  public: void SetFocalPoint(const ignition::math::Vector3d &_pt);
249 
250  // Documentation inherited
251  public: virtual unsigned int GetImageWidth() const;
252 
253  // Documentation inherited
254  public: virtual unsigned int GetImageHeight() const;
255 
258  public: bool IsCameraSetInWorldFile();
259 
262  public: void SetUseSDFPose(bool _value);
263 
268  public: void SetJoyTwistControl(bool _value);
269 
274  public: void SetJoyPoseControl(bool _value);
275 
278  public: bool StereoEnabled() const;
279 
287  public: void EnableStereo(bool _enable);
288 
289  // Documentation inherited.
290  public: virtual bool SetProjectionType(const std::string &_type);
291 
292  // Documentation inherited.
293  public: virtual ignition::math::Vector2i Project(
294  const ignition::math::Vector3d &_pt) const;
295 
307  protected: virtual bool AttachToVisualImpl(VisualPtr _visual,
308  const bool _inheritOrientation, const double _minDist = 0,
309  const double _maxDist = 0);
311 
312  // Documentation inherited.
313  protected: virtual void AnimationComplete();
314 
320  protected: virtual bool TrackVisualImpl(VisualPtr _visual);
321 
322  // Documentation inherited.
323  protected: virtual void UpdateFOV();
324 
326  private: void ToggleShowVisual();
327 
331  private: void ShowVisual(bool _show);
332 
335  private: void OnMoveToVisualComplete();
336 
341  private: void OnJoyTwist(ConstJoystickPtr &_msg);
342 
347  private: void OnJoyPose(ConstPosePtr &_msg);
348 
351  private: UserCameraPrivate *dataPtr;
352  };
354  }
355 }
356 #endif
Basic camera sensor.
Definition: Camera.hh:85
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
Generic integer x, y vector.
Definition: Vector2i.hh:36
A camera used for user visualization of a scene.
Definition: UserCamera.hh:48
A renderable object.
Definition: Visual.hh:63
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
virtual void Render(const bool _force=false)
Render the camera.
virtual void SetClipDist()
Set the clip distance based on stored SDF values.
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
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.