Main MRPT website > C++ reference for MRPT 1.5.9
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-2017, 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 
15 namespace mrpt {
16 namespace opengl {
17 
18  // This must be added to any CSerializable derived class:
19  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CFrustum,CRenderizableDisplayList, OPENGL_IMPEXP)
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;
56  float m_lineWidth;
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 */
93  void render_dl() const MRPT_OVERRIDE;
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. */
103  CFrustum();
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
float getHorzFOVLeft() const
Definition: CFrustum.h:87
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:1989
float getNearPlaneDistance() const
Definition: CFrustum.h:73
float getHorzFOVRight() const
Definition: CFrustum.h:88
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
float getVertFOVUp() const
Definition: CFrustum.h:90
GLenum GLsizei width
Definition: glext.h:3513
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#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...
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
double RAD2DEG(const double x)
Radians to degrees.
float m_fov_vert_up
Semi FOVs (in radians)
Definition: CFrustum.h:54
const GLubyte * c
Definition: glext.h:5590
float getLineWidth() const
Definition: CFrustum.h:64
A RGB color - 8bit.
Definition: TColor.h:26
float getHorzFOV() const
Definition: CFrustum.h:85
const mrpt::utils::TColor & getPlaneColor() const
Definition: CFrustum.h:68
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#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:63
A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assyme...
Definition: CFrustum.h:47
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
float getVertFOV() const
Definition: CFrustum.h:86
mrpt::utils::TColor m_planes_color
Definition: CFrustum.h:57
float getFarPlaneDistance() const
Definition: CFrustum.h:74
float getVertFOVDown() const
Definition: CFrustum.h:89
float m_fov_horz_right
Semi FOVs (in radians)
Definition: CFrustum.h:53



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020