MVSim
Lightweight simulator for 2.5D vehicles and robots
DepthCameraSensor.h
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2026 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/obs/CObservation3DRangeScan.h>
13 #include <mrpt/opengl/CFBORender.h>
14 #include <mrpt/opengl/CPointCloudColoured.h>
15 #include <mvsim/Sensors/SensorBase.h>
16 
17 #include <mutex>
18 
19 namespace mvsim
20 {
35 {
36  DECLARES_REGISTER_SENSOR(DepthCameraSensor)
37 
38  public:
40  virtual ~DepthCameraSensor();
41 
42  // See docs in base class
43  virtual void loadConfigFrom(const rapidxml::xml_node<char>* root) override;
44 
45  virtual void simul_pre_timestep(const TSimulContext& context) override;
46  virtual void simul_post_timestep(const TSimulContext& context) override;
47 
48  void simulateOn3DScene(mrpt::opengl::COpenGLScene& gl_scene) override;
49 
50  void freeOpenGLResources() override;
51 
55  bool publishDepthImage() const { return publish_depth_image_; }
56 
61 
62  protected:
63  virtual void internalGuiUpdate(
64  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& viz,
65  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& physical, bool childrenOnly) override;
66 
67  void notifySimulableSetPose(const mrpt::math::TPose3D& newPose) override;
68 
69  mrpt::math::TPose3D getRelativePose() const override
70  {
71  return sensor_params_.sensorPose.asTPose();
72  }
73  void setRelativePose(const mrpt::math::TPose3D& p) override
74  {
75  sensor_params_.setSensorPose(mrpt::poses::CPose3D(p));
76  }
77 
78  // Store here all sensor intrinsic parameters. This obj will be copied as a
79  // "pattern" to fill it with actual scan data.
80  mrpt::obs::CObservation3DRangeScan sensor_params_;
81 
82  std::mutex last_obs_cs_;
84  mrpt::obs::CObservation3DRangeScan::Ptr last_obs_;
85  mrpt::obs::CObservation3DRangeScan::Ptr last_obs2gui_;
86 
87  // Note: we need 2 to support different resolutions for RGB vs Depth.
88  std::shared_ptr<mrpt::opengl::CFBORender> fbo_renderer_rgb_, fbo_renderer_depth_;
89 
92  bool gui_uptodate_ = false;
93  mrpt::opengl::CPointCloudColoured::Ptr gl_obs_;
94 
95  std::optional<TSimulContext> has_to_render_;
96  std::mutex has_to_render_mtx_;
97 
98  float rgbClipMin_ = 1e-2, rgbClipMax_ = 1e+4;
99  float depth_clip_min_ = 0.1, depth_clip_max_ = 15.0;
100  float depth_resolution_ = 1e-3;
101 
102  bool sense_depth_ = true;
103  bool sense_rgb_ = true;
104 
105  bool publish_depth_image_ = true;
107 
108  float depth_noise_sigma_ = 1e-3;
109  bool show_3d_pointcloud_ = false;
110 
111  mrpt::opengl::CSetOfObjects::Ptr gl_sensor_origin_, gl_sensor_origin_corner_;
112  mrpt::opengl::CSetOfObjects::Ptr gl_sensor_fov_, gl_sensor_frustum_;
113 
114  mrpt::math::CMatrixFloat depthImage_; // to avoid memory allocs
115 };
116 } // namespace mvsim
Definition: DepthCameraSensor.h:35
bool publish_depth_image_
Publish depth as 16UC1 image + CameraInfo.
Definition: DepthCameraSensor.h:105
bool sense_depth_
Simulate the DEPTH sensor part.
Definition: DepthCameraSensor.h:102
virtual void simul_pre_timestep(const TSimulContext &context) override
bool publish_colored_pointcloud_
Publish XYZRGB instead of XYZ pointcloud.
Definition: DepthCameraSensor.h:106
mrpt::obs::CObservation3DRangeScan::Ptr last_obs_
Definition: DepthCameraSensor.h:84
virtual void simul_post_timestep(const TSimulContext &context) override
bool sense_rgb_
Simulate the RGB sensor part.
Definition: DepthCameraSensor.h:103
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root) override
mrpt::math::TPose3D getRelativePose() const override
Definition: DepthCameraSensor.h:69
bool publishDepthImage() const
Definition: DepthCameraSensor.h:55
bool gui_uptodate_
Definition: DepthCameraSensor.h:92
bool publishColoredPointcloud() const
Definition: DepthCameraSensor.h:60
void setRelativePose(const mrpt::math::TPose3D &p) override
Definition: DepthCameraSensor.h:73
Virtual base class for all sensors.
Definition: SensorBase.h:35
Definition: Simulable.h:40
Definition: basic_types.h:58