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
mrpt::maps::CWeightedPointsMap::PLY_import_set_vertex_count
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.
Definition: CWeightedPointsMap.cpp:373
mrpt::opengl::PointCloudAdapter
An adapter to different kinds of point cloud object.
Definition: pointcloud_adapters.h:39
mrpt::maps::CWeightedPointsMap::~CWeightedPointsMap
virtual ~CWeightedPointsMap()
Destructor.
Definition: CWeightedPointsMap.cpp:68
mrpt::maps::CWeightedPointsMap::setPointFast
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...
Definition: CWeightedPointsMap.cpp:102
mrpt::maps::CPointsMap::size
size_t size() const
Returns the number of stored points in the map.
Definition: CPointsMap.h:408
mrpt::maps::CWeightedPointsMap::internal_clear
virtual void internal_clear() override
Clear the map, erasing all the points.
Definition: CWeightedPointsMap.cpp:248
mrpt::maps::CPointsMap::TLikelihoodOptions
Options used when evaluating "computeObservationLikelihood" in the derived classes.
Definition: CPointsMap.h:263
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: CPointsMap.h:450
CPointsMap.h
mrpt::maps::CWeightedPointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Definition: CWeightedPointsMap.h:30
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: CObservation2DRangeScan.h:56
mrpt::maps::CPointsMap::TInsertionOptions
With this struct options are provided to the observation insertion process.
Definition: CPointsMap.h:205
mrpt::opengl::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::PointCloudAdapter
PointCloudAdapter(const mrpt::maps::CWeightedPointsMap &obj)
Constructor (accept a const ref for convenience)
Definition: CWeightedPointsMap.h:180
mrpt::maps::CWeightedPointsMap::insertPointFast
virtual void insertPointFast(float x, float y, float z=0) override
The virtual method for insertPoint() without calling mark_as_modified()
Definition: CWeightedPointsMap.cpp:111
mrpt::opengl::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::coords_t
float coords_t
The type of each point XYZ coordinates.
Definition: CWeightedPointsMap.h:171
mrpt::maps::CWeightedPointsMap::setPointWeight
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...
Definition: CWeightedPointsMap.h:119
mrpt::opengl::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::size
size_t size() const
Get number of points.
Definition: CWeightedPointsMap.h:185
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::maps::CWeightedPointsMap::reserve
virtual void reserve(size_t newLength) override
Reserves memory for a given number of points: the size of the map does not change,...
Definition: CWeightedPointsMap.cpp:72
CMatrix.h
mrpt::maps::CWeightedPointsMap::resize
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...
Definition: CWeightedPointsMap.cpp:83
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: CPointsMap.h:64
CObservation3DRangeScan.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::maps::CWeightedPointsMap::CWeightedPointsMap
CWeightedPointsMap()
Default constructor.
Definition: CWeightedPointsMap.cpp:64
mrpt::aligned_std_vector
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
Definition: aligned_std_vector.h:15
mrpt::opengl::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::resize
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: CWeightedPointsMap.h:187
mrpt::obs::CObservation3DRangeScan
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
Definition: CObservation3DRangeScan.h:224
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::maps::CWeightedPointsMap::pointWeight
mrpt::aligned_std_vector< uint32_t > pointWeight
The points weights.
Definition: CWeightedPointsMap.h:133
index
GLuint index
Definition: glext.h:4054
mrpt::maps::CPointsMap::m_z
mrpt::aligned_std_vector< float > m_z
Definition: CPointsMap.h:1094
mrpt::maps::CWeightedPointsMap::getPointWeight
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...
Definition: CWeightedPointsMap.h:126
mrpt::maps::CPointsMap::m_y
mrpt::aligned_std_vector< float > m_y
Definition: CPointsMap.h:1094
mrpt::maps::detail::pointmap_traits
Definition: CPointsMap.h:39
mrpt::maps::CWeightedPointsMap::setPointAllFieldsFast
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(),...
Definition: CWeightedPointsMap.h:80
mrpt::opengl::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: CWeightedPointsMap.h:190
MAP_DEFINITION_START
#define MAP_DEFINITION_START(_CLASS_NAME_)
Add a MAP_DEFINITION_START() ...
Definition: TMetricMapTypesRegistry.h:57
mrpt::maps::CWeightedPointsMap::loadFromRangeScan
virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
Definition: CWeightedPointsMap.cpp:353
mrpt::maps::CWeightedPointsMap::copyFrom
virtual void copyFrom(const CPointsMap &obj) override
Virtual assignment operator, to be implemented in derived classes
Definition: CWeightedPointsMap.cpp:123
MAP_DEFINITION_END
#define MAP_DEFINITION_END(_CLASS_NAME_)
Definition: TMetricMapTypesRegistry.h:67
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::detail::PointCloudAdapterHelperNoRGB
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: pointcloud_adapters.h:49
mrpt::maps::CPointsMap::m_x
mrpt::aligned_std_vector< float > m_x
The point coordinates.
Definition: CPointsMap.h:1094
z
GLdouble GLdouble z
Definition: glext.h:3872
ASSERTDEB_
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Definition: exceptions.h:205
mrpt::maps::CWeightedPointsMap::addFrom_classSpecific
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 ...
Definition: CWeightedPointsMap.cpp:139
mrpt::maps::CWeightedPointsMap::setSize
virtual void setSize(size_t newLength) override
Resizes all point buffers so they can hold the given number of points, erasing all previous contents ...
Definition: CWeightedPointsMap.cpp:94
mrpt::maps::detail::loadFromRangeImpl
Definition: CPointsMap.h:37
CSerializable.h
mrpt::opengl::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: CWeightedPointsMap.h:195
mrpt::maps::CWeightedPointsMap::getPointAllFieldsFast
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(),...
Definition: CWeightedPointsMap.h:65
mrpt::opengl::PointCloudAdapter< mrpt::maps::CWeightedPointsMap >::m_obj
mrpt::maps::CWeightedPointsMap & m_obj
Definition: CWeightedPointsMap.h:167
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
CObservation2DRangeScan.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST