Main MRPT website > C++ reference
MRPT logo
CEllipsoid.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_CEllipsoid_H
29 #define opengl_CEllipsoid_H
30 
32 #include <mrpt/math/CMatrixD.h>
34 
35 namespace mrpt
36 {
37  namespace opengl
38  {
40 
41  // This must be added to any CSerializable derived class:
43 
44  /** A 2D ellipse or 3D ellipsoid, depending on the size of the m_cov matrix (2x2 or 3x3).
45  * The center of the ellipsoid is the "m_x,m_y,m_z" object's coordinates. In the case of
46  * a 2D ellipse it will be drawn in the XY plane, for z=0.
47  * The color is determined by the RGBA fields in the class "CRenderizable". Note that a
48  * transparent ellipsoid can be drawn for "0<alpha<1" values.
49  * If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not be rendered.
50  * \sa opengl::COpenGLScene
51  *
52  *
53  * Please read the documentation of CGeneralizedEllipsoidTemplate::setQuantiles() for learning
54  * the mathematical details about setting the desired confidence interval.
55  *
56  * <div align="center">
57  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
58  * <tr> <td> mrpt::opengl::CEllipsoid </td> <td> \image html preview_CEllipsoid.png </td> </tr>
59  * </table>
60  * </div>
61  *
62  * \ingroup mrpt_opengl_grp
63  */
65  {
67 
68  protected:
69  /** Used to store computed values the first time this is rendered, and to avoid recomputing them again.
70  */
71  math::CMatrixD m_eigVal,m_eigVec,m_prevComputedCov;
72 
73  math::CMatrixD m_cov; //!< The 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid.
74  bool m_drawSolid3D; //!< If set to true (default), a whole ellipsoid surface will be drawn, or if set to "false" it will be drawn as a "wireframe".
75  float m_quantiles; //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
76  unsigned int m_2D_segments; //!< The number of segments of a 2D ellipse (default=20)
77  unsigned int m_3D_segments; //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
78  float m_lineWidth; //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
79 
80  public:
81  void setCovMatrix( const mrpt::math::CMatrixDouble &m, int resizeToSize = -1 ); //!< Set the 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid (if resizeToSize>0, the matrix will be cut to the square matrix of the given size)
82  void setCovMatrix( const mrpt::math::CMatrixFloat &m, int resizeToSize = -1 ); //!< Set the 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid (if resizeToSize>0, the matrix will be cut to the square matrix of the given size).
83 
84  /** Set the 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid (if resizeToSize>0, the matrix will be cut to the square matrix of the given size)
85  */
86  template <typename T>
87  void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,3,3> &m, int resizeToSize = -1 ) {
88  setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m),resizeToSize);
89  }
90 
91  /** Set the 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid (if resizeToSize>0, the matrix will be cut to the square matrix of the given size)
92  */
93  template <typename T>
96  }
97 
99 
100  void enableDrawSolid3D(bool v) { m_drawSolid3D = v; CRenderizableDisplayList::notifyChange(); } //!< If set to true (default), a whole ellipsoid surface will be drawn, or if set to "false" it will be drawn as a "wireframe".
101  void setQuantiles(float q) { m_quantiles=q; CRenderizableDisplayList::notifyChange(); } //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
102  float getQuantiles() const { return m_quantiles; }
103 
104  void set2DsegmentsCount(unsigned int N) { m_2D_segments=N; CRenderizableDisplayList::notifyChange(); } //!< The number of segments of a 2D ellipse (default=20)
105  void set3DsegmentsCount(unsigned int N) { m_3D_segments=N; CRenderizableDisplayList::notifyChange(); } //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
106 
107  void setLineWidth(float w) { m_lineWidth=w; CRenderizableDisplayList::notifyChange(); } //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
108  float getLineWidth() const { return m_lineWidth; }
109 
110 
111  /** Render
112  * If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not
113  * be rendered to ensure stability in the rendering process.
114  */
115  void render_dl() const;
116  /** Ray tracing
117  */
118  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
119 
120  private:
121  /** Constructor
122  */
123  CEllipsoid() : m_eigVal(),m_eigVec(),m_prevComputedCov(),
124  m_cov(2,2),
125  m_drawSolid3D(true),
126  m_quantiles(3),
127  m_2D_segments(20),
128  m_3D_segments(20),
129  m_lineWidth(1.0)
130  {
131  }
132  /** Private, virtual destructor: only can be deleted from smart pointers */
133  virtual ~CEllipsoid() { }
134  };
135 
136  } // end namespace
137 
138 } // End of namespace
139 
140 
141 #endif



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