Main MRPT website > C++ reference
MRPT logo
CSimplePointsMap.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 CSimplePointsMap_H
00029 #define CSimplePointsMap_H
00030 
00031 #include <mrpt/slam/CPointsMap.h>
00032 #include <mrpt/slam/CObservation2DRangeScan.h>
00033 #include <mrpt/slam/CObservation3DRangeScan.h>
00034 #include <mrpt/utils/CSerializable.h>
00035 #include <mrpt/math/CMatrix.h>
00036 
00037 #include <mrpt/maps/link_pragmas.h>
00038 
00039 namespace mrpt
00040 {
00041         namespace slam
00042         {
00043 
00044                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSimplePointsMap , CPointsMap, MAPS_IMPEXP )
00045 
00046                 /** A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
00047                  *    This class only stores the coordinates (x,y,z) of each point.
00048                  *
00049                  *  See mrpt::slam::CPointsMap and derived classes for other point cloud classes.
00050                  *
00051                  * \sa CMetricMap, CWeightedPointsMap, CPoint, mrpt::utils::CSerializable
00052                  * \ingroup mrpt_maps_grp
00053                  */
00054                 class MAPS_IMPEXP CSimplePointsMap : public CPointsMap
00055                 {
00056                         // This must be added to any CSerializable derived class:
00057                         DEFINE_SERIALIZABLE( CSimplePointsMap )
00058 
00059                  public:
00060                          CSimplePointsMap();          //!< Default constructor
00061                          virtual ~CSimplePointsMap(); //!< Destructor
00062 
00063                         // --------------------------------------------
00064                         /** @name Pure virtual interfaces to be implemented by any class derived from CPointsMap
00065                                 @{ */
00066 
00067                         /** Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.
00068                           *  This is useful for situations where it is approximately known the final size of the map. This method is more
00069                           *  efficient than constantly increasing the size of the buffers. Refer to the STL C++ library's "reserve" methods.
00070                           */
00071                         virtual void reserve(size_t newLength);
00072 
00073                         /** Resizes all point buffers so they can hold the given number of points: newly created points are set to default values,
00074                           *  and old contents are not changed.
00075                           * \sa reserve, setPoint, setPointFast, setSize
00076                           */
00077                         virtual void resize(size_t newLength);
00078 
00079                         /** Resizes all point buffers so they can hold the given number of points, *erasing* all previous contents
00080                           *  and leaving all points to default values.
00081                           * \sa reserve, setPoint, setPointFast, setSize
00082                           */
00083                         virtual void setSize(size_t newLength);
00084 
00085                         /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified()  \sa setPoint */
00086                         virtual void  setPointFast(size_t index,float x, float y, float z);
00087 
00088                         /** The virtual method for \a insertPoint() *without* calling mark_as_modified()   */
00089                         virtual void  insertPointFast( float x, float y, float z = 0 );
00090 
00091                          /** Virtual assignment operator, to be implemented in derived classes.
00092                            */
00093                          virtual void  copyFrom(const CPointsMap &obj);
00094 
00095                         /** Get all the data fields for one point as a vector: [X Y Z]
00096                           *  Unlike getPointAllFields(), this method does not check for index out of bounds
00097                           * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
00098                           */
00099                         virtual void  getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const {
00100                                 point_data.resize(3);
00101                                 point_data[0] = x[index];
00102                                 point_data[1] = y[index];
00103                                 point_data[2] = z[index];
00104                         }
00105 
00106                         /** Set all the data fields for one point as a vector: [X Y Z]
00107                           *  Unlike setPointAllFields(), this method does not check for index out of bounds
00108                           * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
00109                           */
00110                         virtual void  setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) {
00111                                 ASSERTDEB_(point_data.size()==3)
00112                                 x[index] = point_data[0];
00113                                 y[index] = point_data[1];
00114                                 z[index] = point_data[2];
00115                         }
00116 
00117                         /** See CPointsMap::loadFromRangeScan() */
00118                         virtual void  loadFromRangeScan(
00119                                         const CObservation2DRangeScan &rangeScan,
00120                                         const CPose3D                             *robotPose = NULL );
00121 
00122                         /** See CPointsMap::loadFromRangeScan() */
00123                         virtual void  loadFromRangeScan(
00124                                         const CObservation3DRangeScan &rangeScan,
00125                                         const CPose3D                             *robotPose = NULL );
00126 
00127 
00128                 protected:
00129 
00130                         /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data  */
00131                         virtual void  addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) {
00132                                 // No extra data.
00133                         }
00134 
00135                         // Friend methods:
00136                         template <class Derived> friend struct detail::loadFromRangeImpl;
00137                         template <class Derived> friend struct detail::pointmap_traits;
00138 
00139                 public:
00140 
00141 
00142                         /** @} */
00143                         // --------------------------------------------
00144 
00145 
00146                         /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
00147                                 * Otherwise, return NULL
00148                                 */
00149                         virtual const CSimplePointsMap * getAsSimplePointsMap() const { return this; }
00150                         virtual       CSimplePointsMap * getAsSimplePointsMap()       { return this; }
00151 
00152                 protected:
00153                         /** Clear the map, erasing all the points.
00154                          */
00155                         virtual void  internal_clear();
00156 
00157                         /** @name PLY Import virtual methods to implement in base classes
00158                             @{ */
00159                         /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
00160                         virtual void PLY_import_set_vertex_count(const size_t N);
00161                         /** @} */
00162 
00163                 }; // End of class def.
00164         } // End of namespace
00165         
00166         namespace utils
00167         {
00168                 /** Specialization mrpt::utils::PointCloudAdapter<mrpt::slam::CSimplePointsMap>  \ingroup mrpt_adapters_grp*/
00169                 template <>
00170                 class PointCloudAdapter<mrpt::slam::CSimplePointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::slam::CSimplePointsMap,float>
00171                 {
00172                 private:
00173                         mrpt::slam::CSimplePointsMap &m_obj;
00174                 public:
00175                         typedef float  coords_t;         //!< The type of each point XYZ coordinates
00176                         static const int HAS_RGB   = 0;  //!< Has any color RGB info?
00177                         static const int HAS_RGBf  = 0;  //!< Has native RGB info (as floats)?
00178                         static const int HAS_RGBu8 = 0;  //!< Has native RGB info (as uint8_t)?
00179 
00180                         /** Constructor (accept a const ref for convenience) */
00181                         inline PointCloudAdapter(const mrpt::slam::CSimplePointsMap &obj) : m_obj(*const_cast<mrpt::slam::CSimplePointsMap*>(&obj)) { }
00182                         /** Get number of points */
00183                         inline size_t size() const { return m_obj.size(); }
00184                         /** Set number of points (to uninitialized values) */
00185                         inline void resize(const size_t N) { m_obj.resize(N); }
00186 
00187                         /** Get XYZ coordinates of i'th point */
00188                         template <typename T>
00189                         inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00190                                 m_obj.getPointFast(idx,x,y,z);
00191                         }
00192                         /** Set XYZ coordinates of i'th point */
00193                         inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00194                                 m_obj.setPointFast(idx,x,y,z);
00195                         }
00196                 }; // end of PointCloudAdapter<mrpt::slam::CPointsMap>
00197 
00198         }
00199         
00200 } // End of namespace
00201 
00202 #endif



Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 Hosted on:
SourceForge.net Logo