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://mrpt.sourceforge.net/                            |
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 
00034 namespace mrpt
00035 {
00036         namespace opengl
00037         {
00038                 class OPENGL_IMPEXP CEllipsoid;
00039 
00040                 // This must be added to any CSerializable derived class:
00041                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CEllipsoid, CRenderizableDisplayList, OPENGL_IMPEXP )
00042 
00043                 /** A 2D ellipse or 3D ellipsoid, depending on the size of the m_cov matrix (2x2 or 3x3).
00044                   *  The center of the ellipsoid is the "m_x,m_y,m_z" object's coordinates. In the case of
00045                   *   a 2D ellipse it will be drawn in the XY plane, for z=0.
00046                   *  The color is determined by the RGBA fields in the class "CRenderizable". Note that a
00047                   *   transparent ellipsoid can be drawn for "0<alpha<1" values.
00048                   *      If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not be rendered.
00049                   *  \sa opengl::COpenGLScene
00050                   *  
00051                   *  <div align="center">
00052                   *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00053                   *   <tr> <td> mrpt::opengl::CEllipsoid </td> <td> \image html preview_CEllipsoid.png </td> </tr>
00054                   *  </table>
00055                   *  </div>
00056                   *  
00057                   */
00058                 class OPENGL_IMPEXP CEllipsoid : public CRenderizableDisplayList
00059                 {
00060                         DEFINE_SERIALIZABLE( CEllipsoid )
00061 
00062                 protected:
00063                         /** Used to store computed values the first time this is rendered, and to avoid recomputing them again.
00064                          */
00065                         math::CMatrixD          m_eigVal,m_eigVec,m_prevComputedCov;
00066 
00067                         math::CMatrixD  m_cov;          //!< The 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid.
00068                         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".
00069                         float                   m_quantiles;    //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
00070                         unsigned int    m_2D_segments;  //!< The number of segments of a 2D ellipse (default=20)
00071                         unsigned int    m_3D_segments;  //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
00072                         float                   m_lineWidth;    //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
00073 
00074                 public:
00075                         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)
00076                         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).
00077 
00078                         /**  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                         template <typename T>
00081                         void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,3,3> &m, int resizeToSize = -1 )     {
00082                                 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m),resizeToSize);
00083                         }
00084 
00085                         /**  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)
00086                          */
00087                         template <typename T>
00088                         void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,2,2> &m )    {
00089                                 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m));
00090                         }
00091 
00092                         mrpt::math::CMatrixDouble getCovMatrix() const { return mrpt::math::CMatrixDouble(m_cov); }
00093 
00094                         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".
00095                         void setQuantiles(float q) { m_quantiles=q; CRenderizableDisplayList::notifyChange(); } //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3)
00096                         float getQuantiles() const { return m_quantiles; }
00097 
00098                         void set2DsegmentsCount(unsigned int N) { m_2D_segments=N; CRenderizableDisplayList::notifyChange(); }  //!< The number of segments of a 2D ellipse (default=20)
00099                         void set3DsegmentsCount(unsigned int N) { m_3D_segments=N; CRenderizableDisplayList::notifyChange(); } //!< The number of segments of a 3D ellipse (in both "axis") (default=20)
00100 
00101                         void setLineWidth(float w) { m_lineWidth=w; } //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1)
00102                         float getLineWidth() const { return m_lineWidth; }
00103 
00104 
00105                         /** Render
00106                           *     If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not
00107                           * be rendered to ensure stability in the rendering process.
00108                           */
00109                         void  render_dl() const;
00110                         /** Ray tracing
00111                           */
00112                         virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00113 
00114                 private:
00115                         /** Constructor
00116                           */
00117                         CEllipsoid() : m_eigVal(),m_eigVec(),m_prevComputedCov(),
00118                                 m_cov(2,2),
00119                                 m_drawSolid3D(true),
00120                                 m_quantiles(3),
00121                                 m_2D_segments(20),
00122                                 m_3D_segments(20),
00123                                 m_lineWidth(1.0)
00124                         {
00125                         }
00126                         /** Private, virtual destructor: only can be deleted from smart pointers */
00127                         virtual ~CEllipsoid() { }
00128                 };
00129 
00130         } // end namespace
00131 
00132 } // End of namespace
00133 
00134 
00135 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011