Main MRPT website > C++ reference
MRPT logo
CPose3DQuatPDFGaussianInf.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 CPose3DQuatPDFGaussianInf_H
00029 #define CPose3DQuatPDFGaussianInf_H
00030 
00031 #include <mrpt/poses/CPose3DQuatPDF.h>
00032 #include <mrpt/poses/CPose3DPDF.h>
00033 #include <mrpt/poses/CPosePDF.h>
00034 #include <mrpt/math/CMatrixD.h>
00035 
00036 namespace mrpt
00037 {
00038 namespace poses
00039 {
00040         class CPosePDFGaussian;
00041         class CPose3DPDFGaussian;
00042 
00043         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DQuatPDFGaussianInf , CPose3DQuatPDF )
00044 
00045         /** Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion \f$ p(\mathbf{x}) = [x ~ y ~ z ~ qr ~ qx ~ qy ~ qz]^\top \f$.
00046          *
00047          *   This class implements that PDF using a mono-modal Gaussian distribution storing the information matrix instead of its inverse, the covariance matrix.
00048          *     See mrpt::poses::CPose3DQuatPDF for more details, or
00049          *     mrpt::poses::CPose3DPDF for classes based on Euler angles instead.
00050          *
00051          *  Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the methods "CPose3DQuatPDFGaussianInf::operator+=" and "CPose3DQuatPDF::jacobiansPoseComposition".
00052          *
00053          *  For further details on implemented methods and the theory behind them,
00054          *  see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
00055          *
00056          * \sa CPose3DQuat, CPose3DQuatPDF, CPose3DPDF, CPose3DQuatPDFGaussian
00057          * \ingroup poses_pdf_grp
00058          */
00059         class BASE_IMPEXP CPose3DQuatPDFGaussianInf : public CPose3DQuatPDF
00060         {
00061                 // This must be added to any CSerializable derived class:
00062                 DEFINE_SERIALIZABLE( CPose3DQuatPDFGaussianInf )
00063 
00064          public:
00065                  /** Default constructor - set all values to zero. */
00066                 CPose3DQuatPDFGaussianInf();
00067 
00068                 /** Constructor which left all the member uninitialized, for using when speed is critical - as argument, use UNINITIALIZED_QUATERNION. */
00069                 CPose3DQuatPDFGaussianInf(TConstructorFlags_Quaternions constructor_dummy_param);
00070 
00071                 /** Constructor from a default mean value, information matrix equals to zero. */
00072                 explicit CPose3DQuatPDFGaussianInf( const CPose3DQuat &init_Mean );
00073 
00074                 /** Constructor with mean and inverse covariance (information matrix). */
00075                 CPose3DQuatPDFGaussianInf( const CPose3DQuat &init_Mean, const CMatrixDouble77 &init_CovInv );
00076 
00077                 /** The mean value */
00078                 CPose3DQuat             mean;
00079 
00080                 /** The 7x7 information matrix (the inverse of the covariance) */
00081                 CMatrixDouble77         cov_inv;
00082 
00083                 inline const CPose3DQuat & getPoseMean() const { return mean; }
00084                 inline       CPose3DQuat & getPoseMean()       { return mean; }
00085 
00086                  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
00087                    * \sa getCovariance */
00088                 void getMean(CPose3DQuat &mean_pose) const {
00089                         mean_pose = mean;
00090                 }
00091 
00092                 /** Returns an estimate of the pose covariance matrix (7x7 cov matrix) and the mean, both at once.
00093                   * \sa getMean */
00094                 void getCovarianceAndMean(CMatrixDouble77 &cov,CPose3DQuat &mean_point) const {
00095                         cov_inv.inv(cov);
00096                         mean_point = mean;
00097                 }
00098 
00099                 /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
00100                 virtual void getInformationMatrix(CMatrixDouble77 &inf) const { inf=cov_inv; }
00101 
00102 
00103                 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
00104                 void  copyFrom(const CPose3DQuatPDF &o);
00105 
00106                 /** Save the PDF to a text file, containing the 3D pose in the first line (x y z qr qx qy qz), then the information matrix in the next 7 lines. */
00107                 void  saveToTextFile(const std::string &file) const;
00108 
00109                 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00110                   *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00111                   */
00112                 void  changeCoordinatesReference(  const CPose3DQuat &newReferenceBase );
00113 
00114                 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00115                   *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00116                   */
00117                 void  changeCoordinatesReference(  const CPose3D &newReferenceBase );
00118 
00119                 /** Draws a single sample from the distribution */
00120                 void  drawSingleSample( CPose3DQuat &outPart ) const;
00121 
00122                 /** Draws a number of samples from the distribution, and saves as a list of 1x7 vectors, where each row contains a (x,y,z,qr,qx,qy,qz) datum. */
00123                 void  drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
00124 
00125                 /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
00126                 void     inverse(CPose3DQuatPDF &o) const;
00127 
00128                 /** Unary - operator, returns the PDF of the inverse pose.  */
00129                 inline CPose3DQuatPDFGaussianInf operator -() const
00130                 {
00131                         CPose3DQuatPDFGaussianInf p(UNINITIALIZED_QUATERNION);
00132                         this->inverse(p);
00133                         return p;
00134                 }
00135 
00136                 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
00137                   */
00138                 void  operator += ( const CPose3DQuat &Ap);
00139 
00140                 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ).
00141                   */
00142                 void  operator += ( const CPose3DQuatPDFGaussianInf &Ap);
00143 
00144                 /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
00145                   */
00146                 void  operator -= ( const CPose3DQuatPDFGaussianInf &Ap);
00147 
00148                 /** Evaluates the PDF at a given point.
00149                   */
00150                 double  evaluatePDF( const CPose3DQuat &x ) const;
00151 
00152                 /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
00153                   */
00154                 double  evaluateNormalizedPDF( const CPose3DQuat &x ) const;
00155 
00156         }; // End of class def.
00157 
00158 
00159         /** Pose composition for two 3D pose Gaussians  \sa CPose3DQuatPDFGaussianInf::operator += */
00160         inline CPose3DQuatPDFGaussianInf operator +( const CPose3DQuatPDFGaussianInf &x, const CPose3DQuatPDFGaussianInf &u )
00161         {
00162                 CPose3DQuatPDFGaussianInf       res(x);
00163                 res+=u;
00164                 return res;
00165         }
00166 
00167         /** Inverse pose composition for two 3D pose Gaussians  \sa CPose3DQuatPDFGaussianInf::operator -= */
00168         inline CPose3DQuatPDFGaussianInf operator -( const CPose3DQuatPDFGaussianInf &x, const CPose3DQuatPDFGaussianInf &u )
00169         {
00170                 CPose3DQuatPDFGaussianInf       res(x);
00171                 res-=u;
00172                 return res;
00173         }
00174 
00175         /** Dumps the mean and covariance matrix to a text stream.
00176           */
00177         std::ostream  BASE_IMPEXP & operator << (std::ostream & out, const CPose3DQuatPDFGaussianInf& obj);
00178 
00179         bool BASE_IMPEXP operator==(const CPose3DQuatPDFGaussianInf &p1,const CPose3DQuatPDFGaussianInf &p2);
00180 
00181         } // End of namespace
00182 
00183 } // End of namespace
00184 
00185 #endif



Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 Hosted on:
SourceForge.net Logo