Main MRPT website > C++ reference
MRPT logo
CPose3DQuatPDFGaussian.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 CPose3DQuatPDFGaussian_H
29 #define CPose3DQuatPDFGaussian_H
30 
32 #include <mrpt/poses/CPose3DPDF.h>
33 #include <mrpt/poses/CPosePDF.h>
34 #include <mrpt/math/CMatrixD.h>
35 
36 namespace mrpt
37 {
38 namespace poses
39 {
40  class CPosePDFGaussian;
41  class CPose3DPDFGaussian;
42 
44 
45  /** Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion \f$ p(\mathbf{x}) = [x ~ y ~ z ~ qr ~ qx ~ qy ~ qz]^\top \f$.
46  *
47  * This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DQuatPDF for more details, or
48  * mrpt::poses::CPose3DPDF for classes based on Euler angles instead.
49  *
50  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the methods "CPose3DQuatPDFGaussian::operator+=" and "CPose3DQuatPDF::jacobiansPoseComposition".
51  *
52  * For further details on implemented methods and the theory behind them,
53  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
54  *
55  * \sa CPose3DQuat, CPose3DQuatPDF, CPose3DPDF, CPose3DQuatPDFGaussianInf
56  * \ingroup poses_pdf_grp
57  */
59  {
60  // This must be added to any CSerializable derived class:
62 
63  protected:
64  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
65  */
66  void assureSymmetry();
67 
68  public:
69  /** Default constructor - set all values to zero. */
71 
72  /** Constructor which left all the member uninitialized, for using when speed is critical - as argument, use UNINITIALIZED_QUATERNION. */
73  CPose3DQuatPDFGaussian(TConstructorFlags_Quaternions constructor_dummy_param);
74 
75  /** Constructor from a default mean value, covariance equals to zero. */
76  explicit CPose3DQuatPDFGaussian( const CPose3DQuat &init_Mean );
77 
78  /** Constructor with mean and covariance. */
79  CPose3DQuatPDFGaussian( const CPose3DQuat &init_Mean, const CMatrixDouble77 &init_Cov );
80 
81  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables). */
82  explicit CPose3DQuatPDFGaussian( const CPosePDFGaussian &o );
83 
84  /** Constructor from an equivalent Gaussian in Euler angles representation. */
85  explicit CPose3DQuatPDFGaussian( const CPose3DPDFGaussian &o );
86 
87  /** The mean value */
89 
90  /** The 7x7 covariance matrix */
92 
93  inline const CPose3DQuat & getPoseMean() const { return mean; }
94  inline CPose3DQuat & getPoseMean() { return mean; }
95 
96  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
97  * \sa getCovariance
98  */
99  void getMean(CPose3DQuat &mean_pose) const;
100 
101  /** Returns an estimate of the pose covariance matrix (7x7 cov matrix) and the mean, both at once.
102  * \sa getMean
103  */
104  void getCovarianceAndMean(CMatrixDouble77 &cov,CPose3DQuat &mean_point) const;
105 
106  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
107  */
108  void copyFrom(const CPose3DQuatPDF &o);
109 
110  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
111  */
112  void copyFrom(const CPosePDF &o);
113 
114  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
115  */
116  void copyFrom(const CPose3DPDFGaussian &o);
117 
118  /** Save the PDF to a text file, containing the 3D pose in the first line (x y z qr qx qy qz), then the covariance matrix in the next 7 lines.
119  */
120  void saveToTextFile(const std::string &file) const;
121 
122  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
123  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
124  */
125  void changeCoordinatesReference( const CPose3DQuat &newReferenceBase );
126 
127  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
128  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
129  */
130  void changeCoordinatesReference( const CPose3D &newReferenceBase );
131 
132  /** Draws a single sample from the distribution
133  */
134  void drawSingleSample( CPose3DQuat &outPart ) const;
135 
136  /** Draws a number of samples from the distribution, and saves as a list of 1x7 vectors, where each row contains a (x,y,z,qr,qx,qy,qz) datum.
137  */
138  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
139 
140  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
141  */
142  void inverse(CPose3DQuatPDF &o) const;
143 
144  /** Unary - operator, returns the PDF of the inverse pose. */
146  {
148  this->inverse(p);
149  return p;
150  }
151 
152  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
153  */
154  void operator += ( const CPose3DQuat &Ap);
155 
156  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ).
157  */
158  void operator += ( const CPose3DQuatPDFGaussian &Ap);
159 
160  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
161  */
162  void operator -= ( const CPose3DQuatPDFGaussian &Ap);
163 
164  /** Evaluates the PDF at a given point.
165  */
166  double evaluatePDF( const CPose3DQuat &x ) const;
167 
168  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
169  */
170  double evaluateNormalizedPDF( const CPose3DQuat &x ) const;
171 
172  /** Computes the Mahalanobis distance between the centers of two Gaussians.
173  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
174  * "infinity" is returned if the corresponding elements are not exactly equal.
175  */
176  double mahalanobisDistanceTo( const CPose3DQuatPDFGaussian& theOther);
177 
178  }; // End of class def.
179 
180 
181  /** Pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussian::operator += */
183  {
184  CPose3DQuatPDFGaussian res(x);
185  res+=u;
186  return res;
187  }
188 
189  /** Inverse pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussian::operator -= */
191  {
192  CPose3DQuatPDFGaussian res(x);
193  res-=u;
194  return res;
195  }
196 
197  /** Dumps the mean and covariance matrix to a text stream.
198  */
199  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DQuatPDFGaussian& obj);
200 
201  bool BASE_IMPEXP operator==(const CPose3DQuatPDFGaussian &p1,const CPose3DQuatPDFGaussian &p2);
202 
203  } // End of namespace
204 
205  namespace global_settings
206  {
207  /** If set to true (default), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
208  * Affects to:
209  * - CPose3DQuatPDFGaussian::copyFrom(const CPose3DPDFGaussian &o)
210  * - CPose3DQuatPDFGaussianInf::copyFrom(const CPose3DPDFGaussianInf &o)
211  */
213  }
214 
215 } // End of namespace
216 
217 #endif



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