Main MRPT website > C++ reference for MRPT 1.3.2
CPose3DQuatPDFGaussian.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 CPose3DQuatPDFGaussian_H
10 #define CPose3DQuatPDFGaussian_H
11 
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 CPose3DPDFGaussian;
23 
24  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPose3DQuatPDFGaussian , CPose3DQuatPDF )
25 
26  /** 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$.
27  *
28  * This class implements that PDF using a mono-modal Gaussian distribution. See mrpt::poses::CPose3DQuatPDF for more details, or
29  * mrpt::poses::CPose3DPDF for classes based on Euler angles instead.
30  *
31  * Uncertainty of pose composition operations (\f$ y = x \oplus u \f$) is implemented in the methods "CPose3DQuatPDFGaussian::operator+=" and "CPose3DQuatPDF::jacobiansPoseComposition".
32  *
33  * For further details on implemented methods and the theory behind them,
34  * see <a href="http://www.mrpt.org/6D_poses:equivalences_compositions_and_uncertainty" >this report</a>.
35  *
36  * \sa CPose3DQuat, CPose3DQuatPDF, CPose3DPDF, CPose3DQuatPDFGaussianInf
37  * \ingroup poses_pdf_grp
38  */
40  {
41  // 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  /** Default constructor - set all values to zero. */
52 
53  /** Constructor which left all the member uninitialized, for using when speed is critical - as argument, use UNINITIALIZED_QUATERNION. */
54  CPose3DQuatPDFGaussian(mrpt::math::TConstructorFlags_Quaternions constructor_dummy_param);
55 
56  /** Constructor from a default mean value, covariance equals to zero. */
57  explicit CPose3DQuatPDFGaussian( const CPose3DQuat &init_Mean );
58 
59  /** Constructor with mean and covariance. */
60  CPose3DQuatPDFGaussian( const CPose3DQuat &init_Mean, const mrpt::math::CMatrixDouble77 &init_Cov );
61 
62  /** Constructor from a Gaussian 2D pose PDF (sets to 0 the missing variables). */
63  explicit CPose3DQuatPDFGaussian( const CPosePDFGaussian &o );
64 
65  /** Constructor from an equivalent Gaussian in Euler angles representation. */
66  explicit CPose3DQuatPDFGaussian( const CPose3DPDFGaussian &o );
67 
68  /** The mean value */
70 
71  /** The 7x7 covariance matrix */
73 
74  inline const CPose3DQuat & getPoseMean() const { return mean; }
75  inline CPose3DQuat & getPoseMean() { return mean; }
76 
77  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
78  * \sa getCovariance
79  */
80  void getMean(CPose3DQuat &mean_pose) const;
81 
82  /** Returns an estimate of the pose covariance matrix (7x7 cov matrix) and the mean, both at once.
83  * \sa getMean
84  */
85  void getCovarianceAndMean(mrpt::math::CMatrixDouble77 &cov,CPose3DQuat &mean_point) const;
86 
87  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
88  */
89  void copyFrom(const CPose3DQuatPDF &o);
90 
91  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
92  */
93  void copyFrom(const CPosePDF &o);
94 
95  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
96  */
97  void copyFrom(const CPose3DPDFGaussian &o);
98 
99  /** Save the PDF to a text file, containing the 3D pose in the first line (x y z qr qx qy qz), then the covariance matrix in the next 7 lines.
100  */
101  void saveToTextFile(const std::string &file) const;
102 
103  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
104  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
105  */
106  void changeCoordinatesReference( const CPose3DQuat &newReferenceBase );
107 
108  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
109  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
110  */
111  void changeCoordinatesReference( const CPose3D &newReferenceBase );
112 
113  /** Draws a single sample from the distribution
114  */
115  void drawSingleSample( CPose3DQuat &outPart ) const;
116 
117  /** 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.
118  */
119  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const;
120 
121  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
122  */
123  void inverse(CPose3DQuatPDF &o) const;
124 
125  /** Unary - operator, returns the PDF of the inverse pose. */
127  {
129  this->inverse(p);
130  return p;
131  }
132 
133  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
134  */
135  void operator += ( const CPose3DQuat &Ap);
136 
137  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ).
138  */
139  void operator += ( const CPose3DQuatPDFGaussian &Ap);
140 
141  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated).
142  */
143  void operator -= ( const CPose3DQuatPDFGaussian &Ap);
144 
145  /** Evaluates the PDF at a given point.
146  */
147  double evaluatePDF( const CPose3DQuat &x ) const;
148 
149  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
150  */
151  double evaluateNormalizedPDF( const CPose3DQuat &x ) const;
152 
153  /** Computes the Mahalanobis distance between the centers of two Gaussians.
154  * The variables with a variance exactly equal to 0 are not taken into account in the process, but
155  * "infinity" is returned if the corresponding elements are not exactly equal.
156  */
157  double mahalanobisDistanceTo( const CPose3DQuatPDFGaussian& theOther);
158 
159  }; // End of class def.
161 
162 
163  /** Pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussian::operator += */
165  {
166  CPose3DQuatPDFGaussian res(x);
167  res+=u;
168  return res;
169  }
170 
171  /** Inverse pose composition for two 3D pose Gaussians \sa CPose3DQuatPDFGaussian::operator -= */
173  {
174  CPose3DQuatPDFGaussian res(x);
175  res-=u;
176  return res;
177  }
178 
179  /** Dumps the mean and covariance matrix to a text stream.
180  */
181  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPose3DQuatPDFGaussian& obj);
182 
184 
185  } // End of namespace
186 
187  namespace global_settings
188  {
189  /** If set to true (default), a Scaled Unscented Transform is used instead of a linear approximation with Jacobians.
190  * Affects to:
191  * - CPose3DQuatPDFGaussian::copyFrom(const CPose3DPDFGaussian &o)
192  * - CPose3DQuatPDFGaussianInf::copyFrom(const CPose3DPDFGaussianInf &o)
193  */
195  }
196 
197 } // End of namespace
198 
199 #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...
TConstructorFlags_Quaternions
Definition: CQuaternion.h:21
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
BASE_IMPEXP bool USE_SUT_EULER2QUAT_CONVERSION
If set to true (default), a Scaled Unscented Transform is used instead of a linear approximation with...
A numeric matrix of compile-time fixed size.
CMatrixFixedNumeric< double, 7, 7 > CMatrixDouble77
Definition: eigen_frwds.h:51
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
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...
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:41
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
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
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 ...
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.11 for MRPT 1.3.2 SVN:Unversioned directory at Sun May 1 08:45:24 UTC 2016