Main MRPT website > C++ reference
MRPT logo
CPose3DPDFGaussian.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 CPose3DPDFGaussian_H
00029 #define CPose3DPDFGaussian_H
00030 
00031 #include <mrpt/poses/CPose3DPDF.h>
00032 #include <mrpt/poses/CPosePDF.h>
00033 #include <mrpt/math/CMatrixD.h>
00034 
00035 namespace mrpt
00036 {
00037 namespace poses
00038 {
00039         class CPosePDFGaussian;
00040         class CPose3DQuatPDFGaussian;
00041 
00042         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DPDFGaussian , CPose3DPDF )
00043 
00044         /** Declares a class that represents a Probability Density function (PDF) of a 3D pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
00045          *
00046          *   This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DPDF for more details.
00047          *
00048          *  Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussian::operator+=".
00049          *
00050          *  For further details on implemented methods and the theory behind them,
00051          *  see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
00052          *
00053          * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles
00054          * \ingroup poses_pdf_grp
00055          */
00056         class BASE_IMPEXP CPose3DPDFGaussian : public CPose3DPDF
00057         {
00058                 // This must be added to any CSerializable derived class:
00059                 DEFINE_SERIALIZABLE( CPose3DPDFGaussian )
00060 
00061         protected:
00062                 /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
00063                   */
00064                 void  assureSymmetry();
00065 
00066          public:
00067                  /** Default constructor
00068                   */
00069                 CPose3DPDFGaussian();
00070 
00071                 /** Constructor
00072                   */
00073                 explicit CPose3DPDFGaussian( const CPose3D &init_Mean );
00074 
00075                 /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
00076                   */
00077                 CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
00078 
00079                 /** Constructor  */
00080                 CPose3DPDFGaussian( const CPose3D &init_Mean, const CMatrixDouble66 &init_Cov );
00081 
00082                 /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables z,pitch, and roll).
00083                   */
00084                 explicit CPose3DPDFGaussian( const CPosePDFGaussian &o );
00085 
00086                 /** Constructor from a 6D pose PDF described as a Quaternion
00087                   */
00088                 explicit CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o);
00089 
00090                 /** The mean value
00091                  */
00092                 CPose3D         mean;
00093 
00094                 /** The 6x6 covariance matrix
00095                  */
00096                 CMatrixDouble66         cov;
00097 
00098                 inline const CPose3D & getPoseMean() const { return mean; }
00099                 inline       CPose3D & getPoseMean()       { return mean; }
00100 
00101                  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
00102                    * \sa getCovariance
00103                    */
00104                 void getMean(CPose3D &mean_pose) const;
00105 
00106                 /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
00107                   * \sa getMean
00108                   */
00109                 void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const;
00110 
00111                 /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
00112                   */
00113                 void  copyFrom(const CPose3DPDF &o);
00114 
00115                 /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
00116                   */
00117                 void  copyFrom(const CPosePDF &o);
00118 
00119                 /** Copy from a 6D pose PDF described as a Quaternion
00120                   */
00121                 void copyFrom( const CPose3DQuatPDFGaussian &o);
00122 
00123 
00124                 /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
00125                  */
00126                 void  saveToTextFile(const std::string &file) const;
00127 
00128                 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00129                   *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00130                   */
00131                 void  changeCoordinatesReference(  const CPose3D &newReferenceBase );
00132 
00133                 /** Draws a single sample from the distribution
00134                   */
00135                 void  drawSingleSample( CPose3D &outPart ) const;
00136 
00137                 /** Draws a number of samples from the distribution, and saves as a list of 1x6 vectors, where each row contains a (x,y,phi) datum.
00138                   */
00139                 void  drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
00140 
00141                 /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
00142                   *  The process is as follows:<br>
00143                   *             - (x1,S1): Mean and variance of the p1 distribution.
00144                   *             - (x2,S2): Mean and variance of the p2 distribution.
00145                   *             - (x,S): Mean and variance of the resulting distribution.
00146                   *
00147                   *    S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
00148                   *    x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
00149                   */
00150                 void  bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
00151 
00152                 /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
00153                   */
00154                 void     inverse(CPose3DPDF &o) const;
00155 
00156                 /** Unary - operator, returns the PDF of the inverse pose.  */
00157                 inline CPose3DPDFGaussian operator -() const
00158                 {
00159                         CPose3DPDFGaussian p(UNINITIALIZED_POSE);
00160                         this->inverse(p);
00161                         return p;
00162                 }
00163 
00164 
00165                 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
00166                   */
00167                 void  operator += ( const CPose3D &Ap);
00168 
00169                 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
00170                   */
00171                 void  operator += ( const CPose3DPDFGaussian &Ap);
00172 
00173                 /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
00174                   */
00175                 void  operator -= ( const CPose3DPDFGaussian &Ap);
00176 
00177                 /** Evaluates the PDF at a given point.
00178                   */
00179                 double  evaluatePDF( const CPose3D &x ) const;
00180 
00181                 /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
00182                   */
00183                 double  evaluateNormalizedPDF( const CPose3D &x ) const;
00184 
00185                 /** Computes the Mahalanobis distance between the centers of two Gaussians.
00186                   *  The variables with a variance exactly equal to 0 are not taken into account in the process, but
00187                   *   "infinity" is returned if the corresponding elements are not exactly equal.
00188                   */
00189                 double  mahalanobisDistanceTo( const CPose3DPDFGaussian& theOther);
00190 
00191                 /** This static method computes the pose composition Jacobians.
00192                 *
00193                 * See this techical report: http:///www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty
00194                 *
00195                 * Direct equations (for the covariances) in yaw-pitch-roll are too complex.
00196                 *  Make a way around them and consider instead this path:
00197                 * \code
00198                 *      X(6D)       U(6D)
00199                 *        |           |
00200                 *        v           v
00201                 *      X(7D)       U(7D)
00202                 *        |           |
00203                 *        +--- (+) ---+
00204                 *              |
00205                 *              v
00206                 *            RES(7D)
00207                 *              |
00208                 *              v
00209                 *            RES(6D)
00210                 * \endcode
00211                 *
00212                 */
00213                 static void jacobiansPoseComposition(
00214                         const CPose3D &x,
00215                         const CPose3D &u,
00216                         CMatrixDouble66  &df_dx,
00217                         CMatrixDouble66  &df_du);
00218 
00219 
00220                 /** Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
00221                   */
00222                 void getCovSubmatrix2D( CMatrixDouble &out_cov ) const;
00223 
00224 
00225         }; // End of class def.
00226 
00227 
00228         /** Pose composition for two 3D pose Gaussians  \sa CPose3DPDFGaussian::operator +=  */
00229         inline CPose3DPDFGaussian operator +( const CPose3DPDFGaussian &x, const CPose3DPDFGaussian &u )
00230         {
00231                 CPose3DPDFGaussian      res(x);
00232                 res+=u;
00233                 return res;
00234         }
00235 
00236         /** Pose composition for two 3D pose Gaussians  \sa CPose3DPDFGaussian::operator -=  */
00237         inline CPose3DPDFGaussian operator -( const CPose3DPDFGaussian &x, const CPose3DPDFGaussian &u )
00238         {
00239                 CPose3DPDFGaussian      res(x);
00240                 res-=u;
00241                 return res;
00242         }
00243 
00244         /** Dumps the mean and covariance matrix to a text stream.
00245           */
00246         std::ostream  BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
00247 
00248         bool BASE_IMPEXP operator==(const CPose3DPDFGaussian &p1,const CPose3DPDFGaussian &p2);
00249 
00250         } // End of namespace
00251 
00252 
00253         /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-core.
00254           *  See each variable for the description of what classes it affects.
00255           */
00256         namespace global_settings
00257         {
00258                 /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
00259                   * Affects to:
00260                   *             - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
00261                   */
00262                 extern BASE_IMPEXP bool USE_SUT_QUAT2EULER_CONVERSION;
00263         }
00264 
00265 } // End of namespace
00266 
00267 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011