Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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>
14 #include <mrpt/poses/CPosePDF.h>
15 #include <mrpt/poses/CPose3DPDF.h>
17 #include <mrpt/math/math_frwds.h>
18 #include <memory> // unique_ptr
19 
20 namespace mrpt
21 {
22 namespace poses
23 {
24 /** An efficient generator of random samples drawn from a given 2D (CPosePDF) or
25  * 3D (CPose3DPDF) pose probability density function (pdf).
26  * This class keeps an internal state which speeds up the sequential generation
27  * of samples. It can manage
28  * any kind of pose PDF.
29  *
30  * Use with CPoseRandomSampler::setPosePDF, then CPoseRandomSampler::drawSample
31  * to draw values.
32  *
33  * Notice that you can pass a 2D or 3D pose PDF, then ask for a 2D or 3D sample.
34  * This class always returns
35  * the kind of sample you ask it for, but will skip missing terms or fill out
36  * with zeroes as required.
37  * Specifically, when sampling 3D poses from a 2D pose pdf, this class will be
38  * smart enought to draw only
39  * the 3 required dimensions, avoiding a waste of time with the other 3 missing
40  * components.
41  *
42  * \ingroup poses_pdf_grp
43  * \sa CPosePDF, CPose3DPDF
44  */
46 {
47  protected:
48  // Only ONE of these can be not-NULL at a time.
49  /** A local copy of the PDF */
50  std::unique_ptr<const CPosePDF> m_pdf2D;
51  /** A local copy of the PDF */
52  std::unique_ptr<const CPose3DPDF> m_pdf3D;
53 
58 
59  /** Clear internal pdf */
60  void clear();
61 
62  /** Used internally: sample from m_pdf2D */
63  void do_sample_2D(CPose2D& p) const;
64  /** Used internally: sample from m_pdf3D */
65  void do_sample_3D(CPose3D& p) const;
66 
67  public:
68  /** Default constructor */
70 
75 
76  /** This method must be called to select the PDF from which to draw samples.
77  * \sa drawSample
78  */
79  void setPosePDF(const CPosePDF* pdf);
80 
81  /** This method must be called to select the PDF from which to draw samples.
82  * \sa drawSample
83  */
84  void setPosePDF(const CPosePDF::Ptr& pdf);
85 
86  /** This method must be called to select the PDF from which to draw samples.
87  * \sa drawSample
88  */
89  void setPosePDF(const CPosePDF& pdf) { setPosePDF(&pdf); }
90  /** This method must be called to select the PDF from which to draw samples.
91  * \sa drawSample
92  */
93  void setPosePDF(const CPose3DPDF* pdf);
94 
95  /** This method must be called to select the PDF from which to draw samples.
96  * \sa drawSample
97  */
98  void setPosePDF(const CPose3DPDF::Ptr& pdf);
99 
100  /** This method must be called to select the PDF from which to draw samples.
101  * \sa drawSample
102  */
103  void setPosePDF(const CPose3DPDF& pdf) { setPosePDF(&pdf); }
104  /** Generate a new sample from the selected PDF.
105  * \return A reference to the same object passed as argument.
106  * \sa setPosePDF
107  */
108  CPose2D& drawSample(CPose2D& p) const;
109 
110  /** Generate a new sample from the selected PDF.
111  * \return A reference to the same object passed as argument.
112  * \sa setPosePDF
113  */
114  CPose3D& drawSample(CPose3D& p) const;
115 
116  /** Return true if samples can be generated, which only requires a previous
117  * call to setPosePDF */
118  bool isPrepared() const;
119 
120  /** If the object has been loaded with setPosePDF this method returns the 2D
121  * pose mean samples will be drawn around. \return A reference to the
122  * argument */
123  CPose2D& getSamplingMean2D(CPose2D& out_mean) const;
124 
125  /** If the object has been loaded with setPosePDF this method returns the 3D
126  * pose mean samples will be drawn around. \return A reference to the
127  * argument */
128  CPose3D& getSamplingMean3D(CPose3D& out_mean) const;
129 
130  /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ]
131  * \f$. */
133 
134  /** Retrieves the 3x3 covariance of the original PDF in \f$ [ x ~ y ~ \phi ]
135  * \f$. */
137  {
139  this->getOriginalPDFCov2D(M);
140  cov3x3 = mrpt::math::CMatrixDouble(M);
141  }
142 
143  /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~
144  * yaw ~ pitch ~ roll ] \f$. */
146 
147  /** Retrieves the 6x6 covariance of the original PDF in \f$ [ x ~ y ~ z ~
148  * yaw ~ pitch ~ roll ] \f$. */
150  {
152  this->getOriginalPDFCov3D(M);
153  cov6x6 = mrpt::math::CMatrixDouble(M);
154  }
155 
156 }; // End of class def.
157 } // End of namespace
158 } // End of namespace
159 
160 #endif
CPose2D & getSamplingMean2D(CPose2D &out_mean) const
If the object has been loaded with setPosePDF this method returns the 2D pose mean samples will be dr...
CPoseRandomSampler()
Default constructor.
std::unique_ptr< const CPose3DPDF > m_pdf3D
A local copy of the PDF.
bool isPrepared() const
Return true if samples can be generated, which only requires a previous call to setPosePDF.
void getOriginalPDFCov3D(mrpt::math::CMatrixDouble &cov6x6) const
Retrieves the 6x6 covariance of the original PDF in .
void getOriginalPDFCov3D(mrpt::math::CMatrixDouble66 &cov6x6) const
Retrieves the 6x6 covariance of the original PDF in .
CPose3D & getSamplingMean3D(CPose3D &out_mean) const
If the object has been loaded with setPosePDF this method returns the 3D pose mean samples will be dr...
void do_sample_3D(CPose3D &p) const
Used internally: sample from m_pdf3D.
void clear()
Clear internal pdf.
void setPosePDF(const CPosePDF *pdf)
This method must be called to select the PDF from which to draw samples.
void getOriginalPDFCov2D(mrpt::math::CMatrixDouble33 &cov3x3) const
Retrieves the 3x3 covariance of the original PDF in .
void do_sample_2D(CPose2D &p) const
Used internally: sample from m_pdf2D.
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
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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:40
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
CPoseRandomSampler & operator=(const CPoseRandomSampler &o)
std::unique_ptr< const CPosePDF > m_pdf2D
A local copy of the PDF.
CPose2D & drawSample(CPose2D &p) const
Generate a new sample from the selected PDF.
void getOriginalPDFCov2D(mrpt::math::CMatrixDouble &cov3x3) const
Retrieves the 3x3 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...
GLfloat GLfloat p
Definition: glext.h:6305
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019