Main MRPT website > C++ reference
MRPT logo
CPose3DPDFSOG.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPose3DPDFSOG_H
29 #define CPose3DPDFSOG_H
30 
31 #include <mrpt/poses/CPose3DPDF.h>
33 #include <mrpt/math/CMatrix.h>
34 
35 namespace mrpt
36 {
37 namespace poses
38 {
39  // This must be added to any CSerializable derived class:
41 
42  /** Declares a class that represents a Probability Density function (PDF) of a 3D(6D) pose \f$ p(\mathbf{x}) = [x ~ y ~ z ~ yaw ~ pitch ~ roll]^t \f$.
43  * This class implements that PDF as the following multi-modal Gaussian distribution:
44  *
45  * \f$ p(\mathbf{x}) = \sum\limits_{i=1}^N \omega^i \mathcal{N}( \mathbf{x} ; \bar{\mathbf{x}}^i, \mathbf{\Sigma}^i ) \f$
46  *
47  * Where the number of modes N is the size of CPose3DPDFSOG::m_modes. Angles are always in radians.
48  *
49  * See mrpt::poses::CPose3DPDF for more details.
50  * \ingroup poses_pdf_grp
51  * \sa CPose3DPDF
52  */
54  {
55  // This must be added to any CSerializable derived class:
57 
58  public:
59  /** The struct for each mode:
60  */
62  {
63  TGaussianMode() :
64  val(),
65  log_w(0)
66  { }
67 
69 
70  /** The log-weight
71  */
72  double log_w;
73  };
74 
78 
79  protected:
80  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
81  */
82  void assureSymmetry();
83 
84  /** Access directly to this array for modify the modes as desired.
85  * Note that no weight can be zero!!
86  * We must use pointers to satisfy the mem-alignment of the matrixes
87  */
88  TModesList m_modes;
89 
90  public:
91  /** Default constructor
92  * \param nModes The initial size of CPose3DPDFSOG::m_modes
93  */
94  CPose3DPDFSOG( size_t nModes = 1 );
95 
96  void clear(); //!< Clear all the gaussian modes
97  void resize(const size_t N); //!< Set the number of SOG modes
98  size_t size() const { return m_modes.size(); } //!< Return the number of Gaussian modes.
99  bool empty() const { return m_modes.empty(); } //!< Return whether there is any Gaussian mode.
100 
101  iterator begin() { return m_modes.begin(); }
102  iterator end() { return m_modes.end(); }
103  const_iterator begin() const { return m_modes.begin(); }
104  const_iterator end()const { return m_modes.end(); }
105 
106  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF), computed as a weighted average over all m_particles.
107  * \sa getCovariance
108  */
109  void getMean(CPose3D &mean_pose) const;
110 
111  /** Returns an estimate of the pose covariance matrix (6x6 cov matrix) and the mean, both at once.
112  * \sa getMean
113  */
114  void getCovarianceAndMean(CMatrixDouble66 &cov,CPose3D &mean_point) const;
115 
116  /** Normalize the weights in m_modes such as the maximum log-weight is 0.
117  */
118  void normalizeWeights();
119 
120  /** Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in this SOG) */
121  void getMostLikelyMode( CPose3DPDFGaussian& outVal ) const;
122 
123  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
124  */
125  void copyFrom(const CPose3DPDF &o);
126 
127  /** Save the density to a text file, with the following format:
128  * There is one row per Gaussian "mode", and each row contains 10 elements:
129  * - w (The linear weight)
130  * - x_mean (gaussian mean value)
131  * - y_mean (gaussian mean value)
132  * - x_mean (gaussian mean value)
133  * - yaw_mean (gaussian mean value, in radians)
134  * - pitch_mean (gaussian mean value, in radians)
135  * - roll_mean (gaussian mean value, in radians)
136  * - C11,C22,C33,C44,C55,C66 (Covariance elements)
137  * - C12,C13,C14,C15,C16 (Covariance elements)
138  * - C23,C24,C25,C25 (Covariance elements)
139  * - C34,C35,C36 (Covariance elements)
140  * - C45,C46 (Covariance elements)
141  * - C56 (Covariance elements)
142  *
143  */
144  void saveToTextFile(const std::string &file) const;
145 
146  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
147  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
148  */
149  void changeCoordinatesReference(const CPose3D &newReferenceBase );
150 
151  /** Bayesian fusion of two pose distributions, then save the result in this object (WARNING: Currently p1 must be a mrpt::poses::CPose3DPDFSOG object and p2 a mrpt::poses::CPose3DPDFSOG object)
152  */
153  void bayesianFusion( const CPose3DPDF &p1,const CPose3DPDF &p2 );
154 
155  /** Draws a single sample from the distribution
156  */
157  void drawSingleSample( CPose3D &outPart ) const;
158 
159  /** 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.
160  */
161  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
162 
163  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
164  */
165  void inverse(CPose3DPDF &o) const;
166 
167  /** Append the Gaussian modes from "o" to the current set of modes of "this" density.
168  */
169  void appendFrom( const CPose3DPDFSOG &o );
170 
171  }; // End of class def.
172 
173 
174  } // End of namespace
175 } // End of namespace
176 
177 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013