Main MRPT website > C++ reference
MRPT logo
CSimplePointsMap.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 CSimplePointsMap_H
29 #define CSimplePointsMap_H
30 
31 #include <mrpt/slam/CPointsMap.h>
35 #include <mrpt/math/CMatrix.h>
36 
37 #include <mrpt/maps/link_pragmas.h>
38 
39 namespace mrpt
40 {
41  namespace slam
42  {
43 
45 
46  /** A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
47  * This class only stores the coordinates (x,y,z) of each point.
48  *
49  * See mrpt::slam::CPointsMap and derived classes for other point cloud classes.
50  *
51  * \sa CMetricMap, CWeightedPointsMap, CPoint, mrpt::utils::CSerializable
52  * \ingroup mrpt_maps_grp
53  */
55  {
56  // This must be added to any CSerializable derived class:
58 
59  public:
60  CSimplePointsMap(); //!< Default constructor
61  virtual ~CSimplePointsMap(); //!< Destructor
62 
63  // --------------------------------------------
64  /** @name Pure virtual interfaces to be implemented by any class derived from CPointsMap
65  @{ */
66 
67  /** Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.
68  * This is useful for situations where it is approximately known the final size of the map. This method is more
69  * efficient than constantly increasing the size of the buffers. Refer to the STL C++ library's "reserve" methods.
70  */
71  virtual void reserve(size_t newLength);
72 
73  /** Resizes all point buffers so they can hold the given number of points: newly created points are set to default values,
74  * and old contents are not changed.
75  * \sa reserve, setPoint, setPointFast, setSize
76  */
77  virtual void resize(size_t newLength);
78 
79  /** Resizes all point buffers so they can hold the given number of points, *erasing* all previous contents
80  * and leaving all points to default values.
81  * \sa reserve, setPoint, setPointFast, setSize
82  */
83  virtual void setSize(size_t newLength);
84 
85  /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */
86  virtual void setPointFast(size_t index,float x, float y, float z);
87 
88  /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */
89  virtual void insertPointFast( float x, float y, float z = 0 );
90 
91  /** Virtual assignment operator, to be implemented in derived classes.
92  */
93  virtual void copyFrom(const CPointsMap &obj);
94 
95  /** Get all the data fields for one point as a vector: [X Y Z]
96  * Unlike getPointAllFields(), this method does not check for index out of bounds
97  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
98  */
99  virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const {
100  point_data.resize(3);
101  point_data[0] = x[index];
102  point_data[1] = y[index];
103  point_data[2] = z[index];
104  }
105 
106  /** Set all the data fields for one point as a vector: [X Y Z]
107  * Unlike setPointAllFields(), this method does not check for index out of bounds
108  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
109  */
110  virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) {
111  ASSERTDEB_(point_data.size()==3)
112  x[index] = point_data[0];
113  y[index] = point_data[1];
114  z[index] = point_data[2];
115  }
116 
117  /** See CPointsMap::loadFromRangeScan() */
118  virtual void loadFromRangeScan(
119  const CObservation2DRangeScan &rangeScan,
120  const CPose3D *robotPose = NULL );
121 
122  /** See CPointsMap::loadFromRangeScan() */
123  virtual void loadFromRangeScan(
124  const CObservation3DRangeScan &rangeScan,
125  const CPose3D *robotPose = NULL );
126 
127 
128  protected:
129 
130  /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */
131  virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) {
132  // No extra data.
133  }
134 
135  // Friend methods:
136  template <class Derived> friend struct detail::loadFromRangeImpl;
137  template <class Derived> friend struct detail::pointmap_traits;
138 
139  public:
140 
141 
142  /** @} */
143  // --------------------------------------------
144 
145 
146  /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
147  * Otherwise, return NULL
148  */
149  virtual const CSimplePointsMap * getAsSimplePointsMap() const { return this; }
150  virtual CSimplePointsMap * getAsSimplePointsMap() { return this; }
151 
152  protected:
153  /** Clear the map, erasing all the points.
154  */
155  virtual void internal_clear();
156 
157  /** @name PLY Import virtual methods to implement in base classes
158  @{ */
159  /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
160  virtual void PLY_import_set_vertex_count(const size_t N);
161  /** @} */
162 
163  }; // End of class def.
164  } // End of namespace
165 
166  namespace utils
167  {
168  /** Specialization mrpt::utils::PointCloudAdapter<mrpt::slam::CSimplePointsMap> \ingroup mrpt_adapters_grp*/
169  template <>
170  class PointCloudAdapter<mrpt::slam::CSimplePointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::slam::CSimplePointsMap,float>
171  {
172  private:
174  public:
175  typedef float coords_t; //!< The type of each point XYZ coordinates
176  static const int HAS_RGB = 0; //!< Has any color RGB info?
177  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
178  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
179 
180  /** Constructor (accept a const ref for convenience) */
181  inline PointCloudAdapter(const mrpt::slam::CSimplePointsMap &obj) : m_obj(*const_cast<mrpt::slam::CSimplePointsMap*>(&obj)) { }
182  /** Get number of points */
183  inline size_t size() const { return m_obj.size(); }
184  /** Set number of points (to uninitialized values) */
185  inline void resize(const size_t N) { m_obj.resize(N); }
186 
187  /** Get XYZ coordinates of i'th point */
188  template <typename T>
189  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
190  m_obj.getPointFast(idx,x,y,z);
191  }
192  /** Set XYZ coordinates of i'th point */
193  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
194  m_obj.setPointFast(idx,x,y,z);
195  }
196  }; // end of PointCloudAdapter<mrpt::slam::CPointsMap>
197 
198  }
199 
200 } // End of namespace
201 
202 #endif



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