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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020