Main MRPT website > C++ reference
MRPT logo
CSimplePointsMap.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CSimplePointsMap_H
10 #define CSimplePointsMap_H
11 
12 #include <mrpt/slam/CPointsMap.h>
14 #include <mrpt/math/CMatrix.h>
15 
16 #include <mrpt/maps/link_pragmas.h>
17 
18 namespace mrpt
19 {
20  namespace slam
21  {
22  class CObservation2DRangeScan;
23  class CObservation3DRangeScan;
24 
25  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSimplePointsMap , CPointsMap, MAPS_IMPEXP )
26 
27  /** A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
28  * This class only stores the coordinates (x,y,z) of each point.
29  *
30  * See mrpt::slam::CPointsMap and derived classes for other point cloud classes.
31  *
32  * \sa CMetricMap, CWeightedPointsMap, CPoint, mrpt::utils::CSerializable
33  * \ingroup mrpt_maps_grp
34  */
36  {
37  // This must be added to any CSerializable derived class:
39 
40  public:
41  CSimplePointsMap(); //!< Default constructor
42  virtual ~CSimplePointsMap(); //!< Destructor
43 
44  // --------------------------------------------
45  /** @name Pure virtual interfaces to be implemented by any class derived from CPointsMap
46  @{ */
47 
48  /** Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.
49  * This is useful for situations where it is approximately known the final size of the map. This method is more
50  * efficient than constantly increasing the size of the buffers. Refer to the STL C++ library's "reserve" methods.
51  */
52  virtual void reserve(size_t newLength);
53 
54  /** Resizes all point buffers so they can hold the given number of points: newly created points are set to default values,
55  * and old contents are not changed.
56  * \sa reserve, setPoint, setPointFast, setSize
57  */
58  virtual void resize(size_t newLength);
59 
60  /** Resizes all point buffers so they can hold the given number of points, *erasing* all previous contents
61  * and leaving all points to default values.
62  * \sa reserve, setPoint, setPointFast, setSize
63  */
64  virtual void setSize(size_t newLength);
65 
66  /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */
67  virtual void setPointFast(size_t index,float x, float y, float z);
68 
69  /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */
70  virtual void insertPointFast( float x, float y, float z = 0 );
71 
72  /** Virtual assignment operator, to be implemented in derived classes.
73  */
74  virtual void copyFrom(const CPointsMap &obj);
75 
76  /** Get all the data fields for one point as a vector: [X Y Z]
77  * Unlike getPointAllFields(), this method does not check for index out of bounds
78  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
79  */
80  virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const {
81  point_data.resize(3);
82  point_data[0] = x[index];
83  point_data[1] = y[index];
84  point_data[2] = z[index];
85  }
86 
87  /** Set all the data fields for one point as a vector: [X Y Z]
88  * Unlike setPointAllFields(), this method does not check for index out of bounds
89  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
90  */
91  virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) {
92  ASSERTDEB_(point_data.size()==3)
93  x[index] = point_data[0];
94  y[index] = point_data[1];
95  z[index] = point_data[2];
96  }
97 
98  /** See CPointsMap::loadFromRangeScan() */
99  virtual void loadFromRangeScan(
100  const CObservation2DRangeScan &rangeScan,
101  const CPose3D *robotPose = NULL );
102 
103  /** See CPointsMap::loadFromRangeScan() */
104  virtual void loadFromRangeScan(
105  const CObservation3DRangeScan &rangeScan,
106  const CPose3D *robotPose = NULL );
107 
108 
109  protected:
110 
111  /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */
112  virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) {
113  MRPT_UNUSED_PARAM(anotherMap); MRPT_UNUSED_PARAM(nPreviousPoints);
114  // No extra data.
115  }
116 
117  // Friend methods:
118  template <class Derived> friend struct detail::loadFromRangeImpl;
119  template <class Derived> friend struct detail::pointmap_traits;
120 
121  public:
122 
123 
124  /** @} */
125  // --------------------------------------------
126 
127 
128  /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
129  * Otherwise, return NULL
130  */
131  virtual const CSimplePointsMap * getAsSimplePointsMap() const { return this; }
132  virtual CSimplePointsMap * getAsSimplePointsMap() { return this; }
133 
134  protected:
135  /** Clear the map, erasing all the points.
136  */
137  virtual void internal_clear();
138 
139  /** @name PLY Import virtual methods to implement in base classes
140  @{ */
141  /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
142  virtual void PLY_import_set_vertex_count(const size_t N);
143  /** @} */
144 
145  }; // End of class def.
146  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSimplePointsMap , CPointsMap, MAPS_IMPEXP )
147  } // End of namespace
148 
149  namespace utils
150  {
151  /** Specialization mrpt::utils::PointCloudAdapter<mrpt::slam::CSimplePointsMap> \ingroup mrpt_adapters_grp*/
152  template <>
153  class PointCloudAdapter<mrpt::slam::CSimplePointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::slam::CSimplePointsMap,float>
154  {
155  private:
157  public:
158  typedef float coords_t; //!< The type of each point XYZ coordinates
159  static const int HAS_RGB = 0; //!< Has any color RGB info?
160  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
161  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
162 
163  /** Constructor (accept a const ref for convenience) */
164  inline PointCloudAdapter(const mrpt::slam::CSimplePointsMap &obj) : m_obj(*const_cast<mrpt::slam::CSimplePointsMap*>(&obj)) { }
165  /** Get number of points */
166  inline size_t size() const { return m_obj.size(); }
167  /** Set number of points (to uninitialized values) */
168  inline void resize(const size_t N) { m_obj.resize(N); }
169 
170  /** Get XYZ coordinates of i'th point */
171  template <typename T>
172  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
173  m_obj.getPointFast(idx,x,y,z);
174  }
175  /** Set XYZ coordinates of i'th point */
176  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
177  m_obj.setPointFast(idx,x,y,z);
178  }
179  }; // end of PointCloudAdapter<mrpt::slam::CPointsMap>
180 
181  }
182 
183 } // End of namespace
184 
185 #endif
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
void getPointFast(size_t index, float &x, float &y, float &z) const
Just like getPoint() but without checking out-of-bound index and without returning the point weight...
Definition: CPointsMap.h:362
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48
virtual void setPointFast(size_t index, float x, float y, float z)
Changes the coordinates of the given point (0-based index), without checking for out-of-bounds and wi...
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints)
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
size_t size() const
Returns the number of stored points in the map.
Definition: CPointsMap.h:331
STL namespace.
float coords_t
The type of each point XYZ coordinates.
virtual CSimplePointsMap * getAsSimplePointsMap()
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i'th point.
void setPointXYZ(const size_t idx, const coords_t x, const coords_t y, const coords_t z)
Set XYZ coordinates of i'th point.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
virtual void resize(size_t newLength)
Resizes all point buffers so they can hold the given number of points: newly created points are set t...
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
PointCloudAdapter(const mrpt::slam::CSimplePointsMap &obj)
Constructor (accept a const ref for convenience)
virtual const CSimplePointsMap * getAsSimplePointsMap() const
If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
virtual void setPointAllFieldsFast(const size_t index, const std::vector< float > &point_data)
Set all the data fields for one point as a vector: [X Y Z] Unlike setPointAllFields(), this method does not check for index out of bounds.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:59
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement (e...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
void resize(const size_t N)
Set number of points (to uninitialized values)



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014