Main MRPT website > C++ reference for MRPT 1.5.7
CPose3DPDFGaussian.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 CPose3DPDFGaussian_H
10 #define CPose3DPDFGaussian_H
11 
12 #include <mrpt/poses/CPose3DPDF.h>
13 #include <mrpt/poses/CPose3D.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
19  class CPosePDF;
20  class CPosePDFGaussian;
21  class CPose3DQuatPDFGaussian;
22 
23  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DPDFGaussian , CPose3DPDF )
24 
25  /** 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$.
26  *
27  * This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DPDF for more details.
28  *
29  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the method "CPose3DPDFGaussian::operator+=".
30  *
31  * For further details on implemented methods and the theory behind them,
32  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
33  *
34  * \sa CPose3D, CPose3DPDF, CPose3DPDFParticles
35  * \ingroup poses_pdf_grp
36  */
38  {
39  // This must be added to any CSerializable derived class:
41 
42  protected:
43  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
44  */
45  void assureSymmetry();
46 
47  public:
48  /** Default constructor
49  */
51 
52  /** Constructor
53  */
54  explicit CPose3DPDFGaussian( const CPose3D &init_Mean );
55 
56  /** Uninitialized constructor: leave all fields uninitialized - Call with UNINITIALIZED_POSE as argument
57  */
58  CPose3DPDFGaussian(TConstructorFlags_Poses constructor_dummy_param);
59 
60  /** Constructor */
61  CPose3DPDFGaussian( const CPose3D &init_Mean, const mrpt::math::CMatrixDouble66 &init_Cov );
62 
63  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables z,pitch, and roll).
64  */
65  explicit CPose3DPDFGaussian( const CPosePDFGaussian &o );
66 
67  /** Constructor from a 6D pose PDF described as a Quaternion
68  */
69  explicit CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o);
70 
71  /** The mean value
72  */
74 
75  /** The 6x6 covariance matrix
76  */
78 
79  inline const CPose3D & getPoseMean() const { return mean; }
80  inline CPose3D & getPoseMean() { return mean; }
81 
82  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
83  * \sa getCovariance
84  */
85  void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE {
86  mean_pose = mean;
87  }
88 
89  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
90  * \sa getMean
91  */
93  out_cov = this->cov;
94  mean_point = this->mean;
95  }
96 
97  void asString(std::string &s) const;
98  inline std::string asString() const { std::string s; asString(s); return s; }
99 
100  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
101  */
102  void copyFrom(const CPose3DPDF &o) MRPT_OVERRIDE;
103 
104  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
105  */
106  void copyFrom(const CPosePDF &o);
107 
108  /** Copy from a 6D pose PDF described as a Quaternion
109  */
110  void copyFrom( const CPose3DQuatPDFGaussian &o);
111 
112 
113  /** Save the PDF to a text file, containing the 3D pose in the first line, then the covariance matrix in next 3 lines.
114  */
115  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
116 
117  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
118  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
119  */
120  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
121 
122  /** Draws a single sample from the distribution
123  */
124  void drawSingleSample( CPose3D &outPart ) const MRPT_OVERRIDE;
125 
126  /** 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.
127  */
128  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
129 
130  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
131  * The process is as follows:<br>
132  * - (x1,S1): Mean and variance of the p1 distribution.
133  * - (x2,S2): Mean and variance of the p2 distribution.
134  * - (x,S): Mean and variance of the resulting distribution.
135  *
136  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
137  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
138  */
139  void bayesianFusion( const CPose3DPDF &p1, const CPose3DPDF &p2 ) MRPT_OVERRIDE;
140 
141  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
142  */
143  void inverse(CPose3DPDF &o) const MRPT_OVERRIDE;
144 
145  /** Unary - operator, returns the PDF of the inverse pose. */
147  {
149  this->inverse(p);
150  return p;
151  }
152 
153 
154  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
155  */
156  void operator += ( const CPose3D &Ap);
157 
158  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
159  */
160  void operator += ( const CPose3DPDFGaussian &Ap);
161 
162  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
163  */
164  void operator -= ( const CPose3DPDFGaussian &Ap);
165 
166  /** Evaluates the PDF at a given point.
167  */
168  double evaluatePDF( const CPose3D &x ) const;
169 
170  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
171  */
172  double evaluateNormalizedPDF( const CPose3D &x ) const;
173 
174  /** Computes the Mahalanobis distance between the centers of two Gaussians.
175  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
176  * "infinity" is returned if the corresponding elements are not exactly equal.
177  */
178  double mahalanobisDistanceTo( const CPose3DPDFGaussian& theOther);
179 
180  /** Returns a 3x3 matrix with submatrix of the covariance for the variables (x,y,yaw) only.
181  */
182  void getCovSubmatrix2D( mrpt::math::CMatrixDouble &out_cov ) const;
183 
184 
185  }; // End of class def.
186  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPose3DPDFGaussian , CPose3DPDF )
187 
188 
189  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator += */
190  inline CPose3DPDFGaussian operator +( const CPose3DPDFGaussian &x, const CPose3DPDFGaussian &u )
191  {
193  res+=u;
194  return res;
195  }
196 
197  /** Pose composition for two 3D pose Gaussians \sa CPose3DPDFGaussian::operator -= */
199  {
201  res-=u;
202  return res;
203  }
204 
205  /** Dumps the mean and covariance matrix to a text stream.
206  */
207  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DPDFGaussian& obj);
208 
209  bool BASE_IMPEXP operator==(const CPose3DPDFGaussian &p1,const CPose3DPDFGaussian &p2);
210 
211  } // End of namespace
212 
213 
214  /** Global variables to change the run-time behaviour of some MRPT classes within mrpt-base.
215  * See each variable for the description of what classes it affects.
216  */
217  namespace global_settings
218  {
219  /** If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
220  * Affects to:
221  * - CPose3DPDFGaussian::CPose3DPDFGaussian( const CPose3DQuatPDFGaussian &o)
222  */
224  }
225 
226 } // End of namespace
227 
228 #endif
CPose3D mean
The mean value.
const CPose3D & getPoseMean() const
#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...
GLdouble s
Definition: glext.h:3602
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...
BASE_IMPEXP bool USE_SUT_QUAT2EULER_CONVERSION
If set to true (false), a Scaled Unscented Transform is used instead of a linear approximation with J...
A numeric matrix of compile-time fixed size.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
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
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
void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
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 ...
GLuint res
Definition: glext.h:6298
GLenum GLint x
Definition: glext.h:3516
void getCovarianceAndMean(mrpt::math::CMatrixDouble66 &out_cov, CPose3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
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.
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.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019