Main MRPT website > C++ reference
MRPT logo
CPoseRandomSampler.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 CPoseRandomSampler_H
00029 #define CPoseRandomSampler_H
00030 
00031 #include <mrpt/poses/CPosePDF.h>
00032 #include <mrpt/poses/CPose3DPDF.h>
00033 #include <mrpt/math/CMatrixTemplateNumeric.h>
00034 
00035 namespace mrpt
00036 {
00037     namespace poses
00038     {
00039         using namespace mrpt::math;
00040 
00041         /** An efficient generator of random samples drawn from a given 2D (CPosePDF) or 3D (CPose3DPDF) pose probability density function (pdf).
00042          * This class keeps an internal state which speeds up the sequential generation of samples. It can manage
00043          *  any kind of pose PDF.
00044                  *
00045          * Use with CPoseRandomSampler::setPosePDF, then CPoseRandomSampler::drawSample to draw values.
00046                  *
00047          * Notice that you can pass a 2D or 3D pose PDF, then ask for a 2D or 3D sample. This class always returns
00048          *  the kind of sample you ask it for, but will skip missing terms or fill out with zeroes as required.
00049                  * Specifically, when sampling 3D poses from a 2D pose pdf, this class will be smart enought to draw only
00050                  *  the 3 required dimensions, avoiding a waste of time with the other 3 missing components.
00051          *
00052                  * \ingroup poses_pdf_grp
00053          * \sa CPosePDF, CPose3DPDF
00054          */
00055         class BASE_IMPEXP CPoseRandomSampler
00056         {
00057         protected:
00058                         // Only ONE of these can be not-NULL at a time.
00059             CPosePDF*   m_pdf2D;        //!< A local copy of the PDF
00060             CPose3DPDF* m_pdf3D;        //!< A local copy of the PDF
00061 
00062             CMatrixDouble33 m_fastdraw_gauss_Z3;
00063             CMatrixDouble66 m_fastdraw_gauss_Z6;
00064             CPose2D         m_fastdraw_gauss_M_2D;
00065             CPose3D         m_fastdraw_gauss_M_3D;
00066 
00067             void clear(); //!< Clear internal pdf
00068 
00069                         void do_sample_2D( CPose2D &p ) const;  //!< Used internally: sample from m_pdf2D
00070                         void do_sample_3D( CPose3D &p ) const;  //!< Used internally: sample from m_pdf3D
00071 
00072         public:
00073             /** Default constructor */
00074             CPoseRandomSampler();
00075 
00076             /** Destructor */
00077             ~CPoseRandomSampler();
00078 
00079             /** This method must be called to select the PDF from which to draw samples.
00080               * \sa drawSample
00081               */
00082             void setPosePDF( const CPosePDF *pdf );
00083 
00084             /** This method must be called to select the PDF from which to draw samples.
00085               * \sa drawSample
00086               */
00087             void setPosePDF( const CPosePDFPtr &pdf ) { setPosePDF(pdf.pointer()); }
00088 
00089             /** This method must be called to select the PDF from which to draw samples.
00090               * \sa drawSample
00091               */
00092             void setPosePDF( const CPosePDF &pdf ) { setPosePDF(&pdf); }
00093 
00094             /** This method must be called to select the PDF from which to draw samples.
00095               * \sa drawSample
00096               */
00097             void setPosePDF( const CPose3DPDF *pdf );
00098 
00099             /** This method must be called to select the PDF from which to draw samples.
00100               * \sa drawSample
00101               */
00102             void setPosePDF( const CPose3DPDFPtr &pdf ) { setPosePDF(pdf.pointer()); }
00103 
00104             /** This method must be called to select the PDF from which to draw samples.
00105               * \sa drawSample
00106               */
00107             void setPosePDF( const CPose3DPDF &pdf ) { setPosePDF(&pdf); }
00108 
00109             /** Generate a new sample from the selected PDF.
00110               * \return A reference to the same object passed as argument.
00111               * \sa setPosePDF
00112               */
00113             CPose2D & drawSample( CPose2D &p ) const;
00114 
00115             /** Generate a new sample from the selected PDF.
00116               * \return A reference to the same object passed as argument.
00117               * \sa setPosePDF
00118               */
00119             CPose3D & drawSample( CPose3D &p ) const;
00120 
00121                         /** Return true if samples can be generated, which only requires a previous call to setPosePDF */
00122                         bool isPrepared() const;
00123 
00124                         /** If the object has been loaded with setPosePDF this method returns the 2D pose mean samples will be drawn around. \return A reference to the argument */
00125                         CPose2D &getSamplingMean2D(CPose2D &out_mean) const;
00126 
00127                         /** If the object has been loaded with setPosePDF this method returns the 3D pose mean samples will be drawn around. \return A reference to the argument */
00128                         CPose3D &getSamplingMean3D(CPose3D &out_mean) const;
00129 
00130                         /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ] \f$. */
00131                         void getOriginalPDFCov2D( CMatrixDouble33 &cov3x3 ) const;
00132 
00133                         /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ] \f$. */
00134                         inline void getOriginalPDFCov2D( CMatrixDouble &cov3x3 ) const {
00135                                 CMatrixDouble33 M;
00136                                 this->getOriginalPDFCov2D(M);
00137                                 cov3x3 = CMatrixDouble(M);
00138                         }
00139 
00140                         /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~ yaw ~ pitch ~ roll ] \f$. */
00141                         void getOriginalPDFCov3D( CMatrixDouble66 &cov6x6 ) const;
00142 
00143                         /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~ yaw ~ pitch ~ roll ] \f$. */
00144                         inline void getOriginalPDFCov3D( CMatrixDouble &cov6x6 ) const {
00145                                 CMatrixDouble66 M;
00146                                 this->getOriginalPDFCov3D(M);
00147                                 cov6x6 = CMatrixDouble(M);
00148                         }
00149 
00150         }; // End of class def.
00151         } // End of namespace
00152 } // End of namespace
00153 
00154 #endif



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