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



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