Main MRPT website > C++ reference for MRPT 1.9.9
CPose3DPDFGaussian.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 CPose3DPDFGaussian_H
10 #define CPose3DPDFGaussian_H
11 
12 #include <mrpt/poses/CPose3DPDF.h>
13 #include <mrpt/poses/CPose3D.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
19 class CPosePDF;
20 class CPosePDFGaussian;
21 class CPose3DQuatPDFGaussian;
22 
23 /** Declares a class that represents a Probability Density function (PDF) of a
24  * 3D pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
25  *
26  * This class implements that PDF using a mono-modal Gaussian distribution.
27  * See mrpt::poses::CPose3DPDF for more details.
28  *
29  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is
30  * implemented in the method "CPose3DPDFGaussian::operator+=".
31  *
32  * For further details on implemented methods and the theory behind them,
33  * see <a
34  * href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty"
35  * >this report</a>.
36  *
37  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles
38  * \ingroup poses_pdf_grp
39  */
41 {
43 
44  protected:
45  /** Assures the symmetry of the covariance matrix (eventually certain
46  * operations in the math-coprocessor lead to non-symmetric matrixes!)
47  */
48  void assureSymmetry();
49 
50  public:
51  /** Default constructor
52  */
54 
55  /** Constructor
56  */
57  explicit CPose3DPDFGaussian(const CPose3D& init_Mean);
58 
59  /** Uninitialized constructor: leave all fields uninitialized - Call with
60  * UNINITIALIZED_POSE as argument
61  */
62  CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
63 
64  /** Constructor */
66  const CPose3D& init_Mean, const mrpt::math::CMatrixDouble66& init_Cov);
67 
68  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables
69  * z,pitch, and roll).
70  */
71  explicit CPose3DPDFGaussian(const CPosePDFGaussian& o);
72 
73  /** Constructor from a 6D pose PDF described as a Quaternion
74  */
75  explicit CPose3DPDFGaussian(const CPose3DQuatPDFGaussian& o);
76 
77  /** The mean value
78  */
80 
81  /** The 6x6 covariance matrix
82  */
84 
85  inline const CPose3D& getPoseMean() const { return mean; }
86  inline CPose3D& getPoseMean() { return mean; }
87  /** Returns an estimate of the pose, (the mean, or mathematical expectation
88  * of the PDF).
89  * \sa getCovariance
90  */
91  void getMean(CPose3D& mean_pose) const override { mean_pose = mean; }
92  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and
93  * the mean, both at once.
94  * \sa getMean
95  */
98  CPose3D& mean_point) const override
99  {
100  out_cov = this->cov;
101  mean_point = this->mean;
102  }
103 
104  void asString(std::string& s) const;
105  inline std::string asString() const
106  {
107  std::string s;
108  asString(s);
109  return s;
110  }
111 
112  /** Copy operator, translating if necesary (for example, between particles
113  * and gaussian representations)
114  */
115  void copyFrom(const CPose3DPDF& o) override;
116 
117  /** Copy operator, translating if necesary (for example, between particles
118  * and gaussian representations)
119  */
120  void copyFrom(const CPosePDF& o);
121 
122  /** Copy from a 6D pose PDF described as a Quaternion
123  */
124  void copyFrom(const CPose3DQuatPDFGaussian& o);
125 
126  /** Save the PDF to a text file, containing the 3D pose in the first line,
127  * then the covariance matrix in next 3 lines.
128  */
129  bool saveToTextFile(const std::string& file) const override;
130 
131  /** this = p (+) this. This can be used to convert a PDF from local
132  * coordinates to global, providing the point (newReferenceBase) from which
133  * "to project" the current pdf. Result PDF substituted the currently
134  * stored one in the object.
135  */
136  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
137 
138  /** Draws a single sample from the distribution
139  */
140  void drawSingleSample(CPose3D& outPart) const override;
141 
142  /** Draws a number of samples from the distribution, and saves as a list of
143  * 1x6 vectors, where each row contains a (x,y,phi) datum.
144  */
145  void drawManySamples(
146  size_t N,
147  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
148 
149  /** Bayesian fusion of two points gauss. distributions, then save the result
150  *in this object.
151  * The process is as follows:<br>
152  * - (x1,S1): Mean and variance of the p1 distribution.
153  * - (x2,S2): Mean and variance of the p2 distribution.
154  * - (x,S): Mean and variance of the resulting distribution.
155  *
156  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
157  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
158  */
159  void bayesianFusion(const CPose3DPDF& p1, const CPose3DPDF& p2) override;
160 
161  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
162  */
163  void inverse(CPose3DPDF& o) const override;
164 
165  /** Unary - operator, returns the PDF of the inverse pose. */
167  {
169  this->inverse(p);
170  return p;
171  }
172 
173  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
174  * mean, and the covariance matrix are updated).
175  */
176  void operator+=(const CPose3D& Ap);
177 
178  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
179  * mean, and the covariance matrix are updated).
180  */
181  void operator+=(const CPose3DPDFGaussian& Ap);
182 
183  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
184  * (both the mean, and the covariance matrix are updated).
185  */
186  void operator-=(const CPose3DPDFGaussian& Ap);
187 
188  /** Evaluates the PDF at a given point.
189  */
190  double evaluatePDF(const CPose3D& x) const;
191 
192  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
193  * the range [0,1].
194  */
195  double evaluateNormalizedPDF(const CPose3D& x) const;
196 
197  /** Computes the Mahalanobis distance between the centers of two Gaussians.
198  * The variables with a variance exactly equal to 0 are not taken into
199  * account in the process, but
200  * "infinity" is returned if the corresponding elements are not exactly
201  * equal.
202  */
203  double mahalanobisDistanceTo(const CPose3DPDFGaussian& theOther);
204 
205  /** Returns a 3x3 matrix with submatrix of the covariance for the variables
206  * (x,y,yaw) only.
207  */
208  void getCovSubmatrix2D(mrpt::math::CMatrixDouble& out_cov) const;
209 
210 }; // End of class def.
211 /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator
212  * += */
214  const CPose3DPDFGaussian& x, const CPose3DPDFGaussian& u)
215 {
217  res += u;
218  return res;
219 }
220 
221 /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator
222  * -= */
224  const CPose3DPDFGaussian& x, const CPose3DPDFGaussian& u)
225 {
227  res -= u;
228  return res;
229 }
230 
231 /** Dumps the mean and covariance matrix to a text stream.
232  */
233 std::ostream& operator<<(std::ostream& out, const CPose3DPDFGaussian& obj);
234 
235 bool operator==(const CPose3DPDFGaussian& p1, const CPose3DPDFGaussian& p2);
236 
237 } // End of namespace
238 
239 /** Global variables to change the run-time behaviour of some MRPT classes
240  * within mrpt-base.
241  * See each variable for the description of what classes it affects.
242  */
243 namespace global_settings
244 {
245 /** If set to true (false), a Scaled Unscented Transform is used instead of a
246  *linear approximation with Jacobians.
247  * Affects to:
248  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian
249  *&o)
250  */
253 }
254 
255 } // End of namespace
256 
257 #endif
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) ...
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:364
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
GLdouble s
Definition: glext.h:3676
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
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 ...
A numeric matrix of compile-time fixed size.
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:315
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.
GLsizei const GLchar ** string
Definition: glext.h:4101
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:41
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.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void getCovarianceAndMean(mrpt::math::CMatrixDouble66 &out_cov, CPose3D &mean_point) const override
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:166
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
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).
GLsizei const GLfloat * value
Definition: glext.h:4117
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
GLuint res
Definition: glext.h:7268
GLenum GLint x
Definition: glext.h:3538
CPose3DPDFGaussian operator-() const
Unary - operator, returns the PDF of the inverse pose.
GLfloat GLfloat p
Definition: glext.h:6305
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:42
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