00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 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/CRenderizable.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, CRenderizable, 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 class OPENGL_IMPEXP CEllipsoid : public CRenderizable 00052 { 00053 DEFINE_SERIALIZABLE( CEllipsoid ) 00054 00055 protected: 00056 /** Used to store computed values the first time this is rendered, and to avoid recomputing them again. 00057 */ 00058 math::CMatrixD m_eigVal,m_eigVec,m_prevComputedCov; 00059 00060 math::CMatrixD m_cov; //!< The 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid. 00061 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". 00062 float m_quantiles; //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3) 00063 unsigned int m_2D_segments; //!< The number of segments of a 2D ellipse (default=20) 00064 unsigned int m_3D_segments; //!< The number of segments of a 3D ellipse (in both "axis") (default=20) 00065 float m_lineWidth; //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1) 00066 00067 public: 00068 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) 00069 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). 00070 00071 /** 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) 00072 */ 00073 template <typename T> 00074 void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,3,3> &m, int resizeToSize = -1 ) { 00075 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m),resizeToSize); 00076 } 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,2,2> &m ) { 00082 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m)); 00083 } 00084 00085 mrpt::math::CMatrixDouble getCovMatrix() const { return mrpt::math::CMatrixDouble(m_cov); } 00086 00087 void enableDrawSolid3D(bool v) { m_drawSolid3D = v; } //!< If set to true (default), a whole ellipsoid surface will be drawn, or if set to "false" it will be drawn as a "wireframe". 00088 void setQuantiles(float q) { m_quantiles=q; } //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3) 00089 float getQuantiles() const { return m_quantiles; } 00090 00091 void set2DsegmentsCount(unsigned int N) { m_2D_segments=N; } //!< The number of segments of a 2D ellipse (default=20) 00092 void set3DsegmentsCount(unsigned int N) { m_3D_segments=N; } //!< The number of segments of a 3D ellipse (in both "axis") (default=20) 00093 00094 void setLineWidth(float w) { m_lineWidth=w; } //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1) 00095 float getLineWidth() const { return m_lineWidth; } 00096 00097 00098 /** Render 00099 * If one of the eigen value of the covariance matrix of the ellipsoid is null, ellipsoid will not 00100 * be rendered to ensure stability in the rendering process. 00101 */ 00102 void render() const; 00103 /** Ray tracing 00104 */ 00105 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const; 00106 00107 private: 00108 /** Constructor 00109 */ 00110 CEllipsoid() : m_eigVal(),m_eigVec(),m_prevComputedCov(), 00111 m_cov(2,2), 00112 m_drawSolid3D(true), 00113 m_quantiles(3), 00114 m_2D_segments(20), 00115 m_3D_segments(20), 00116 m_lineWidth(1.0) 00117 { 00118 } 00119 /** Private, virtual destructor: only can be deleted from smart pointers */ 00120 virtual ~CEllipsoid() { } 00121 }; 00122 00123 } // end namespace 00124 00125 } // End of namespace 00126 00127 00128 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
