Main MRPT website > C++ reference
MRPT logo
CFrustum.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_CFrustum_H
29 #define opengl_CFrustum_H
30 
33 
34 namespace mrpt {
35 namespace opengl {
36 
37  // This must be added to any CSerializable derived class:
39 
40  /** A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assymetric) field-of-view angles.
41  *
42  * You can switch whether to show only the lines, the surface of the frustum, or both.
43  * By default only the lines are drawn.
44  *
45  * The color of the object (via CRenderizable::setColor()) affects the color of lines.
46  * To set the color of planes use \a setPlaneColor()
47  *
48  * As usual in MRPT, the +X axis is assumed to by the main direction, in this case of the pyramid axis.
49  *
50  * The horizontal and vertical FOVs can be set directly with \a setHorzFOV() and \a setVertFOV() if
51  * they are symmetric, or with \a setHorzFOVAsymmetric() and \a setVertFOVAsymmetric() otherwise.
52  *
53  * All FOV angles are positive numbers. FOVs must be below 90deg on each side (below 180deg in total).
54  * If you try to set FOVs to larger values they'll truncated to 89.9deg.
55  *
56  * \sa opengl::COpenGLScene,opengl::CRenderizable
57  *
58  * <div align="center">
59  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
60  * <tr> <td> mrpt::opengl::CFrustum </td> <td> \image html preview_CFrustum.png </td> </tr>
61  * </table>
62  * </div>
63  *
64  * \ingroup mrpt_opengl_grp
65  */
67  {
69 
70  protected:
71  float m_min_distance, m_max_distance; //!< Near and far planes
72  float m_fov_horz_left,m_fov_horz_right; //!< Semi FOVs (in radians)
73  float m_fov_vert_down,m_fov_vert_up; //!< Semi FOVs (in radians)
74  bool m_draw_lines, m_draw_planes;
75  float m_lineWidth;
76  mrpt::utils::TColor m_planes_color;
77 
78  public:
79  /** Constructor returning a smart pointer to the newly created object. */
80  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 )
81  {
82  return CFrustumPtr(new CFrustum(near_distance,far_distance,horz_FOV_degrees,vert_FOV_degrees,lineWidth,draw_lines,draw_planes));
83  }
84 
85  inline void setLineWidth(float width) { m_lineWidth = width; CRenderizableDisplayList::notifyChange(); }
86  inline float getLineWidth() const { return m_lineWidth; }
87 
88  /** Changes the color of the planes; to change color of lines, use CRenderizable base methods. */
89  inline void setPlaneColor(const mrpt::utils::TColor &c) { m_planes_color=c; CRenderizableDisplayList::notifyChange(); }
90  inline const mrpt::utils::TColor &getPlaneColor() const { return m_planes_color; }
91 
92  /** Changes distance of near & far planes */
93  void setNearFarPlanes(const float near_distance, const float far_distance);
94 
95  float getNearPlaneDistance() const { return m_min_distance; }
96  float getFarPlaneDistance() const { return m_max_distance; }
97 
98  /** Changes horizontal FOV (symmetric) */
99  void setHorzFOV(const float fov_horz_degrees);
100  /** Changes vertical FOV (symmetric) */
101  void setVertFOV(const float fov_vert_degrees);
102  /** Changes horizontal FOV (asymmetric) */
103  void setHorzFOVAsymmetric(const float fov_horz_left_degrees,const float fov_horz_right_degrees);
104  /** Changes vertical FOV (asymmetric) */
105  void setVertFOVAsymmetric(const float fov_vert_down_degrees,const float fov_vert_up_degrees);
106 
107  float getHorzFOV() const { return mrpt::utils::RAD2DEG(m_fov_horz_left+m_fov_horz_right); }
108  float getVertFOV() const { return mrpt::utils::RAD2DEG(m_fov_vert_down+m_fov_vert_up); }
109  float getHorzFOVLeft() const { return mrpt::utils::RAD2DEG(m_fov_horz_left); }
110  float getHorzFOVRight() const { return mrpt::utils::RAD2DEG(m_fov_horz_right); }
111  float getVertFOVDown() const { return mrpt::utils::RAD2DEG(m_fov_vert_down); }
112  float getVertFOVUp() const { return mrpt::utils::RAD2DEG(m_fov_vert_up); }
113 
114  /** Render \sa mrpt::opengl::CRenderizable */
115  void render_dl() const;
116 
117  /** Ray tracing. \sa mrpt::opengl::CRenderizable */
118  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
119 
120 
121  private:
122  /** Basic empty constructor. Set all parameters to default. */
123  CFrustum();
124  /** Constructor with some parameters */
125  CFrustum(float near_distance, float far_distance, float horz_FOV_degrees, float vert_FOV_degrees, float lineWidth, bool draw_lines, bool draw_planes);
126 
127  /** Destructor */
128  virtual ~CFrustum() { }
129  };
130 }
131 }
132 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013