Main MRPT website > C++ reference
MRPT logo
CEllipsoid.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef opengl_CEllipsoid_H
00029 #define opengl_CEllipsoid_H
00030 
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/math/CMatrixD.h>
00033 #include <mrpt/math/CMatrixFixedNumeric.h>
00034 
00035 namespace mrpt
00036 {
00037         namespace opengl
00038         {
00039                 class OPENGL_IMPEXP CEllipsoid;
00040 
00041                 // This must be added to any CSerializable derived class:
00042                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CEllipsoid, CRenderizableDisplayList, OPENGL_IMPEXP )
00043 
00044                 /** A 2D ellipse or 3D ellipsoid, depending on the size of the m_cov matrix (2x2 or 3x3).
00045                   *  The center of the ellipsoid is the "m_x,m_y,m_z" object's coordinates. In the case of
00046                   *   a 2D ellipse it will be drawn in the XY plane, for z=0.
00047                   *  The color is determined by the RGBA fields in the class "CRenderizable". Note that a
00048                   *   transparent ellipsoid can be drawn for "0<alpha<1" values.
00049                   *      If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not be rendered.
00050                   *  \sa opengl::COpenGLScene
00051                   *
00052                   *  <div align="center">
00053                   *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00054                   *   <tr> <td> mrpt::opengl::CEllipsoid </td> <td> \image html preview_CEllipsoid.png </td> </tr>
00055                   *  </table>
00056                   *  </div>
00057                   *
00058                   * \ingroup mrpt_opengl_grp
00059                   */
00060                 class OPENGL_IMPEXP CEllipsoid : public CRenderizableDisplayList
00061                 {
00062                         DEFINE_SERIALIZABLE( CEllipsoid )
00063 
00064                 protected:
00065                         /** Used to store computed values the first time this is rendered, and to avoid recomputing them again.
00066                          */
00067                         math::CMatrixD          m_eigVal,m_eigVec,m_prevComputedCov;
00068 
00069                         math::CMatrixD  m_cov;          //!< The 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid.
00070                         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".
00071                         float                   m_quantiles;    //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
00072                         unsigned int    m_2D_segments;  //!< The number of segments of a 2D ellipse (default=20)
00073                         unsigned int    m_3D_segments;  //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
00074                         float                   m_lineWidth;    //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
00075 
00076                 public:
00077                         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)
00078                         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).
00079 
00080                         /**  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)
00081                          */
00082                         template <typename T>
00083                         void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,3,3> &m, int resizeToSize = -1 )     {
00084                                 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m),resizeToSize);
00085                         }
00086 
00087                         /**  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)
00088                          */
00089                         template <typename T>
00090                         void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,2,2> &m )    {
00091                                 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m));
00092                         }
00093 
00094                         mrpt::math::CMatrixDouble getCovMatrix() const { return mrpt::math::CMatrixDouble(m_cov); }
00095 
00096                         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".
00097                         void setQuantiles(float q) { m_quantiles=q; CRenderizableDisplayList::notifyChange(); } //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
00098                         float getQuantiles() const { return m_quantiles; }
00099 
00100                         void set2DsegmentsCount(unsigned int N) { m_2D_segments=N; CRenderizableDisplayList::notifyChange(); }  //!< The number of segments of a 2D ellipse (default=20)
00101                         void set3DsegmentsCount(unsigned int N) { m_3D_segments=N; CRenderizableDisplayList::notifyChange(); } //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
00102 
00103                         void setLineWidth(float w) { m_lineWidth=w; } //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
00104                         float getLineWidth() const { return m_lineWidth; }
00105 
00106 
00107                         /** Render
00108                           *     If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not
00109                           * be rendered to ensure stability in the rendering process.
00110                           */
00111                         void  render_dl() const;
00112                         /** Ray tracing
00113                           */
00114                         virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00115 
00116                 private:
00117                         /** Constructor
00118                           */
00119                         CEllipsoid() : m_eigVal(),m_eigVec(),m_prevComputedCov(),
00120                                 m_cov(2,2),
00121                                 m_drawSolid3D(true),
00122                                 m_quantiles(3),
00123                                 m_2D_segments(20),
00124                                 m_3D_segments(20),
00125                                 m_lineWidth(1.0)
00126                         {
00127                         }
00128                         /** Private, virtual destructor: only can be deleted from smart pointers */
00129                         virtual ~CEllipsoid() { }
00130                 };
00131 
00132         } // end namespace
00133 
00134 } // End of namespace
00135 
00136 
00137 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011