Main MRPT website > C++ reference
MRPT logo
CBeacon.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 CBeacon_H
29 #define CBeacon_H
30 
32 #include <mrpt/math/CMatrix.h>
33 #include <mrpt/system/os.h>
34 #include <mrpt/utils/CStringList.h>
35 #include <mrpt/poses/CPoint3D.h>
39 
41 
42 #include <mrpt/maps/link_pragmas.h>
43 
44 
45 namespace mrpt
46 {
47 namespace slam
48 {
49  using namespace mrpt::poses;
50  using namespace mrpt::utils;
51 
52  class CBeaconMap;
54 
55  /** The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions.
56  * This class is used for storage within the class CBeaconMap.
57  * The class implements the same methods than the interface "CPointPDF", and invoking them actually becomes
58  * a mapping into the methods of the current PDF representation of the beacon, selectable by means of "m_typePDF"
59  * \sa CBeaconMap, CPointPDFSOG
60  * \ingroup mrpt_maps_grp
61  */
62  class MAPS_IMPEXP CBeacon : public CPointPDF
63  {
64  // This must be added to any CSerializable derived class:
66 
67  public:
68  /** The type for the IDs of landmarks.
69  */
70  typedef int64_t TBeaconID;
71 
72  /** See m_typePDF
73  */
74  enum TTypePDF { pdfMonteCarlo = 0, pdfGauss, pdfSOG };
75 
76  /** Which one of the different 3D point PDF is currently used in this object: montecarlo, gaussian, or a sum of gaussians.
77  * \sa m_location
78  */
80 
81  /** The individual PDF, if m_typePDF=pdfMonteCarlo (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
82  */
84 
85  /** The individual PDF, if m_typePDF=pdfGauss (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
86  */
88 
89  /** The individual PDF, if m_typePDF=pdfSOG (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
90  */
92 
93  /** An ID for the landmark (see details next...)
94  * This ID was introduced in the version 3 of this class (21/NOV/2006), and its aim is
95  * to provide a way for easily establishing correspondences between landmarks detected
96  * in sequential image frames. Thus, the management of this field should be:
97  * - In 'servers' (classes/modules/... that detect landmarks from images): A different ID must be assigned to every landmark (e.g. a sequential counter), BUT only in the case of being sure of the correspondence of one landmark with another one in the past (e.g. tracking).
98  * - In 'clients': This field can be ignored, but if it is used, the advantage is solving the correspondence between landmarks detected in consequentive instants of time: Two landmarks with the same ID <b>correspond</b> to the same physical feature, BUT it should not be expected the inverse to be always true.
99  *
100  * Note that this field is never fill out automatically, it must be set by the programmer if used.
101  */
103 
104  /** Default constructor
105  */
106  CBeacon();
107 
108  /** Virtual destructor
109  */
110  virtual ~CBeacon();
111 
112  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF).
113  * \sa getCovariance
114  */
115  void getMean(CPoint3D &mean_point) const;
116 
117  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
118  * \sa getMean
119  */
120  void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const;
121 
122  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
123  */
124  void copyFrom(const CPointPDF &o);
125 
126  /** Save PDF's particles to a text file. See derived classes for more information about the format of generated files.
127  */
128  void saveToTextFile(const std::string &file) const;
129 
130  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
131  * "to project" the current pdf. Result PDF substituted the currently stored one in the object.
132  */
133  void changeCoordinatesReference( const CPose3D &newReferenceBase );
134 
135  /** Saves a 3D representation of the beacon into a given OpenGL scene
136  */
137  void getAs3DObject( mrpt::opengl::CSetOfObjectsPtr &outObj ) const;
138 
139  /** Gets a set of MATLAB commands which draw the current state of the beacon:
140  */
141  void getAsMatlabDrawCommands( utils::CStringList &out_Str ) const;
142 
143  /** Draw a sample from the pdf.
144  */
145  void drawSingleSample(CPoint3D &outSample) const;
146 
147  /** 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!)
148  * \param p1 The first distribution to fuse
149  * \param p2 The second distribution to fuse
150  * \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.
151  */
152  void bayesianFusion(const CPointPDF &p1,const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
153 
154 
155  /** Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an approximate SOG.
156  * Note that if the beacon is a SOG itself, the number of gaussian modes will be square.
157  * As a speed-up, if a "center point"+"maxDistanceFromCenter" is supplied (maxDistanceFromCenter!=0), those modes farther than this sphere will be discarded.
158  * Parameters such as the stdSigma of the sensor are gathered from "myBeaconMap"
159  * The result is one "ring" for each Gaussian mode that represent the beacon position in this object.
160  * The position of the sensor on the robot is used to shift the resulting densities such as they represent the position of the robot, not the sensor.
161  * \sa CBeaconMap::insertionOptions, generateRingSOG
162  */
163  void generateObservationModelDistribution(
164  const float &sensedRange,
165  CPointPDFSOG &outPDF,
166  const CBeaconMap *myBeaconMap,
167  const CPoint3D &sensorPntOnRobot,
168  const CPoint3D &centerPoint = CPoint3D(0,0,0),
169  const float &maxDistanceFromCenter = 0
170  ) const;
171 
172  /** This static method returns a SOG with ring-shape (or as a 3D sphere) that can be used to initialize a beacon if observed the first time.
173  * sensorPnt is the center of the ring/sphere, i.e. the absolute position of the range sensor.
174  * If clearPreviousContentsOutPDF=false, the SOG modes will be added to the current contents of outPDF
175  * If the 3x3 matrix covarianceCompositionToAdd is provided, it will be add to every Gaussian (to model the composition of uncertainty).
176  * \sa generateObservationModelDistribution
177  */
178  static void generateRingSOG(
179  const float &sensedRange,
180  CPointPDFSOG &outPDF,
181  const CBeaconMap *myBeaconMap,
182  const CPoint3D &sensorPnt,
183  const CMatrixDouble33 *covarianceCompositionToAdd = NULL,
184  bool clearPreviousContentsOutPDF = true,
185  const CPoint3D &centerPoint = CPoint3D(0,0,0),
186  const float &maxDistanceFromCenter = 0
187  );
188 
189 
190  }; // End of class definition
191 
192 
193  } // End of namespace
194 } // End of namespace
195 
196 #endif



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