Main MRPT website > C++ reference
MRPT logo
CPose3DPDFGaussian.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 CPose3DPDFGaussian_H
29 #define CPose3DPDFGaussian_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$.
45  *
46  * This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DPDF for more details.
47  *
48  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussian::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
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  /** Default constructor
68  */
70 
71  /** Constructor
72  */
73  explicit CPose3DPDFGaussian( const CPose3D &init_Mean );
74 
75  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
76  */
77  CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
78 
79  /** Constructor */
80  CPose3DPDFGaussian( const CPose3D &init_Mean, const CMatrixDouble66 &init_Cov );
81 
82  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables z,pitch, and roll).
83  */
84  explicit CPose3DPDFGaussian( const CPosePDFGaussian &o );
85 
86  /** Constructor from a 6D pose PDF described as a Quaternion
87  */
88  explicit CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o);
89 
90  /** The mean value
91  */
93 
94  /** The 6x6 covariance matrix
95  */
97 
98  inline const CPose3D & getPoseMean() const { return mean; }
99  inline CPose3D & getPoseMean() { return mean; }
100 
101  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
102  * \sa getCovariance
103  */
104  void getMean(CPose3D &mean_pose) const {
105  mean_pose = mean;
106  }
107 
108  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
109  * \sa getMean
110  */
111  void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const {
112  cov = this->cov;
113  mean_point = this->mean;
114  }
115 
116  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
117  */
118  void copyFrom(const CPose3DPDF &o);
119 
120  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
121  */
122  void copyFrom(const CPosePDF &o);
123 
124  /** Copy from a 6D pose PDF described as a Quaternion
125  */
126  void copyFrom( const CPose3DQuatPDFGaussian &o);
127 
128 
129  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
130  */
131  void saveToTextFile(const std::string &file) const;
132 
133  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
134  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
135  */
136  void changeCoordinatesReference( const CPose3D &newReferenceBase );
137 
138  /** Draws a single sample from the distribution
139  */
140  void drawSingleSample( CPose3D &outPart ) const;
141 
142  /** 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.
143  */
144  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
145 
146  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
147  * The process is as follows:<br>
148  * - (x1,S1): Mean and variance of the p1 distribution.
149  * - (x2,S2): Mean and variance of the p2 distribution.
150  * - (x,S): Mean and variance of the resulting distribution.
151  *
152  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
153  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
154  */
155  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
156 
157  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
158  */
159  void inverse(CPose3DPDF &o) const;
160 
161  /** Unary - operator, returns the PDF of the inverse pose. */
163  {
165  this->inverse(p);
166  return p;
167  }
168 
169 
170  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
171  */
172  void operator += ( const CPose3D &Ap);
173 
174  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
175  */
176  void operator += ( const CPose3DPDFGaussian &Ap);
177 
178  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
179  */
180  void operator -= ( const CPose3DPDFGaussian &Ap);
181 
182  /** Evaluates the PDF at a given point.
183  */
184  double evaluatePDF( const CPose3D &x ) const;
185 
186  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
187  */
188  double evaluateNormalizedPDF( const CPose3D &x ) const;
189 
190  /** Computes the Mahalanobis distance between the centers of two Gaussians.
191  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
192  * "infinity" is returned if the corresponding elements are not exactly equal.
193  */
194  double mahalanobisDistanceTo( const CPose3DPDFGaussian& theOther);
195 
196  /** Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
197  */
198  void getCovSubmatrix2D( CMatrixDouble &out_cov ) const;
199 
200 
201  }; // End of class def.
202 
203 
204  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
206  {
207  CPose3DPDFGaussian res(x);
208  res+=u;
209  return res;
210  }
211 
212  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator -= */
214  {
215  CPose3DPDFGaussian res(x);
216  res-=u;
217  return res;
218  }
219 
220  /** Dumps the mean and covariance matrix to a text stream.
221  */
222  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
223 
224  bool BASE_IMPEXP operator==(const CPose3DPDFGaussian &p1,const CPose3DPDFGaussian &p2);
225 
226  } // End of namespace
227 
228 
229  /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-core.
230  * See each variable for the description of what classes it affects.
231  */
232  namespace global_settings
233  {
234  /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
235  * Affects to:
236  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
237  */
239  }
240 
241 } // End of namespace
242 
243 #endif



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