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/Matrix4.hh> 33 #include <ignition/math/Pose3.hh> 34 #include <ignition/math/Quaternion.hh> 35 #include <ignition/math/Vector2.hh> 36 #include <ignition/math/Vector3.hh> 51 #include "gazebo/msgs/MessageTypes.hh" 85 public boost::enable_shared_from_this<Camera>
92 bool _autoRender =
true);
99 public:
virtual void Load(sdf::ElementPtr _sdf);
102 public:
virtual void Load();
111 public:
void UpdateCameraIntrinsics(
112 const double _cameraIntrinsicsFx,
const double _cameraIntrinsicsFy,
113 const double _cameraIntrinsicsCx,
const double _cameraIntrinsicsCy,
114 const double _cameraIntrinsicsS);
117 private:
virtual void LoadCameraIntrinsics();
131 public:
static ignition::math::Matrix4d BuildNDCMatrix(
132 const double _left,
const double _right,
133 const double _bottom,
const double _top,
134 const double _near,
const double _far);
150 public:
static ignition::math::Matrix4d BuildPerspectiveMatrix(
151 const double _intrinsicsFx,
const double _intrinsicsFy,
152 const double _intrinsicsCx,
const double _intrinsicsCy,
153 const double _intrinsicsS,
154 const double _clipNear,
const double _clipFar);
175 public:
static ignition::math::Matrix4d BuildProjectiveMatrix(
176 const double _imageWidth,
const double _imageHeight,
177 const double _intrinsicsFx,
const double _intrinsicsFy,
178 const double _intrinsicsCx,
const double _intrinsicsCy,
179 const double _intrinsicsS,
180 const double _clipNear,
const double _clipFar);
183 public:
virtual void Init();
187 public:
void SetRenderRate(
const double _hz);
191 public:
double RenderRate()
const;
198 public:
virtual void Render(
const bool _force =
false);
203 public:
virtual void PostRender();
210 public:
virtual void Update();
215 public:
virtual void Fini();
219 public:
bool Initialized()
const;
224 public:
void SetWindowId(
unsigned int _windowId);
228 public:
unsigned int WindowId()
const;
232 public:
void SetScene(
ScenePtr _scene);
236 public: ignition::math::Vector3d WorldPosition()
const;
240 public: ignition::math::Quaterniond WorldRotation()
const;
244 public:
virtual void SetWorldPose(
const ignition::math::Pose3d &_pose);
248 public: ignition::math::Pose3d WorldPose()
const;
252 public:
void SetWorldPosition(
const ignition::math::Vector3d &_pos);
256 public:
void SetWorldRotation(
const ignition::math::Quaterniond &_quat);
260 public:
void Translate(
const ignition::math::Vector3d &_direction);
266 public:
void Roll(
const ignition::math::Angle &_angle,
273 public:
void Pitch(
const ignition::math::Angle &_angle,
280 public:
void Yaw(
const ignition::math::Angle &_angle,
286 public:
virtual void SetClipDist(
const float _near,
const float _far);
290 public:
void SetHFOV(
const ignition::math::Angle &_angle);
294 public: ignition::math::Angle HFOV()
const;
298 public: ignition::math::Angle VFOV()
const;
303 public:
void SetImageSize(
const unsigned int _w,
const unsigned int _h);
307 public:
void SetImageWidth(
const unsigned int _w);
311 public:
void SetImageHeight(
const unsigned int _h);
315 public:
virtual unsigned int ImageWidth()
const;
319 public:
unsigned int ImageMemorySize()
const;
323 public:
unsigned int TextureWidth()
const;
327 public:
virtual unsigned int ImageHeight()
const;
331 public:
unsigned int ImageDepth()
const;
335 public: std::string ImageFormat()
const;
339 public:
unsigned int TextureHeight()
const;
343 public:
size_t ImageByteSize()
const;
350 public:
static size_t ImageByteSize(
const unsigned int _width,
351 const unsigned int _height,
352 const std::string &_format);
359 public:
double ZValue(
const int _x,
const int _y);
363 public:
double NearClip()
const;
367 public:
double FarClip()
const;
371 public:
void EnableSaveFrame(
const bool _enable);
375 public:
bool CaptureData()
const;
379 public:
void SetSaveFramePathname(
const std::string &_pathname);
384 public:
bool SaveFrame(
const std::string &_filename);
388 public: Ogre::Camera *OgreCamera()
const;
392 public: Ogre::Viewport *OgreViewport()
const;
396 public:
unsigned int ViewportWidth()
const;
400 public:
unsigned int ViewportHeight()
const;
404 public: ignition::math::Vector3d Up()
const;
408 public: ignition::math::Vector3d Right()
const;
412 public:
virtual float AvgFPS()
const;
416 public:
virtual unsigned int TriangleCount()
const;
420 public:
void SetAspectRatio(
float _ratio);
424 public:
float AspectRatio()
const;
428 public:
void SetSceneNode(Ogre::SceneNode *_node);
432 public: Ogre::SceneNode *SceneNode()
const;
439 public:
virtual const unsigned char *ImageData(
const unsigned int i = 0)
444 public: std::string Name()
const;
448 public: std::string ScopedName()
const;
452 public:
void SetName(
const std::string &_name);
455 public:
void ToggleShowWireframe();
459 public:
void ShowWireframe(
const bool _s);
463 public:
void SetCaptureData(
const bool _value);
466 public:
void SetCaptureDataOnce();
481 public:
bool StartVideo(
const std::string &_format,
482 const std::string &_filename =
"");
488 public:
bool StopVideo();
495 public:
bool SaveVideo(
const std::string &_filename);
503 public:
bool ResetVideo();
507 public:
void CreateRenderTexture(
const std::string &_textureName);
519 public:
bool WorldPointOnPlane(
const int _x,
const int _y,
520 const ignition::math::Planed &_plane,
521 ignition::math::Vector3d &_result);
530 public:
virtual void CameraToViewportRay(
const int _screenx,
532 ignition::math::Vector3d &_origin,
533 ignition::math::Vector3d &_dir)
const;
537 public:
virtual void SetRenderTarget(Ogre::RenderTarget *_target);
547 public:
void AttachToVisual(
const std::string &_visualName,
548 const bool _inheritOrientation,
549 const double _minDist = 0.0,
const double _maxDist = 0.0);
559 public:
void AttachToVisual(uint32_t _id,
560 const bool _inheritOrientation,
561 const double _minDist = 0.0,
const double _maxDist = 0.0);
565 public:
void TrackVisual(
const std::string &_visualName);
569 public: Ogre::Texture *RenderTexture()
const;
573 public: ignition::math::Vector3d Direction()
const;
580 std::function<
void (
const unsigned char *,
unsigned int,
unsigned int,
581 unsigned int,
const std::string &)> _subscriber);
591 public:
static bool SaveFrame(
const unsigned char *_image,
592 const unsigned int _width,
const unsigned int _height,
593 const int _depth,
const std::string &_format,
594 const std::string &_filename);
604 public:
bool IsVisible(
VisualPtr _visual);
610 public:
bool IsVisible(
const std::string &_visualName);
613 public:
bool IsAnimating()
const;
619 public:
virtual bool MoveToPosition(
const ignition::math::Pose3d &_pose,
629 public:
bool MoveToPositions(
630 const std::vector<ignition::math::Pose3d> &_pts,
632 std::function<
void()> _onComplete =
NULL);
636 public: std::string ScreenshotPath()
const;
647 public:
virtual bool SetProjectionType(
const std::string &_type);
652 public: std::string ProjectionType()
const;
657 public:
virtual bool SetBackgroundColor(
658 const ignition::math::Color &_color);
662 public: ignition::math::Matrix4d ProjectionMatrix()
const;
667 public:
virtual ignition::math::Vector2i Project(
668 const ignition::math::Vector3d &_pt)
const;
677 public:
bool TrackIsStatic()
const;
683 public:
void SetTrackIsStatic(
const bool _isStatic);
689 public:
bool TrackUseModelFrame()
const;
696 public:
void SetTrackUseModelFrame(
const bool _useModelFrame);
701 public: ignition::math::Vector3d TrackPosition()
const;
706 public:
void SetTrackPosition(
const ignition::math::Vector3d &_pos);
711 public:
double TrackMinDistance()
const;
716 public:
double TrackMaxDistance()
const;
722 public:
void SetTrackMinDistance(
const double _dist);
728 public:
void SetTrackMaxDistance(
const double _dist);
735 public:
bool TrackInheritYaw()
const;
742 public:
void SetTrackInheritYaw(
const bool _inheritYaw);
745 protected:
virtual void RenderImpl();
748 protected:
void ReadPixelBuffer();
753 protected:
bool TrackVisualImpl(
const std::string &_visualName);
758 protected:
virtual bool TrackVisualImpl(
VisualPtr _visual);
769 protected:
virtual bool AttachToVisualImpl(
const std::string &_name,
770 const bool _inheritOrientation,
771 const double _minDist = 0,
const double _maxDist = 0);
782 protected:
virtual bool AttachToVisualImpl(uint32_t _id,
783 const bool _inheritOrientation,
784 const double _minDist = 0,
const double _maxDist = 0);
795 protected:
virtual bool AttachToVisualImpl(
VisualPtr _visual,
796 const bool _inheritOrientation,
797 const double _minDist = 0,
const double _maxDist = 0);
801 protected: std::string FrameFilename();
805 protected:
virtual void AnimationComplete();
808 protected:
virtual void UpdateFOV();
811 protected:
virtual void SetClipDist();
817 protected:
static double LimitFOV(
const double _fov);
825 protected:
virtual void SetFixedYawAxis(
const bool _useFixed,
826 const ignition::math::Vector3d &_fixedAxis =
827 ignition::math::Vector3d::UnitY);
836 private:
void ConvertRGBToBAYER(
unsigned char *_dst,
837 const unsigned char *_src,
const std::string &_format,
838 const int _width,
const int _height);
843 private:
static int OgrePixelFormat(
const std::string &_format);
847 private:
void OnCmdMsg(ConstCameraCmdPtr &_msg);
850 private:
void CreateCamera();
862 protected: sdf::ElementPtr
sdf;
886 protected: Ogre::SceneNode *cameraNode =
nullptr;
935 unsigned int,
unsigned int,
unsigned int,
958 private: std::unique_ptr<CameraPrivate> dataPtr;
Basic camera sensor.
Definition: Camera.hh:84
common::Time lastRenderWallTime
Time the last frame was rendered.
Definition: Camera.hh:928
ReferenceFrame
Frame of reference.
Definition: RenderTypes.hh:244
bool initialized
True if initialized.
Definition: Camera.hh:945
bool cameraUsingIntrinsics
Flag for signaling the usage of camera intrinsics within OGRE.
Definition: Camera.hh:880
Ogre::Texture * renderTexture
Texture that receives results from rendering.
Definition: Camera.hh:916
Forward declarations for the common classes.
Definition: Animation.hh:26
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:859
ignition::math::Matrix4d cameraProjectiveMatrix
Camera projective matrix.
Definition: Camera.hh:877
unsigned char * saveFrameBuffer
Buffer for a single image frame.
Definition: Camera.hh:892
unsigned char * bayerFrameBuffer
Buffer for a bayer image frame.
Definition: Camera.hh:895
std::string screenshotPath
Path to saved screenshots.
Definition: Camera.hh:901
bool captureDataOnce
True to capture a frame once and save to disk.
Definition: Camera.hh:922
bool captureData
True to capture frames into an image buffer.
Definition: Camera.hh:919
sdf::ElementPtr sdf
Camera's SDF values.
Definition: Camera.hh:862
Ogre::RenderTarget * renderTarget
Target that renders frames.
Definition: Camera.hh:913
Ogre::SceneNode * sceneNode
Scene node that controls camera position and orientation.
Definition: Camera.hh:889
Local frame.
Definition: RenderTypes.hh:247
std::vector< event::ConnectionPtr > connections
The camera's event connections.
Definition: Camera.hh:939
Ogre::Viewport * viewport
Viewport the ogre camera uses.
Definition: Camera.hh:883
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
int imageWidth
Save image width.
Definition: Camera.hh:907
bool newData
True if new data is available.
Definition: Camera.hh:925
unsigned int windowId
ID of the window that the camera is attached to.
Definition: Camera.hh:865
common::Time prevAnimTime
Previous time the camera animation was updated.
Definition: Camera.hh:951
std::string scopedName
Scene scoped name of the camera.
Definition: Camera.hh:856
ScenePtr scene
Pointer to the scene.
Definition: Camera.hh:931
unsigned int saveCount
Number of saved frames.
Definition: Camera.hh:898
std::list< msgs::Request > requests
List of requests.
Definition: Camera.hh:942
unsigned int textureHeight
Height of the render texture.
Definition: Camera.hh:871
int imageHeight
Save image height.
Definition: Camera.hh:910
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:954
#define NULL
Definition: CommonTypes.hh:31
Definition: JointMaker.hh:39
int imageFormat
Format for saving images.
Definition: Camera.hh:904
unsigned int textureWidth
Width of the render texture.
Definition: Camera.hh:868
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
std::string name
Name of the camera.
Definition: Camera.hh:853
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:936
A class for event processing.
Definition: Event.hh:97
Ogre::AnimationState * animState
Animation state, used to animate the camera.
Definition: Camera.hh:948
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:874