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
mrpt::math::CMatrixDouble
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
Definition: CMatrixTemplateNumeric.h:144
mrpt::poses::CPoseRandomSampler::m_fastdraw_gauss_Z6
mrpt::math::CMatrixDouble66 m_fastdraw_gauss_Z6
Definition: CPoseRandomSampler.h:55
mrpt::poses::CPoseRandomSampler::getSamplingMean2D
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...
Definition: CPoseRandomSampler.cpp:414
mrpt::poses::CPoseRandomSampler::setPosePDF
void setPosePDF(const CPose3DPDF &pdf)
This method must be called to select the PDF from which to draw samples.
Definition: CPoseRandomSampler.h:103
mrpt::poses::CPoseRandomSampler::m_pdf3D
std::unique_ptr< const CPose3DPDF > m_pdf3D
A local copy of the PDF.
Definition: CPoseRandomSampler.h:52
mrpt::poses::CPoseRandomSampler::setPosePDF
void setPosePDF(const CPosePDF *pdf)
This method must be called to select the PDF from which to draw samples.
Definition: CPoseRandomSampler.cpp:110
mrpt::poses::CPoseRandomSampler::getOriginalPDFCov3D
void getOriginalPDFCov3D(mrpt::math::CMatrixDouble66 &cov6x6) const
Retrieves the 6x6 covariance of the original PDF in .
Definition: CPoseRandomSampler.cpp:391
mrpt::poses::CPoseRandomSampler::m_fastdraw_gauss_M_2D
CPose2D m_fastdraw_gauss_M_2D
Definition: CPoseRandomSampler.h:56
mrpt::poses::CPoseRandomSampler::isPrepared
bool isPrepared() const
Return true if samples can be generated, which only requires a previous call to setPosePDF.
Definition: CPoseRandomSampler.cpp:363
mrpt::poses::CPose3DPDF
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:42
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::poses::CPoseRandomSampler::drawSample
CPose2D & drawSample(CPose2D &p) const
Generate a new sample from the selected PDF.
Definition: CPoseRandomSampler.cpp:208
p
GLfloat GLfloat p
Definition: glext.h:6305
CPose2D.h
mrpt::math::CMatrixTemplateNumeric< double >
mrpt::poses::CPoseRandomSampler::m_pdf2D
std::unique_ptr< const CPosePDF > m_pdf2D
A local copy of the PDF.
Definition: CPoseRandomSampler.h:50
mrpt::poses::CPoseRandomSampler::operator=
CPoseRandomSampler & operator=(const CPoseRandomSampler &o)
Definition: CPoseRandomSampler.cpp:43
CPosePDF.h
CMatrixTemplateNumeric.h
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
math_frwds.h
mrpt::poses::CPoseRandomSampler::do_sample_3D
void do_sample_3D(CPose3D &p) const
Used internally: sample from m_pdf3D.
Definition: CPoseRandomSampler.cpp:309
mrpt::math::CMatrixFixedNumeric< double, 3, 3 >
mrpt::poses::CPoseRandomSampler
An efficient generator of random samples drawn from a given 2D (CPosePDF) or 3D (CPose3DPDF) pose pro...
Definition: CPoseRandomSampler.h:45
CPose3D.h
mrpt::poses::CPosePDF
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:41
mrpt::poses::CPoseRandomSampler::getOriginalPDFCov2D
void getOriginalPDFCov2D(mrpt::math::CMatrixDouble33 &cov3x3) const
Retrieves the 3x3 covariance of the original PDF in .
Definition: CPoseRandomSampler.cpp:367
mrpt::poses::CPoseRandomSampler::CPoseRandomSampler
CPoseRandomSampler()
Default constructor.
Definition: CPoseRandomSampler.cpp:30
mrpt::poses::CPoseRandomSampler::getOriginalPDFCov2D
void getOriginalPDFCov2D(mrpt::math::CMatrixDouble &cov3x3) const
Retrieves the 3x3 covariance of the original PDF in .
Definition: CPoseRandomSampler.h:136
mrpt::poses::CPoseRandomSampler::getOriginalPDFCov3D
void getOriginalPDFCov3D(mrpt::math::CMatrixDouble &cov6x6) const
Retrieves the 6x6 covariance of the original PDF in .
Definition: CPoseRandomSampler.h:149
mrpt::poses::CPose3DPDF::Ptr
std::shared_ptr< CPose3DPDF > Ptr
Definition: CPose3DPDF.h:45
mrpt::poses::CPoseRandomSampler::m_fastdraw_gauss_Z3
mrpt::math::CMatrixDouble33 m_fastdraw_gauss_Z3
Definition: CPoseRandomSampler.h:54
CPose3DPDF.h
mrpt::poses::CPosePDF::Ptr
std::shared_ptr< CPosePDF > Ptr
Definition: CPosePDF.h:44
mrpt::poses::CPoseRandomSampler::getSamplingMean3D
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...
Definition: CPoseRandomSampler.cpp:431
mrpt::poses::CPoseRandomSampler::do_sample_2D
void do_sample_2D(CPose2D &p) const
Used internally: sample from m_pdf2D.
Definition: CPoseRandomSampler.cpp:258
mrpt::poses::CPoseRandomSampler::clear
void clear()
Clear internal pdf.
Definition: CPoseRandomSampler.cpp:101
mrpt::poses::CPoseRandomSampler::setPosePDF
void setPosePDF(const CPosePDF &pdf)
This method must be called to select the PDF from which to draw samples.
Definition: CPoseRandomSampler.h:89
mrpt::poses::CPoseRandomSampler::m_fastdraw_gauss_M_3D
CPose3D m_fastdraw_gauss_M_3D
Definition: CPoseRandomSampler.h:57



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST