Gazebo Rendering

API Reference

6.7.0
gz/rendering/Camera.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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 GZ_RENDERING_CAMERA_HH_
18 #define GZ_RENDERING_CAMERA_HH_
19 
20 #include <string>
21 
22 #include <gz/common/Event.hh>
23 #include <gz/math/Matrix4.hh>
24 
25 #include "gz/rendering/config.hh"
26 #include "gz/rendering/Image.hh"
29 #include "gz/rendering/Sensor.hh"
30 #include "gz/rendering/Scene.hh"
31 
32 
33 namespace ignition
34 {
35  namespace rendering
36  {
37  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
38  //
40  enum IGNITION_RENDERING_VISIBLE CameraProjectionType
41  {
46  };
47 
50  class IGNITION_RENDERING_VISIBLE Camera :
51  public virtual Sensor
52  {
54  public: typedef std::function<void(const void*, unsigned int,
55  unsigned int, unsigned int, const std::string&)> NewFrameListener;
56 
58  public: virtual ~Camera() { }
59 
62  public: virtual unsigned int ImageWidth() const = 0;
63 
66  public: virtual void SetImageWidth(unsigned int _width) = 0;
67 
70  public: virtual unsigned int ImageHeight() const = 0;
71 
74  public: virtual void SetImageHeight(unsigned int _height) = 0;
75 
79  public: virtual PixelFormat ImageFormat() const = 0;
80 
83  public: virtual void SetImageFormat(PixelFormat _format) = 0;
84 
87  public: virtual unsigned int ImageMemorySize() const = 0;
88 
91  public: virtual math::Angle HFOV() const = 0;
92 
95  public: virtual void SetHFOV(const math::Angle &_hfov) = 0;
96 
99  public: virtual double AspectRatio() const = 0;
100 
105  public: virtual void SetAspectRatio(const double _ratio) = 0;
106 
107  // TODO(anyone): add auto-aspect ratio
108 
111  public: virtual unsigned int AntiAliasing() const = 0;
112 
118  public: virtual void SetAntiAliasing(const unsigned int _aa) = 0;
119 
122  public: virtual double FarClipPlane() const = 0;
123 
126  public: virtual void SetFarClipPlane(const double _far) = 0;
127 
130  public: virtual double NearClipPlane() const = 0;
131 
134  public: virtual void SetNearClipPlane(const double _near) = 0;
135 
139  public: virtual void Render() = 0;
140 
145  public: virtual void PostRender() = 0;
146 
149  // \return visual for that position, null if no visual was found
150  public: virtual VisualPtr VisualAt(const gz::math::Vector2i
151  &_mousePos) = 0;
152 
158  public: virtual void Update() = 0;
159 
165  public: virtual Image CreateImage() const = 0;
166 
173  public: virtual void Capture(Image &_image) = 0;
174 
180  public: virtual void Copy(Image &_image) const = 0;
181 
192  public: bool CopyTo(const PixelBuffer &_buffer) const;
193 
199  public: virtual bool SaveFrame(const std::string &_name) = 0;
200 
204  NewFrameListener _listener) = 0;
205 
208  public: virtual RenderWindowPtr CreateRenderWindow() = 0;
209 
212  public: virtual math::Matrix4d ProjectionMatrix() const = 0;
213 
216  public: virtual math::Matrix4d ViewMatrix() const = 0;
217 
221  public: virtual void SetProjectionMatrix(const math::Matrix4d &_matrix)
222  = 0;
223 
226  public: virtual CameraProjectionType ProjectionType() const = 0;
227 
236  public: virtual void SetProjectionType(CameraProjectionType _type) = 0;
237 
241  public: virtual math::Vector2i Project(const math::Vector3d &_pt) const
242  = 0;
243 
256  public: virtual void SetTrackTarget(const NodePtr &_target,
257  const math::Vector3d &_offset = math::Vector3d::Zero,
258  const bool _worldFrame = false) = 0;
259 
262  public: virtual NodePtr TrackTarget() const = 0;
263 
268  public: virtual void SetTrackOffset(const math::Vector3d &_offset) = 0;
269 
273  public: virtual math::Vector3d TrackOffset() const = 0;
274 
278  public: virtual void SetTrackPGain(const double _pGain) = 0;
279 
282  public: virtual double TrackPGain() const = 0;
283 
295  public: virtual void SetFollowTarget(const NodePtr &_target,
296  const math::Vector3d &_offset = math::Vector3d::Zero,
297  const bool _worldFrame = false) = 0;
298 
301  public: virtual NodePtr FollowTarget() const = 0;
302 
307  public: virtual void SetFollowOffset(const math::Vector3d &_offset) = 0;
308 
312  public: virtual math::Vector3d FollowOffset() const = 0;
313 
317  public: virtual void SetFollowPGain(const double _pGain) = 0;
318 
321  public: virtual double FollowPGain() const = 0;
322 
325  public: virtual void SetMaterial(const MaterialPtr &_material) = 0;
326 
331  public: virtual unsigned int RenderTextureGLId() const = 0;
332 
335  public: virtual void AddRenderPass(const RenderPassPtr &_pass) = 0;
336 
339  public: virtual void RemoveRenderPass(const RenderPassPtr &_pass) = 0;
340 
343  public: virtual unsigned int RenderPassCount() const = 0;
344 
347  public: virtual RenderPassPtr RenderPassByIndex(unsigned int _index)
348  const = 0;
349 
352  public: virtual void SetShadowsDirty() = 0;
353  };
354  }
355  }
356 }
357 #endif
static const Vector3 Zero
Posable camera used for rendering the scene graph.
Definition: gz/rendering/Camera.hh:52
virtual unsigned int ImageWidth() const =0
Get the image width in pixels.
virtual double NearClipPlane() const =0
Get the camera's near clipping plane distance.
virtual math::Angle HFOV() const =0
Get the camera's horizontal field-of-view.
virtual double FarClipPlane() const =0
Get the camera's far clipping plane distance.
virtual PixelFormat ImageFormat() const =0
Get the image pixel format. If the image pixel format has not been set with a valid value,...
virtual RenderWindowPtr CreateRenderWindow()=0
Create a render window.
virtual void SetFollowOffset(const math::Vector3d &_offset)=0
Set offset of camera from target node being followed. The offset will be in the frame that is specifi...
virtual void RemoveRenderPass(const RenderPassPtr &_pass)=0
Remove a render pass from the camera.
virtual void Update()=0
Renders a new frame. This is a convenience function for single-camera scenes. It wraps the pre-render...
bool CopyTo(const PixelBuffer &_buffer) const
Writes the last rendered image into a caller owned buffer, for example a message payload,...
virtual RenderPassPtr RenderPassByIndex(unsigned int _index) const =0
Get a render passes by index.
virtual void SetTrackPGain(const double _pGain)=0
Set track P Gain. Determines how fast the camera rotates to look at the target node....
virtual void AddRenderPass(const RenderPassPtr &_pass)=0
Add a render pass to the camera.
virtual bool SaveFrame(const std::string &_name)=0
Writes the previously rendered frame to a file. This function can be called multiple times after Post...
virtual void SetTrackTarget(const NodePtr &_target, const math::Vector3d &_offset=math::Vector3d::Zero, const bool _worldFrame=false)=0
Set a node for camera to track. The camera will automatically change its orientation to face the targ...
virtual math::Matrix4d ViewMatrix() const =0
Get the view matrix for this camera.
virtual void SetHFOV(const math::Angle &_hfov)=0
Set the camera's horizontal field-of-view.
virtual unsigned int RenderPassCount() const =0
Get the number of render passes applied to the camera.
virtual math::Vector2i Project(const math::Vector3d &_pt) const =0
Project point in 3d world space to 2d screen space.
virtual double FollowPGain() const =0
Get the camera follow movement P gain.
virtual void SetShadowsDirty()=0
virtual void SetMaterial(const MaterialPtr &_material)=0
Set a material that the camera should see on all objects.
virtual void Capture(Image &_image)=0
Renders a new frame and writes the results to the given image. This is a convenience function for sin...
virtual void SetImageFormat(PixelFormat _format)=0
Set the image pixel format.
virtual math::Vector3d FollowOffset() const =0
Get the follow offset vector in the frame specified at the time the follow target is set.
virtual double TrackPGain() const =0
Get the camera track rotation P gain.
virtual void SetFarClipPlane(const double _far)=0
Set the camera's far clipping plane distance.
virtual math::Vector3d TrackOffset() const =0
Get the track offset vector in the frame specified at the time the track target is set.
virtual unsigned int RenderTextureGLId() const =0
Get the OpenGL texture id associated with the render texture used by this camera. A valid id is retur...
virtual ~Camera()
Deconstructor.
Definition: gz/rendering/Camera.hh:58
virtual void SetImageHeight(unsigned int _height)=0
Set the image height in pixels.
virtual void SetNearClipPlane(const double _near)=0
Set the camera's near clipping plane distance.
virtual Image CreateImage() const =0
Created an empty image buffer for capturing images. The resulting image will have sufficient memory a...
std::function< void(const void *, unsigned int, unsigned int, unsigned int, const std::string &)> NewFrameListener
Callback function for new frame render event listeners.
Definition: gz/rendering/Camera.hh:55
virtual NodePtr TrackTarget() const =0
Get the target node being tracked.
virtual void SetProjectionType(CameraProjectionType _type)=0
Set the projection type for this camera This changes the projection matrix of the camera based on the...
virtual void SetAntiAliasing(const unsigned int _aa)=0
Set the level of anti-aliasing used during rendering. If a value of 0 is given, no anti-aliasing will...
virtual void SetProjectionMatrix(const math::Matrix4d &_matrix)=0
Set the projection matrix for this camera. This overrides the standard projection matrix computed bas...
virtual void SetTrackOffset(const math::Vector3d &_offset)=0
Set track offset. Camera will track a point that's at an offset from the target node....
virtual void Copy(Image &_image) const =0
Writes the last rendered image to the given image buffer. This function can be called multiple times ...
virtual void SetImageWidth(unsigned int _width)=0
Set the image width in pixels.
virtual unsigned int ImageMemorySize() const =0
Get the total image memory size in bytes.
virtual common::ConnectionPtr ConnectNewImageFrame(NewFrameListener _listener)=0
Subscribes a new listener to this camera's new frame event.
virtual math::Matrix4d ProjectionMatrix() const =0
Get the projection matrix for this camera.
virtual void SetAspectRatio(const double _ratio)=0
Set the camera's aspect ratio. This value determines the cameras vertical field-of-view....
virtual void SetFollowPGain(const double _pGain)=0
Set follow P Gain. Determines how fast the camera moves to follow the target node....
virtual unsigned int AntiAliasing() const =0
Get the level of anti-aliasing used during rendering.
virtual void Render()=0
Renders the current scene using this camera. This function assumes PreRender() has already been calle...
virtual void SetFollowTarget(const NodePtr &_target, const math::Vector3d &_offset=math::Vector3d::Zero, const bool _worldFrame=false)=0
Set a node for camera to follow. The camera will automatically update its position to keep itself at ...
virtual NodePtr FollowTarget() const =0
Get the target node being followed.
virtual void PostRender()=0
Preforms any necessary final rendering work. Once rendering is complete the camera will alert any lis...
virtual double AspectRatio() const =0
Get the camera's aspect ratio.
virtual CameraProjectionType ProjectionType() const =0
Get the projection type for this camera.
virtual unsigned int ImageHeight() const =0
Get the image height in pixels.
virtual VisualPtr VisualAt(const gz::math::Vector2i &_mousePos)=0
Get the visual for a given mouse position param[in] _mousePos mouse position.
Encapsulates a raw image buffer and relevant properties.
Definition: gz/rendering/Image.hh:40
Non owning, writable view of a caller owned pixel buffer.
Definition: gz/rendering/PixelBuffer.hh:49
Represents a scene sensor. The most obvious example is a camera, but it can be anything that generate...
Definition: gz/rendering/Sensor.hh:34
CameraProjectionType
Enum for projection types.
Definition: gz/rendering/Camera.hh:41
@ CPT_PERSPECTIVE
Perspective projection.
Definition: gz/rendering/Camera.hh:43
@ CPT_ORTHOGRAPHIC
Orthographic projection.
Definition: gz/rendering/Camera.hh:45
PixelFormat
Image pixel format types.
Definition: gz/rendering/PixelFormat.hh:33