Main MRPT website > C++ reference
MRPT logo
CPosePDFGrid.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 CPosePDFGrid_H
29 #define CPosePDFGrid_H
30 
31 #include <mrpt/poses/CPosePDF.h>
33 
34 namespace mrpt
35 {
36 namespace poses
37 {
38  using namespace mrpt::utils;
39 
40  // This must be added to any CSerializable derived class:
42 
43  /** Declares a class that represents a Probability Distribution
44  * function (PDF) of a 2D pose (x,y,phi).
45  * This class implements that PDF using a 3D grid.
46  *
47  * \sa CPose2D, CPosePDF, CPose2DGridTemplate
48  * \ingroup poses_pdf_grp
49  */
50  class BASE_IMPEXP CPosePDFGrid : public CPosePDF, public CPose2DGridTemplate<double>
51  {
52  // This must be added to any CSerializable derived class:
54 
55  protected:
56 
57 
58  public:
59  /** Constructor: Initializes a, uniform distribution over the whole given range.
60  */
62  double xMin = -1.0f,
63  double xMax = 1.0f,
64  double yMin = -1.0f,
65  double yMax = 1.0f,
66  double resolutionXY = 0.5f,
67  double resolutionPhi = DEG2RAD(180),
68  double phiMin = -M_PIf,
69  double phiMax = M_PIf
70  );
71 
72  /** Destructor
73  */
74  virtual ~CPosePDFGrid();
75 
76  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
77  */
78  void copyFrom(const CPosePDF &o);
79 
80  /** Normalizes the PDF, such as all cells sum the unity.
81  */
82  void normalize();
83 
84  /** Assigns the same value to all the cells in the grid, so the sum 1.
85  */
86  void uniformDistribution();
87 
88  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
89  * \sa getCovariance
90  */
91  void getMean(CPose2D &mean_pose) const;
92 
93  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
94  * \sa getMean
95  */
96  void getCovarianceAndMean(CMatrixDouble33 &cov,CPose2D &mean_point) const;
97 
98  /** Save the contents of the 3D grid in one file, as a vertical concatenation of rectangular matrix for the different "PHI" discrete levels, and the size in X,Y,and PHI in another file named "<filename>_dims.txt"
99  */
100  void saveToTextFile(const std::string &dataFile) const;
101 
102  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
103  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
104  */
105  void changeCoordinatesReference( const CPose3D &newReferenceBase );
106 
107  /** Bayesian fusion of 2 densities (In the grid representation this becomes a pointwise multiplication)
108  */
109  void bayesianFusion(const CPosePDF &p1,const CPosePDF &p2, const double &minMahalanobisDistToDrop = 0 );
110 
111  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
112  */
113  void inverse(CPosePDF &o) const;
114 
115  /** Draws a single sample from the distribution (WARNING: weights are assumed to be normalized!)
116  */
117  void drawSingleSample( CPose2D &outPart ) const;
118 
119  /** Draws a number of samples from the distribution, and saves as a list of 1x3 vectors, where each row contains a (x,y,phi) datum.
120  */
121  void drawManySamples( size_t N, std::vector<vector_double> & outSamples ) const;
122 
123  }; // End of class def.
124 
125 
126  } // End of namespace
127 } // End of namespace
128 
129 #endif



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