18 #ifndef _GAZEBO_RENDERING_CAMERA_HH_
19 #define _GAZEBO_RENDERING_CAMERA_HH_
21 #include <boost/enable_shared_from_this.hpp>
44 #include "gazebo/msgs/MessageTypes.hh"
85 bool _autoRender =
true);
92 public:
virtual void Load(sdf::ElementPtr _sdf);
95 public:
virtual void Load();
98 public:
virtual void Init();
102 public:
void SetRenderRate(
double _hz);
106 public:
double GetRenderRate()
const;
113 public:
void Render(
bool _force =
false);
118 public:
virtual void PostRender();
125 public:
virtual void Update();
130 public:
virtual void Fini();
134 public:
bool GetInitialized()
const;
139 public:
void SetWindowId(
unsigned int _windowId);
143 public:
unsigned int GetWindowId()
const;
147 public:
void SetScene(
ScenePtr _scene);
159 public:
virtual void SetWorldPose(
const math::Pose &_pose);
183 Ogre::Node::TransformSpace _relativeTo =
184 Ogre::Node::TS_LOCAL);
192 Ogre::Node::TransformSpace _relativeTo =
193 Ogre::Node::TS_LOCAL);
201 Ogre::Node::TransformSpace _relativeTo =
202 Ogre::Node::TS_WORLD);
215 public:
void SetClipDist(
float _near,
float _far);
232 public:
void SetImageSize(
unsigned int _w,
unsigned int _h);
236 public:
void SetImageWidth(
unsigned int _w);
240 public:
void SetImageHeight(
unsigned int _h);
244 public:
virtual unsigned int GetImageWidth()
const;
248 public:
unsigned int GetTextureWidth()
const;
252 public:
virtual unsigned int GetImageHeight()
const;
256 public:
unsigned int GetImageDepth()
const;
260 public: std::string GetImageFormat()
const;
264 public:
unsigned int GetTextureHeight()
const;
268 public:
size_t GetImageByteSize()
const;
275 public:
static size_t GetImageByteSize(
unsigned int _width,
276 unsigned int _height,
277 const std::string &_format);
284 public:
double GetZValue(
int _x,
int _y);
288 public:
double GetNearClip();
292 public:
double GetFarClip();
296 public:
void EnableSaveFrame(
bool _enable);
300 public:
bool GetCaptureData()
const;
304 public:
void SetSaveFramePathname(
const std::string &_pathname);
309 public:
bool SaveFrame(
const std::string &_filename);
313 public: Ogre::Camera *GetOgreCamera()
const;
317 public: Ogre::Viewport *GetViewport()
const;
321 public:
unsigned int GetViewportWidth()
const;
325 public:
unsigned int GetViewportHeight()
const;
345 public:
void SetAspectRatio(
float _ratio);
349 public:
float GetAspectRatio()
const;
353 public:
void SetSceneNode(Ogre::SceneNode *_node);
357 public: Ogre::SceneNode *GetSceneNode()
const;
364 public:
virtual const unsigned char *GetImageData(
unsigned int i = 0);
368 public: std::string GetName()
const;
372 public: std::string GetScopedName()
const;
376 public:
void SetName(
const std::string &_name);
379 public:
void ToggleShowWireframe();
383 public:
void ShowWireframe(
bool _s);
392 public:
void GetCameraToViewportRay(
int _screenx,
int _screeny,
398 public:
void SetCaptureData(
bool _value);
401 public:
void SetCaptureDataOnce();
405 public:
void CreateRenderTexture(
const std::string &_textureName);
417 public:
bool GetWorldPointOnPlane(
int _x,
int _y,
422 public:
virtual void SetRenderTarget(Ogre::RenderTarget *_target);
432 public:
void AttachToVisual(
const std::string &_visualName,
433 bool _inheritOrientation,
434 double _minDist = 0.0,
double _maxDist = 0.0);
444 public:
void AttachToVisual(uint32_t _id,
445 bool _inheritOrientation,
446 double _minDist = 0.0,
double _maxDist = 0.0);
450 public:
void TrackVisual(
const std::string &_visualName);
454 public: Ogre::Texture *GetRenderTexture()
const;
464 public:
template<
typename T>
466 {
return newImageFrame.Connect(_subscriber);}
471 {newImageFrame.Disconnect(_c);}
481 public:
static bool SaveFrame(
const unsigned char *_image,
482 unsigned int _width,
unsigned int _height,
int _depth,
483 const std::string &_format,
484 const std::string &_filename);
495 public:
bool IsVisible(
VisualPtr _visual);
501 public:
bool IsVisible(
const std::string &_visualName);
504 public:
bool IsAnimating()
const;
510 public:
virtual bool MoveToPosition(
const math::Pose &_pose,
520 public:
bool MoveToPositions(
const std::vector<math::Pose> &_pts,
522 boost::function<
void()> _onComplete =
NULL);
526 public: std::string GetScreenshotPath()
const;
533 protected:
virtual void RenderImpl();
536 protected:
void ReadPixelBuffer();
541 protected:
bool TrackVisualImpl(
const std::string &_visualName);
546 protected:
virtual bool TrackVisualImpl(
VisualPtr _visual);
557 protected:
virtual bool AttachToVisualImpl(
const std::string &_name,
558 bool _inheritOrientation,
559 double _minDist = 0,
double _maxDist = 0);
570 protected:
virtual bool AttachToVisualImpl(uint32_t _id,
571 bool _inheritOrientation,
572 double _minDist = 0,
double _maxDist = 0);
583 protected:
virtual bool AttachToVisualImpl(
VisualPtr _visual,
584 bool _inheritOrientation,
585 double _minDist = 0,
double _maxDist = 0);
589 protected: std::string GetFrameFilename();
593 protected:
virtual void AnimationComplete();
602 private:
void ConvertRGBToBAYER(
unsigned char *_dst,
unsigned char *_src,
603 std::string _format,
int _width,
int _height);
606 private:
void SetClipDist();
611 private:
static int GetOgrePixelFormat(
const std::string &_format);
615 private:
void OnCmdMsg(ConstCameraCmdPtr &_msg);
618 private:
void CreateCamera();
630 protected: sdf::ElementPtr
sdf;
694 unsigned int,
unsigned int,
unsigned int,
int imageHeight
Save image height.
Definition: Camera.hh:669
Basic camera sensor.
Definition: Camera.hh:78
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
Ogre::Viewport * viewport
Viewport the ogre camera uses.
Definition: Camera.hh:645
unsigned int saveCount
Number of saved frames.
Definition: Camera.hh:657
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
event::EventT< void(const unsigned char *, unsigned int, unsigned int, unsigned int, const std::string &)> newImageFrame
Event triggered when a new frame is generated.
Definition: Camera.hh:695
virtual float GetAvgFPS() const
Get the average FPS.
Definition: Camera.hh:337
bool captureData
True to capture frames into an image buffer.
Definition: Camera.hh:678
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:44
void DisconnectNewImageFrame(event::ConnectionPtr &_c)
Disconnect from an image frame.
Definition: Camera.hh:470
boost::shared_ptr< Distortion > DistortionPtr
Definition: RenderTypes.hh:162
Ogre::Texture * renderTexture
Texture that receives results from rendering.
Definition: Camera.hh:675
unsigned char * bayerFrameBuffer
Buffer for a bayer image frame.
Definition: Camera.hh:654
bool initialized
True if initialized.
Definition: Camera.hh:704
Ogre::Camera * camera
The OGRE camera.
Definition: Camera.hh:642
Private data for the Camera class.
Definition: CameraPrivate.hh:37
event::ConnectionPtr ConnectNewImageFrame(T _subscriber)
Connect to the new image signal.
Definition: Camera.hh:465
Ogre::SceneNode * sceneNode
Scene node that controls camera position and orientation.
Definition: Camera.hh:648
std::list< msgs::Request > requests
List of requests.
Definition: Camera.hh:701
ScenePtr scene
Pointer to the scene.
Definition: Camera.hh:690
Ogre::RenderTarget * renderTarget
Target that renders frames.
Definition: Camera.hh:672
boost::function< void()> onAnimationComplete
User callback for when an animation completes.
Definition: Camera.hh:713
common::Time lastRenderWallTime
Time the last frame was rendered.
Definition: Camera.hh:687
unsigned int textureHeight
Height of the render texture.
Definition: Camera.hh:639
unsigned char * saveFrameBuffer
Buffer for a single image frame.
Definition: Camera.hh:651
bool captureDataOnce
True to capture a frame once and save to disk.
Definition: Camera.hh:681
A plane and related functions.
Definition: Plane.hh:33
A quaternion class.
Definition: Quaternion.hh:41
bool newData
True if new data is available.
Definition: Camera.hh:684
std::string screenshotPath
Path to saved screenshots.
Definition: Camera.hh:660
unsigned int windowId
ID of the window that the camera is attached to.
Definition: Camera.hh:633
unsigned int textureWidth
Width of the render texture.
Definition: Camera.hh:636
sdf::ElementPtr sdf
Camera's SDF values.
Definition: Camera.hh:630
#define NULL
Definition: CommonTypes.hh:30
int imageFormat
Format for saving images.
Definition: Camera.hh:663
std::string name
Name of the camera.
Definition: Camera.hh:621
std::string scopedName
Scene scoped name of the camera.
Definition: Camera.hh:624
std::vector< event::ConnectionPtr > connections
The camera's event connections.
Definition: Camera.hh:698
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:74
common::Time prevAnimTime
Previous time the camera animation was updated.
Definition: Camera.hh:710
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
A class for event processing.
Definition: Event.hh:156
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
Ogre::AnimationState * animState
Animation state, used to animate the camera.
Definition: Camera.hh:707
An angle and related functions.
Definition: Angle.hh:52
int imageWidth
Save image width.
Definition: Camera.hh:666
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
std::string scopedUniqueName
Scene scoped name of the camera with a unique ID.
Definition: Camera.hh:627
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
virtual unsigned int GetTriangleCount() const
Get the triangle count.
Definition: Camera.hh:341