MRPT  2.0.0
CPlanarLaserScan.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/img/TColor.h>
13 #include <mrpt/maps/CMetricMap.h>
15 #include <mrpt/obs/CObservation.h>
20 
21 namespace mrpt
22 {
23 /** \ingroup mrpt_maps_grp */
24 namespace opengl
25 {
26 class CPlanarLaserScan;
27 
28 /** This object renders a 2D laser scan by means of three elements: the points,
29  * the line along end-points and the 2D scanned surface.
30  *
31  * By default, all those three elements are drawn, but you can individually
32  * switch them on/off with:
33  * - CPlanarLaserScan::enablePoints()
34  * - CPlanarLaserScan::enableLine()
35  * - CPlanarLaserScan::enableSurface()
36  *
37  * To change the final result, more methods allow further customization of the
38  * 3D object (color of each element, etc.).
39  *
40  * The scan is passed or updated through CPlanarLaserScan::setScan()
41  *
42  * <div align="center">
43  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
44  * border-style: solid;">
45  * <tr> <td> mrpt::opengl::CPlanarLaserScan </td> <td> \image html
46  * preview_CPlanarLaserScan.png </td> </tr>
47  * </table>
48  * </div>
49  *
50  * \note The laser points are projected at the sensor pose as given in the
51  * "scan" object, so this CPlanarLaserScan object should be placed at the exact
52  * pose of the robot coordinates origin.
53  *
54  * \sa mrpt::opengl::CPointCloud, opengl::COpenGLScene
55  * \ingroup mrpt_maps_grp
56  */
60 {
62 
63  public:
64  /** @name Renderizable shader API virtual methods
65  * @{ */
66  void render(const RenderContext& rc) const override;
67  void renderUpdateBuffers() const override;
68  void freeOpenGLResources() override
69  {
73  }
74 
75  virtual shader_list_t requiredShaders() const override
76  {
79  }
80  void onUpdateBuffers_Wireframe() override;
81  void onUpdateBuffers_Triangles() override;
82  void onUpdateBuffers_Points() override;
84  /** @} */
85 
86  CPlanarLaserScan() = default;
87  ~CPlanarLaserScan() override = default;
88 
89  /** Clear the scan */
90  void clear();
91 
92  /** Show or hides the scanned points \sa sePointsWidth, setPointsColor*/
93  inline void enablePoints(bool enable = true)
94  {
95  m_enable_points = enable;
97  }
98 
99  /** Show or hides lines along all scanned points \sa setLineWidth,
100  * setLineColor*/
101  inline void enableLine(bool enable = true)
102  {
103  m_enable_line = enable;
105  }
106 
107  /** Show or hides the scanned area as a 2D surface \sa setSurfaceColor */
108  inline void enableSurface(bool enable = true)
109  {
110  m_enable_surface = enable;
112  }
113 
114  void setLineColor(float R, float G, float B, float A = 1.0f)
115  {
116  m_line_R = R;
117  m_line_G = G;
118  m_line_B = B;
119  m_line_A = A;
120  }
121  void setPointsColor(float R, float G, float B, float A = 1.0f)
122  {
123  m_points_R = R;
124  m_points_G = G;
125  m_points_B = B;
126  m_points_A = A;
127  }
128  void setSurfaceColor(float R, float G, float B, float A = 1.0f)
129  {
130  m_plane_R = R;
131  m_plane_G = G;
132  m_plane_B = B;
133  m_plane_A = A;
134  }
135 
137  {
139  m_cache_valid = false;
140  m_scan = scan;
141  }
142 
143  void getBoundingBox(
145  mrpt::math::TPoint3D& bb_max) const override;
146 
147  protected:
150  mutable bool m_cache_valid{false};
151 
152  float m_line_R{1.f}, m_line_G{0.f}, m_line_B{0.f}, m_line_A{0.5f};
153 
154  float m_points_R{1.0f}, m_points_G{0.0f}, m_points_B{0.0f},
155  m_points_A{1.0f};
156 
157  float m_plane_R{0.01f}, m_plane_G{0.01f}, m_plane_B{0.6f}, m_plane_A{0.6f};
158 
159  bool m_enable_points{true};
160  bool m_enable_line{true};
161  bool m_enable_surface{true};
162 };
163 
164 } // namespace opengl
165 } // namespace mrpt
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
mrpt::maps::CSimplePointsMap m_cache_points
void setSurfaceColor(float R, float G, float B, float A=1.0f)
void freeOpenGLResources() override
Free opengl buffers.
const double G
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
Renderizable generic renderer for objects using the triangles shader.
void freeOpenGLResources() override
Free opengl buffers.
mrpt::math::TPoint3Df getLocalRepresentativePoint() const override
Provide a representative point (in object local coordinates), used to sort objects by eye-distance wh...
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
void enableLine(bool enable=true)
Show or hides lines along all scanned points.
Context for calls to render()
~CPlanarLaserScan() override=default
void enableSurface(bool enable=true)
Show or hides the scanned area as a 2D surface.
static constexpr shader_id_t WIREFRAME
void freeOpenGLResources() override
Free opengl buffers.
This object renders a 2D laser scan by means of three elements: the points, the line along end-points...
Renderizable generic renderer for objects using the points shader.
static constexpr shader_id_t TRIANGLES
void enablePoints(bool enable=true)
Show or hides the scanned points.
mrpt::obs::CObservation2DRangeScan m_scan
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
const float R
Renderizable generic renderer for objects using the wireframe shader.
void setLineColor(float R, float G, float B, float A=1.0f)
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
void setPointsColor(float R, float G, float B, float A=1.0f)
void freeOpenGLResources() override
Free opengl buffers.
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
void clear()
Clear the scan.
void setScan(const mrpt::obs::CObservation2DRangeScan &scan)
static constexpr shader_id_t POINTS
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at mar mar 31 20:00:11 CEST 2020