Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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 
24 
25  /** Declares a class that represents a Probability Density function (PDF) of a 3D pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
26  *
27  * This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DPDF for more details.
28  *
29  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussian::operator+=".
30  *
31  * For further details on implemented methods and the theory behind them,
32  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
33  *
34  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles
35  * \ingroup poses_pdf_grp
36  */
38  {
39  // This must be added to any CSerializable derived class:
41 
42  protected:
43  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
44  */
46 
47  public:
48  /** Default constructor
49  */
51 
52  /** Constructor
53  */
54  explicit CPose3DPDFGaussian( const CPose3D &init_Mean );
55 
56  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
57  */
58  CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
59 
60  /** Constructor */
61  CPose3DPDFGaussian( const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_Cov );
62 
63  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables z,pitch, and roll).
64  */
65  explicit CPose3DPDFGaussian( const CPosePDFGaussian &o );
66 
67  /** Constructor from a 6D pose PDF described as a Quaternion
68  */
70 
71  /** The mean value
72  */
74 
75  /** The 6x6 covariance matrix
76  */
78 
79  inline const CPose3D & getPoseMean() const { return mean; }
80  inline CPose3D & getPoseMean() { return mean; }
81 
82  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
83  * \sa getCovariance
84  */
85  void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE {
86  mean_pose = mean;
87  }
88 
89  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
90  * \sa getMean
91  */
93  cov = this->cov;
94  mean_point = this->mean;
95  }
96 
97  void asString(std::string &s) const;
98  inline std::string asString() const { std::string s; asString(s); return s; }
99 
100  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
101  */
103 
104  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
105  */
106  void copyFrom(const CPosePDF &o);
107 
108  /** Copy from a 6D pose PDF described as a Quaternion
109  */
111 
112 
113  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
114  */
115  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
116 
117  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
118  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
119  */
120  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
121 
122  /** Draws a single sample from the distribution
123  */
124  void drawSingleSample( CPose3D &outPart ) const MRPT_OVERRIDE;
125 
126  /** 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.
127  */
128  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
129 
130  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
131  * The process is as follows:<br>
132  * - (x1,S1): Mean and variance of the p1 distribution.
133  * - (x2,S2): Mean and variance of the p2 distribution.
134  * - (x,S): Mean and variance of the resulting distribution.
135  *
136  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
137  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
138  */
139  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 ) MRPT_OVERRIDE;
140 
141  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
142  */
144 
145  /** Unary - operator, returns the PDF of the inverse pose. */
147  {
149  this->inverse(p);
150  return p;
151  }
152 
153 
154  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
155  */
156  void operator += ( const CPose3D &Ap);
157 
158  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
159  */
161 
162  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
163  */
164  void operator -= ( const CPose3DPDFGaussian &Ap);
165 
166  /** Evaluates the PDF at a given point.
167  */
168  double evaluatePDF( const CPose3D &x ) const;
169 
170  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
171  */
172  double evaluateNormalizedPDF( const CPose3D &x ) const;
173 
174  /** Computes the Mahalanobis distance between the centers of two Gaussians.
175  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
176  * "infinity" is returned if the corresponding elements are not exactly equal.
177  */
178  double mahalanobisDistanceTo( const CPose3DPDFGaussian& theOther);
179 
180  /** Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
181  */
183 
184 
185  }; // End of class def.
187 
188 
189  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
190  inline CPose3DPDFGaussian operator +( const CPose3DPDFGaussian &x, const CPose3DPDFGaussian &u )
191  {
192  CPose3DPDFGaussian res(x);
193  res+=u;
194  return res;
195  }
196 
197  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator -= */
199  {
200  CPose3DPDFGaussian res(x);
201  res-=u;
202  return res;
203  }
204 
205  /** Dumps the mean and covariance matrix to a text stream.
206  */
207  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
208 
210 
211  } // End of namespace
212 
213 
214  /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-base.
215  * See each variable for the description of what classes it affects.
216  */
217  namespace global_settings
218  {
219  /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
220  * Affects to:
221  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
222  */
224  }
225 
226 } // End of namespace
227 
228 #endif
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A numeric matrix of compile-time fixed size.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
void bayesianFusion(const CPose3DPDF &p1, const CPose3DPDF &p2) MRPT_OVERRIDE
Bayesian fusion of two points gauss.
CPose3DPDFGaussian(const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_Cov)
Constructor
void saveToTextFile(const std::string &file) const MRPT_OVERRIDE
Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in ...
const CPose3D & getPoseMean() const
void getCovSubmatrix2D(mrpt::math::CMatrixDouble &out_cov) const
Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param)
Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument.
void getCovarianceAndMean(mrpt::math::CMatrixDouble66 &cov, CPose3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
void copyFrom(const CPose3DPDF &o) MRPT_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.
double evaluatePDF(const CPose3D &x) const
Evaluates the PDF at a given point.
CPose3DPDFGaussian()
Default constructor.
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
CPose3DPDFGaussian(const CPosePDFGaussian &o)
Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables z,pitch, and roll).
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.
void inverse(CPose3DPDF &o) const MRPT_OVERRIDE
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
CPose3DPDFGaussian(const CPose3DQuatPDFGaussian &o)
Constructor from a 6D pose PDF described as a Quaternion.
void copyFrom(const CPosePDF &o)
Copy operator, translating if necesary (for example, between particles and gaussian representations)
void copyFrom(const CPose3DQuatPDFGaussian &o)
Copy from a 6D pose PDF described as a Quaternion.
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const MRPT_OVERRIDE
Draws a number of samples from the distribution, and saves as a list of 1x6 vectors,...
CPose3DPDFGaussian(const CPose3D &init_Mean)
Constructor.
void drawSingleSample(CPose3D &outPart) const MRPT_OVERRIDE
Draws a single sample from the 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,...
void asString(std::string &s) const
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:41
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:40
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
BASE_IMPEXP bool USE_SUT_QUAT2EULER_CONVERSION
If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with J...
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:135
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:74
CPose2D BASE_IMPEXP operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
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:106
@ UNINITIALIZED_POSE
Definition: CPoseOrPoint.h:35
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:130
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.1 for MRPT 1.4.0 SVN: at Mon Apr 18 04:07:33 UTC 2022