Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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 namespace mrpt
19 {
20 namespace maps
21 {
22 /** A cloud of points in 2D or 3D, which can be built from a sequence of laser
23  * scans.
24  * This class stores the coordinates (x,y,z) and a "weight", or counter of
25  * how many times that point has been seen, used only if points fusion is
26  * enabled in the options structure.
27  * \sa CMetricMap, CPoint, mrpt::serialization::CSerializable, CSimplePointsMap
28  * \ingroup mrpt_maps_grp
29  */
31 {
33 
34  public:
35  /** Default constructor */
37  /** Destructor */
38  virtual ~CWeightedPointsMap();
39 
40  // --------------------------------------------
41  /** @name Pure virtual interfaces to be implemented by any class derived
42  from CPointsMap
43  @{ */
44  virtual void reserve(size_t newLength) override; // See base class docs
45  virtual void resize(size_t newLength) override; // See base class docs
46  virtual void setSize(size_t newLength) override; // See base class docs
47 
48  /** Changes the coordinates of the given point (0-based index), *without*
49  * checking for out-of-bounds and *without* calling mark_as_modified() \sa
50  * setPoint */
51  virtual void setPointFast(size_t index, float x, float y, float z) override;
52 
53  /** The virtual method for \a insertPoint() *without* calling
54  * mark_as_modified() */
55  virtual void insertPointFast(float x, float y, float z = 0) override;
56 
57  /** Virtual assignment operator, to be implemented in derived classes */
58  virtual void copyFrom(const CPointsMap& obj) override;
59 
60  /** Get all the data fields for one point as a vector: [X Y Z WEIGHT]
61  * Unlike getPointAllFields(), this method does not check for index out of
62  * bounds
63  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
64  */
65  virtual void getPointAllFieldsFast(
66  const size_t index, std::vector<float>& point_data) const override
67  {
68  point_data.resize(4);
69  point_data[0] = m_x[index];
70  point_data[1] = m_y[index];
71  point_data[2] = m_z[index];
72  point_data[3] = pointWeight[index];
73  }
74 
75  /** Set all the data fields for one point as a vector: [X Y Z WEIGHT]
76  * Unlike setPointAllFields(), this method does not check for index out of
77  * bounds
78  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
79  */
80  virtual void setPointAllFieldsFast(
81  const size_t index, const std::vector<float>& point_data) override
82  {
83  ASSERTDEB_(point_data.size() == 4);
84  m_x[index] = point_data[0];
85  m_y[index] = point_data[1];
86  m_z[index] = point_data[2];
87  pointWeight[index] = point_data[3];
88  }
89 
90  /** See CPointsMap::loadFromRangeScan() */
91  virtual void loadFromRangeScan(
92  const mrpt::obs::CObservation2DRangeScan& rangeScan,
93  const mrpt::poses::CPose3D* robotPose = nullptr) override;
94 
95  /** See CPointsMap::loadFromRangeScan() */
96  virtual void loadFromRangeScan(
97  const mrpt::obs::CObservation3DRangeScan& rangeScan,
98  const mrpt::poses::CPose3D* robotPose = nullptr) override;
99 
100  protected:
101  /** Auxiliary method called from within \a addFrom() automatically, to
102  * finish the copying of class-specific data */
103  virtual void addFrom_classSpecific(
104  const CPointsMap& anotherMap, const size_t nPreviousPoints) override;
105 
106  // Friend methods:
107  template <class Derived>
109  template <class Derived>
110  friend struct detail::pointmap_traits;
111 
112  public:
113  /** @} */
114  // --------------------------------------------
115 
116  /// Sets the point weight, which is ignored in all classes but those which
117  /// actually store that field (Note: No checks are done for out-of-bounds
118  /// index). \sa getPointWeight
119  virtual void setPointWeight(size_t index, unsigned long w) override
120  {
121  pointWeight[index] = w;
122  }
123  /// Gets the point weight, which is ignored in all classes (defaults to 1)
124  /// but in those which actually store that field (Note: No checks are done
125  /// for out-of-bounds index). \sa setPointWeight
126  virtual unsigned int getPointWeight(size_t index) const override
127  {
128  return pointWeight[index];
129  }
130 
131  protected:
132  /** The points weights */
134 
135  /** Clear the map, erasing all the points.
136  */
137  virtual void internal_clear() override;
138 
139  protected:
140  /** @name PLY Import virtual methods to implement in base classes
141  @{ */
142  /** In a base class, reserve memory to prepare subsequent calls to
143  * PLY_import_set_vertex */
144  virtual void PLY_import_set_vertex_count(const size_t N) override;
145  /** @} */
146 
148  /** Observations insertion options */
149  mrpt::maps::CPointsMap::TInsertionOptions insertionOpts;
150  /** Probabilistic observation likelihood options */
151  mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts;
153 }; // End of class def.
154 } // namespace maps
155 
156 namespace opengl
157 {
158 /** Specialization
159  * mrpt::opengl::PointCloudAdapter<mrpt::maps::CWeightedPointsMap> \ingroup
160  * mrpt_adapters_grp*/
161 template <>
164  mrpt::maps::CWeightedPointsMap, float>
165 {
166  private:
168 
169  public:
170  /** The type of each point XYZ coordinates */
171  using coords_t = float;
172  /** Has any color RGB info? */
173  static const int HAS_RGB = 0;
174  /** Has native RGB info (as floats)? */
175  static const int HAS_RGBf = 0;
176  /** Has native RGB info (as uint8_t)? */
177  static const int HAS_RGBu8 = 0;
178 
179  /** Constructor (accept a const ref for convenience) */
181  : m_obj(*const_cast<mrpt::maps::CWeightedPointsMap*>(&obj))
182  {
183  }
184  /** Get number of points */
185  inline size_t size() const { return m_obj.size(); }
186  /** Set number of points (to uninitialized values) */
187  inline void resize(const size_t N) { m_obj.resize(N); }
188  /** Get XYZ coordinates of i'th point */
189  template <typename T>
190  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
191  {
192  m_obj.getPointFast(idx, x, y, z);
193  }
194  /** Set XYZ coordinates of i'th point */
195  inline void setPointXYZ(
196  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
197  {
198  m_obj.setPointFast(idx, x, y, z);
199  }
200 }; // end of PointCloudAdapter<mrpt::maps::CPointsMap>
201 } // namespace opengl
202 } // namespace mrpt
203 
204 #endif
virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) override
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
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:450
GLdouble GLdouble z
Definition: glext.h:3872
virtual ~CWeightedPointsMap()
Destructor.
virtual void setPointWeight(size_t index, unsigned long w) override
Sets the point weight, which is ignored in all classes but those which actually store that field (Not...
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.
virtual void reserve(size_t newLength) override
Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.
#define MAP_DEFINITION_START(_CLASS_NAME_)
Add a MAP_DEFINITION_START() ...
virtual void PLY_import_set_vertex_count(const size_t N) override
In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex.
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 getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
virtual void insertPointFast(float x, float y, float z=0) override
The virtual method for insertPoint() without calling mark_as_modified()
PointCloudAdapter(const mrpt::maps::CWeightedPointsMap &obj)
Constructor (accept a const ref for convenience)
With this struct options are provided to the observation insertion process.
Definition: CPointsMap.h:205
virtual void setPointAllFieldsFast(const size_t index, const std::vector< float > &point_data) 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 cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:64
An adapter to different kinds of point cloud object.
GLuint index
Definition: glext.h:4054
CWeightedPointsMap()
Default constructor.
virtual void resize(size_t newLength) 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)
mrpt::aligned_std_vector< float > m_z
Definition: CPointsMap.h:1094
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...
virtual void copyFrom(const CPointsMap &obj) override
Virtual assignment operator, to be implemented in derived classes.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
mrpt::aligned_std_vector< float > m_y
Definition: CPointsMap.h:1094
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:88
Options used when evaluating "computeObservationLikelihood" in the derived classes.
Definition: CPointsMap.h:263
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Definition: exceptions.h:205
mrpt::aligned_std_vector< uint32_t > pointWeight
The points weights.
virtual unsigned int getPointWeight(size_t index) const override
Gets the point weight, which is ignored in all classes (defaults to 1) but in those which actually st...
GLenum GLint GLint y
Definition: glext.h:3538
virtual void getPointAllFieldsFast(const size_t index, std::vector< float > &point_data) const override
Get all the data fields for one point as a vector: [X Y Z WEIGHT] Unlike getPointAllFields(), 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...
GLenum GLint x
Definition: glext.h:3538
virtual void internal_clear() override
Clear the map, erasing all the points.
float coords_t
The type of each point XYZ coordinates.
mrpt::aligned_std_vector< float > m_x
The point coordinates.
Definition: CPointsMap.h:1094
#define MAP_DEFINITION_END(_CLASS_NAME_)
size_t size() const
Returns the number of stored points in the map.
Definition: CPointsMap.h:408
virtual void setSize(size_t newLength) override
Resizes all point buffers so they can hold the given number of points, erasing all previous contents ...
virtual void setPointFast(size_t index, float x, float y, float z) 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.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019