17 #ifndef GAZEBO_RENDERING_CAMERA_HH_
18 #define GAZEBO_RENDERING_CAMERA_HH_
23 #include <boost/enable_shared_from_this.hpp>
30 #include <ignition/math/Angle.hh>
31 #include <ignition/math/Color.hh>
32 #include <ignition/math/Pose3.hh>
33 #include <ignition/math/Quaternion.hh>
34 #include <ignition/math/Vector2.hh>
35 #include <ignition/math/Vector3.hh>
47 #include "gazebo/msgs/MessageTypes.hh"
82 public boost::enable_shared_from_this<Camera>
89 bool _autoRender =
true);
96 public:
virtual void Load(sdf::ElementPtr _sdf);
99 public:
virtual void Load();
102 public:
virtual void Init();
106 public:
void SetRenderRate(
const double _hz);
110 public:
double RenderRate()
const;
117 public:
virtual void Render(
const bool _force =
false);
122 public:
virtual void PostRender();
129 public:
virtual void Update();
134 public:
virtual void Fini();
138 public:
bool Initialized()
const;
143 public:
void SetWindowId(
unsigned int _windowId);
147 public:
unsigned int WindowId()
const;
151 public:
void SetScene(
ScenePtr _scene);
155 public: ignition::math::Vector3d WorldPosition()
const;
159 public: ignition::math::Quaterniond WorldRotation()
const;
163 public:
virtual void SetWorldPose(
const ignition::math::Pose3d &_pose);
167 public: ignition::math::Pose3d WorldPose()
const;
171 public:
void SetWorldPosition(
const ignition::math::Vector3d &_pos);
175 public:
void SetWorldRotation(
const ignition::math::Quaterniond &_quat);
179 public:
void Translate(
const ignition::math::Vector3d &_direction);
185 public:
void Roll(
const ignition::math::Angle &_angle,
192 public:
void Pitch(
const ignition::math::Angle &_angle,
199 public:
void Yaw(
const ignition::math::Angle &_angle,
205 public:
virtual void SetClipDist(
const float _near,
const float _far);
209 public:
void SetHFOV(
const ignition::math::Angle &_angle);
213 public: ignition::math::Angle HFOV()
const;
217 public: ignition::math::Angle VFOV()
const;
222 public:
void SetImageSize(
const unsigned int _w,
const unsigned int _h);
226 public:
void SetImageWidth(
const unsigned int _w);
230 public:
void SetImageHeight(
const unsigned int _h);
234 public:
virtual unsigned int ImageWidth()
const;
238 public:
unsigned int TextureWidth()
const;
242 public:
virtual unsigned int ImageHeight()
const;
246 public:
unsigned int ImageDepth()
const;
250 public: std::string ImageFormat()
const;
254 public:
unsigned int TextureHeight()
const;
258 public:
size_t ImageByteSize()
const;
265 public:
static size_t ImageByteSize(
const unsigned int _width,
266 const unsigned int _height,
267 const std::string &_format);
274 public:
double ZValue(
const int _x,
const int _y);
278 public:
double NearClip()
const;
282 public:
double FarClip()
const;
286 public:
void EnableSaveFrame(
const bool _enable);
290 public:
bool CaptureData()
const;
294 public:
void SetSaveFramePathname(
const std::string &_pathname);
299 public:
bool SaveFrame(
const std::string &_filename);
303 public: Ogre::Camera *OgreCamera()
const;
307 public: Ogre::Viewport *OgreViewport()
const;
311 public:
unsigned int ViewportWidth()
const;
315 public:
unsigned int ViewportHeight()
const;
319 public: ignition::math::Vector3d Up()
const;
323 public: ignition::math::Vector3d Right()
const;
327 public:
virtual float AvgFPS()
const;
331 public:
virtual unsigned int TriangleCount()
const;
335 public:
void SetAspectRatio(
float _ratio);
339 public:
float AspectRatio()
const;
343 public:
void SetSceneNode(Ogre::SceneNode *_node);
347 public: Ogre::SceneNode *SceneNode()
const;
354 public:
virtual const unsigned char *ImageData(
const unsigned int i = 0)
359 public: std::string Name()
const;
363 public: std::string ScopedName()
const;
367 public:
void SetName(
const std::string &_name);
370 public:
void ToggleShowWireframe();
374 public:
void ShowWireframe(
const bool _s);
378 public:
void SetCaptureData(
const bool _value);
381 public:
void SetCaptureDataOnce();
396 public:
bool StartVideo(
const std::string &_format,
397 const std::string &_filename =
"");
403 public:
bool StopVideo();
410 public:
bool SaveVideo(
const std::string &_filename);
418 public:
bool ResetVideo();
422 public:
void CreateRenderTexture(
const std::string &_textureName);
434 public:
bool WorldPointOnPlane(
const int _x,
const int _y,
435 const ignition::math::Planed &_plane,
436 ignition::math::Vector3d &_result);
445 public:
virtual void CameraToViewportRay(
const int _screenx,
447 ignition::math::Vector3d &_origin,
448 ignition::math::Vector3d &_dir)
const;
452 public:
virtual void SetRenderTarget(Ogre::RenderTarget *_target);
462 public:
void AttachToVisual(
const std::string &_visualName,
463 const bool _inheritOrientation,
464 const double _minDist = 0.0,
const double _maxDist = 0.0);
474 public:
void AttachToVisual(uint32_t _id,
475 const bool _inheritOrientation,
476 const double _minDist = 0.0,
const double _maxDist = 0.0);
480 public:
void TrackVisual(
const std::string &_visualName);
484 public: Ogre::Texture *RenderTexture()
const;
488 public: ignition::math::Vector3d Direction()
const;
495 std::function<
void (
const unsigned char *,
unsigned int,
unsigned int,
496 unsigned int,
const std::string &)> _subscriber);
506 public:
static bool SaveFrame(
const unsigned char *_image,
507 const unsigned int _width,
const unsigned int _height,
508 const int _depth,
const std::string &_format,
509 const std::string &_filename);
519 public:
bool IsVisible(
VisualPtr _visual);
525 public:
bool IsVisible(
const std::string &_visualName);
528 public:
bool IsAnimating()
const;
534 public:
virtual bool MoveToPosition(
const ignition::math::Pose3d &_pose,
544 public:
bool MoveToPositions(
545 const std::vector<ignition::math::Pose3d> &_pts,
547 std::function<
void()> _onComplete =
NULL);
551 public: std::string ScreenshotPath()
const;
562 public:
virtual bool SetProjectionType(
const std::string &_type);
567 public: std::string ProjectionType()
const;
573 public:
virtual bool SetBackgroundColor(
const common::Color &_color)
579 public:
virtual bool SetBackgroundColor(
580 const ignition::math::Color &_color);
584 public: ignition::math::Matrix4d ProjectionMatrix()
const;
589 public:
virtual ignition::math::Vector2i Project(
590 const ignition::math::Vector3d &_pt)
const;
599 public:
bool TrackIsStatic()
const;
605 public:
void SetTrackIsStatic(
const bool _isStatic);
611 public:
bool TrackUseModelFrame()
const;
618 public:
void SetTrackUseModelFrame(
const bool _useModelFrame);
623 public: ignition::math::Vector3d TrackPosition()
const;
628 public:
void SetTrackPosition(
const ignition::math::Vector3d &_pos);
633 public:
double TrackMinDistance()
const;
638 public:
double TrackMaxDistance()
const;
644 public:
void SetTrackMinDistance(
const double _dist);
650 public:
void SetTrackMaxDistance(
const double _dist);
657 public:
bool TrackInheritYaw()
const;
664 public:
void SetTrackInheritYaw(
const bool _inheritYaw);
667 protected:
virtual void RenderImpl();
670 protected:
void ReadPixelBuffer();
675 protected:
bool TrackVisualImpl(
const std::string &_visualName);
680 protected:
virtual bool TrackVisualImpl(
VisualPtr _visual);
691 protected:
virtual bool AttachToVisualImpl(
const std::string &_name,
692 const bool _inheritOrientation,
693 const double _minDist = 0,
const double _maxDist = 0);
704 protected:
virtual bool AttachToVisualImpl(uint32_t _id,
705 const bool _inheritOrientation,
706 const double _minDist = 0,
const double _maxDist = 0);
717 protected:
virtual bool AttachToVisualImpl(
VisualPtr _visual,
718 const bool _inheritOrientation,
719 const double _minDist = 0,
const double _maxDist = 0);
723 protected: std::string FrameFilename();
727 protected:
virtual void AnimationComplete();
730 protected:
virtual void UpdateFOV();
733 protected:
virtual void SetClipDist();
741 protected:
virtual void SetFixedYawAxis(
const bool _useFixed,
742 const ignition::math::Vector3d &_fixedAxis =
743 ignition::math::Vector3d::UnitY);
752 private:
void ConvertRGBToBAYER(
unsigned char *_dst,
753 const unsigned char *_src,
const std::string &_format,
754 const int _width,
const int _height);
759 private:
static int OgrePixelFormat(
const std::string &_format);
763 private:
void OnCmdMsg(ConstCameraCmdPtr &_msg);
766 private:
void CreateCamera();
778 protected: sdf::ElementPtr
sdf;
842 unsigned int,
unsigned int,
unsigned int,
865 private: std::unique_ptr<CameraPrivate> dataPtr;
Basic camera sensor.
Definition: Camera.hh:81
common::Time lastRenderWallTime
Time the last frame was rendered.
Definition: Camera.hh:835
ReferenceFrame
Frame of reference.
Definition: RenderTypes.hh:244
bool initialized
True if initialized.
Definition: Camera.hh:852
Ogre::Texture * renderTexture
Texture that receives results from rendering.
Definition: Camera.hh:823
boost::shared_ptr< Distortion > DistortionPtr
Definition: RenderTypes.hh:198
std::string scopedUniqueName
Scene scoped name of the camera with a unique ID.
Definition: Camera.hh:775
unsigned char * saveFrameBuffer
Buffer for a single image frame.
Definition: Camera.hh:799
unsigned char * bayerFrameBuffer
Buffer for a bayer image frame.
Definition: Camera.hh:802
std::string screenshotPath
Path to saved screenshots.
Definition: Camera.hh:808
bool captureDataOnce
True to capture a frame once and save to disk.
Definition: Camera.hh:829
bool captureData
True to capture frames into an image buffer.
Definition: Camera.hh:826
sdf::ElementPtr sdf
Camera's SDF values.
Definition: Camera.hh:778
Ogre::RenderTarget * renderTarget
Target that renders frames.
Definition: Camera.hh:820
Ogre::SceneNode * sceneNode
Scene node that controls camera position and orientation.
Definition: Camera.hh:796
Local frame.
Definition: RenderTypes.hh:247
std::vector< event::ConnectionPtr > connections
The camera's event connections.
Definition: Camera.hh:846
Ogre::Viewport * viewport
Viewport the ogre camera uses.
Definition: Camera.hh:793
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
int imageWidth
Save image width.
Definition: Camera.hh:814
bool newData
True if new data is available.
Definition: Camera.hh:832
unsigned int windowId
ID of the window that the camera is attached to.
Definition: Camera.hh:781
common::Time prevAnimTime
Previous time the camera animation was updated.
Definition: Camera.hh:858
std::string scopedName
Scene scoped name of the camera.
Definition: Camera.hh:772
ScenePtr scene
Pointer to the scene.
Definition: Camera.hh:838
unsigned int saveCount
Number of saved frames.
Definition: Camera.hh:805
std::list< msgs::Request > requests
List of requests.
Definition: Camera.hh:849
unsigned int textureHeight
Height of the render texture.
Definition: Camera.hh:787
int imageHeight
Save image height.
Definition: Camera.hh:817
World frame.
Definition: RenderTypes.hh:253
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
std::function< void()> onAnimationComplete
User callback for when an animation completes.
Definition: Camera.hh:861
#define NULL
Definition: CommonTypes.hh:31
Defines a color.
Definition: Color.hh:36
int imageFormat
Format for saving images.
Definition: Camera.hh:811
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
unsigned int textureWidth
Width of the render texture.
Definition: Camera.hh:784
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
std::string name
Name of the camera.
Definition: Camera.hh:769
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
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:843
A class for event processing.
Definition: Event.hh:97
Ogre::AnimationState * animState
Animation state, used to animate the camera.
Definition: Camera.hh:855
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
Ogre::Camera * camera
The OGRE camera.
Definition: Camera.hh:790