Main MRPT website > C++ reference
MRPT logo
CReflectivityGridMap2D.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 
00029 #ifndef CReflectivityGridMap2D_H
00030 #define CReflectivityGridMap2D_H
00031 
00032 #include <mrpt/utils/CImage.h>
00033 #include <mrpt/utils/CDynamicGrid.h>
00034 #include <mrpt/utils/CSerializable.h>
00035 #include <mrpt/utils/CLoadableOptions.h>
00036 #include <mrpt/utils/stl_extensions.h>
00037 
00038 #include <mrpt/slam/CMetricMap.h>
00039 #include <mrpt/slam/CLogOddsGridMap2D.h>
00040 
00041 #include <mrpt/maps/link_pragmas.h>
00042 
00043 namespace mrpt
00044 {
00045         namespace slam
00046         {
00047                 using namespace mrpt;
00048                 using namespace mrpt::utils;
00049 
00050                 class CObservation;
00051 
00052                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CReflectivityGridMap2D, CMetricMap, MAPS_IMPEXP  )
00053 
00054                 /** A 2D grid map representing the reflectivity of the environment (for example, measured with an IR proximity sensor).
00055                   *
00056                   *  Important implemented features are:
00057                   *             - Insertion of mrpt::slam::CObservationReflectivity observations.
00058                   *             - Probability estimation of observations. See base class.
00059                   *             - Rendering as 3D object: a 2D textured plane.
00060                   *             - Automatic resizing of the map limits when inserting observations close to the border.
00061                   *
00062                   *   Each cell contains the up-to-date average height from measured falling in that cell. Algorithms that can be used:
00063                   *             - mrSimpleAverage: Each cell only stores the current average value.
00064                   * \ingroup mrpt_maps_grp
00065                   */
00066                 class MAPS_IMPEXP CReflectivityGridMap2D :
00067                         public CMetricMap,
00068                         public utils::CDynamicGrid<int8_t>,
00069                         public CLogOddsGridMap2D<int8_t>
00070                 {
00071                         // This must be added to any CSerializable derived class:
00072                         DEFINE_SERIALIZABLE( CReflectivityGridMap2D )
00073 
00074                 protected:
00075                         static CLogOddsGridMapLUT<cell_t>  m_logodd_lut; //!< Lookup tables for log-odds
00076 
00077                 public:
00078 
00079                         /** Calls the base CMetricMap::clear
00080                           * Declared here to avoid ambiguity between the two clear() in both base classes.
00081                           */
00082                         inline void clear() { CMetricMap::clear(); }
00083 
00084                         float cell2float(const int8_t& c) const
00085                         {
00086                                 return m_logodd_lut.l2p(c);
00087                         }
00088 
00089                         /** Constructor
00090                           */
00091                         CReflectivityGridMap2D(
00092                                 float                           x_min = -2,
00093                                 float                           x_max = 2,
00094                                 float                           y_min = -2,
00095                                 float                           y_max = 2,
00096                                 float                           resolution = 0.1
00097                                 );
00098 
00099                          /** Returns true if the map is empty/no observation has been inserted.
00100                            */
00101                          bool  isEmpty() const;
00102 
00103                         /** Computes the likelihood that a given observation was taken from a given pose in the world being modeled with this map.
00104                          *
00105                          * \param takenFrom The robot's pose the observation is supposed to be taken from.
00106                          * \param obs The observation.
00107                          * \return This method returns a likelihood in the range [0,1].
00108                          *
00109                          * \sa Used in particle filter algorithms, see: CMultiMetricMapPDF::update
00110                          */
00111                          double  computeObservationLikelihood( const CObservation *obs, const CPose3D &takenFrom );
00112 
00113                         /** Parameters related with inserting observations into the map.
00114                           */
00115                         struct MAPS_IMPEXP TInsertionOptions : public utils::CLoadableOptions
00116                         {
00117                                 /** Default values loader:
00118                                   */
00119                                 TInsertionOptions();
00120 
00121                                 /** See utils::CLoadableOptions
00122                                   */
00123                                 void  loadFromConfigFile(
00124                                         const mrpt::utils::CConfigFileBase  &source,
00125                                         const std::string &section);
00126 
00127                                 /** See utils::CLoadableOptions
00128                                   */
00129                                 void  dumpToTextStream(CStream  &out) const;
00130 
00131                         } insertionOptions;
00132 
00133                         /** Computes the ratio in [0,1] of correspondences between "this" and the "otherMap" map, whose 6D pose relative to "this" is "otherMapPose"
00134                          *   In the case of a multi-metric map, this returns the average between the maps. This method always return 0 for grid maps.
00135                          * \param  otherMap                                       [IN] The other map to compute the matching with.
00136                          * \param  otherMapPose                           [IN] The 6D pose of the other map as seen from "this".
00137                          * \param  minDistForCorr                         [IN] The minimum distance between 2 non-probabilistic map elements for counting them as a correspondence.
00138                          * \param  minMahaDistForCorr             [IN] The minimum Mahalanobis distance between 2 probabilistic map elements for counting them as a correspondence.
00139                          *
00140                          * \return The matching ratio [0,1]
00141                          * \sa computeMatchingWith2D
00142                          */
00143                         float  compute3DMatchingRatio(
00144                                         const CMetricMap                                                *otherMap,
00145                                         const CPose3D                                                   &otherMapPose,
00146                                         float                                                                   minDistForCorr = 0.10f,
00147                                         float                                                                   minMahaDistForCorr = 2.0f
00148                                         ) const;
00149 
00150                         /** The implementation in this class just calls all the corresponding method of the contained metric maps.
00151                           */
00152                         void  saveMetricMapRepresentationToFile(
00153                                 const std::string       &filNamePrefix
00154                                 ) const;
00155 
00156                         /** Returns a 3D object representing the map: by default, it will be a mrpt::opengl::CMesh object, unless
00157                           *   it is specified otherwise in mrpt::
00158                           */
00159                         void  getAs3DObject ( mrpt::opengl::CSetOfObjectsPtr    &outObj ) const;
00160 
00161                         /** Returns the grid as a 8-bit graylevel image, where each pixel is a cell (output image is RGB only if forceRGB is true)
00162                           */
00163                         void  getAsImage( utils::CImage &img, bool verticalFlip = false, bool forceRGB=false) const;
00164 
00165                 protected:
00166 
00167                          /** Erase all the contents of the map
00168                           */
00169                          virtual void  internal_clear();
00170 
00171                          /** Insert the observation information into this map. This method must be implemented
00172                           *    in derived classes.
00173                           * \param obs The observation
00174                           * \param robotPose The 3D pose of the robot mobile base in the map reference system, or NULL (default) if you want to use CPose2D(0,0,deg)
00175                           *
00176                           * \sa CObservation::insertObservationInto
00177                           */
00178                          virtual bool  internal_insertObservation( const CObservation *obs, const CPose3D *robotPose = NULL );
00179 
00180                 };
00181 
00182 
00183         } // End of namespace
00184 
00185 
00186 } // End of namespace
00187 
00188 #endif



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