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://mrpt.sourceforge.net/                            |
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           */
00061         class MAPS_IMPEXP CBeacon : public CPointPDF
00062         {
00063                 // This must be added to any CSerializable derived class:
00064                 DEFINE_SERIALIZABLE( CBeacon )
00065 
00066         public:
00067                 /** The type for the IDs of landmarks.
00068                   */
00069                 typedef int64_t TBeaconID;
00070 
00071                 /** See m_typePDF
00072                   */
00073                 enum TTypePDF { pdfMonteCarlo = 0, pdfGauss, pdfSOG };
00074 
00075                 /** Which one of the different 3D point PDF is currently used in this object: montecarlo, gaussian, or a sum of gaussians.
00076                   * \sa m_location
00077                   */
00078                 TTypePDF        m_typePDF;
00079 
00080                 /** The individual PDF, if m_typePDF=pdfMonteCarlo (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00081                   */
00082                 CPointPDFParticles      m_locationMC;
00083 
00084                 /** The individual PDF, if m_typePDF=pdfGauss (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00085                   */
00086                 CPointPDFGaussian       m_locationGauss;
00087 
00088                 /** The individual PDF, if m_typePDF=pdfSOG (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon).
00089                   */
00090                 CPointPDFSOG            m_locationSOG;
00091 
00092                 /** An ID for the landmark (see details next...)
00093                   *  This ID was introduced in the version 3 of this class (21/NOV/2006), and its aim is
00094                   *  to provide a way for easily establishing correspondences between landmarks detected
00095                   *  in sequential image frames. Thus, the management of this field should be:
00096                   *             - 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).
00097                   *             - 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.
00098                   *
00099                   * Note that this field is never fill out automatically, it must be set by the programmer if used.
00100                   */
00101                 TBeaconID                       m_ID;
00102 
00103                 /** Default constructor
00104                   */
00105                 CBeacon();
00106 
00107                 /** Virtual destructor
00108                   */
00109                 virtual ~CBeacon();
00110 
00111                  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF).
00112                    * \sa getCovariance
00113                    */
00114                 void getMean(CPoint3D &mean_point) const;
00115 
00116                 /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
00117                   * \sa getMean
00118                   */
00119                 void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const;
00120 
00121                 /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
00122                   */
00123                 void  copyFrom(const CPointPDF &o);
00124 
00125                 /** Save PDF's particles to a text file. See derived classes for more information about the format of generated files.
00126                  */
00127                 void  saveToTextFile(const std::string &file) const;
00128 
00129                 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
00130                   *   "to project" the current pdf. Result PDF substituted the currently stored one in the object.
00131                   */
00132                 void  changeCoordinatesReference( const CPose3D &newReferenceBase );
00133 
00134                 /** Saves a 3D representation of the beacon into a given OpenGL scene
00135                   */
00136                 void  getAs3DObject( mrpt::opengl::CSetOfObjectsPtr     &outObj ) const;
00137 
00138                 /** Gets a set of MATLAB commands which draw the current state of the beacon:
00139                   */
00140                 void getAsMatlabDrawCommands( utils::CStringList &out_Str ) const;
00141 
00142                 /** Draw a sample from the pdf.
00143                   */
00144                 void drawSingleSample(CPoint3D &outSample) const;
00145 
00146                 /** 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!)
00147                   * \param p1 The first distribution to fuse
00148                   * \param p2 The second distribution to fuse
00149                   * \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.
00150                   */
00151                 void  bayesianFusion(const  CPointPDF &p1,const  CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
00152 
00153 
00154                 /** Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an approximate SOG.
00155                   *  Note that if the beacon is a SOG itself, the number of gaussian modes will be square.
00156                   *  As a speed-up, if a "center point"+"maxDistanceFromCenter" is supplied (maxDistanceFromCenter!=0), those modes farther than this sphere will be discarded.
00157                   *  Parameters such as the stdSigma of the sensor are gathered from "myBeaconMap"
00158                   *  The result is one "ring" for each Gaussian mode that represent the beacon position in this object.
00159                   *  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.
00160                   *  \sa CBeaconMap::insertionOptions, generateRingSOG
00161                   */
00162                 void generateObservationModelDistribution(
00163                         const float &sensedRange,
00164                         CPointPDFSOG    &outPDF,
00165                         const CBeaconMap *myBeaconMap,
00166                         const CPoint3D  &sensorPntOnRobot,
00167                         const CPoint3D &centerPoint = CPoint3D(0,0,0),
00168                         const float &maxDistanceFromCenter = 0
00169                         ) const;
00170 
00171                 /** 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.
00172                   *  sensorPnt is the center of the ring/sphere, i.e. the absolute position of the range sensor.
00173                   *  If clearPreviousContentsOutPDF=false, the SOG modes will be added to the current contents of outPDF
00174                   *  If the 3x3 matrix covarianceCompositionToAdd is provided, it will be add to every Gaussian (to model the composition of uncertainty).
00175                   * \sa generateObservationModelDistribution
00176                   */
00177                 static void generateRingSOG(
00178                         const float &sensedRange,
00179                         CPointPDFSOG    &outPDF,
00180                         const CBeaconMap *myBeaconMap,
00181                         const CPoint3D  &sensorPnt,
00182                         const CMatrixDouble33   *covarianceCompositionToAdd = NULL,
00183                         bool  clearPreviousContentsOutPDF = true,
00184                         const CPoint3D &centerPoint = CPoint3D(0,0,0),
00185                         const float &maxDistanceFromCenter = 0
00186                         );
00187 
00188 
00189         }; // End of class definition
00190 
00191 
00192         } // End of namespace
00193 } // End of namespace
00194 
00195 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011