MRPT  1.9.9
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-2019, 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>
13 
14 namespace mrpt::opengl
15 {
16 /** A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with
17  * arbitrary (possibly assymetric) field-of-view angles.
18  *
19  * You can switch whether to show only the lines, the surface of the frustum,
20  * or both.
21  * By default only the lines are drawn.
22  *
23  * The color of the object (via CRenderizable::setColor()) affects the color
24  * of lines.
25  * To set the color of planes use \a setPlaneColor()
26  *
27  * As usual in MRPT, the +X axis is assumed to by the main direction, in this
28  * case of the pyramid axis.
29  *
30  * The horizontal and vertical FOVs can be set directly with \a setHorzFOV()
31  * and \a setVertFOV() if
32  * they are symmetric, or with \a setHorzFOVAsymmetric() and \a
33  * setVertFOVAsymmetric() otherwise.
34  *
35  * All FOV angles are positive numbers. FOVs must be below 90deg on each side
36  * (below 180deg in total).
37  * If you try to set FOVs to larger values they'll truncated to 89.9deg.
38  *
39  * \sa opengl::COpenGLScene,opengl::CRenderizable
40  *
41  * <div align="center">
42  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
43  * border-style: solid;">
44  * <tr> <td> mrpt::opengl::CFrustum </td> <td> \image html
45  * preview_CFrustum.png </td> </tr>
46  * </table>
47  * </div>
48  *
49  * \ingroup mrpt_opengl_grp
50  */
52 {
54 
55  protected:
56  /** Near and far planes */
57  float m_min_distance{0.1f}, m_max_distance{1.f};
58  /** Semi FOVs (in radians) */
60  /** Semi FOVs (in radians) */
62  bool m_draw_lines{true}, m_draw_planes{false};
63  float m_lineWidth{1.5f};
65 
66  public:
67  inline void setLineWidth(float width)
68  {
71  }
72  inline float getLineWidth() const { return m_lineWidth; }
73  /** Changes the color of the planes; to change color of lines, use
74  * CRenderizable base methods. */
75  inline void setPlaneColor(const mrpt::img::TColor& c)
76  {
77  m_planes_color = c;
79  }
80  inline const mrpt::img::TColor& getPlaneColor() const
81  {
82  return m_planes_color;
83  }
84 
85  /** Changes distance of near & far planes */
86  void setNearFarPlanes(const float near_distance, const float far_distance);
87 
88  float getNearPlaneDistance() const { return m_min_distance; }
89  float getFarPlaneDistance() const { return m_max_distance; }
90  /** Changes horizontal FOV (symmetric) */
91  void setHorzFOV(const float fov_horz_degrees);
92  /** Changes vertical FOV (symmetric) */
93  void setVertFOV(const float fov_vert_degrees);
94  /** Changes horizontal FOV (asymmetric) */
96  const float fov_horz_left_degrees, const float fov_horz_right_degrees);
97  /** Changes vertical FOV (asymmetric) */
99  const float fov_vert_down_degrees, const float fov_vert_up_degrees);
100 
101  float getHorzFOV() const
102  {
104  }
105  float getVertFOV() const
106  {
108  }
109  float getHorzFOVLeft() const { return mrpt::RAD2DEG(m_fov_horz_left); }
110  float getHorzFOVRight() const { return mrpt::RAD2DEG(m_fov_horz_right); }
111  float getVertFOVDown() const { return mrpt::RAD2DEG(m_fov_vert_down); }
112  float getVertFOVUp() const { return mrpt::RAD2DEG(m_fov_vert_up); }
113  /** Render \sa mrpt::opengl::CRenderizable */
114  void render_dl() const override;
115 
116  /** Ray tracing. \sa mrpt::opengl::CRenderizable */
117  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
118 
119  /** Evaluates the bounding box of this object (including possible children)
120  * in the coordinate frame of the object parent. */
121  void getBoundingBox(
123  mrpt::math::TPoint3D& bb_max) const override;
124 
125  /** Basic empty constructor. Set all parameters to default. */
126  CFrustum();
127  /** Constructor with some parameters */
128  CFrustum(
129  float near_distance, float far_distance, float horz_FOV_degrees,
130  float vert_FOV_degrees, float lineWidth, bool draw_lines,
131  bool draw_planes);
132 
133  /** Destructor */
134  ~CFrustum() override = default;
135 };
136 } // namespace mrpt::opengl
float getHorzFOVLeft() const
Definition: CFrustum.h:109
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CFrustum.cpp:167
double RAD2DEG(const double x)
Radians to degrees.
float getNearPlaneDistance() const
Definition: CFrustum.h:88
float m_min_distance
Near and far planes.
Definition: CFrustum.h:57
void setVertFOV(const float fov_vert_degrees)
Changes vertical FOV (symmetric)
Definition: CFrustum.cpp:191
float getHorzFOVRight() const
Definition: CFrustum.h:110
void setHorzFOV(const float fov_horz_degrees)
Changes horizontal FOV (symmetric)
Definition: CFrustum.cpp:182
float getVertFOVUp() const
Definition: CFrustum.h:112
GLenum GLsizei width
Definition: glext.h:3535
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
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:75
CFrustum()
Basic empty constructor.
Definition: CFrustum.cpp:104
const GLubyte * c
Definition: glext.h:6406
float getLineWidth() const
Definition: CFrustum.h:72
~CFrustum() override=default
Destructor.
float getHorzFOV() const
Definition: CFrustum.h:101
const mrpt::img::TColor & getPlaneColor() const
Definition: CFrustum.h:80
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void setLineWidth(float width)
Definition: CFrustum.h:67
mrpt::img::TColor m_planes_color
Definition: CFrustum.h:64
float m_fov_horz_left
Semi FOVs (in radians)
Definition: CFrustum.h:59
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
void setNearFarPlanes(const float near_distance, const float far_distance)
Changes distance of near & far planes.
Definition: CFrustum.cpp:175
void render_dl() const override
Render.
Definition: CFrustum.cpp:29
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
void setVertFOVAsymmetric(const float fov_vert_down_degrees, const float fov_vert_up_degrees)
Changes vertical FOV (asymmetric)
Definition: CFrustum.cpp:211
const auto bb_max
A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assyme...
Definition: CFrustum.h:51
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:223
const auto bb_min
A RGB color - 8bit.
Definition: TColor.h:20
Lightweight 3D point.
Definition: TPoint3D.h:90
void setHorzFOVAsymmetric(const float fov_horz_left_degrees, const float fov_horz_right_degrees)
Changes horizontal FOV (asymmetric)
Definition: CFrustum.cpp:200
float getVertFOV() const
Definition: CFrustum.h:105
float getFarPlaneDistance() const
Definition: CFrustum.h:89
float m_fov_vert_down
Semi FOVs (in radians)
Definition: CFrustum.h:61
float getVertFOVDown() const
Definition: CFrustum.h:111



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019