Main MRPT website > C++ reference for MRPT 1.5.9
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-2017, 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
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...
#define MAP_DEFINITION_END(_CLASS_NAME_, _LINKAGE_)
GLdouble GLdouble z
Definition: glext.h:3734
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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(), this method does not check for index out of bounds.
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48
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...
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
void setPointXYZ(const size_t idx, const coords_t x, const coords_t y, const coords_t z)
Set XYZ coordinates of i&#39;th point.
STL namespace.
std::vector< uint32_t > pointWeight
The points weights.
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
With this struct options are provided to the observation insertion process.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
#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...
GLuint index
Definition: glext.h:3891
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::maps::CWeightedPointsMap &obj)
Constructor (accept a const ref for convenience)
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...
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
Options used when evaluating "computeObservationLikelihood" in the derived classes.
GLenum GLint GLint y
Definition: glext.h:3516
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...
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
GLenum GLint x
Definition: glext.h:3516
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
size_t size() const
Returns the number of stored points in the map.
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...
void resize(const size_t N)
Set number of points (to uninitialized values)
#define MAP_DEFINITION_START(_CLASS_NAME_, _LINKAGE_)
Add a MAP_DEFINITION_START() ...
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...



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020