Main MRPT website > C++ reference
MRPT logo
CPosePDFGrid.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-2014, 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 CPosePDFGrid_H
10 #define CPosePDFGrid_H
11 
12 #include <mrpt/poses/CPosePDF.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
20 
21  // This must be added to any CSerializable derived class:
22  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPosePDFGrid, CPosePDF )
23 
24  /** Declares a class that represents a Probability Distribution
25  * function (PDF) of a 2D pose (x,y,phi).
26  * This class implements that PDF using a 3D grid.
27  *
28  * \sa CPose2D, CPosePDF, CPose2DGridTemplate
29  * \ingroup poses_pdf_grp
30  */
31  class BASE_IMPEXP CPosePDFGrid : public CPosePDF, public CPose2DGridTemplate<double>
32  {
33  // This must be added to any CSerializable derived class:
35 
36  protected:
37 
38 
39  public:
40  /** Constructor: Initializes a, uniform distribution over the whole given range.
41  */
43  double xMin = -1.0f,
44  double xMax = 1.0f,
45  double yMin = -1.0f,
46  double yMax = 1.0f,
47  double resolutionXY = 0.5f,
48  double resolutionPhi = DEG2RAD(180),
49  double phiMin = -M_PIf,
50  double phiMax = M_PIf
51  );
52 
53  /** Destructor
54  */
55  virtual ~CPosePDFGrid();
56 
57  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
58  */
59  void copyFrom(const CPosePDF &o);
60 
61  /** Normalizes the PDF, such as all cells sum the unity.
62  */
63  void normalize();
64 
65  /** Assigns the same value to all the cells in the grid, so the sum 1.
66  */
67  void uniformDistribution();
68 
69  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
70  * \sa getCovariance
71  */
72  void getMean(CPose2D &mean_pose) const;
73 
74  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
75  * \sa getMean
76  */
77  void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov,CPose2D &mean_point) const;
78 
79  /** 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"
80  */
81  void saveToTextFile(const std::string &dataFile) const;
82 
83  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
84  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
85  */
86  void changeCoordinatesReference( const CPose3D &newReferenceBase );
87 
88  /** Bayesian fusion of 2 densities (In the grid representation this becomes a pointwise multiplication)
89  */
90  void bayesianFusion(const CPosePDF &p1,const CPosePDF &p2, const double &minMahalanobisDistToDrop = 0 );
91 
92  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
93  */
94  void inverse(CPosePDF &o) const;
95 
96  /** Draws a single sample from the distribution (WARNING: weights are assumed to be normalized!)
97  */
98  void drawSingleSample( CPose2D &outPart ) const;
99 
100  /** 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.
101  */
102  void drawManySamples( size_t N, std::vector<CVectorDouble> & outSamples ) const;
103 
104  }; // End of class def.
105  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPosePDFGrid, CPosePDF )
106 
107 
108  } // End of namespace
109 } // End of namespace
110 
111 #endif
double DEG2RAD(const double x)
Degrees to radians.
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...
STL namespace.
#define DEG2RAD(x)
Definition: Utils.h:61
#define M_PIf
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
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...
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
Definition: eigen_frwds.h:64
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:39
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
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 2D pose.
Definition: CPose2D.h:36
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:53
Declares a class that represents a Probability Distribution function (PDF) of a 2D pose (x...
Definition: CPosePDFGrid.h:31
This is a template class for storing a 3D (2D+heading) grid containing any kind of data...



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014