Main MRPT website > C++ reference
MRPT logo
CPose3DQuatPDFGaussianInf.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 CPose3DQuatPDFGaussianInf_H
29 #define CPose3DQuatPDFGaussianInf_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 storing the information matrix instead of its inverse, the covariance matrix.
48  * See mrpt::poses::CPose3DQuatPDF for more details, or
49  * mrpt::poses::CPose3DPDF for classes based on Euler angles instead.
50  *
51  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the methods "CPose3DQuatPDFGaussianInf::operator+=" and "CPose3DQuatPDF::jacobiansPoseComposition".
52  *
53  * For further details on implemented methods and the theory behind them,
54  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
55  *
56  * \sa CPose3DQuat, CPose3DQuatPDF, CPose3DPDF, CPose3DQuatPDFGaussian
57  * \ingroup poses_pdf_grp
58  */
60  {
61  // This must be added to any CSerializable derived class:
63 
64  public:
65  /** Default constructor - set all values to zero. */
67 
68  /** Constructor which left all the member uninitialized, for using when speed is critical - as argument, use UNINITIALIZED_QUATERNION. */
69  CPose3DQuatPDFGaussianInf(TConstructorFlags_Quaternions constructor_dummy_param);
70 
71  /** Constructor from a default mean value, information matrix equals to zero. */
72  explicit CPose3DQuatPDFGaussianInf( const CPose3DQuat &init_Mean );
73 
74  /** Constructor with mean and inverse covariance (information matrix). */
75  CPose3DQuatPDFGaussianInf( const CPose3DQuat &init_Mean, const CMatrixDouble77 &init_CovInv );
76 
77  /** The mean value */
79 
80  /** The 7x7 information matrix (the inverse of the covariance) */
81  CMatrixDouble77 cov_inv;
82 
83  inline const CPose3DQuat & getPoseMean() const { return mean; }
84  inline CPose3DQuat & getPoseMean() { return mean; }
85 
86  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
87  * \sa getCovariance */
88  void getMean(CPose3DQuat &mean_pose) const {
89  mean_pose = mean;
90  }
91 
92  /** Returns an estimate of the pose covariance matrix (7x7 cov matrix) and the mean, both at once.
93  * \sa getMean */
95  cov_inv.inv(cov);
96  mean_point = mean;
97  }
98 
99  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
100  virtual void getInformationMatrix(CMatrixDouble77 &inf) const { inf=cov_inv; }
101 
102 
103  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
104  void copyFrom(const CPose3DQuatPDF &o);
105 
106  /** Save the PDF to a text file, containing the 3D pose in the first line (x y z qr qx qy qz), then the information matrix in the next 7 lines. */
107  void saveToTextFile(const std::string &file) const;
108 
109  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
110  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
111  */
112  void changeCoordinatesReference( const CPose3DQuat &newReferenceBase );
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  void drawSingleSample( CPose3DQuat &outPart ) const;
121 
122  /** 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. */
123  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
124 
125  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
126  void inverse(CPose3DQuatPDF &o) const;
127 
128  /** Unary - operator, returns the PDF of the inverse pose. */
130  {
132  this->inverse(p);
133  return p;
134  }
135 
136  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
137  */
138  void operator += ( const CPose3DQuat &Ap);
139 
140  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ).
141  */
142  void operator += ( const CPose3DQuatPDFGaussianInf &Ap);
143 
144  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
145  */
146  void operator -= ( const CPose3DQuatPDFGaussianInf &Ap);
147 
148  /** Evaluates the PDF at a given point.
149  */
150  double evaluatePDF( const CPose3DQuat &x ) const;
151 
152  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
153  */
154  double evaluateNormalizedPDF( const CPose3DQuat &x ) const;
155 
156  }; // End of class def.
157 
158 
159  /** Pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussianInf::operator += */
161  {
163  res+=u;
164  return res;
165  }
166 
167  /** Inverse pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussianInf::operator -= */
169  {
171  res-=u;
172  return res;
173  }
174 
175  /** Dumps the mean and covariance matrix to a text stream.
176  */
177  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DQuatPDFGaussianInf& obj);
178 
179  bool BASE_IMPEXP operator==(const CPose3DQuatPDFGaussianInf &p1,const CPose3DQuatPDFGaussianInf &p2);
180 
181  } // End of namespace
182 
183 } // End of namespace
184 
185 #endif



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