Main MRPT website > C++ reference for MRPT 1.3.2
CPose3DPDFGaussianInf.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 CPose3DPDFGaussianInf_H
10 #define CPose3DPDFGaussianInf_H
11 
12 #include <mrpt/poses/CPose3D.h>
13 #include <mrpt/poses/CPose3DPDF.h>
14 #include <mrpt/poses/CPosePDF.h>
15 #include <mrpt/math/CMatrixD.h>
16 
17 namespace mrpt
18 {
19 namespace poses
20 {
21  class CPosePDFGaussian;
22  class CPose3DQuatPDFGaussian;
23 
24  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DPDFGaussianInf , CPose3DPDF )
25 
26  /** 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.
27  *
28  * This class implements that PDF using a mono-modal Gaussian distribution in "information" form (inverse covariance matrix).
29  *
30  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussianInf::operator+=".
31  *
32  * For further details on implemented methods and the theory behind them,
33  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
34  *
35  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles, CPose3DPDFGaussian
36  * \ingroup poses_pdf_grp
37  */
39  {
40  // This must be added to any CSerializable derived class:
42 
43  protected:
44  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
45  */
46  void assureSymmetry();
47 
48  public:
49  /** @name Data fields
50  @{ */
51 
52  CPose3D mean; //!< The mean value
53  mrpt::math::CMatrixDouble66 cov_inv; //!< The inverse of the 6x6 covariance matrix
54 
55  /** @} */
56 
57  inline const CPose3D & getPoseMean() const { return mean; }
58  inline CPose3D & getPoseMean() { return mean; }
59 
60  /** Default constructor - mean: all zeros, inverse covariance=all zeros -> so be careful!
61  */
63 
64  /** Constructor with a mean value, inverse covariance=all zeros -> so be careful! */
65  explicit CPose3DPDFGaussianInf( const CPose3D &init_Mean );
66 
67  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
68  */
69  CPose3DPDFGaussianInf(TConstructorFlags_Poses constructor_dummy_param);
70 
71  /** Constructor with mean and inv cov. */
72  CPose3DPDFGaussianInf( const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_CovInv );
73 
74  /** Constructor from a 6D pose PDF described as a Quaternion
75  */
77 
78  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
79  * \sa getCovariance
80  */
81  void getMean(CPose3D &mean_pose) const {
82  mean_pose = mean;
83  }
84 
85  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
86  * \sa getMean
87  */
89  mean_point = this->mean;
90  this->cov_inv.inv(cov);
91  }
92 
93  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
94  virtual void getInformationMatrix(mrpt::math::CMatrixDouble66 &inf) const { inf=cov_inv; }
95 
96  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
97  */
98  void copyFrom(const CPose3DPDF &o);
99 
100  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
101  */
102  void copyFrom(const CPosePDF &o);
103 
104  /** Copy from a 6D pose PDF described as a Quaternion
105  */
106  void copyFrom( const CPose3DQuatPDFGaussian &o);
107 
108  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
109  */
110  void saveToTextFile(const std::string &file) const;
111 
112  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
113  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
114  */
115  void changeCoordinatesReference( const CPose3D &newReferenceBase );
116 
117  /** Draws a single sample from the distribution
118  */
119  void drawSingleSample( CPose3D &outPart ) const;
120 
121  /** 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.
122  */
123  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const;
124 
125  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
126  * The process is as follows:<br>
127  * - (x1,S1): Mean and variance of the p1 distribution.
128  * - (x2,S2): Mean and variance of the p2 distribution.
129  * - (x,S): Mean and variance of the resulting distribution.
130  *
131  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
132  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
133  */
134  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 );
135 
136  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
137  */
138  void inverse(CPose3DPDF &o) const;
139 
140  /** Unary - operator, returns the PDF of the inverse pose. */
142  {
144  this->inverse(p);
145  return p;
146  }
147 
148  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
149  */
150  void operator += ( const CPose3D &Ap);
151 
152  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
153  */
154  void operator += ( const CPose3DPDFGaussianInf &Ap);
155 
156  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
157  */
158  void operator -= ( const CPose3DPDFGaussianInf &Ap);
159 
160  /** Evaluates the PDF at a given point.
161  */
162  double evaluatePDF( const CPose3D &x ) const;
163 
164  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
165  */
166  double evaluateNormalizedPDF( const CPose3D &x ) const;
167 
168  /** Computes the Mahalanobis distance between the centers of two Gaussians.
169  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
170  * "infinity" is returned if the corresponding elements are not exactly equal.
171  */
172  double mahalanobisDistanceTo( const CPose3DPDFGaussianInf& theOther);
173 
174  /** Returns a 3x3 matrix with submatrix of the inverse covariance for the variables (x,y,yaw) only.
175  */
176  void getInvCovSubmatrix2D( mrpt::math::CMatrixDouble &out_cov ) const;
177 
178  }; // End of class def.
180 
181 
182  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
183  inline CPose3DPDFGaussianInf operator +( const CPose3DPDFGaussianInf &x, const CPose3DPDFGaussianInf &u )
184  {
185  CPose3DPDFGaussianInf res(x);
186  res+=u;
187  return res;
188  }
189 
190  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussianInf::operator -= */
192  {
193  CPose3DPDFGaussianInf res(x);
194  res-=u;
195  return res;
196  }
197 
198  /** Dumps the mean and covariance matrix to a text stream.
199  */
200  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussianInf& obj);
201 
203 
204  } // End of namespace
205 } // End of namespace
206 
207 #endif
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...
void getMean(CPose3D &mean_pose) const
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
virtual void getInformationMatrix(mrpt::math::CMatrixDouble66 &inf) const
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) ...
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.
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 as a Gaussian des...
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.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016