Main MRPT website > C++ reference
MRPT logo
CBeacon.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CBeacon_H
00029 #define CBeacon_H
00030 
00031 #include <mrpt/utils/CSerializable.h>
00032 #include <mrpt/math/CMatrix.h>
00033 #include <mrpt/system/os.h>
00034 #include <mrpt/utils/CStringList.h>
00035 #include <mrpt/poses/CPoint3D.h>
00036 #include <mrpt/poses/CPointPDFParticles.h>
00037 #include <mrpt/poses/CPointPDFGaussian.h>
00038 #include <mrpt/poses/CPointPDFSOG.h>
00039 
00040 #include <mrpt/opengl/CSetOfObjects.h>
00041 
00042 #include <mrpt/maps/link_pragmas.h>
00043 
00044 
00045 namespace mrpt
00046 {
00047 namespace slam
00048 {
00049         using namespace mrpt::poses;
00050         using namespace mrpt::utils;
00051 
00052         class CBeaconMap;
00053         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CBeacon, mrpt::utils::CSerializable, MAPS_IMPEXP )
00054 
00055         /** The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions.
00056           *  This class is used for storage within the class CBeaconMap.
00057           *  The class implements the same methods than the interface "CPointPDF", and invoking them actually becomes
00058           *   a mapping into the methods of the current PDF representation of the beacon, selectable by means of "m_typePDF"
00059           * \sa CBeaconMap, CPointPDFSOG
00060           * \ingroup mrpt_maps_grp
00061           */
00062         class MAPS_IMPEXP CBeacon : public CPointPDF
00063         {
00064                 // This must be added to any CSerializable derived class:
00065                 DEFINE_SERIALIZABLE( CBeacon )
00066 
00067         public:
00068                 /** The type for the IDs of landmarks.
00069                   */
00070                 typedef int64_t TBeaconID;
00071 
00072                 /** See m_typePDF
00073                   */
00074                 enum TTypePDF { pdfMonteCarlo = 0, pdfGauss, pdfSOG };
00075 
00076                 /** Which one of the different 3D point PDF is currently used in this object: montecarlo, gaussian, or a sum of gaussians.
00077                   * \sa m_location
00078                   */
00079                 TTypePDF        m_typePDF;
00080 
00081                 /** The individual PDF, if m_typePDF=pdfMonteCarlo (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00082                   */
00083                 CPointPDFParticles      m_locationMC;
00084 
00085                 /** The individual PDF, if m_typePDF=pdfGauss (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00086                   */
00087                 CPointPDFGaussian       m_locationGauss;
00088 
00089                 /** The individual PDF, if m_typePDF=pdfSOG (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00090                   */
00091                 CPointPDFSOG            m_locationSOG;
00092 
00093                 /** An ID for the landmark (see details next...)
00094                   *  This ID was introduced in the version 3 of this class (21/NOV/2006), and its aim is
00095                   *  to provide a way for easily establishing correspondences between landmarks detected
00096                   *  in sequential image frames. Thus, the management of this field should be:
00097                   *             - 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).
00098                   *             - 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.
00099                   *
00100                   * Note that this field is never fill out automatically, it must be set by the programmer if used.
00101                   */
00102                 TBeaconID                       m_ID;
00103 
00104                 /** Default constructor
00105                   */
00106                 CBeacon();
00107 
00108                 /** Virtual destructor
00109                   */
00110                 virtual ~CBeacon();
00111 
00112                  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF).
00113                    * \sa getCovariance
00114                    */
00115                 void getMean(CPoint3D &mean_point) const;
00116 
00117                 /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
00118                   * \sa getMean
00119                   */
00120                 void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const;
00121 
00122                 /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
00123                   */
00124                 void  copyFrom(const CPointPDF &o);
00125 
00126                 /** Save PDF's particles to a text file. See derived classes for more information about the format of generated files.
00127                  */
00128                 void  saveToTextFile(const std::string &file) const;
00129 
00130                 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00131                   *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00132                   */
00133                 void  changeCoordinatesReference( const CPose3D &newReferenceBase );
00134 
00135                 /** Saves a 3D representation of the beacon into a given OpenGL scene
00136                   */
00137                 void  getAs3DObject( mrpt::opengl::CSetOfObjectsPtr     &outObj ) const;
00138 
00139                 /** Gets a set of MATLAB commands which draw the current state of the beacon:
00140                   */
00141                 void getAsMatlabDrawCommands( utils::CStringList &out_Str ) const;
00142 
00143                 /** Draw a sample from the pdf.
00144                   */
00145                 void drawSingleSample(CPoint3D &outSample) const;
00146 
00147                 /** 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!)
00148                   * \param p1 The first distribution to fuse
00149                   * \param p2 The second distribution to fuse
00150                   * \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.
00151                   */
00152                 void  bayesianFusion(const  CPointPDF &p1,const  CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
00153 
00154 
00155                 /** Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an approximate SOG.
00156                   *  Note that if the beacon is a SOG itself, the number of gaussian modes will be square.
00157                   *  As a speed-up, if a "center point"+"maxDistanceFromCenter" is supplied (maxDistanceFromCenter!=0), those modes farther than this sphere will be discarded.
00158                   *  Parameters such as the stdSigma of the sensor are gathered from "myBeaconMap"
00159                   *  The result is one "ring" for each Gaussian mode that represent the beacon position in this object.
00160                   *  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.
00161                   *  \sa CBeaconMap::insertionOptions, generateRingSOG
00162                   */
00163                 void generateObservationModelDistribution(
00164                         const float &sensedRange,
00165                         CPointPDFSOG    &outPDF,
00166                         const CBeaconMap *myBeaconMap,
00167                         const CPoint3D  &sensorPntOnRobot,
00168                         const CPoint3D &centerPoint = CPoint3D(0,0,0),
00169                         const float &maxDistanceFromCenter = 0
00170                         ) const;
00171 
00172                 /** 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.
00173                   *  sensorPnt is the center of the ring/sphere, i.e. the absolute position of the range sensor.
00174                   *  If clearPreviousContentsOutPDF=false, the SOG modes will be added to the current contents of outPDF
00175                   *  If the 3x3 matrix covarianceCompositionToAdd is provided, it will be add to every Gaussian (to model the composition of uncertainty).
00176                   * \sa generateObservationModelDistribution
00177                   */
00178                 static void generateRingSOG(
00179                         const float &sensedRange,
00180                         CPointPDFSOG    &outPDF,
00181                         const CBeaconMap *myBeaconMap,
00182                         const CPoint3D  &sensorPnt,
00183                         const CMatrixDouble33   *covarianceCompositionToAdd = NULL,
00184                         bool  clearPreviousContentsOutPDF = true,
00185                         const CPoint3D &centerPoint = CPoint3D(0,0,0),
00186                         const float &maxDistanceFromCenter = 0
00187                         );
00188 
00189 
00190         }; // End of class definition
00191 
00192 
00193         } // End of namespace
00194 } // End of namespace
00195 
00196 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011