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/Pose3.hh>
32 #include <ignition/math/Quaternion.hh>
33 #include <ignition/math/Vector2.hh>
34 #include <ignition/math/Vector3.hh>
46 #include "gazebo/msgs/MessageTypes.hh"
86 public boost::enable_shared_from_this<Camera>
93 bool _autoRender =
true);
100 public:
virtual void Load(sdf::ElementPtr _sdf);
103 public:
virtual void Load();
106 public:
virtual void Init();
110 public:
void SetRenderRate(
const double _hz);
114 public:
double RenderRate()
const;
121 public:
virtual void Render(
const bool _force =
false);
126 public:
virtual void PostRender();
133 public:
virtual void Update();
138 public:
virtual void Fini();
142 public:
bool Initialized()
const;
147 public:
void SetWindowId(
unsigned int _windowId);
151 public:
unsigned int WindowId()
const;
155 public:
void SetScene(
ScenePtr _scene);
159 public: ignition::math::Vector3d WorldPosition()
const;
163 public: ignition::math::Quaterniond WorldRotation()
const;
168 public:
virtual void SetWorldPose(
const math::Pose &_pose)
173 public:
virtual void SetWorldPose(
const ignition::math::Pose3d &_pose);
177 public: ignition::math::Pose3d WorldPose()
const;
181 public:
void SetWorldPosition(
const ignition::math::Vector3d &_pos);
185 public:
void SetWorldRotation(
const ignition::math::Quaterniond &_quat);
189 public:
void Translate(
const ignition::math::Vector3d &_direction);
195 public:
void Roll(
const ignition::math::Angle &_angle,
202 public:
void Pitch(
const ignition::math::Angle &_angle,
209 public:
void Yaw(
const ignition::math::Angle &_angle,
215 public:
virtual void SetClipDist(
const float _near,
const float _far);
219 public:
void SetHFOV(
const ignition::math::Angle &_angle);
223 public: ignition::math::Angle HFOV()
const;
229 public: ignition::math::Angle VFOV()
const;
234 public:
void SetImageSize(
const unsigned int _w,
const unsigned int _h);
238 public:
void SetImageWidth(
const unsigned int _w);
242 public:
void SetImageHeight(
const unsigned int _h);
246 public:
virtual unsigned int ImageWidth()
const;
250 public:
unsigned int TextureWidth()
const;
254 public:
virtual unsigned int ImageHeight()
const;
258 public:
unsigned int ImageDepth()
const;
262 public: std::string ImageFormat()
const;
266 public:
unsigned int TextureHeight()
const;
270 public:
size_t ImageByteSize()
const;
277 public:
static size_t ImageByteSize(
const unsigned int _width,
278 const unsigned int _height,
279 const std::string &_format);
286 public:
double ZValue(
const int _x,
const int _y);
290 public:
double NearClip()
const;
294 public:
double FarClip()
const;
298 public:
void EnableSaveFrame(
const bool _enable);
302 public:
bool CaptureData()
const;
306 public:
void SetSaveFramePathname(
const std::string &_pathname);
311 public:
bool SaveFrame(
const std::string &_filename);
315 public: Ogre::Camera *OgreCamera()
const;
319 public: Ogre::Viewport *OgreViewport()
const;
323 public:
unsigned int ViewportWidth()
const;
327 public:
unsigned int ViewportHeight()
const;
331 public: ignition::math::Vector3d Up()
const;
335 public: ignition::math::Vector3d Right()
const;
339 public:
virtual float AvgFPS()
const;
343 public:
virtual unsigned int TriangleCount()
const;
347 public:
void SetAspectRatio(
float _ratio);
351 public:
float AspectRatio()
const;
355 public:
void SetSceneNode(Ogre::SceneNode *_node);
359 public: Ogre::SceneNode *SceneNode()
const;
366 public:
virtual const unsigned char *ImageData(
const unsigned int i = 0)
371 public: std::string Name()
const;
375 public: std::string ScopedName()
const;
379 public:
void SetName(
const std::string &_name);
382 public:
void ToggleShowWireframe();
386 public:
void ShowWireframe(
const bool _s);
390 public:
void SetCaptureData(
const bool _value);
393 public:
void SetCaptureDataOnce();
408 public:
bool StartVideo(
const std::string &_format,
409 const std::string &_filename =
"");
415 public:
bool StopVideo();
422 public:
bool SaveVideo(
const std::string &_filename);
430 public:
bool ResetVideo();
434 public:
void CreateRenderTexture(
const std::string &_textureName);
446 public:
bool WorldPointOnPlane(
const int _x,
const int _y,
447 const ignition::math::Planed &_plane,
448 ignition::math::Vector3d &_result);
457 public:
virtual void CameraToViewportRay(
const int _screenx,
459 ignition::math::Vector3d &_origin,
460 ignition::math::Vector3d &_dir)
const;
464 public:
virtual void SetRenderTarget(Ogre::RenderTarget *_target);
474 public:
void AttachToVisual(
const std::string &_visualName,
475 const bool _inheritOrientation,
476 const double _minDist = 0.0,
const double _maxDist = 0.0);
486 public:
void AttachToVisual(uint32_t _id,
487 const bool _inheritOrientation,
488 const double _minDist = 0.0,
const double _maxDist = 0.0);
492 public:
void TrackVisual(
const std::string &_visualName);
496 public: Ogre::Texture *RenderTexture()
const;
500 public: ignition::math::Vector3d Direction()
const;
507 std::function<
void (
const unsigned char *,
unsigned int,
unsigned int,
508 unsigned int,
const std::string &)> _subscriber);
524 public:
static bool SaveFrame(
const unsigned char *_image,
525 const unsigned int _width,
const unsigned int _height,
526 const int _depth,
const std::string &_format,
527 const std::string &_filename);
537 public:
bool IsVisible(
VisualPtr _visual);
543 public:
bool IsVisible(
const std::string &_visualName);
546 public:
bool IsAnimating()
const;
552 public:
virtual bool MoveToPosition(
const ignition::math::Pose3d &_pose,
562 public:
bool MoveToPositions(
563 const std::vector<ignition::math::Pose3d> &_pts,
565 std::function<
void()> _onComplete =
NULL);
569 public: std::string ScreenshotPath()
const;
580 public:
virtual bool SetProjectionType(
const std::string &_type);
585 public: std::string ProjectionType()
const;
590 public:
virtual bool SetBackgroundColor(
const common::Color &_color);
594 public: ignition::math::Matrix4d ProjectionMatrix()
const;
599 public:
virtual ignition::math::Vector2i Project(
600 const ignition::math::Vector3d &_pt)
const;
609 public:
bool TrackIsStatic()
const;
615 public:
void SetTrackIsStatic(
const bool _isStatic);
621 public:
bool TrackUseModelFrame()
const;
628 public:
void SetTrackUseModelFrame(
const bool _useModelFrame);
633 public: ignition::math::Vector3d TrackPosition()
const;
638 public:
void SetTrackPosition(
const ignition::math::Vector3d &_pos);
643 public:
double TrackMinDistance()
const;
648 public:
double TrackMaxDistance()
const;
654 public:
void SetTrackMinDistance(
const double _dist);
660 public:
void SetTrackMaxDistance(
const double _dist);
667 public:
bool TrackInheritYaw()
const;
674 public:
void SetTrackInheritYaw(
const bool _inheritYaw);
677 protected:
virtual void RenderImpl();
680 protected:
void ReadPixelBuffer();
685 protected:
bool TrackVisualImpl(
const std::string &_visualName);
690 protected:
virtual bool TrackVisualImpl(
VisualPtr _visual);
701 protected:
virtual bool AttachToVisualImpl(
const std::string &_name,
702 const bool _inheritOrientation,
703 const double _minDist = 0,
const double _maxDist = 0);
714 protected:
virtual bool AttachToVisualImpl(uint32_t _id,
715 const bool _inheritOrientation,
716 const double _minDist = 0,
const double _maxDist = 0);
727 protected:
virtual bool AttachToVisualImpl(
VisualPtr _visual,
728 const bool _inheritOrientation,
729 const double _minDist = 0,
const double _maxDist = 0);
733 protected: std::string FrameFilename();
737 protected:
virtual void AnimationComplete();
740 protected:
virtual void UpdateFOV();
743 protected:
virtual void SetClipDist();
751 protected:
virtual void SetFixedYawAxis(
const bool _useFixed,
752 const ignition::math::Vector3d &_fixedAxis =
753 ignition::math::Vector3d::UnitY);
762 private:
void ConvertRGBToBAYER(
unsigned char *_dst,
763 const unsigned char *_src,
const std::string &_format,
764 const int _width,
const int _height);
769 private:
static int OgrePixelFormat(
const std::string &_format);
773 private:
void OnCmdMsg(ConstCameraCmdPtr &_msg);
776 private:
void CreateCamera();
788 protected: sdf::ElementPtr
sdf;
852 unsigned int,
unsigned int,
unsigned int,
875 private: std::unique_ptr<CameraPrivate> dataPtr;
Basic camera sensor.
Definition: Camera.hh:85
common::Time lastRenderWallTime
Time the last frame was rendered.
Definition: Camera.hh:845
ReferenceFrame
Frame of reference.
Definition: RenderTypes.hh:239
bool initialized
True if initialized.
Definition: Camera.hh:862
Ogre::Texture * renderTexture
Texture that receives results from rendering.
Definition: Camera.hh:833
boost::shared_ptr< Distortion > DistortionPtr
Definition: RenderTypes.hh:197
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
std::string scopedUniqueName
Scene scoped name of the camera with a unique ID.
Definition: Camera.hh:785
unsigned char * saveFrameBuffer
Buffer for a single image frame.
Definition: Camera.hh:809
unsigned char * bayerFrameBuffer
Buffer for a bayer image frame.
Definition: Camera.hh:812
std::string screenshotPath
Path to saved screenshots.
Definition: Camera.hh:818
bool captureDataOnce
True to capture a frame once and save to disk.
Definition: Camera.hh:839
bool captureData
True to capture frames into an image buffer.
Definition: Camera.hh:836
sdf::ElementPtr sdf
Camera's SDF values.
Definition: Camera.hh:788
Ogre::RenderTarget * renderTarget
Target that renders frames.
Definition: Camera.hh:830
Ogre::SceneNode * sceneNode
Scene node that controls camera position and orientation.
Definition: Camera.hh:806
Local frame.
Definition: RenderTypes.hh:242
std::vector< event::ConnectionPtr > connections
The camera's event connections.
Definition: Camera.hh:856
Ogre::Viewport * viewport
Viewport the ogre camera uses.
Definition: Camera.hh:803
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
int imageWidth
Save image width.
Definition: Camera.hh:824
bool newData
True if new data is available.
Definition: Camera.hh:842
unsigned int windowId
ID of the window that the camera is attached to.
Definition: Camera.hh:791
common::Time prevAnimTime
Previous time the camera animation was updated.
Definition: Camera.hh:868
std::string scopedName
Scene scoped name of the camera.
Definition: Camera.hh:782
ScenePtr scene
Pointer to the scene.
Definition: Camera.hh:848
unsigned int saveCount
Number of saved frames.
Definition: Camera.hh:815
std::list< msgs::Request > requests
List of requests.
Definition: Camera.hh:859
unsigned int textureHeight
Height of the render texture.
Definition: Camera.hh:797
int imageHeight
Save image height.
Definition: Camera.hh:827
World frame.
Definition: RenderTypes.hh:248
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
std::function< void()> onAnimationComplete
User callback for when an animation completes.
Definition: Camera.hh:871
#define NULL
Definition: CommonTypes.hh:31
Defines a color.
Definition: Color.hh:36
int imageFormat
Format for saving images.
Definition: Camera.hh:821
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
unsigned int textureWidth
Width of the render texture.
Definition: Camera.hh:794
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
std::string name
Name of the camera.
Definition: Camera.hh:779
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:853
A class for event processing.
Definition: Event.hh:113
Ogre::AnimationState * animState
Animation state, used to animate the camera.
Definition: Camera.hh:865
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:800