MRPT  2.0.4
CFrustum.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 #pragma once
10 
11 #include <mrpt/math/TPoint3D.h>
14 
15 namespace mrpt::opengl
16 {
17 /** A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with
18  * arbitrary (possibly assymetric) field-of-view angles.
19  *
20  * You can switch whether to show only the lines, the surface of the frustum,
21  * or both.
22  * By default only the lines are drawn.
23  *
24  * The color of the object (via CRenderizable::setColor()) affects the color
25  * of lines.
26  * To set the color of planes use \a setPlaneColor()
27  *
28  * As usual in MRPT, the +X axis is assumed to by the main direction, in this
29  * case of the pyramid axis.
30  *
31  * The horizontal and vertical FOVs can be set directly with \a setHorzFOV()
32  * and \a setVertFOV() if
33  * they are symmetric, or with \a setHorzFOVAsymmetric() and \a
34  * setVertFOVAsymmetric() otherwise.
35  *
36  * All FOV angles are positive numbers. FOVs must be below 90deg on each side
37  * (below 180deg in total).
38  * If you try to set FOVs to larger values they'll truncated to 89.9deg.
39  *
40  * \sa opengl::COpenGLScene,opengl::CRenderizable
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::CFrustum </td> <td> \image html
46  * preview_CFrustum.png </td> </tr>
47  * </table>
48  * </div>
49  *
50  * \ingroup mrpt_opengl_grp
51  */
54 {
56 
57  public:
58  /** @name Renderizable shader API virtual methods
59  * @{ */
60  void render(const RenderContext& rc) const override;
61  void renderUpdateBuffers() const override;
62  void freeOpenGLResources() override
63  {
66  }
67 
68  virtual shader_list_t requiredShaders() const override
69  {
70  // May use up to two shaders (triangles and lines):
72  }
73  void onUpdateBuffers_Wireframe() override;
74  void onUpdateBuffers_Triangles() override;
75  /** @} */
76 
77  /** Changes the color of the planes; to change color of lines, use
78  * CRenderizable base methods. */
79  inline void setPlaneColor(const mrpt::img::TColor& c)
80  {
81  m_planes_color = c;
83  }
84  inline const mrpt::img::TColor& getPlaneColor() const
85  {
86  return m_planes_color;
87  }
88 
89  /** Changes distance of near & far planes */
90  void setNearFarPlanes(const float near_distance, const float far_distance);
91 
92  float getNearPlaneDistance() const { return m_min_distance; }
93  float getFarPlaneDistance() const { return m_max_distance; }
94  /** Changes horizontal FOV (symmetric) */
95  void setHorzFOV(const float fov_horz_degrees);
96  /** Changes vertical FOV (symmetric) */
97  void setVertFOV(const float fov_vert_degrees);
98  /** Changes horizontal FOV (asymmetric) */
100  const float fov_horz_left_degrees, const float fov_horz_right_degrees);
101  /** Changes vertical FOV (asymmetric) */
103  const float fov_vert_down_degrees, const float fov_vert_up_degrees);
104 
105  float getHorzFOV() const
106  {
108  }
109  float getVertFOV() const
110  {
112  }
113  float getHorzFOVLeft() const { return mrpt::RAD2DEG(m_fov_horz_left); }
114  float getHorzFOVRight() const { return mrpt::RAD2DEG(m_fov_horz_right); }
115  float getVertFOVDown() const { return mrpt::RAD2DEG(m_fov_vert_down); }
116  float getVertFOVUp() const { return mrpt::RAD2DEG(m_fov_vert_up); }
117 
118  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
119  void getBoundingBox(
121  mrpt::math::TPoint3D& bb_max) const override;
122 
123  /** Basic empty constructor. Set all parameters to default. */
124  CFrustum();
125  /** Constructor with some parameters */
126  CFrustum(
127  float near_distance, float far_distance, float horz_FOV_degrees,
128  float vert_FOV_degrees, float lineWidth, bool draw_lines,
129  bool draw_planes);
130 
131  /** Destructor */
132  ~CFrustum() override = default;
133 
134  protected:
135  /** Near and far planes */
136  float m_min_distance{0.1f}, m_max_distance{1.f};
137  /** Semi FOVs (in radians) */
139  /** Semi FOVs (in radians) */
141  bool m_draw_lines{true}, m_draw_planes{false};
143 
144  // Compute the 8 corners of the frustum:
145  std::array<mrpt::math::TPoint3Df, 8> computeFrustumCorners() const;
146 };
147 } // namespace mrpt::opengl
float getHorzFOVLeft() const
Definition: CFrustum.h:113
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CFrustum.cpp:172
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CFrustum.cpp:80
void freeOpenGLResources() override
Free opengl buffers.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CFrustum.cpp:59
float getNearPlaneDistance() const
Definition: CFrustum.h:92
float m_min_distance
Near and far planes.
Definition: CFrustum.h:136
void setVertFOV(const float fov_vert_degrees)
Changes vertical FOV (symmetric)
Definition: CFrustum.cpp:196
float getHorzFOVRight() const
Definition: CFrustum.h:114
Renderizable generic renderer for objects using the triangles shader.
std::array< mrpt::math::TPoint3Df, 8 > computeFrustumCorners() const
Definition: CFrustum.cpp:40
void setHorzFOV(const float fov_horz_degrees)
Changes horizontal FOV (symmetric)
Definition: CFrustum.cpp:187
float getVertFOVUp() const
Definition: CFrustum.h:116
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CFrustum.cpp:34
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
Context for calls to render()
void setPlaneColor(const mrpt::img::TColor &c)
Changes the color of the planes; to change color of lines, use CRenderizable base methods...
Definition: CFrustum.h:79
CFrustum()
Basic empty constructor.
Definition: CFrustum.cpp:110
static constexpr shader_id_t WIREFRAME
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CFrustum.cpp:22
void freeOpenGLResources() override
Free opengl buffers.
Definition: CFrustum.h:62
~CFrustum() override=default
Destructor.
float getHorzFOV() const
Definition: CFrustum.h:105
static constexpr shader_id_t TRIANGLES
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CFrustum.h:68
const mrpt::img::TColor & getPlaneColor() const
Definition: CFrustum.h:84
mrpt::img::TColor m_planes_color
Definition: CFrustum.h:142
float m_fov_horz_left
Semi FOVs (in radians)
Definition: CFrustum.h:138
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
void setNearFarPlanes(const float near_distance, const float far_distance)
Changes distance of near & far planes.
Definition: CFrustum.cpp:180
Renderizable generic renderer for objects using the wireframe shader.
constexpr double RAD2DEG(const double x)
Radians to degrees.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void setVertFOVAsymmetric(const float fov_vert_down_degrees, const float fov_vert_up_degrees)
Changes vertical FOV (asymmetric)
Definition: CFrustum.cpp:216
const auto bb_max
A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assyme...
Definition: CFrustum.h:52
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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...
Definition: CFrustum.cpp:228
const auto bb_min
A RGB color - 8bit.
Definition: TColor.h:25
void setHorzFOVAsymmetric(const float fov_horz_left_degrees, const float fov_horz_right_degrees)
Changes horizontal FOV (asymmetric)
Definition: CFrustum.cpp:205
void freeOpenGLResources() override
Free opengl buffers.
float getVertFOV() const
Definition: CFrustum.h:109
float getFarPlaneDistance() const
Definition: CFrustum.h:93
float m_fov_vert_down
Semi FOVs (in radians)
Definition: CFrustum.h:140
float getVertFOVDown() const
Definition: CFrustum.h:115



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020