Main MRPT website > C++ reference for MRPT 1.3.2
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-2015, 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  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DPDFGaussian , CPose3DPDF )
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 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  */
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  */
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<mrpt::math::CVectorDouble> & 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( mrpt::math::CMatrixDouble &out_cov ) const;
180 
181 
182  }; // End of class def.
183  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPose3DPDFGaussian , CPose3DPDF )
184 
185 
186  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
187  inline CPose3DPDFGaussian operator +( const CPose3DPDFGaussian &x, const CPose3DPDFGaussian &u )
188  {
189  CPose3DPDFGaussian res(x);
190  res+=u;
191  return res;
192  }
193 
194  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator -= */
196  {
197  CPose3DPDFGaussian res(x);
198  res-=u;
199  return res;
200  }
201 
202  /** Dumps the mean and covariance matrix to a text stream.
203  */
204  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
205 
206  bool BASE_IMPEXP operator==(const CPose3DPDFGaussian &p1,const CPose3DPDFGaussian &p2);
207 
208  } // End of namespace
209 
210 
211  /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-base.
212  * See each variable for the description of what classes it affects.
213  */
214  namespace global_settings
215  {
216  /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
217  * Affects to:
218  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
219  */
221  }
222 
223 } // End of namespace
224 
225 #endif
void getMean(CPose3D &mean_pose) const
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
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...
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...
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...
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
A numeric matrix of compile-time fixed size.
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:135
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:74
#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:39
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 &cov, CPose3D &mean_point) const
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:130
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
CMatrixFixedNumeric< double, 6, 6 > CMatrixDouble66
Definition: eigen_frwds.h:50
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
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



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Tue Dec 8 09:49:21 UTC 2015