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
mrpt::poses::CPose3DPDFGaussian::operator-
CPose3DPDFGaussian operator-() const
Unary - operator, returns the PDF of the inverse pose.
Definition: CPose3DPDFGaussian.h:162
mrpt::poses::CPose3DPDFGaussian
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
Definition: CPose3DPDFGaussian.h:39
mrpt::poses::CPose3DPDFGaussian::asString
std::string asString() const
Definition: CPose3DPDFGaussian.h:101
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::poses::CPose3DPDFGaussian::operator+=
void operator+=(const CPose3D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
Definition: CPose3DPDFGaussian.cpp:424
mrpt::poses::CPose3DPDFGaussian::getMean
void getMean(CPose3D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
Definition: CPose3DPDFGaussian.h:90
mrpt::poses::TConstructorFlags_Poses
TConstructorFlags_Poses
Definition: CPoseOrPoint.h:32
mrpt::poses::CPose3DPDF
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:39
mrpt::poses::operator+
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
mrpt::poses::CPose3DPDFGaussian::getCovarianceAndMean
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.
Definition: CPose3DPDFGaussian.h:95
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt::poses::CPose3DPDFGaussian::enforceCovSymmetry
void enforceCovSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
Definition: CPose3DPDFGaussian.cpp:544
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::poses::operator<<
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
mrpt::poses::operator-
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
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
mrpt::poses::CPose3DPDFGaussian::CPose3DPDFGaussian
CPose3DPDFGaussian()
Default constructor.
Definition: CPose3DPDFGaussian.cpp:48
mrpt::poses::CPose3DPDFGaussian::drawManySamples
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,...
Definition: CPose3DPDFGaussian.cpp:342
mrpt::global_settings::USE_SUT_QUAT2EULER_CONVERSION
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...
Definition: CPose3DPDFGaussian.cpp:34
mrpt::poses::CPose3DPDFGaussian::mahalanobisDistanceTo
double mahalanobisDistanceTo(const CPose3DPDFGaussian &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
Definition: CPose3DPDFGaussian.cpp:555
mrpt::poses::CPose3DPDFGaussian::evaluateNormalizedPDF
double evaluateNormalizedPDF(const CPose3D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,...
Definition: CPose3DPDFGaussian.cpp:525
mrpt::poses::CPose3DPDFGaussian::bayesianFusion
void bayesianFusion(const CPose3DPDF &p1, const CPose3DPDF &p2) override
Bayesian fusion of two points gauss.
Definition: CPose3DPDFGaussian.cpp:365
mrpt::poses::CPose3DPDFGaussian::inverse
void inverse(CPose3DPDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
Definition: CPose3DPDFGaussian.cpp:408
mrpt::math::CMatrixFixed
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
mrpt::poses::CPose3DPDFGaussian::drawSingleSample
void drawSingleSample(CPose3D &outPart) const override
Draws a single sample from the distribution.
Definition: CPose3DPDFGaussian.cpp:324
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::poses::CPose3DPDFGaussian::getCovSubmatrix2D
void getCovSubmatrix2D(mrpt::math::CMatrixDouble &out_cov) const
Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
Definition: CPose3DPDFGaussian.cpp:595
mrpt::poses::CPose3DPDFGaussian::getPoseMean
CPose3D & getPoseMean()
Definition: CPose3DPDFGaussian.h:85
mrpt::poses::CPose3DPDFGaussian::saveToTextFile
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 ...
Definition: CPose3DPDFGaussian.cpp:276
mrpt::poses::CPose3DPDFGaussian::evaluatePDF
double evaluatePDF(const CPose3D &x) const
Evaluates the PDF at a given point.
Definition: CPose3DPDFGaussian.cpp:504
mrpt::poses::CPose3DPDFGaussian::changeCoordinatesReference
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
Definition: CPose3DPDFGaussian.cpp:297
CPose3D.h
mrpt::poses::CPosePDF
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:38
mrpt::poses::operator==
bool operator==(const CPoint< DERIVEDCLASS, DIM > &p1, const CPoint< DERIVEDCLASS, DIM > &p2)
Definition: CPoint.h:119
mrpt::poses::CPose3DPDFGaussian::operator-=
void operator-=(const CPose3DPDFGaussian &Ap)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean,...
Definition: CPose3DPDFGaussian.cpp:475
mrpt::poses::CPose3DPDFGaussian::getPoseMean
const CPose3D & getPoseMean() const
Definition: CPose3DPDFGaussian.h:84
mrpt::poses::CPose3DQuatPDFGaussian
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
Definition: CPose3DQuatPDFGaussian.h:43
mrpt::poses::CPose3DPDFGaussian::cov
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
Definition: CPose3DPDFGaussian.h:82
CPose3DPDF.h
mrpt::poses::UNINITIALIZED_POSE
@ UNINITIALIZED_POSE
Definition: CPoseOrPoint.h:34
mrpt::poses::CPosePDFGaussian
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
Definition: CPosePDFGaussian.h:28
mrpt::poses::CPose3DPDFGaussian::copyFrom
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations)
Definition: CPose3DPDFGaussian.cpp:245
mrpt::poses::CPose3DPDFGaussian::mean
CPose3D mean
The mean value.
Definition: CPose3DPDFGaussian.h:78
mrpt::math::CMatrixDynamic< double >



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sat Jun 27 14:00:59 UTC 2020