Main MRPT website > C++ reference for MRPT 1.9.9
CPose3DPDFSOG.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 CPose3DPDFSOG_H
10 #define CPose3DPDFSOG_H
11 
12 #include <mrpt/poses/CPose3DPDF.h>
15 
16 namespace mrpt
17 {
18 namespace poses
19 {
20 /** Declares a class that represents a Probability Density function (PDF) of a
21  * 3D(6D) pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
22  * This class implements that PDF as the following multi-modal Gaussian
23  * distribution:
24  *
25  * \f$ p(\mathbf{x}) = \sum\limits_{i=1}^N \omega^i \mathcal{N}( \mathbf{x} ;
26  * \bar{\mathbf{x}}^i, \mathbf{\Sigma}^i ) \f$
27  *
28  * Where the number of modes N is the size of CPose3DPDFSOG::m_modes. Angles
29  * are always in radians.
30  *
31  * See mrpt::poses::CPose3DPDF for more details.
32  * \ingroup poses_pdf_grp
33  * \sa CPose3DPDF
34  */
35 class CPose3DPDFSOG : public CPose3DPDF
36 {
38 
39  public:
40  /** The struct for each mode:
41  */
43  {
44  TGaussianMode() : val(), log_w(0) {}
46 
47  /** The log-weight
48  */
49  double log_w;
50  };
51 
55 
56  protected:
57  /** Assures the symmetry of the covariance matrix (eventually certain
58  * operations in the math-coprocessor lead to non-symmetric matrixes!)
59  */
60  void assureSymmetry();
61 
62  /** Access directly to this array for modify the modes as desired.
63  * Note that no weight can be zero!!
64  * We must use pointers to satisfy the mem-alignment of the matrixes
65  */
67 
68  public:
69  /** Default constructor
70  * \param nModes The initial size of CPose3DPDFSOG::m_modes
71  */
72  CPose3DPDFSOG(size_t nModes = 1);
73 
74  /** Clear all the gaussian modes */
75  void clear();
76  /** Set the number of SOG modes */
77  void resize(const size_t N);
78  /** Return the number of Gaussian modes. */
79  size_t size() const { return m_modes.size(); }
80  /** Return whether there is any Gaussian mode. */
81  bool empty() const { return m_modes.empty(); }
82  iterator begin() { return m_modes.begin(); }
83  iterator end() { return m_modes.end(); }
84  const_iterator begin() const { return m_modes.begin(); }
85  const_iterator end() const { return m_modes.end(); }
86  /** Returns an estimate of the pose, (the mean, or mathematical expectation
87  * of the PDF), computed as a weighted average over all m_particles. \sa
88  * getCovariance */
89  void getMean(CPose3D& mean_pose) const override;
90  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and
91  * the mean, both at once. \sa getMean */
93  mrpt::math::CMatrixDouble66& cov, CPose3D& mean_point) const override;
94  /** Normalize the weights in m_modes such as the maximum log-weight is 0. */
95  void normalizeWeights();
96  /** Return the Gaussian mode with the highest likelihood (or an empty
97  * Gaussian if there are no modes in this SOG) */
98  void getMostLikelyMode(CPose3DPDFGaussian& outVal) const;
99 
100  /** Copy operator, translating if necesary (for example, between particles
101  * and gaussian representations) */
102  void copyFrom(const CPose3DPDF& o) override;
103 
104  /** Save the density to a text file, with the following format:
105  * There is one row per Gaussian "mode", and each row contains 10
106  * elements:
107  * - w (The linear weight)
108  * - x_mean (gaussian mean value)
109  * - y_mean (gaussian mean value)
110  * - x_mean (gaussian mean value)
111  * - yaw_mean (gaussian mean value, in radians)
112  * - pitch_mean (gaussian mean value, in radians)
113  * - roll_mean (gaussian mean value, in radians)
114  * - C11,C22,C33,C44,C55,C66 (Covariance elements)
115  * - C12,C13,C14,C15,C16 (Covariance elements)
116  * - C23,C24,C25,C25 (Covariance elements)
117  * - C34,C35,C36 (Covariance elements)
118  * - C45,C46 (Covariance elements)
119  * - C56 (Covariance elements)
120  *
121  */
122  void saveToTextFile(const std::string& file) const override;
123 
124  /** this = p (+) this. This can be used to convert a PDF from local
125  * coordinates to global, providing the point (newReferenceBase) from which
126  * "to project" the current pdf. Result PDF substituted the currently
127  * stored one in the object. */
128  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
129 
130  /** Bayesian fusion of two pose distributions, then save the result in this
131  * object (WARNING: Currently p1 must be a mrpt::poses::CPose3DPDFSOG object
132  * and p2 a mrpt::poses::CPose3DPDFSOG object) */
133  void bayesianFusion(const CPose3DPDF& p1, const CPose3DPDF& p2) override;
134 
135  /** Draws a single sample from the distribution */
136  void drawSingleSample(CPose3D& outPart) const override;
137  /** Draws a number of samples from the distribution, and saves as a list of
138  * 1x6 vectors, where each row contains a (x,y,z,yaw,pitch,roll) datum */
139  void drawManySamples(
140  size_t N,
141  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
142  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
143  void inverse(CPose3DPDF& o) const override;
144 
145  /** Append the Gaussian modes from "o" to the current set of modes of "this"
146  * density */
147  void appendFrom(const CPose3DPDFSOG& o);
148 
149 }; // End of class def.
150 } // End of namespace
151 } // End of namespace
152 #endif
CPose3DPDFSOG(size_t nModes=1)
Default constructor.
void getCovarianceAndMean(mrpt::math::CMatrixDouble66 &cov, CPose3D &mean_point) const override
Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once...
TModesList::iterator iterator
Definition: CPose3DPDFSOG.h:54
void getMostLikelyMode(CPose3DPDFGaussian &outVal) const
Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in t...
void appendFrom(const CPose3DPDFSOG &o)
Append the Gaussian modes from "o" to the current set of modes of "this" density. ...
Scalar * iterator
Definition: eigen_plugins.h:26
Declares a class that represents a Probability Density function (PDF) of a 3D(6D) pose ...
Definition: CPose3DPDFSOG.h:35
mrpt::aligned_containers< TGaussianMode >::vector_t TModesList
Definition: CPose3DPDFSOG.h:52
void getMean(CPose3D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF), computed as a weighted average over all m_particles.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
void normalizeWeights()
Normalize the weights in m_modes such as the maximum log-weight is 0.
void inverse(CPose3DPDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
A numeric matrix of compile-time fixed size.
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const override
Draws a number of samples from the distribution, and saves as a list of 1x6 vectors, where each row contains a (x,y,z,yaw,pitch,roll) datum.
TModesList m_modes
Access directly to this array for modify the modes as desired.
Definition: CPose3DPDFSOG.h:66
TModesList::const_iterator const_iterator
Definition: CPose3DPDFSOG.h:53
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
bool empty() const
Return whether there is any Gaussian mode.
Definition: CPose3DPDFSOG.h:81
void drawSingleSample(CPose3D &outPart) const override
Draws a single sample from the distribution.
void saveToTextFile(const std::string &file) const override
Save the density to a text file, with the following format: There is one row per Gaussian "mode"...
GLsizei const GLchar ** string
Definition: glext.h:4101
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void clear()
Clear all the gaussian modes.
const_iterator end() const
Definition: CPose3DPDFSOG.h:85
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
void bayesianFusion(const CPose3DPDF &p1, const CPose3DPDF &p2) override
Bayesian fusion of two pose distributions, then save the result in this object (WARNING: Currently p1...
size_t size() const
Return the number of Gaussian modes.
Definition: CPose3DPDFSOG.h:79
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
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:148
const_iterator begin() const
Definition: CPose3DPDFSOG.h:84
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
void resize(const size_t N)
Set the number of SOG modes.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019