Main MRPT website > C++ reference for MRPT 1.9.9
CPosePDFParticles.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 CPosePDFParticles_H
10 #define CPosePDFParticles_H
11 
12 #include <mrpt/poses/CPosePDF.h>
15 
16 namespace mrpt
17 {
18 namespace poses
19 {
20 /** Declares a class that represents a Probability Density Function (PDF) over a
21  * 2D pose (x,y,phi), using a set of weighted samples.
22  *
23  * This class is also the base for the implementation of Monte-Carlo
24  * Localization (MCL), in mrpt::slam::CMonteCarloLocalization2D.
25  *
26  * See the application "app/pf-localization" for an example of usage.
27  *
28  * \sa CPose2D, CPosePDF, CPoseGaussianPDF, CParticleFilterCapable
29  * \ingroup poses_pdf_grp
30  */
32  : public CPosePDF,
33  public mrpt::bayes::CParticleFilterData<CPose2D>,
35  CPosePDFParticles,
36  mrpt::bayes::CParticleFilterData<CPose2D>::CParticleList>
37 {
39 
40  public:
41  /** Free all the memory associated to m_particles, and set the number of
42  * parts = 0 */
43  void clear();
44 
45  /** Constructor
46  * \param M The number of m_particles.
47  */
48  CPosePDFParticles(size_t M = 1);
49 
50  /** Copy operator, translating if necesary (for example, between m_particles
51  * and gaussian representations)
52  */
53  void copyFrom(const CPosePDF& o) override;
54 
55  /** Reset the PDF to a single point: All m_particles will be set exactly to
56  * the supplied pose.
57  * \param location The location to set all the m_particles.
58  * \param particlesCount If this is set to 0 the number of m_particles
59  * remains unchanged.
60  * \sa resetUniform, resetUniformFreeSpace, resetAroundSetOfPoses
61  */
62  void resetDeterministic(const CPose2D& location, size_t particlesCount = 0);
63 
64  /** Reset the PDF to an uniformly distributed one, inside of the defined
65  * cube.
66  * If particlesCount is set to -1 the number of m_particles remains
67  * unchanged.
68  * \sa resetDeterministic, resetUniformFreeSpace, resetAroundSetOfPoses
69  */
70  void resetUniform(
71  const double& x_min, const double& x_max, const double& y_min,
72  const double& y_max, const double& phi_min = -M_PI,
73  const double& phi_max = M_PI, const int& particlesCount = -1);
74 
75  /** Reset the PDF to a multimodal distribution over a set of "spots"
76  * (x,y,phi)
77  * The total number of particles will be `list_poses.size() *
78  * num_particles_per_pose`.
79  * \param[in] list_poses The poses (x,y,phi) around which particles will be
80  * spread. Must contains at least one pose.
81  * \param[in] num_particles_per_pose Number of particles to be spread
82  * around each of the "spots" in list_poses. Must be >=1.
83  *
84  * Particles will be spread uniformly in a box of width
85  * `spread_{x,y,phi_rad}` in each of
86  * the three coordinates (meters, radians), so it can be understood as the
87  * "initial uncertainty".
88  *
89  * \sa resetDeterministic, resetUniformFreeSpace
90  */
92  const std::vector<mrpt::math::TPose2D>& list_poses,
93  const size_t num_particles_per_pose, const double spread_x,
94  const double spread_y, const double spread_phi_rad);
95 
96  /** Returns an estimate of the pose, (the mean, or mathematical expectation
97  * of the PDF).
98  * \sa getCovariance
99  */
100  void getMean(CPose2D& mean_pose) const override;
101 
102  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and
103  * the mean, both at once.
104  * \sa getMean
105  */
107  mrpt::math::CMatrixDouble33& cov, CPose2D& mean_point) const override;
108 
109  /** Returns the pose of the i'th particle.
110  */
111  CPose2D getParticlePose(size_t i) const;
112 
113  /** Save PDF's m_particles to a text file. In each line it will go: "x y phi
114  * weight"
115  */
116  void saveToTextFile(const std::string& file) const override;
117 
118  /** Get the m_particles count (equivalent to "particlesCount")
119  */
120  inline size_t size() const { return m_particles.size(); }
121  /** this = p (+) this. This can be used to convert a PDF from local
122  * coordinates to global, providing the point (newReferenceBase) from which
123  * "to project" the current pdf. Result PDF substituted the currently
124  * stored one in the object.
125  */
126  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
127 
128  /** Draws a single sample from the distribution (WARNING: weights are
129  * assumed to be normalized!)
130  */
131  void drawSingleSample(CPose2D& outPart) const override;
132 
133  /** Appends (pose-composition) a given pose "p" to each particle
134  */
135  void operator+=(const CPose2D& Ap);
136 
137  /** Appends (add to the list) a set of m_particles to the existing ones, and
138  * then normalize weights.
139  */
140  void append(CPosePDFParticles& o);
141 
142  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
143  */
144  void inverse(CPosePDF& o) const override;
145 
146  /** Returns the particle with the highest weight.
147  */
149 
150  /** Bayesian fusion.
151  */
152  void bayesianFusion(
153  const CPosePDF& p1, const CPosePDF& p2,
154  const double& minMahalanobisDistToDrop = 0) override;
155 
156  /** Evaluates the PDF at a given arbitrary point as reconstructed by a
157  * Parzen window.
158  * \sa saveParzenPDFToTextFile
159  */
160  double evaluatePDF_parzen(
161  const double& x, const double& y, const double& phi,
162  const double& stdXY, const double& stdPhi) const;
163 
164  /** Save a text file (compatible with matlab) representing the 2D evaluation
165  * of the PDF as reconstructed by a Parzen window.
166  * \sa evaluatePDF_parzen
167  */
169  const char* fileName, const double& x_min, const double& x_max,
170  const double& y_min, const double& y_max, const double& phi,
171  const double& stepSizeXY, const double& stdXY,
172  const double& stdPhi) const;
173 
174 }; // End of class def.
175 
176 } // End of namespace
177 } // End of namespace
178 
179 #endif
CPose2D getParticlePose(size_t i) const
Returns the pose of the i&#39;th particle.
CPosePDFParticles(size_t M=1)
Constructor.
GLint location
Definition: glext.h:4086
void inverse(CPosePDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPose2D &mean_point) const override
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once...
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double &minMahalanobisDistToDrop=0) override
Bayesian fusion.
void saveParzenPDFToTextFile(const char *fileName, const double &x_min, const double &x_max, const double &y_min, const double &y_max, const double &phi, const double &stepSizeXY, const double &stdXY, const double &stdPhi) const
Save a text file (compatible with matlab) representing the 2D evaluation of the PDF as reconstructed ...
#define M_PI
Definition: bits.h:92
void clear()
Free all the memory associated to m_particles, and set the number of parts = 0.
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution (WARNING: weights are assumed to be normalized!) ...
CParticleList m_particles
The array of particles.
void getMean(CPose2D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between m_particles and gaussian representations...
void operator+=(const CPose2D &Ap)
Appends (pose-composition) a given pose "p" to each particle.
void resetUniform(const double &x_min, const double &x_max, const double &y_min, const double &y_max, const double &phi_min=-M_PI, const double &phi_max=M_PI, const int &particlesCount=-1)
Reset the PDF to an uniformly distributed one, inside of the defined cube.
double evaluatePDF_parzen(const double &x, const double &y, const double &phi, const double &stdXY, const double &stdPhi) const
Evaluates the PDF at a given arbitrary point as reconstructed by a Parzen window. ...
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x...
GLsizei const GLchar ** string
Definition: glext.h:4101
This template class declares the array of particles and its internal data, managing some memory-relat...
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
void resetAroundSetOfPoses(const std::vector< mrpt::math::TPose2D > &list_poses, const size_t num_particles_per_pose, const double spread_x, const double spread_y, const double spread_phi_rad)
Reset the PDF to a multimodal distribution over a set of "spots" (x,y,phi) The total number of partic...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
size_t size() const
Get the m_particles count (equivalent to "particlesCount")
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
void resetDeterministic(const CPose2D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
void append(CPosePDFParticles &o)
Appends (add to the list) a set of m_particles to the existing ones, and then normalize weights...
GLenum GLint GLint y
Definition: glext.h:3538
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
Definition: ops_matrices.h:148
CPose2D getMostLikelyParticle() const
Returns the particle with the highest weight.
GLenum GLint x
Definition: glext.h:3538
void saveToTextFile(const std::string &file) const override
Save PDF&#39;s m_particles to a text file.
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
A curiously recurring template pattern (CRTP) approach to providing the basic functionality of any CP...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019