Main MRPT website > C++ reference for MRPT 1.5.6
CPoseRandomSampler.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CPoseRandomSampler_H
10 #define CPoseRandomSampler_H
11 
12 #include <mrpt/poses/CPose3D.h>
13 #include <mrpt/poses/CPose2D.h>
15 #include <mrpt/math/math_frwds.h>
16 
17 namespace mrpt
18 {
19  namespace poses
20  {
21  /** An efficient generator of random samples drawn from a given 2D (CPosePDF) or 3D (CPose3DPDF) pose probability density function (pdf).
22  * This class keeps an internal state which speeds up the sequential generation of samples. It can manage
23  * any kind of pose PDF.
24  *
25  * Use with CPoseRandomSampler::setPosePDF, then CPoseRandomSampler::drawSample to draw values.
26  *
27  * Notice that you can pass a 2D or 3D pose PDF, then ask for a 2D or 3D sample. This class always returns
28  * the kind of sample you ask it for, but will skip missing terms or fill out with zeroes as required.
29  * Specifically, when sampling 3D poses from a 2D pose pdf, this class will be smart enought to draw only
30  * the 3 required dimensions, avoiding a waste of time with the other 3 missing components.
31  *
32  * \ingroup poses_pdf_grp
33  * \sa CPosePDF, CPose3DPDF
34  */
36  {
37  protected:
38  // Only ONE of these can be not-NULL at a time.
39  CPosePDF* m_pdf2D; //!< A local copy of the PDF
40  CPose3DPDF* m_pdf3D; //!< A local copy of the PDF
41 
46 
47  void clear(); //!< Clear internal pdf
48 
49  void do_sample_2D( CPose2D &p ) const; //!< Used internally: sample from m_pdf2D
50  void do_sample_3D( CPose3D &p ) const; //!< Used internally: sample from m_pdf3D
51 
52  public:
53  CPoseRandomSampler(); //!< Ctor
54  ~CPoseRandomSampler(); //!< Dtor
55 
57  CPoseRandomSampler & operator =(const CPoseRandomSampler &o);
58 #if MRPT_HAS_CXX11
60  CPoseRandomSampler & operator =(CPoseRandomSampler &&o);
61 #endif
62 
63  /** This method must be called to select the PDF from which to draw samples.
64  * \sa drawSample
65  */
66  void setPosePDF( const CPosePDF *pdf );
67 
68  /** This method must be called to select the PDF from which to draw samples.
69  * \sa drawSample
70  */
71  void setPosePDF( const CPosePDFPtr &pdf );
72 
73  /** This method must be called to select the PDF from which to draw samples.
74  * \sa drawSample
75  */
76  void setPosePDF( const CPosePDF &pdf ) { setPosePDF(&pdf); }
77 
78  /** This method must be called to select the PDF from which to draw samples.
79  * \sa drawSample
80  */
81  void setPosePDF( const CPose3DPDF *pdf );
82 
83  /** This method must be called to select the PDF from which to draw samples.
84  * \sa drawSample
85  */
86  void setPosePDF( const CPose3DPDFPtr &pdf );
87 
88  /** This method must be called to select the PDF from which to draw samples.
89  * \sa drawSample
90  */
91  void setPosePDF( const CPose3DPDF &pdf ) { setPosePDF(&pdf); }
92 
93  /** Generate a new sample from the selected PDF.
94  * \return A reference to the same object passed as argument.
95  * \sa setPosePDF
96  */
97  CPose2D & drawSample( CPose2D &p ) const;
98 
99  /** Generate a new sample from the selected PDF.
100  * \return A reference to the same object passed as argument.
101  * \sa setPosePDF
102  */
103  CPose3D & drawSample( CPose3D &p ) const;
104 
105  /** Return true if samples can be generated, which only requires a previous call to setPosePDF */
106  bool isPrepared() const;
107 
108  /** 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 */
109  CPose2D &getSamplingMean2D(CPose2D &out_mean) const;
110 
111  /** 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 */
112  CPose3D &getSamplingMean3D(CPose3D &out_mean) const;
113 
114  /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ] \f$. */
115  void getOriginalPDFCov2D( mrpt::math::CMatrixDouble33 &cov3x3 ) const;
116 
117  /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ] \f$. */
118  inline void getOriginalPDFCov2D( mrpt::math::CMatrixDouble &cov3x3 ) const {
120  this->getOriginalPDFCov2D(M);
121  cov3x3 = mrpt::math::CMatrixDouble(M);
122  }
123 
124  /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~ yaw ~ pitch ~ roll ] \f$. */
125  void getOriginalPDFCov3D( mrpt::math::CMatrixDouble66 &cov6x6 ) const;
126 
127  /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~ yaw ~ pitch ~ roll ] \f$. */
128  inline void getOriginalPDFCov3D( mrpt::math::CMatrixDouble &cov6x6 ) const {
130  this->getOriginalPDFCov3D(M);
131  cov6x6 = mrpt::math::CMatrixDouble(M);
132  }
133 
134  }; // End of class def.
135  } // End of namespace
136 } // End of namespace
137 
138 #endif
CPosePDF * m_pdf2D
A local copy of the PDF.
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
void setPosePDF(const CPose3DPDF &pdf)
This method must be called to select the PDF from which to draw samples.
mrpt::math::CMatrixDouble33 m_fastdraw_gauss_Z3
GLfloat GLfloat p
Definition: glew.h:10113
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:39
CPose3DPDF * m_pdf3D
A local copy of the PDF.
void getOriginalPDFCov2D(mrpt::math::CMatrixDouble &cov3x3) const
Retrieves the 3x3 covariance of the original PDF in .
void setPosePDF(const CPosePDF &pdf)
This method must be called to select the PDF from which to draw samples.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:36
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
void getOriginalPDFCov3D(mrpt::math::CMatrixDouble &cov6x6) const
Retrieves the 6x6 covariance of the original PDF in .
mrpt::math::CMatrixDouble66 m_fastdraw_gauss_Z6
An efficient generator of random samples drawn from a given 2D (CPosePDF) or 3D (CPose3DPDF) pose pro...
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018