Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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:
43 
44  protected:
45  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
46  */
47  void assureSymmetry();
48 
49  public:
50  /** @name Data fields
51  @{ */
52 
53  CPose3D mean; //!< The mean value
54  mrpt::math::CMatrixDouble66 cov_inv; //!< The inverse of the 6x6 covariance matrix
55 
56  /** @} */
57 
58  inline const CPose3D & getPoseMean() const { return mean; }
59  inline CPose3D & getPoseMean() { return mean; }
60 
61  /** Default constructor - mean: all zeros, inverse covariance=all zeros -> so be careful! */
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  CPose3DPDFGaussianInf(TConstructorFlags_Poses constructor_dummy_param);
69 
70  /** Constructor with mean and inv cov. */
71  CPose3DPDFGaussianInf( const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_CovInv );
72 
73  /** Constructor from a 6D pose PDF described as a Quaternion */
75 
76  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
77  * \sa getCovariance */
78  void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE {
79  mean_pose = mean;
80  }
81  bool isInfType() const MRPT_OVERRIDE { return true; }
82 
83  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
84  * \sa getMean */
86  mean_point = this->mean;
87  this->cov_inv.inv(cov);
88  }
89 
90  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
91  virtual void getInformationMatrix(mrpt::math::CMatrixDouble66 &inf) const MRPT_OVERRIDE { inf=cov_inv; }
92 
93  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
94  void copyFrom(const CPose3DPDF &o) MRPT_OVERRIDE;
95 
96  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
97  void copyFrom(const CPosePDF &o);
98 
99  /** Copy from a 6D pose PDF described as a Quaternion
100  */
101  void copyFrom( const CPose3DQuatPDFGaussian &o);
102 
103  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines. */
104  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
105 
106  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
107  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. */
108  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
109 
110  /** Draws a single sample from the distribution */
111  void drawSingleSample( CPose3D &outPart ) const MRPT_OVERRIDE;
112 
113  /** 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. */
114  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
115 
116  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
117  * The process is as follows:<br>
118  * - (x1,S1): Mean and variance of the p1 distribution.
119  * - (x2,S2): Mean and variance of the p2 distribution.
120  * - (x,S): Mean and variance of the resulting distribution.
121  *
122  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
123  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
124  */
125  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 ) MRPT_OVERRIDE;
126 
127  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
128  void inverse(CPose3DPDF &o) const MRPT_OVERRIDE;
129 
130  /** Unary - operator, returns the PDF of the inverse pose. */
132  {
134  this->inverse(p);
135  return p;
136  }
137 
138 
139  void operator += ( const CPose3D &Ap); //!< Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated)
140  void operator += ( const CPose3DPDFGaussianInf &Ap); //!< Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated)
141  void operator -= ( const CPose3DPDFGaussianInf &Ap); //!< Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
142  double evaluatePDF( const CPose3D &x ) const; //!< Evaluates the PDF at a given point
143  double evaluateNormalizedPDF( const CPose3D &x ) const; //!< Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1]
144  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
145 
146  /** Computes the Mahalanobis distance between the centers of two Gaussians.
147  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
148  * "infinity" is returned if the corresponding elements are not exactly equal.
149  */
150  double mahalanobisDistanceTo( const CPose3DPDFGaussianInf& theOther);
151 
152  }; // End of class def.
153  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPose3DPDFGaussianInf , CPose3DPDF );
154 
155 
156  bool BASE_IMPEXP operator==(const CPose3DPDFGaussianInf &p1,const CPose3DPDFGaussianInf &p2);
157  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
158  CPose3DPDFGaussianInf BASE_IMPEXP operator +( const CPose3DPDFGaussianInf &x, const CPose3DPDFGaussianInf &u );
159  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussianInf::operator -= */
160  CPose3DPDFGaussianInf BASE_IMPEXP operator -( const CPose3DPDFGaussianInf &x, const CPose3DPDFGaussianInf &u );
161  /** Dumps the mean and covariance matrix to a text stream. */
162  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussianInf& obj);
163 
164  } // End of namespace
165 
166 
167 } // End of namespace
168 #endif
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(CPose3DPDFGaussianInf, CPose3DPDF)
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...
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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.
Definition: CPose2D.cpp:359
mrpt::math::CMatrixDouble66 cov_inv
The inverse of the 6x6 covariance matrix.
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...
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
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
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...
Definition: CPose2D.cpp:307
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...
GLsizei const GLchar ** string
Definition: glext.h:3919
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
bool isInfType() const MRPT_OVERRIDE
Returns whether the class instance holds the uncertainty in covariance or information form...
Declares a class that represents a Probability Density function (PDF) of a 3D pose as a Gaussian des...
GLenum GLint x
Definition: glext.h:3516
GLfloat GLfloat p
Definition: glext.h:5587
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
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.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019