Main MRPT website > C++ reference
MRPT logo
CPose3DPDFGaussianInf.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPose3DPDFGaussianInf_H
29 #define CPose3DPDFGaussianInf_H
30 
31 #include <mrpt/poses/CPose3DPDF.h>
32 #include <mrpt/poses/CPosePDF.h>
33 #include <mrpt/math/CMatrixD.h>
34 
35 namespace mrpt
36 {
37 namespace poses
38 {
39  class CPosePDFGaussian;
40  class CPose3DQuatPDFGaussian;
41 
43 
44  /** 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$ as a Gaussian described by its mean and its inverse covariance matrix.
45  *
46  * This class implements that PDF using a mono-modal Gaussian distribution in "information" form (inverse covariance matrix).
47  *
48  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussianInf::operator+=".
49  *
50  * For further details on implemented methods and the theory behind them,
51  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
52  *
53  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles, CPose3DPDFGaussian
54  * \ingroup poses_pdf_grp
55  */
57  {
58  // This must be added to any CSerializable derived class:
60 
61  protected:
62  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
63  */
64  void assureSymmetry();
65 
66  public:
67  /** @name Data fields
68  @{ */
69 
70  CPose3D mean; //!< The mean value
71  CMatrixDouble66 cov_inv; //!< The inverse of the 6x6 covariance matrix
72 
73  /** @} */
74 
75  inline const CPose3D & getPoseMean() const { return mean; }
76  inline CPose3D & getPoseMean() { return mean; }
77 
78  /** Default constructor - mean: all zeros, inverse covariance=all zeros -> so be careful!
79  */
81 
82  /** Constructor with a mean value, inverse covariance=all zeros -> so be careful! */
83  explicit CPose3DPDFGaussianInf( const CPose3D &init_Mean );
84 
85  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
86  */
87  CPose3DPDFGaussianInf(TConstructorFlags_Poses constructor_dummy_param);
88 
89  /** Constructor with mean and inv cov. */
90  CPose3DPDFGaussianInf( const CPose3D &init_Mean, const CMatrixDouble66 &init_CovInv );
91 
92  /** Constructor from a 6D pose PDF described as a Quaternion
93  */
95 
96  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
97  * \sa getCovariance
98  */
99  void getMean(CPose3D &mean_pose) const {
100  mean_pose = mean;
101  }
102 
103  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
104  * \sa getMean
105  */
106  void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const {
107  mean_point = this->mean;
108  this->cov_inv.inv(cov);
109  }
110 
111  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
112  virtual void getInformationMatrix(CMatrixDouble66 &inf) const { inf=cov_inv; }
113 
114  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
115  */
116  void copyFrom(const CPose3DPDF &o);
117 
118  /** Copy operator, translating if necesary (for example, between particles 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, then the covariance matrix in next 3 lines.
127  */
128  void saveToTextFile(const std::string &file) const;
129 
130  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
131  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
132  */
133  void changeCoordinatesReference( const CPose3D &newReferenceBase );
134 
135  /** Draws a single sample from the distribution
136  */
137  void drawSingleSample( CPose3D &outPart ) const;
138 
139  /** 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.
140  */
141  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
142 
143  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
144  * The process is as follows:<br>
145  * - (x1,S1): Mean and variance of the p1 distribution.
146  * - (x2,S2): Mean and variance of the p2 distribution.
147  * - (x,S): Mean and variance of the resulting distribution.
148  *
149  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
150  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
151  */
152  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
153 
154  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
155  */
156  void inverse(CPose3DPDF &o) const;
157 
158  /** Unary - operator, returns the PDF of the inverse pose. */
160  {
162  this->inverse(p);
163  return p;
164  }
165 
166  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
167  */
168  void operator += ( const CPose3D &Ap);
169 
170  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
171  */
172  void operator += ( const CPose3DPDFGaussianInf &Ap);
173 
174  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
175  */
176  void operator -= ( const CPose3DPDFGaussianInf &Ap);
177 
178  /** Evaluates the PDF at a given point.
179  */
180  double evaluatePDF( const CPose3D &x ) const;
181 
182  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
183  */
184  double evaluateNormalizedPDF( const CPose3D &x ) const;
185 
186  /** Computes the Mahalanobis distance between the centers of two Gaussians.
187  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
188  * "infinity" is returned if the corresponding elements are not exactly equal.
189  */
190  double mahalanobisDistanceTo( const CPose3DPDFGaussianInf& theOther);
191 
192  /** Returns a 3x3 matrix with submatrix of the inverse covariance for the variables (x,y,yaw) only.
193  */
194  void getInvCovSubmatrix2D( CMatrixDouble &out_cov ) const;
195 
196  }; // End of class def.
197 
198 
199  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
201  {
202  CPose3DPDFGaussianInf res(x);
203  res+=u;
204  return res;
205  }
206 
207  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussianInf::operator -= */
209  {
210  CPose3DPDFGaussianInf res(x);
211  res-=u;
212  return res;
213  }
214 
215  /** Dumps the mean and covariance matrix to a text stream.
216  */
217  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussianInf& obj);
218 
219  bool BASE_IMPEXP operator==(const CPose3DPDFGaussianInf &p1,const CPose3DPDFGaussianInf &p2);
220 
221  } // End of namespace
222 } // End of namespace
223 
224 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013