Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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! */
62 
63  /** Constructor with a mean value, inverse covariance=all zeros -> so be careful! */
64  explicit CPose3DPDFGaussianInf( const CPose3D &init_Mean );
65 
66  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument */
67  CPose3DPDFGaussianInf(TConstructorFlags_Poses constructor_dummy_param);
68 
69  /** Constructor with mean and inv cov. */
70  CPose3DPDFGaussianInf( const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_CovInv );
71 
72  /** Constructor from a 6D pose PDF described as a Quaternion */
74 
75  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
76  * \sa getCovariance */
77  void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE {
78  mean_pose = mean;
79  }
80 
81  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
82  * \sa getMean */
84  mean_point = this->mean;
85  this->cov_inv.inv(cov);
86  }
87 
88  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
89  virtual void getInformationMatrix(mrpt::math::CMatrixDouble66 &inf) const MRPT_OVERRIDE { inf=cov_inv; }
90 
91  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
92  void copyFrom(const CPose3DPDF &o) MRPT_OVERRIDE;
93 
94  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
95  void copyFrom(const CPosePDF &o);
96 
97  /** Copy from a 6D pose PDF described as a Quaternion
98  */
99  void copyFrom( const CPose3DQuatPDFGaussian &o);
100 
101  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines. */
102  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
103 
104  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
105  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. */
106  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
107 
108  /** Draws a single sample from the distribution */
109  void drawSingleSample( CPose3D &outPart ) const MRPT_OVERRIDE;
110 
111  /** 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. */
112  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
113 
114  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
115  * The process is as follows:<br>
116  * - (x1,S1): Mean and variance of the p1 distribution.
117  * - (x2,S2): Mean and variance of the p2 distribution.
118  * - (x,S): Mean and variance of the resulting distribution.
119  *
120  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
121  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
122  */
123  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 ) MRPT_OVERRIDE;
124 
125  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
126  void inverse(CPose3DPDF &o) const MRPT_OVERRIDE;
127 
128  /** Unary - operator, returns the PDF of the inverse pose. */
130  {
132  this->inverse(p);
133  return p;
134  }
135 
136 
137  void operator += ( const CPose3D &Ap); //!< Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated)
138  void operator += ( const CPose3DPDFGaussianInf &Ap); //!< Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated)
139  void operator -= ( const CPose3DPDFGaussianInf &Ap); //!< Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
140  double evaluatePDF( const CPose3D &x ) const; //!< Evaluates the PDF at a given point
141  double evaluateNormalizedPDF( const CPose3D &x ) const; //!< Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1]
142  void getInvCovSubmatrix2D( mrpt::math::CMatrixDouble &out_cov ) const; //!< Returns a 3x3 matrix with submatrix of the inverse covariance for the variables (x,y,yaw) only
143 
144  /** Computes the Mahalanobis distance between the centers of two Gaussians.
145  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
146  * "infinity" is returned if the corresponding elements are not exactly equal.
147  */
148  double mahalanobisDistanceTo( const CPose3DPDFGaussianInf& theOther);
149 
150  }; // End of class def.
152 
153 
155  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
157  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussianInf::operator -= */
159  /** Dumps the mean and covariance matrix to a text stream. */
160  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussianInf& obj);
161 
162  } // End of namespace
163 } // End of namespace
164 #endif
void getCovarianceAndMean(mrpt::math::CMatrixDouble66 &cov, CPose3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
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...
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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...
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
mrpt::math::TPoint2D BASE_IMPEXP operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
virtual void getInformationMatrix(mrpt::math::CMatrixDouble66 &inf) const MRPT_OVERRIDE
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) ...
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...
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
void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
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.4.0 SVN: at Mon Aug 15 11:50:21 UTC 2016