Main MRPT website > C++ reference for MRPT 1.4.0
CFrustum.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9#ifndef opengl_CFrustum_H
10#define opengl_CFrustum_H
11
14
15namespace mrpt {
16namespace opengl {
17
18 // This must be added to any CSerializable derived class:
20
21 /** A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assymetric) field-of-view angles.
22 *
23 * You can switch whether to show only the lines, the surface of the frustum, or both.
24 * By default only the lines are drawn.
25 *
26 * The color of the object (via CRenderizable::setColor()) affects the color of lines.
27 * To set the color of planes use \a setPlaneColor()
28 *
29 * As usual in MRPT, the +X axis is assumed to by the main direction, in this case of the pyramid axis.
30 *
31 * The horizontal and vertical FOVs can be set directly with \a setHorzFOV() and \a setVertFOV() if
32 * they are symmetric, or with \a setHorzFOVAsymmetric() and \a setVertFOVAsymmetric() otherwise.
33 *
34 * All FOV angles are positive numbers. FOVs must be below 90deg on each side (below 180deg in total).
35 * If you try to set FOVs to larger values they'll truncated to 89.9deg.
36 *
37 * \sa opengl::COpenGLScene,opengl::CRenderizable
38 *
39 * <div align="center">
40 * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
41 * <tr> <td> mrpt::opengl::CFrustum </td> <td> \image html preview_CFrustum.png </td> </tr>
42 * </table>
43 * </div>
44 *
45 * \ingroup mrpt_opengl_grp
46 */
48 {
50
51 protected:
52 float m_min_distance, m_max_distance; //!< Near and far planes
53 float m_fov_horz_left,m_fov_horz_right; //!< Semi FOVs (in radians)
54 float m_fov_vert_down,m_fov_vert_up; //!< Semi FOVs (in radians)
55 bool m_draw_lines, m_draw_planes;
58
59 public:
60 /** Constructor returning a smart pointer to the newly created object. */
61 static CFrustumPtr Create(float near_distance, float far_distance, float horz_FOV_degrees, float vert_FOV_degrees, float lineWidth = 1.5f, bool draw_lines = true, bool draw_planes = false );
62
63 inline void setLineWidth(float width) { m_lineWidth = width; CRenderizableDisplayList::notifyChange(); }
64 inline float getLineWidth() const { return m_lineWidth; }
65
66 /** Changes the color of the planes; to change color of lines, use CRenderizable base methods. */
67 inline void setPlaneColor(const mrpt::utils::TColor &c) { m_planes_color=c; CRenderizableDisplayList::notifyChange(); }
68 inline const mrpt::utils::TColor &getPlaneColor() const { return m_planes_color; }
69
70 /** Changes distance of near & far planes */
71 void setNearFarPlanes(const float near_distance, const float far_distance);
72
73 float getNearPlaneDistance() const { return m_min_distance; }
74 float getFarPlaneDistance() const { return m_max_distance; }
75
76 /** Changes horizontal FOV (symmetric) */
77 void setHorzFOV(const float fov_horz_degrees);
78 /** Changes vertical FOV (symmetric) */
79 void setVertFOV(const float fov_vert_degrees);
80 /** Changes horizontal FOV (asymmetric) */
81 void setHorzFOVAsymmetric(const float fov_horz_left_degrees,const float fov_horz_right_degrees);
82 /** Changes vertical FOV (asymmetric) */
83 void setVertFOVAsymmetric(const float fov_vert_down_degrees,const float fov_vert_up_degrees);
84
85 float getHorzFOV() const { return mrpt::utils::RAD2DEG(m_fov_horz_left+m_fov_horz_right); }
86 float getVertFOV() const { return mrpt::utils::RAD2DEG(m_fov_vert_down+m_fov_vert_up); }
87 float getHorzFOVLeft() const { return mrpt::utils::RAD2DEG(m_fov_horz_left); }
88 float getHorzFOVRight() const { return mrpt::utils::RAD2DEG(m_fov_horz_right); }
89 float getVertFOVDown() const { return mrpt::utils::RAD2DEG(m_fov_vert_down); }
90 float getVertFOVUp() const { return mrpt::utils::RAD2DEG(m_fov_vert_up); }
91
92 /** Render \sa mrpt::opengl::CRenderizable */
94
95 /** Ray tracing. \sa mrpt::opengl::CRenderizable */
96 bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const MRPT_OVERRIDE;
97
98 /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
99 void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
100
101 private:
102 /** Basic empty constructor. Set all parameters to default. */
104 /** Constructor with some parameters */
105 CFrustum(float near_distance, float far_distance, float horz_FOV_degrees, float vert_FOV_degrees, float lineWidth, bool draw_lines, bool draw_planes);
106
107 /** Destructor */
108 virtual ~CFrustum() { }
109 };
110 DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(CFrustum,CRenderizableDisplayList, OPENGL_IMPEXP)
111}
112}
113#endif
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assyme...
Definition: CFrustum.h:48
void setLineWidth(float width)
Definition: CFrustum.h:63
void setVertFOV(const float fov_vert_degrees)
Changes vertical FOV (symmetric)
float getHorzFOV() const
Definition: CFrustum.h:85
static CFrustumPtr Create(float near_distance, float far_distance, float horz_FOV_degrees, float vert_FOV_degrees, float lineWidth=1.5f, bool draw_lines=true, bool draw_planes=false)
Constructor returning a smart pointer to the newly created object.
float getVertFOVUp() const
Definition: CFrustum.h:90
float getHorzFOVLeft() const
Definition: CFrustum.h:87
float getLineWidth() const
Definition: CFrustum.h:64
float getHorzFOVRight() const
Definition: CFrustum.h:88
float getNearPlaneDistance() const
Definition: CFrustum.h:73
void setVertFOVAsymmetric(const float fov_vert_down_degrees, const float fov_vert_up_degrees)
Changes vertical FOV (asymmetric)
float getVertFOV() const
Definition: CFrustum.h:86
void setHorzFOVAsymmetric(const float fov_horz_left_degrees, const float fov_horz_right_degrees)
Changes horizontal FOV (asymmetric)
void render_dl() const MRPT_OVERRIDE
Render.
void setPlaneColor(const mrpt::utils::TColor &c)
Changes the color of the planes; to change color of lines, use CRenderizable base methods.
Definition: CFrustum.h:67
float getFarPlaneDistance() const
Definition: CFrustum.h:74
mrpt::utils::TColor m_planes_color
Definition: CFrustum.h:57
float m_max_distance
Near and far planes.
Definition: CFrustum.h:52
const mrpt::utils::TColor & getPlaneColor() const
Definition: CFrustum.h:68
float getVertFOVDown() const
Definition: CFrustum.h:89
void setNearFarPlanes(const float near_distance, const float far_distance)
Changes distance of near & far planes.
void setHorzFOV(const float fov_horz_degrees)
Changes horizontal FOV (symmetric)
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
struct OPENGL_IMPEXP CFrustumPtr
Definition: CFrustum.h:19
double RAD2DEG(const double x)
Radians to degrees.
Definition: bits.h:75
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A RGB color - 8bit.
Definition: TColor.h:26



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Wed Mar 22 09:54:56 UTC 2023