Main MRPT website > C++ reference for MRPT 1.4.0
maps/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-2016, 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/maps/CPointsMap.h>
16 #include <mrpt/math/CMatrix.h>
17 
18 #include <mrpt/maps/link_pragmas.h>
19 
20 namespace mrpt
21 {
22  namespace maps
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  virtual void reserve(size_t newLength) MRPT_OVERRIDE; // See base class docs
45  virtual void resize(size_t newLength) MRPT_OVERRIDE; // See base class docs
46  virtual void setSize(size_t newLength) MRPT_OVERRIDE; // See base class docs
47 
48  /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */
49  virtual void setPointFast(size_t index,float x, float y, float z) MRPT_OVERRIDE;
50 
51  /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */
52  virtual void insertPointFast( float x, float y, float z = 0 ) MRPT_OVERRIDE;
53 
54  /** Virtual assignment operator, to be implemented in derived classes */
55  virtual void copyFrom(const CPointsMap &obj) MRPT_OVERRIDE;
56 
57  /** Get all the data fields for one point as a vector: [X Y Z WEIGHT]
58  * Unlike getPointAllFields(), this method does not check for index out of bounds
59  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
60  */
61  virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const MRPT_OVERRIDE {
62  point_data.resize(4);
63  point_data[0] = x[index];
64  point_data[1] = y[index];
65  point_data[2] = z[index];
66  point_data[3] = pointWeight[index];
67  }
68 
69  /** Set all the data fields for one point as a vector: [X Y Z WEIGHT]
70  * Unlike setPointAllFields(), this method does not check for index out of bounds
71  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
72  */
73  virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) MRPT_OVERRIDE {
74  ASSERTDEB_(point_data.size()==4)
75  x[index] = point_data[0];
76  y[index] = point_data[1];
77  z[index] = point_data[2];
78  pointWeight[index] = point_data[3];
79  }
80 
81  /** See CPointsMap::loadFromRangeScan() */
82  virtual void loadFromRangeScan(
83  const mrpt::obs::CObservation2DRangeScan &rangeScan,
84  const mrpt::poses::CPose3D *robotPose = NULL ) MRPT_OVERRIDE;
85 
86  /** See CPointsMap::loadFromRangeScan() */
87  virtual void loadFromRangeScan(
88  const mrpt::obs::CObservation3DRangeScan &rangeScan,
89  const mrpt::poses::CPose3D *robotPose = NULL ) MRPT_OVERRIDE;
90 
91  protected:
92 
93  /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */
94  virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) MRPT_OVERRIDE;
95 
96  // Friend methods:
97  template <class Derived> friend struct detail::loadFromRangeImpl;
98  template <class Derived> friend struct detail::pointmap_traits;
99 
100  public:
101 
102  /** @} */
103  // --------------------------------------------
104 
105  /// 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
106  virtual void setPointWeight(size_t index,unsigned long w) MRPT_OVERRIDE { pointWeight[index]=w; }
107  /// 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
108  virtual unsigned int getPointWeight(size_t index) const MRPT_OVERRIDE { return pointWeight[index]; }
109 
110  protected:
111  std::vector<uint32_t> pointWeight; //!< The points weights
112 
113  /** Clear the map, erasing all the points.
114  */
115  virtual void internal_clear() MRPT_OVERRIDE;
116 
117  protected:
118  /** @name PLY Import virtual methods to implement in base classes
119  @{ */
120  /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
121  virtual void PLY_import_set_vertex_count(const size_t N) MRPT_OVERRIDE;
122  /** @} */
123 
125  mrpt::maps::CPointsMap::TInsertionOptions insertionOpts; //!< Observations insertion options
126  mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts; //!< Probabilistic observation likelihood options
128  }; // End of class def.
130  } // End of namespace
131 
132  namespace utils
133  {
134  /** Specialization mrpt::utils::PointCloudAdapter<mrpt::maps::CWeightedPointsMap> \ingroup mrpt_adapters_grp*/
135  template <>
136  class PointCloudAdapter<mrpt::maps::CWeightedPointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::maps::CWeightedPointsMap,float>
137  {
138  private:
140  public:
141  typedef float coords_t; //!< The type of each point XYZ coordinates
142  static const int HAS_RGB = 0; //!< Has any color RGB info?
143  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
144  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
145 
146  /** Constructor (accept a const ref for convenience) */
147  inline PointCloudAdapter(const mrpt::maps::CWeightedPointsMap &obj) : m_obj(*const_cast<mrpt::maps::CWeightedPointsMap*>(&obj)) { }
148  /** Get number of points */
149  inline size_t size() const { return m_obj.size(); }
150  /** Set number of points (to uninitialized values) */
151  inline void resize(const size_t N) { m_obj.resize(N); }
152 
153  /** Get XYZ coordinates of i'th point */
154  template <typename T>
155  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
156  m_obj.getPointFast(idx,x,y,z);
157  }
158  /** Set XYZ coordinates of i'th point */
159  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
160  m_obj.setPointFast(idx,x,y,z);
161  }
162  }; // end of PointCloudAdapter<mrpt::maps::CPointsMap>
163  }
164 } // End of namespace
165 
166 #endif
mrpt::utils::PointCloudAdapter
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
mrpt::maps::CPointsMap::size
size_t size() const
Returns the number of stored points in the map.
Definition: maps/CPointsMap.h:319
mrpt::maps::CPointsMap::TLikelihoodOptions
Options used when evaluating "computeObservationLikelihood" in the derived classes.
Definition: maps/CPointsMap.h:190
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::resize
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: maps/CWeightedPointsMap.h:151
mrpt::maps::CPointsMap::getPointFast
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: maps/CPointsMap.h:350
mrpt::maps::CWeightedPointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Definition: maps/CWeightedPointsMap.h:32
MAP_DEFINITION_END
#define MAP_DEFINITION_END(_CLASS_NAME_, _LINKAGE_)
Definition: TMetricMapTypesRegistry.h:52
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: obs/CObservation2DRangeScan.h:40
mrpt::maps::CPointsMap::TInsertionOptions
With this struct options are provided to the observation insertion process.
Definition: maps/CPointsMap.h:164
CPointsMap.h
mrpt::maps::CWeightedPointsMap::setPointFast
virtual void setPointFast(size_t index, float x, float y, float z) MRPT_OVERRIDE
Changes the coordinates of the given point (0-based index), without checking for out-of-bounds and wi...
CMatrix.h
mrpt::maps::CPointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.
Definition: maps/CPointsMap.h:56
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:16
mrpt::maps::CWeightedPointsMap::getPointWeight
virtual unsigned int getPointWeight(size_t index) const MRPT_OVERRIDE
Gets the point weight, which is ignored in all classes (defaults to 1) but in those which actually st...
Definition: maps/CWeightedPointsMap.h:108
mrpt::maps::CWeightedPointsMap::resize
virtual void resize(size_t newLength) MRPT_OVERRIDE
Resizes all point buffers so they can hold the given number of points: newly created points are set t...
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::PointCloudAdapter
PointCloudAdapter(const mrpt::maps::CWeightedPointsMap &obj)
Constructor (accept a const ref for convenience)
Definition: maps/CWeightedPointsMap.h:147
MAP_DEFINITION_START
#define MAP_DEFINITION_START(_CLASS_NAME_, _LINKAGE_)
Add a MAP_DEFINITION_START() ...
Definition: TMetricMapTypesRegistry.h:44
ASSERTDEB_
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Definition: mrpt_macros.h:283
CObservation3DRangeScan.h
mrpt::obs::CObservation3DRangeScan
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
Definition: obs/CObservation3DRangeScan.h:112
CObservation2DRangeScan.h
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::m_obj
mrpt::maps::CWeightedPointsMap & m_obj
Definition: maps/CWeightedPointsMap.h:139
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CSerializable.h:174
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::setPointXYZ
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.
Definition: maps/CWeightedPointsMap.h:159
mrpt::maps::detail::pointmap_traits
Definition: maps/CPointsMap.h:38
setSize
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...
Definition: eigen_plugins.h:280
DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE
#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...
Definition: CSerializable.h:170
mrpt::maps::CWeightedPointsMap::setPointWeight
virtual void setPointWeight(size_t index, unsigned long w) MRPT_OVERRIDE
Sets the point weight, which is ignored in all classes but those which actually store that field (Not...
Definition: maps/CWeightedPointsMap.h:106
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::coords_t
float coords_t
The type of each point XYZ coordinates.
Definition: maps/CWeightedPointsMap.h:141
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:147
mrpt::maps::detail::loadFromRangeImpl
Definition: maps/CPointsMap.h:37
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::size
size_t size() const
Get number of points.
Definition: maps/CWeightedPointsMap.h:149
mrpt::utils::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::getPointXYZ
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i'th point.
Definition: maps/CWeightedPointsMap.h:155
CSerializable.h
mrpt::maps::CWeightedPointsMap::setPointAllFieldsFast
virtual void setPointAllFieldsFast(const size_t index, const std::vector< float > &point_data) MRPT_OVERRIDE
Set all the data fields for one point as a vector: [X Y Z WEIGHT] Unlike setPointAllFields(),...
Definition: maps/CWeightedPointsMap.h:73
mrpt::maps::CWeightedPointsMap::pointWeight
std::vector< uint32_t > pointWeight
The points weights.
Definition: maps/CWeightedPointsMap.h:111
MRPT_OVERRIDE
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
mrpt::utils::detail::PointCloudAdapterHelperNoRGB
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Tue Mar 3 09:15:16 UTC 2020