Main MRPT website > C++ reference
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-2014, 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/CPosePDF.h>
14 #include <mrpt/math/CMatrixD.h>
15
16 namespace mrpt
17 {
18 namespace poses
19 {
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  */
45  void assureSymmetry();
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 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  */
69  explicit CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o);
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 {
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  */
92  void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const {
93  cov = this->cov;
94  mean_point = this->mean;
95  }
96
97  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
98  */
99  void copyFrom(const CPose3DPDF &o);
100
101  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
102  */
103  void copyFrom(const CPosePDF &o);
104
105  /** Copy from a 6D pose PDF described as a Quaternion
106  */
107  void copyFrom( const CPose3DQuatPDFGaussian &o);
108
109
110  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
111  */
112  void saveToTextFile(const std::string &file) const;
113
114  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
115  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
116  */
117  void changeCoordinatesReference( const CPose3D &newReferenceBase );
118
119  /** Draws a single sample from the distribution
120  */
121  void drawSingleSample( CPose3D &outPart ) const;
122
123  /** 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.
124  */
125  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
126
127  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
128  * The process is as follows:<br>
129  * - (x1,S1): Mean and variance of the p1 distribution.
130  * - (x2,S2): Mean and variance of the p2 distribution.
131  * - (x,S): Mean and variance of the resulting distribution.
132  *
133  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
134  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
135  */
136  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
137
138  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
139  */
140  void inverse(CPose3DPDF &o) const;
141
142  /** Unary - operator, returns the PDF of the inverse pose. */
144  {
146  this->inverse(p);
147  return p;
148  }
149
150
151  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
152  */
153  void operator += ( const CPose3D &Ap);
154
155  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
156  */
157  void operator += ( const CPose3DPDFGaussian &Ap);
158
159  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
160  */
161  void operator -= ( const CPose3DPDFGaussian &Ap);
162
163  /** Evaluates the PDF at a given point.
164  */
165  double evaluatePDF( const CPose3D &x ) const;
166
167  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
168  */
169  double evaluateNormalizedPDF( const CPose3D &x ) const;
170
171  /** Computes the Mahalanobis distance between the centers of two Gaussians.
172  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
173  * "infinity" is returned if the corresponding elements are not exactly equal.
174  */
175  double mahalanobisDistanceTo( const CPose3DPDFGaussian& theOther);
176
177  /** Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
178  */
179  void getCovSubmatrix2D( CMatrixDouble &out_cov ) const;
180
181
182  }; // End of class def.
183
184
185  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
187  {
188  CPose3DPDFGaussian res(x);
189  res+=u;
190  return res;
191  }
192
193  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator -= */
195  {
196  CPose3DPDFGaussian res(x);
197  res-=u;
198  return res;
199  }
200
201  /** Dumps the mean and covariance matrix to a text stream.
202  */
203  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
204
205  bool BASE_IMPEXP operator==(const CPose3DPDFGaussian &p1,const CPose3DPDFGaussian &p2);
206
207  } // End of namespace
208
209
210  /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-base.
211  * See each variable for the description of what classes it affects.
212  */
213  namespace global_settings
214  {
215  /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
216  * Affects to:
217  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
218  */
220  }
221
222 } // End of namespace
223
224 #endif
CMatrixDouble66 cov
The 6x6 covariance matrix.
CPose3D mean
The mean value.
const CPose3D & getPoseMean() const
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...
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...
void getMean(CPose3D &mean_pose) const
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...
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 ...
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:214
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:64
mrpt::math::TPoint2D BASE_IMPEXP operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:71
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
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...
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:129
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:71
void getCovarianceAndMean(CMatrixDouble66 &cov, CPose3D &mean_point) const
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
CMatrixFixedNumeric< double, 6, 6 > CMatrixDouble66
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
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:105

 Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on: 