MVSim
Lightweight simulator for 2.5D vehicles and robots
Lidar3D.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/CObservationPointCloud.h>
13 #include <mrpt/obs/CObservationRotatingScan.h>
14 #include <mrpt/opengl/CFBORender.h>
15 #include <mrpt/opengl/CPointCloudColoured.h>
16 #include <mrpt/poses/CPose2D.h>
17 #include <mvsim/Sensors/SensorBase.h>
18 
19 #include <mutex>
20 
21 namespace mvsim
22 {
30 class Lidar3D : public SensorBase
31 {
32  DECLARES_REGISTER_SENSOR(Lidar3D)
33  public:
34  Lidar3D(Simulable& parent, const rapidxml::xml_node<char>* root);
35 
36  // See docs in base class
37  virtual void loadConfigFrom(const rapidxml::xml_node<char>* root) override;
38 
39  virtual void simul_pre_timestep(const TSimulContext& context) override;
40  virtual void simul_post_timestep(const TSimulContext& context) override;
41 
42  void simulateOn3DScene(mrpt::opengl::COpenGLScene& gl_scene) override;
43  void freeOpenGLResources() override;
44 
45  protected:
46  virtual void internalGuiUpdate(
47  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& viz,
48  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& physical, bool childrenOnly) override;
49 
50  void notifySimulableSetPose(const mrpt::math::TPose3D& newPose) override;
51 
52  mrpt::math::TPose3D getRelativePose() const override { return sensorPoseOnVeh_.asTPose(); }
53  void setRelativePose(const mrpt::math::TPose3D& p) override
54  {
55  sensorPoseOnVeh_ = mrpt::poses::CPose3D(p);
56  }
57 
58  mrpt::poses::CPose3D sensorPoseOnVeh_;
59 
60  double rangeStdNoise_ = 0.01;
61  bool ignore_parent_body_ = false;
62 
63  float viz_pointSize_ = 3.0f;
64  float minRange_ = 0.01f;
65  float maxRange_ = 80.0f;
66 
69  double vertical_fov_ = 30.0;
70 
76 
77  int vertNumRays_ = 16, horzNumRays_ = 180;
78  double horzResolutionFactor_ = 1.0;
79  double vertResolutionFactor_ = 1.0;
80  float maxDepthInterpolationStepVert_ = 0.30f;
81  float maxDepthInterpolationStepHorz_ = 0.10f;
82 
84  mrpt::obs::CObservationPointCloud::Ptr last_scan2gui_, last_scan_;
85  std::mutex last_scan_cs_;
86 
89  bool gui_uptodate_ = false;
90 
91  mrpt::opengl::CPointCloudColoured::Ptr glPoints_;
92  mrpt::opengl::CSetOfObjects::Ptr gl_sensor_origin_, gl_sensor_origin_corner_;
93  mrpt::opengl::CSetOfObjects::Ptr gl_sensor_fov_;
94 
95  std::optional<TSimulContext> has_to_render_;
96  std::mutex has_to_render_mtx_;
97 
98  std::shared_ptr<mrpt::opengl::CFBORender> fbo_renderer_depth_;
99 
103 
104  struct PerRayLUT
105  {
106  float u = 0, v = 0;
107  float depth2range = 0;
108  };
110  {
111  std::vector<PerRayLUT> column;
112  };
113 
114  std::vector<PerHorzAngleLUT> lut_;
115 
118  std::vector<double> vertical_ray_angles_;
119 };
120 } // namespace mvsim
Definition: Lidar3D.h:31
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root) override
std::string vertical_ray_angles_str_
Definition: Lidar3D.h:75
bool gui_uptodate_
Definition: Lidar3D.h:89
bool generateIntensityFromRGB_
Definition: Lidar3D.h:102
void setRelativePose(const mrpt::math::TPose3D &p) override
Definition: Lidar3D.h:53
mrpt::math::TPose3D getRelativePose() const override
Definition: Lidar3D.h:52
virtual void simul_post_timestep(const TSimulContext &context) override
virtual void simul_pre_timestep(const TSimulContext &context) override
double vertical_fov_
In degrees !!
Definition: Lidar3D.h:69
mrpt::obs::CObservationPointCloud::Ptr last_scan2gui_
Definition: Lidar3D.h:84
std::vector< double > vertical_ray_angles_
Definition: Lidar3D.h:118
Virtual base class for all sensors.
Definition: SensorBase.h:35
Definition: Simulable.h:40
Definition: Lidar3D.h:110
Definition: Lidar3D.h:105
float v
Pixel coords.
Definition: Lidar3D.h:106
Definition: basic_types.h:58