MRPT  2.0.4
CPose3DPDFGaussian.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/poses/CPose3D.h>
12 #include <mrpt/poses/CPose3DPDF.h>
13 
14 namespace mrpt
15 {
16 namespace poses
17 {
18 class CPosePDF;
19 class CPosePDFGaussian;
20 class CPose3DQuatPDFGaussian;
21 
22 /** Declares a class that represents a Probability Density function (PDF) of a
23  * 3D pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
24  *
25  * This class implements that PDF using a mono-modal Gaussian distribution.
26  * See mrpt::poses::CPose3DPDF for more details.
27  *
28  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is
29  * implemented in the method "CPose3DPDFGaussian::operator+=".
30  *
31  * For further details on implemented methods and the theory behind them,
32  * see <a
33  * href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty"
34  * >this report</a>.
35  *
36  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles
37  * \ingroup poses_pdf_grp
38  */
40 {
42 
43  protected:
44  /** Assures the symmetry of the covariance matrix (eventually certain
45  * operations in the math-coprocessor lead to non-symmetric matrixes!)
46  */
47  void enforceCovSymmetry();
48 
49  public:
50  /** Default constructor
51  */
53 
54  /** Constructor
55  */
56  explicit CPose3DPDFGaussian(const CPose3D& init_Mean);
57 
58  /** Uninitialized constructor: leave all fields uninitialized - Call with
59  * UNINITIALIZED_POSE as argument
60  */
61  CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
62 
63  /** Constructor */
65  const CPose3D& init_Mean, const mrpt::math::CMatrixDouble66& init_Cov);
66 
67  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables
68  * z,pitch, and roll).
69  */
70  explicit CPose3DPDFGaussian(const CPosePDFGaussian& o);
71 
72  /** Constructor from a 6D pose PDF described as a Quaternion
73  */
74  explicit CPose3DPDFGaussian(const CPose3DQuatPDFGaussian& o);
75 
76  /** The mean value
77  */
79 
80  /** The 6x6 covariance matrix
81  */
83 
84  inline const CPose3D& getPoseMean() const { return mean; }
85  inline CPose3D& getPoseMean() { return mean; }
86  /** Returns an estimate of the pose, (the mean, or mathematical expectation
87  * of the PDF).
88  * \sa getCovariance
89  */
90  void getMean(CPose3D& mean_pose) const override { mean_pose = mean; }
91  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and
92  * the mean, both at once.
93  * \sa getMean
94  */
95  std::tuple<cov_mat_t, type_value> getCovarianceAndMean() const override
96  {
97  return {this->cov, this->mean};
98  }
99 
100  void asString(std::string& s) const;
101  inline std::string asString() const
102  {
103  std::string s;
104  asString(s);
105  return s;
106  }
107 
108  /** Copy operator, translating if necesary (for example, between particles
109  * and gaussian representations)
110  */
111  void copyFrom(const CPose3DPDF& o) override;
112 
113  /** Copy operator, translating if necesary (for example, between particles
114  * and gaussian representations)
115  */
116  void copyFrom(const CPosePDF& o);
117 
118  /** Copy from a 6D pose PDF described as a Quaternion
119  */
120  void copyFrom(const CPose3DQuatPDFGaussian& o);
121 
122  /** Save the PDF to a text file, containing the 3D pose in the first line,
123  * then the covariance matrix in next 3 lines.
124  */
125  bool saveToTextFile(const std::string& file) const override;
126 
127  /** this = p (+) this. This can be used to convert a PDF from local
128  * coordinates to global, providing the point (newReferenceBase) from which
129  * "to project" the current pdf. Result PDF substituted the currently
130  * stored one in the object.
131  */
132  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
133 
134  /** Draws a single sample from the distribution
135  */
136  void drawSingleSample(CPose3D& outPart) const override;
137 
138  /** Draws a number of samples from the distribution, and saves as a list of
139  * 1x6 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(const CPose3DPDF& p1, const CPose3DPDF& p2) override;
156 
157  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
158  */
159  void inverse(CPose3DPDF& o) const override;
160 
161  /** Unary - operator, returns the PDF of the inverse pose. */
163  {
165  this->inverse(p);
166  return p;
167  }
168 
169  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
170  * mean, and the covariance matrix are updated).
171  */
172  void operator+=(const CPose3D& Ap);
173 
174  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
175  * mean, and the covariance matrix are updated).
176  */
177  void operator+=(const CPose3DPDFGaussian& Ap);
178 
179  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
180  * (both the mean, and the covariance matrix are updated).
181  */
182  void operator-=(const CPose3DPDFGaussian& Ap);
183 
184  /** Evaluates the PDF at a given point.
185  */
186  double evaluatePDF(const CPose3D& x) const;
187 
188  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
189  * the range [0,1].
190  */
191  double evaluateNormalizedPDF(const CPose3D& x) const;
192 
193  /** Computes the Mahalanobis distance between the centers of two Gaussians.
194  * The variables with a variance exactly equal to 0 are not taken into
195  * account in the process, but
196  * "infinity" is returned if the corresponding elements are not exactly
197  * equal.
198  */
199  double mahalanobisDistanceTo(const CPose3DPDFGaussian& theOther);
200 
201  /** Returns a 3x3 matrix with submatrix of the covariance for the variables
202  * (x,y,yaw) only.
203  */
204  void getCovSubmatrix2D(mrpt::math::CMatrixDouble& out_cov) const;
205 
206 }; // End of class def.
207 /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator
208  * += */
210  const CPose3DPDFGaussian& x, const CPose3DPDFGaussian& u)
211 {
212  CPose3DPDFGaussian res(x);
213  res += u;
214  return res;
215 }
216 
217 /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator
218  * -= */
220  const CPose3DPDFGaussian& x, const CPose3DPDFGaussian& u)
221 {
222  CPose3DPDFGaussian res(x);
223  res -= u;
224  return res;
225 }
226 
227 /** Dumps the mean and covariance matrix to a text stream.
228  */
229 std::ostream& operator<<(std::ostream& out, const CPose3DPDFGaussian& obj);
230 
231 bool operator==(const CPose3DPDFGaussian& p1, const CPose3DPDFGaussian& p2);
232 
233 } // namespace poses
234 
235 /** Global variables to change the run-time behaviour of some MRPT classes
236  * within mrpt-base.
237  * See each variable for the description of what classes it affects.
238  */
239 namespace global_settings
240 {
241 /** If set to true (false), a Scaled Unscented Transform is used instead of a
242  *linear approximation with Jacobians.
243  * Affects to:
244  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian
245  *&o)
246  */
247 void USE_SUT_QUAT2EULER_CONVERSION(bool value);
249 } // namespace global_settings
250 
251 } // namespace mrpt
void enforceCovSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
CPose3D mean
The mean value.
void getMean(CPose3D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
const CPose3D & getPoseMean() const
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
std::tuple< cov_mat_t, type_value > getCovarianceAndMean() const override
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
double mahalanobisDistanceTo(const CPose3DPDFGaussian &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
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:394
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
bool saveToTextFile(const std::string &file) const override
Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in ...
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
void USE_SUT_QUAT2EULER_CONVERSION(bool value)
If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with J...
double evaluatePDF(const CPose3D &x) const
Evaluates the PDF at a given point.
void inverse(CPose3DPDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
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:356
void operator+=(const CPose3D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
CPose3DPDFGaussian()
Default constructor.
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 1x6 vectors, where each row contains a (x,y,phi) datum.
void bayesianFusion(const CPose3DPDF &p1, const CPose3DPDF &p2) override
Bayesian fusion of two points gauss.
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:38
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
double evaluateNormalizedPDF(const CPose3D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
void getCovSubmatrix2D(mrpt::math::CMatrixDouble &out_cov) const
Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool operator==(const CPoint< DERIVEDCLASS, DIM > &p1, const CPoint< DERIVEDCLASS, DIM > &p2)
Definition: CPoint.h:119
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
void operator-=(const CPose3DPDFGaussian &Ap)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
CPose3DPDFGaussian operator-() const
Unary - operator, returns the PDF of the inverse pose.
void drawSingleSample(CPose3D &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:39



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020