Main MRPT website > C++ reference
MRPT logo
CPose3DPDFParticles.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 CPose3DPDFParticles_H
00029 #define CPose3DPDFParticles_H
00030 
00031 #include <mrpt/poses/CPose3DPDF.h>
00032 #include <mrpt/bayes/CProbabilityParticle.h>
00033 #include <mrpt/bayes/CParticleFilterCapable.h>
00034 #include <mrpt/bayes/CParticleFilterData.h>
00035 
00036 namespace mrpt
00037 {
00038         namespace poses
00039         {
00040                 using namespace mrpt::bayes;
00041                 using namespace mrpt::utils;
00042 
00043                 /** \typedef CProbabilityParticle<CPose3D> CPose3DParticle
00044                  *  A type definition for m_particles containing a 3D pose.
00045                  */
00046                 typedef CProbabilityParticle<CPose3D> CPose3DParticle;
00047 
00048                 // This must be added to any CSerializable derived class:
00049                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(CPose3DPDFParticles,CPose3DPDF)
00050 
00051                 /** Declares a class that represents a Probability Density function (PDF) of a 3D pose
00052                  *
00053                  *  This class is also the base for the implementation of Monte-Carlo Localization (MCL), in mrpt::slam::CMonteCarloLocalization2D.
00054                  *
00055                  *  See the application "app/pf-localization" for an example of usage.
00056                  *
00057                  * \sa CPose3D, CPose3DPDF, CPoseGaussianPDF
00058                  * \ingroup poses_pdf_grp
00059                  */
00060                 class BASE_IMPEXP CPose3DPDFParticles :
00061                         public CPose3DPDF,
00062                         public mrpt::bayes::CParticleFilterData<CPose3D>,
00063                         public mrpt::bayes::CParticleFilterCapable
00064                 {
00065                         // This must be added to any CSerializable derived class:
00066                         DEFINE_SERIALIZABLE( CPose3DPDFParticles )
00067 
00068                         // This uses CParticleFilterData to implement some methods required for CParticleFilterCapable:
00069                         IMPLEMENT_PARTICLE_FILTER_CAPABLE(CPose3D)
00070 
00071                  public:
00072                         /** Constructor
00073                           * \param M The number of m_particles.
00074                           */
00075                         CPose3DPDFParticles( size_t M = 1 );
00076 
00077                         /** Copy constructor:
00078                           */
00079                         inline CPose3DPDFParticles( const CPose3DPDFParticles& obj ) :
00080                                 CPose3DPDF(),
00081                                 CParticleFilterData<CPose3D>()
00082                         {
00083                                 copyFrom( obj );
00084                         }
00085 
00086                         /** Destructor
00087                          */
00088                         virtual ~CPose3DPDFParticles();
00089 
00090 
00091                         /** Copy operator, translating if necesary (for example, between m_particles and gaussian representations)
00092                           */
00093                         void  copyFrom(const CPose3DPDF &o);
00094 
00095                         /** Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose.
00096                           * \param location The location to set all the m_particles.
00097                           * \param particlesCount If this is set to 0 the number of m_particles remains unchanged.
00098                           *  \sa resetUniform, resetUniformFreeSpace
00099                           */
00100                         void  resetDeterministic( const CPose3D &location,
00101                                                                                                 size_t  particlesCount = 0);
00102 
00103                          /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF), computed as a weighted average over all m_particles.
00104                            * \sa getCovariance
00105                            */
00106                         void getMean(CPose3D &mean_pose) const;
00107 
00108                         /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
00109                           * \sa getMean
00110                           */
00111                         void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const;
00112 
00113                         /** Returns the pose of the i'th particle.
00114                           */
00115                         CPose3D  getParticlePose(int i) const;
00116 
00117                         /** Save PDF's m_particles to a text file. In each line it will go: "x y z"
00118                          */
00119                         void  saveToTextFile(const std::string &file) const;
00120 
00121                         /** Get the m_particles count (equivalent to "particlesCount")
00122                          */
00123                         size_t  size() const { return m_particles.size(); }
00124 
00125                         /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00126                           *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00127                           */
00128                         void  changeCoordinatesReference( const CPose3D &newReferenceBase );
00129 
00130                         /** Draws a single sample from the distribution (WARNING: weights are assumed to be normalized!)
00131                           */
00132                         void  drawSingleSample( CPose3D &outPart ) const;
00133 
00134                         /** 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.
00135                           */
00136                         void  drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
00137 
00138                         /** Appends (pose-composition) a given pose "p" to each particle
00139                           */
00140                         void  operator += ( const CPose3D &Ap);
00141 
00142                         /** Appends (add to the list) a set of m_particles to the existing ones, and then normalize weights.
00143                           */
00144                         void append( CPose3DPDFParticles &o );
00145 
00146                         /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
00147                           */
00148                         void inverse(CPose3DPDF &o) const;
00149 
00150                         /** Returns the particle with the highest weight.
00151                           */
00152                         CPose3D  getMostLikelyParticle() const;
00153 
00154                         /** Bayesian fusion.
00155                           */
00156                         void  bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
00157 
00158                 }; // End of class def.
00159 
00160 
00161         } // End of namespace
00162 } // End of namespace
00163 
00164 #endif



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