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 CPointPDFGaussian_H 00029 #define CPointPDFGaussian_H 00030 00031 #include <mrpt/poses/CPointPDF.h> 00032 #include <mrpt/math/CMatrix.h> 00033 00034 namespace mrpt 00035 { 00036 namespace poses 00037 { 00038 using namespace mrpt::math; 00039 00040 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPointPDFGaussian, CPointPDF ) 00041 00042 /** A gaussian distribution for 3D points. Also a method for bayesian fusion is provided. 00043 * 00044 * \sa CPointPDF 00045 * \ingroup poses_pdf_grp 00046 */ 00047 class BASE_IMPEXP CPointPDFGaussian : public CPointPDF 00048 { 00049 // This must be added to any CSerializable derived class: 00050 DEFINE_SERIALIZABLE( CPointPDFGaussian ) 00051 00052 public: 00053 /** Default constructor 00054 */ 00055 CPointPDFGaussian(); 00056 00057 /** Constructor 00058 */ 00059 CPointPDFGaussian( const CPoint3D &init_Mean ); 00060 00061 /** Constructor 00062 */ 00063 CPointPDFGaussian( const CPoint3D &init_Mean, const CMatrixDouble33 &init_Cov ); 00064 00065 /** The mean value 00066 */ 00067 CPoint3D mean; 00068 00069 /** The 3x3 covariance matrix 00070 */ 00071 CMatrixDouble33 cov; 00072 00073 /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) 00074 */ 00075 void getMean(CPoint3D &p) const; 00076 00077 /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once. 00078 * \sa getMean 00079 */ 00080 void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const; 00081 00082 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) 00083 */ 00084 void copyFrom(const CPointPDF &o); 00085 00086 /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines. 00087 */ 00088 void saveToTextFile(const std::string &file) const; 00089 00090 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which 00091 * "to project" the current pdf. Result PDF substituted the currently stored one in the object. Both the mean value and the covariance matrix are updated correctly. 00092 */ 00093 void changeCoordinatesReference( const CPose3D &newReferenceBase ); 00094 00095 /** Bayesian fusion of two points gauss. distributions, then save the result in this object. 00096 * The process is as follows:<br> 00097 * - (x1,S1): Mean and variance of the p1 distribution. 00098 * - (x2,S2): Mean and variance of the p2 distribution. 00099 * - (x,S): Mean and variance of the resulting distribution. 00100 * 00101 * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>; 00102 * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 ); 00103 */ 00104 void bayesianFusion( const CPointPDFGaussian &p1, const CPointPDFGaussian &p2 ); 00105 00106 /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF. 00107 * The resulting number is >=0. 00108 * \sa productIntegralNormalizedWith 00109 * \exception std::exception On errors like covariance matrix with null determinant, etc... 00110 */ 00111 double productIntegralWith( const CPointPDFGaussian &p) const; 00112 00113 /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF. 00114 * The resulting number is >=0. 00115 * NOTE: This version ignores the "z" coordinates!! 00116 * \sa productIntegralNormalizedWith 00117 * \exception std::exception On errors like covariance matrix with null determinant, etc... 00118 */ 00119 double productIntegralWith2D( const CPointPDFGaussian &p) const; 00120 00121 /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF. 00122 * The resulting number is in the range [0,1] 00123 * Note that the resulting value is in fact 00124 * \f[ exp( -\frac{1}{2} D^2 ) \f] 00125 * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs. 00126 * \sa productIntegralWith 00127 * \exception std::exception On errors like covariance matrix with null determinant, etc... 00128 */ 00129 double productIntegralNormalizedWith( const CPointPDFGaussian &p) const; 00130 00131 /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF. 00132 * The resulting number is in the range [0,1]. This versions ignores the "z" coordinate. 00133 * 00134 * Note that the resulting value is in fact 00135 * \f[ exp( -\frac{1}{2} D^2 ) \f] 00136 * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs. 00137 * \sa productIntegralWith 00138 * \exception std::exception On errors like covariance matrix with null determinant, etc... 00139 */ 00140 double productIntegralNormalizedWith2D( const CPointPDFGaussian &p) const; 00141 00142 /** Draw a sample from the pdf. 00143 */ 00144 void drawSingleSample(CPoint3D &outSample) const; 00145 00146 /** Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!) 00147 * \param p1 The first distribution to fuse 00148 * \param p2 The second distribution to fuse 00149 * \param minMahalanobisDistToDrop If set to different of 0, the result of very separate Gaussian modes (that will result in negligible components) in SOGs will be dropped to reduce the number of modes in the output. 00150 */ 00151 void bayesianFusion( const CPointPDF &p1,const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0); 00152 00153 00154 /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0) 00155 */ 00156 double mahalanobisDistanceTo( const CPointPDFGaussian & other, bool only_2D = false ) const; 00157 00158 00159 }; // End of class def. 00160 00161 00162 } // End of namespace 00163 } // End of namespace 00164 00165 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |