00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 MRPTDLLIMPEXP CEllipsoid; 00039 00040 // This must be added to any CSerializable derived class: 00041 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CEllipsoid, CRenderizable ) 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 * \sa opengl::COpenGLScene 00049 */ 00050 class MRPTDLLIMPEXP CEllipsoid : public CRenderizable 00051 { 00052 DEFINE_SERIALIZABLE( CEllipsoid ) 00053 00054 protected: 00055 /** Used to store computed values the first time this is rendered, and to avoid recomputing them again. 00056 */ 00057 math::CMatrixD m_eigVal,m_eigVec,m_prevComputedCov; 00058 00059 math::CMatrixD m_cov; //!< The 2x2 or 3x3 covariance matrix that will determine the aspect of the ellipsoid. 00060 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". 00061 float m_quantiles; //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3) 00062 unsigned int m_2D_segments; //!< The number of segments of a 2D ellipse (default=20) 00063 unsigned int m_3D_segments; //!< The number of segments of a 3D ellipse (in both "axis") (default=20) 00064 float m_lineWidth; //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1) 00065 00066 public: 00067 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) 00068 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). 00069 00070 /** 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) 00071 */ 00072 template <typename T> 00073 void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,3,3> &m, int resizeToSize = -1 ) { 00074 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m),resizeToSize); 00075 } 00076 00077 /** 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 */ 00079 template <typename T> 00080 void setCovMatrix( const mrpt::math::CMatrixFixedNumeric<T,2,2> &m ) { 00081 setCovMatrix(mrpt::math::CMatrixTemplateNumeric<T>(m)); 00082 } 00083 00084 mrpt::math::CMatrixDouble getCovMatrix() const { return mrpt::math::CMatrixDouble(m_cov); } 00085 00086 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". 00087 void setQuantiles(float q) { m_quantiles=q; } //!< The number of "sigmas" for drawing the ellipse/ellipsoid (default=3) 00088 float getQuantiles() const { return m_quantiles; } 00089 00090 void set2DsegmentsCount(unsigned int N) { m_2D_segments=N; } //!< The number of segments of a 2D ellipse (default=20) 00091 void set3DsegmentsCount(unsigned int N) { m_3D_segments=N; } //!< The number of segments of a 3D ellipse (in both "axis") (default=20) 00092 00093 void setLineWidth(float w) { m_lineWidth=w; } //!< The line width for 2D ellipses or 3D wireframe ellipsoids (default=1) 00094 float getLineWidth() const { return m_lineWidth; } 00095 00096 00097 /** Render 00098 */ 00099 void render() const; 00100 /** Ray tracing 00101 */ 00102 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const; 00103 00104 private: 00105 /** Constructor 00106 */ 00107 CEllipsoid() : m_eigVal(),m_eigVec(),m_prevComputedCov(), 00108 m_cov(2,2), 00109 m_drawSolid3D(true), 00110 m_quantiles(3), 00111 m_2D_segments(20), 00112 m_3D_segments(20), 00113 m_lineWidth(1.0) 00114 { 00115 } 00116 /** Private, virtual destructor: only can be deleted from smart pointers */ 00117 virtual ~CEllipsoid() { } 00118 }; 00119 00120 } // end namespace 00121 00122 } // End of namespace 00123 00124 00125 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:20:53 EDT 2009 |