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-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 CPosePDFParticles_H
10 #define CPosePDFParticles_H
11 
12 #include <mrpt/poses/CPosePDF.h>
17 
18 namespace mrpt::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,
34  mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>,
36  CPosePDFParticles,
37  mrpt::bayes::CParticleFilterData<
38  mrpt::math::TPose2D,
39  mrpt::bayes::particle_storage_mode::VALUE>::CParticleList>
40 {
42 
43  public:
44  /** Free all the memory associated to m_particles, and set the number of
45  * parts = 0 */
46  void clear();
47 
48  /** Constructor
49  * \param M The number of m_particles.
50  */
51  CPosePDFParticles(size_t M = 1);
52 
53  /** Copy operator, translating if necesary (for example, between m_particles
54  * and gaussian representations)
55  */
56  void copyFrom(const CPosePDF& o) override;
57 
58  /** Reset the PDF to a single point: All m_particles will be set exactly to
59  * the supplied pose.
60  * \param location The location to set all the m_particles.
61  * \param particlesCount If this is set to 0 the number of m_particles
62  * remains unchanged.
63  * \sa resetUniform, resetUniformFreeSpace, resetAroundSetOfPoses
64  */
65  void resetDeterministic(
66  const mrpt::math::TPose2D& location, size_t particlesCount = 0);
67 
68  /** Reset the PDF to an uniformly distributed one, inside of the defined
69  * cube.
70  * If particlesCount is set to -1 the number of m_particles remains
71  * unchanged.
72  * \sa resetDeterministic, resetUniformFreeSpace, resetAroundSetOfPoses
73  */
74  void resetUniform(
75  const double x_min, const double x_max, const double y_min,
76  const double y_max, const double phi_min = -M_PI,
77  const double phi_max = M_PI, const int particlesCount = -1);
78 
79  /** Reset the PDF to a multimodal distribution over a set of "spots"
80  * (x,y,phi)
81  * The total number of particles will be `list_poses.size() *
82  * num_particles_per_pose`.
83  * \param[in] list_poses The poses (x,y,phi) around which particles will be
84  * spread. Must contains at least one pose.
85  * \param[in] num_particles_per_pose Number of particles to be spread
86  * around each of the "spots" in list_poses. Must be >=1.
87  *
88  * Particles will be spread uniformly in a box of width
89  * `spread_{x,y,phi_rad}` in each of
90  * the three coordinates (meters, radians), so it can be understood as the
91  * "initial uncertainty".
92  *
93  * \sa resetDeterministic, resetUniformFreeSpace
94  */
96  const std::vector<mrpt::math::TPose2D>& list_poses,
97  const size_t num_particles_per_pose, const double spread_x,
98  const double spread_y, const double spread_phi_rad);
99 
100  /** Returns an estimate of the pose, (the mean, or mathematical expectation
101  * of the PDF).
102  * \sa getCovariance
103  */
104  void getMean(CPose2D& mean_pose) const override;
105 
106  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and
107  * the mean, both at once.
108  * \sa getMean
109  */
111  mrpt::math::CMatrixDouble33& cov, CPose2D& mean_point) const override;
112 
113  /** Returns the pose of the i'th particle.
114  */
115  mrpt::math::TPose2D getParticlePose(size_t i) const;
116 
117  /** Save PDF's m_particles to a text file. In each line it will go: "x y phi
118  * weight"
119  */
120  bool saveToTextFile(const std::string& file) const override;
121 
122  /** Get the m_particles count (equivalent to "particlesCount")
123  */
124  inline size_t size() const { return m_particles.size(); }
125  /** this = p (+) this. This can be used to convert a PDF from local
126  * coordinates to global, providing the point (newReferenceBase) from which
127  * "to project" the current pdf. Result PDF substituted the currently
128  * stored one in the object.
129  */
130  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
131 
132  /** Draws a single sample from the distribution (WARNING: weights are
133  * assumed to be normalized!)
134  */
135  void drawSingleSample(CPose2D& outPart) const override;
136 
137  /** Appends (pose-composition) a given pose "p" to each particle
138  */
139  void operator+=(const mrpt::math::TPose2D& Ap);
140 
141  /** Appends (add to the list) a set of m_particles to the existing ones, and
142  * then normalize weights.
143  */
144  void append(CPosePDFParticles& o);
145 
146  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
147  */
148  void inverse(CPosePDF& o) const override;
149 
150  /** Returns the particle with the highest weight.
151  */
153 
154  /** Bayesian fusion.
155  */
156  void bayesianFusion(
157  const CPosePDF& p1, const CPosePDF& p2,
158  const double minMahalanobisDistToDrop = 0) override;
159 
160  /** Evaluates the PDF at a given arbitrary point as reconstructed by a
161  * Parzen window.
162  * \sa saveParzenPDFToTextFile
163  */
164  double evaluatePDF_parzen(
165  const double x, const double y, const double phi,
166  const double stdXY, const double stdPhi) const;
167 
168  /** Save a text file (compatible with matlab) representing the 2D evaluation
169  * of the PDF as reconstructed by a Parzen window.
170  * \sa evaluatePDF_parzen
171  */
173  const char* fileName, const double x_min, const double x_max,
174  const double y_min, const double y_max, const double phi,
175  const double stepSizeXY, const double stdXY, const double stdPhi) const;
176 
177 }; // End of class def.
178 
179 }
180 #endif
181 
182 
bool saveToTextFile(const std::string &file) const override
Save PDF&#39;s m_particles to a text file.
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.
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 operator+=(const mrpt::math::TPose2D &Ap)
Appends (pose-composition) a given pose "p" to each particle.
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 clear()
Free all the memory associated to m_particles, and set the number of parts = 0.
void resetDeterministic(const mrpt::math::TPose2D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution (WARNING: weights are assumed to be normalized!) ...
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...
mrpt::math::TPose2D getMostLikelyParticle() const
Returns the particle with the highest weight.
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 ...
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x...
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. ...
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:39
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
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...
#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:38
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
mrpt::math::TPose2D getParticlePose(size_t i) const
Returns the pose of the i&#39;th particle.
void append(CPosePDFParticles &o)
Appends (add to the list) a set of m_particles to the existing ones, and then normalize weights...
Lightweight 2D pose.
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion.
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
GLenum GLint x
Definition: glext.h:3538
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020