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



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