Main MRPT website > C++ reference for MRPT 1.9.9
CPosePDFGaussian.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 CPosePDFGaussian_H
10 #define CPosePDFGaussian_H
11 
12 #include <mrpt/poses/CPosePDF.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
19 class CPose3DPDF;
20 class CPoint2DPDFGaussian;
21 
22 /** Declares a class that represents a Probability Density function (PDF) of a
23  * 2D pose \f$ p(\mathbf{x}) = [x ~ y ~ \phi ]^t \f$.
24  *
25  * This class implements that PDF using a mono-modal Gaussian distribution.
26  * See mrpt::poses::CPosePDF for more details.
27  *
28  * \sa CPose2D, CPosePDF, CPosePDFParticles
29  * \ingroup poses_pdf_grp
30  */
31 class CPosePDFGaussian : public CPosePDF
32 {
34 
35  protected:
36  /** Assures the symmetry of the covariance matrix (eventually certain
37  * operations in the math-coprocessor lead to non-symmetric matrixes!)
38  */
39  void assureSymmetry();
40 
41  public:
42  /** @name Data fields
43  @{ */
44 
45  /** The mean value */
47  /** The 3x3 covariance matrix */
49 
50  /** @} */
51 
52  inline const CPose2D& getPoseMean() const { return mean; }
53  inline CPose2D& getPoseMean() { return mean; }
54  /** Default constructor
55  */
57 
58  /** Constructor
59  */
60  explicit CPosePDFGaussian(const CPose2D& init_Mean);
61 
62  /** Constructor
63  */
65  const CPose2D& init_Mean, const mrpt::math::CMatrixDouble33& init_Cov);
66 
67  /** Copy constructor, including transformations between other PDFs */
68  explicit CPosePDFGaussian(const CPosePDF& o) { copyFrom(o); }
69  /** Copy constructor, including transformations between other PDFs */
70  explicit CPosePDFGaussian(const CPose3DPDF& o) { copyFrom(o); }
71  /** Returns an estimate of the pose, (the mean, or mathematical expectation
72  * of the PDF).
73  * \sa getCovariance
74  */
75  void getMean(CPose2D& mean_pose) const override { mean_pose = mean; }
76  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and
77  * the mean, both at once.
78  * \sa getMean
79  */
82  CPose2D& mean_point) const override
83  {
84  mean_point = mean;
85  out_cov = this->cov;
86  }
87 
88  /** Copy operator, translating if necesary (for example, between particles
89  * and gaussian representations) */
90  void copyFrom(const CPosePDF& o) override;
91 
92  /** Copy operator, translating if necesary (for example, between particles
93  * and gaussian representations) */
94  void copyFrom(const CPose3DPDF& o);
95 
96  /** Save PDF's particles to a text file, containing the 2D pose in the first
97  * line, then the covariance matrix in next 3 lines. */
98  bool saveToTextFile(const std::string& file) const override;
99 
100  /** this = p (+) this. This can be used to convert a PDF from local
101  * coordinates to global, providing the point (newReferenceBase) from which
102  * "to project" the current pdf. Result PDF substituted the currently
103  * stored one in the object.
104  */
105  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
106 
107  /** this = p (+) this. This can be used to convert a PDF from local
108  * coordinates to global, providing the point (newReferenceBase) from which
109  * "to project" the current pdf. Result PDF substituted the currently
110  * stored one in the object.
111  */
112  void changeCoordinatesReference(const CPose2D& newReferenceBase);
113 
114  /** Rotate the covariance matrix by replacing it by \f$
115  * \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[
116  * \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha &
117  * \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$.
118  */
119  void rotateCov(const double ang);
120 
121  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
122  * operator and the covariances through the corresponding Jacobians (For
123  * 'x0' and 'x1' being independent variables!). */
124  void inverseComposition(
125  const CPosePDFGaussian& x, const CPosePDFGaussian& ref);
126 
127  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
128  * operator and the covariances through the corresponding Jacobians (Given
129  * the 3x3 cross-covariance matrix of variables x0 and x1). */
130  void inverseComposition(
131  const CPosePDFGaussian& x1, const CPosePDFGaussian& x0,
132  const mrpt::math::CMatrixDouble33& COV_01);
133 
134  /** Draws a single sample from the distribution
135  */
136  void drawSingleSample(CPose2D& outPart) const override;
137 
138  /** Draws a number of samples from the distribution, and saves as a list of
139  * 1x3 vectors, where each row contains a (x,y,phi) datum.
140  */
141  void drawManySamples(
142  size_t N,
143  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
144 
145  /** Bayesian fusion of two points gauss. distributions, then save the result
146  *in this object.
147  * The process is as follows:<br>
148  * - (x1,S1): Mean and variance of the p1 distribution.
149  * - (x2,S2): Mean and variance of the p2 distribution.
150  * - (x,S): Mean and variance of the resulting distribution.
151  *
152  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
153  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
154  */
155  void bayesianFusion(
156  const CPosePDF& p1, const CPosePDF& p2,
157  const double minMahalanobisDistToDrop = 0) override;
158 
159  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
160  */
161  void inverse(CPosePDF& o) const override;
162 
163  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
164  * mean, and the covariance matrix are updated). */
165  void operator+=(const CPose2D& Ap);
166 
167  /** Evaluates the PDF at a given point. */
168  double evaluatePDF(const CPose2D& x) const;
169 
170  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
171  * the range [0,1]. */
172  double evaluateNormalizedPDF(const CPose2D& x) const;
173 
174  /** Computes the Mahalanobis distance between the centers of two Gaussians.
175  */
176  double mahalanobisDistanceTo(const CPosePDFGaussian& theOther);
177 
178  /** Substitutes the diagonal elements if (square) they are below some given
179  * minimum values (Use this before bayesianFusion, for example, to avoid
180  * inversion of singular matrixes, etc...) */
181  void assureMinCovariance(const double& minStdXY, const double& minStdPhi);
182 
183  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
184  * mean, and the covariance matrix are updated) (see formulas in
185  * jacobiansPoseComposition ). */
186  void operator+=(const CPosePDFGaussian& Ap);
187 
188  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
189  * (both the mean, and the covariance matrix are updated) */
190  inline void operator-=(const CPosePDFGaussian& ref)
191  {
192  this->inverseComposition(*this, ref);
193  }
194 
195  /** Returns the PDF of the 2D point \f$ g = q \oplus l\f$ with "q"=this pose
196  * and "l" a point without uncertainty */
197  void composePoint(
198  const mrpt::math::TPoint2D& l, CPoint2DPDFGaussian& g) const;
199 
200 }; // End of class def.
201 
202 /** Pose compose operator: RES = A (+) B , computing both the mean and the
203  * covariance */
204 CPosePDFGaussian operator+(
205  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
206 
207 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and
208  * the covariance */
209 CPosePDFGaussian operator-(
210  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
211 
212 /** Dumps the mean and covariance matrix to a text stream. */
213 std::ostream& operator<<(std::ostream& out, const CPosePDFGaussian& obj);
214 
215 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C}
216  * = \mathbf{A} \oplus \mathbf{B} \f$. */
219 
220 bool operator==(const CPosePDFGaussian& p1, const CPosePDFGaussian& p2);
221 
222 } // End of namespace
223 } // End of namespace
224 
225 #endif
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
CPosePDFGaussian(const CPosePDF &o)
Copy constructor, including transformations between other PDFs.
CPose2D mean
The mean value.
A gaussian distribution for 2D points.
GLenum GLint ref
Definition: glext.h:4050
mrpt::math::TPoint2D operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
Definition: CPose2D.cpp:364
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two points gauss.
double mahalanobisDistanceTo(const CPosePDFGaussian &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
void composePoint(const mrpt::math::TPoint2D &l, CPoint2DPDFGaussian &g) const
Returns the PDF of the 2D point with "q"=this pose and "l" a point without uncertainty.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
const CPose2D & getPoseMean() const
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &out_cov, CPose2D &mean_point) const override
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once...
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
CPosePDFGaussian()
Default constructor.
CPosePDFGaussian(const CPose3DPDF &o)
Copy constructor, including transformations between other PDFs.
CPose2D operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
Definition: CPose2D.cpp:315
double evaluatePDF(const CPose2D &x) const
Evaluates the PDF at a given point.
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const override
Draws a number of samples from the distribution, and saves as a list of 1x3 vectors, where each row contains a (x,y,phi) datum.
double evaluateNormalizedPDF(const CPose2D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
GLsizei const GLchar ** string
Definition: glext.h:4101
void inverseComposition(const CPosePDFGaussian &x, const CPosePDFGaussian &ref)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
void operator-=(const CPosePDFGaussian &ref)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
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...
void assureMinCovariance(const double &minStdXY, const double &minStdPhi)
Substitutes the diagonal elements if (square) they are below some given minimum values (Use this befo...
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:166
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 assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void getMean(CPose2D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
GLenum GLint x
Definition: glext.h:3538
void operator+=(const CPose2D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
void rotateCov(const double ang)
Rotate the covariance matrix by replacing it by , where .
Lightweight 2D point.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution.
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
bool saveToTextFile(const std::string &file) const override
Save PDF&#39;s particles to a text file, containing the 2D pose in the first line, then the covariance ma...
void inverse(CPosePDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
std::ostream & operator<<(std::ostream &o, const CPoint< DERIVEDCLASS > &p)
Dumps a point as a string [x,y] or [x,y,z].
Definition: CPoint.h:140



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