Main MRPT website > C++ reference
MRPT logo
CPointPDFParticles.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 CPointPDFParticles_H
29 #define CPointPDFParticles_H
30 
31 #include <mrpt/poses/CPointPDF.h>
32 #include <mrpt/math/CMatrix.h>
35 
36 namespace mrpt
37 {
38 namespace poses
39 {
41 
42  /** Data within each particle
43  * \ingroup poses_pdf_grp
44  */
45  class BASE_IMPEXP TSimple3DPoint : public mrpt::utils::CSerializable
46  {
47  // This must be added to any CSerializable derived class:
49  public:
50  TSimple3DPoint(const TSimple3DPoint&o) : x(o.x),y(o.y),z(o.z)
51  {
52  }
53 
54  TSimple3DPoint() : x(0),y(0),z(0)
55  {
56  }
57 
58  TSimple3DPoint(const CPoint3D &v) : x(v.x()),y(v.y()),z(v.z())
59  {
60  }
61 
62  float x,y,z;
63  };
64 
66 
67  /** A probability distribution of a 2D/3D point, represented as a set of random samples (particles).
68  * \sa CPointPDF
69  * \ingroup poses_pdf_grp
70  */
72  {
73  // This must be added to any CSerializable derived class:
75 
76  // This uses CParticleFilterData to implement some methods required for CParticleFilterCapable:
77  IMPLEMENT_PARTICLE_FILTER_CAPABLE(TSimple3DPoint);
78 
79  public:
80  /** Default constructor
81  */
82  CPointPDFParticles(size_t numParticles = 1);
83 
84  /** Destructor
85  */
86  virtual ~CPointPDFParticles();
87 
88  /** Clear all the particles (free memory)
89  */
90  void clear() { setSize(0); }
91 
92  /** Erase all the previous particles and change the number of particles, with a given initial value
93  */
94  void setSize(size_t numberParticles, const CPoint3D &defaultValue = CPoint3D(0,0,0) );
95 
96  /** Returns the number of particles
97  */
98  size_t size() const
99  {
100  return m_particles.size();
101  }
102 
103  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF).
104  * \sa getCovariance
105  */
106  void getMean(CPoint3D &mean_point) const;
107 
108  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
109  * \sa getMean
110  */
111  void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const;
112 
113  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
114  */
115  void copyFrom(const CPointPDF &o);
116 
117  /** Save PDF's particles to a text file, where each line is: X Y Z LOG_W
118  */
119  void saveToTextFile(const std::string &file) const;
120 
121  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
122  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. Both the mean value and the covariance matrix are updated correctly.
123  */
124  void changeCoordinatesReference( const CPose3D &newReferenceBase );
125 
126  /** Compute the kurtosis of the distribution.
127  */
128  double computeKurtosis();
129 
130  /** Draw a sample from the pdf.
131  */
132  void drawSingleSample(CPoint3D &outSample) const;
133 
134  /** Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
135  * \param p1 The first distribution to fuse
136  * \param p2 The second distribution to fuse
137  * \param minMahalanobisDistToDrop If set to different of 0, the result of very separate Gaussian modes (that will result in negligible components) in SOGs will be dropped to reduce the number of modes in the output.
138  */
139  void bayesianFusion( const CPointPDF &p1, const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
140 
141  }; // End of class def.
142 
143 
144  } // End of namespace
145 } // End of namespace
146 
147 #endif



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