MRPT  1.9.9
CPointsMapXYZI.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/maps/CPointsMap.h>
12 #include <mrpt/math/CMatrix.h>
14 #include <mrpt/obs/obs_frwds.h>
17 
18 namespace mrpt
19 {
20 namespace maps
21 {
22 /** A map of 3D points with reflectance/intensity (float).
23  * \sa mrpt::maps::CPointsMap, mrpt::maps::CMetricMap
24  * \ingroup mrpt_maps_grp
25  */
26 class CPointsMapXYZI : public CPointsMap
27 {
29 
30  public:
31  // --------------------------------------------
32  /** @name Pure virtual interfaces to be implemented by any class derived
33  from CPointsMap
34  @{ */
35 
36  void reserve(size_t newLength) override; // See base class docs
37  void resize(size_t newLength) override; // See base class docs
38  void setSize(size_t newLength) override; // See base class docs
39 
40  /** The virtual method for \a insertPoint() *without* calling
41  * mark_as_modified() */
42  void insertPointFast(float x, float y, float z = 0) override;
43 
44  /** Get all the data fields for one point as a vector: [X Y Z I]
45  * Unlike getPointAllFields(), this method does not check for index out of
46  * bounds
47  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
48  */
50  const size_t index, std::vector<float>& point_data) const override
51  {
52  point_data.resize(4);
53  point_data[0] = m_x[index];
54  point_data[1] = m_y[index];
55  point_data[2] = m_z[index];
56  point_data[3] = m_intensity[index];
57  }
58 
59  /** Set all the data fields for one point as a vector: [X Y Z I]
60  * Unlike setPointAllFields(), this method does not check for index out of
61  * bounds
62  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
63  */
65  const size_t index, const std::vector<float>& point_data) override
66  {
67  ASSERT_(point_data.size() == 4);
68  m_x[index] = point_data[0];
69  m_y[index] = point_data[1];
70  m_z[index] = point_data[2];
71  m_intensity[index] = point_data[3];
72  }
73 
74  /** Loads from a Kitti dataset Velodyne scan binary file.
75  * The file can be gz compressed (only enabled if the filename ends in ".gz"
76  * to prevent spurious false autodetection of gzip files).
77  * \return true on success */
78  bool loadFromKittiVelodyneFile(const std::string& filename);
79 
80  /** See CPointsMap::loadFromRangeScan() */
81  void loadFromRangeScan(
82  const mrpt::obs::CObservation2DRangeScan& rangeScan,
83  const mrpt::poses::CPose3D* robotPose = nullptr) override;
84  /** See CPointsMap::loadFromRangeScan() */
85  void loadFromRangeScan(
86  const mrpt::obs::CObservation3DRangeScan& rangeScan,
87  const mrpt::poses::CPose3D* robotPose = nullptr) override;
88 
89  protected:
90  // See base class
91  void impl_copyFrom(const CPointsMap& obj) override;
92  // See base class
94  const CPointsMap& anotherMap, const size_t nPreviousPoints) override;
95 
96  // Friend methods:
97  template <class Derived>
99  template <class Derived>
100  friend struct detail::pointmap_traits;
101 
102  public:
103  /** @} */
104  // --------------------------------------------
105 
106  /** Save to a text file. In each line contains X Y Z (meters) I (intensity)
107  * Returns false if any error occured, true elsewere.
108  */
109  bool saveXYZI_to_text_file(const std::string& file) const;
110 
111  /** Changes a given point from map. First index is 0.
112  * \exception Throws std::exception on index out of bound.
113  */
114  void setPointRGB(
115  size_t index, float x, float y, float z, float R_intensity,
116  float G_ignored, float B_ignored) override;
117 
118  /** Adds a new point given its coordinates and color (colors range is [0,1])
119  */
120  void insertPointRGB(
121  float x, float y, float z, float R_intensity, float G_ignored,
122  float B_ignored) override;
123 
124  /** Changes the intensity of a given point from the map. First index is 0.
125  * \exception Throws std::exception on index out of bound.
126  */
127  void setPointIntensity(size_t index, float intensity);
128 
129  /** Like \c setPointColor but without checking for out-of-index erors */
130  inline void setPointColor_fast(size_t index, float R, float G, float B)
131  {
132  m_intensity[index] = R;
133  }
134 
135  /** Retrieves a point and its color (colors range is [0,1])
136  */
137  void getPointRGB(
138  size_t index, float& x, float& y, float& z, float& R_intensity,
139  float& G_intensity, float& B_intensity) const override;
140 
141  /** Retrieves a point intensity (range [0,1]) */
142  float getPointIntensity(size_t index) const;
143 
144  /** Like \c getPointColor but without checking for out-of-index erors */
145  inline float getPointIntensity_fast(size_t index) const
146  {
147  return m_intensity[index];
148  }
149 
150  /** Returns true if the point map has a color field for each point */
151  bool hasColorPoints() const override { return true; }
152 
153  /** Override of the default 3D scene builder to account for the individual
154  * points' color.
155  */
156  void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr& outObj) const override;
157 
158  /** @name PCL library support
159  @{ */
160 
161  /** Save the point cloud as a PCL PCD file, in either ASCII or binary format
162  * \return false on any error */
163  bool savePCDFile(
164  const std::string& filename, bool save_as_binary) const override;
165 
166  /** Loads a PCL point cloud (WITH XYZI information) into this MRPT class.
167  * Usage example:
168  * \code
169  * pcl::PointCloud<pcl::PointXYZI> cloud;
170  * mrpt::maps::CPointsMapXYZI pc;
171  *
172  * pc.setFromPCLPointCloudXYZI(cloud);
173  * \endcode
174  * \sa CPointsMap::setFromPCLPointCloud()
175  */
176  template <class POINTCLOUD>
177  void setFromPCLPointCloudXYZI(const POINTCLOUD& cloud)
178  {
179  const size_t N = cloud.points.size();
180  clear();
181  reserve(N);
182  for (size_t i = 0; i < N; ++i)
183  this->insertPoint(
184  cloud.points[i].x, cloud.points[i].y, cloud.points[i].z,
185  cloud.points[i].intensity);
186  }
187 
188  /** Like CPointsMap::getPCLPointCloud() but for PointCloud<PointXYZI> */
189  template <class POINTCLOUD>
190  void getPCLPointCloudXYZI(POINTCLOUD& cloud) const
191  {
192  const size_t nThis = this->size();
193  this->getPCLPointCloud(cloud); // 1st: xyz data
194  // 2nd: I data
195  for (size_t i = 0; i < nThis; ++i)
196  cloud.points[i].intensity = m_intensity[i];
197  }
198  /** @} */
199 
200  protected:
201  /** The intensity/reflectance data */
203 
204  /** Clear the map, erasing all the points */
205  void internal_clear() override;
206 
207  /** @name Redefinition of PLY Import virtual methods from CPointsMap
208  @{ */
210  const size_t idx, const mrpt::math::TPoint3Df& pt,
211  const mrpt::img::TColorf* pt_color = nullptr) override;
212 
213  void PLY_import_set_vertex_count(const size_t N) override;
214  /** @} */
215 
216  /** @name Redefinition of PLY Export virtual methods from CPointsMap
217  @{ */
219  const size_t idx, mrpt::math::TPoint3Df& pt, bool& pt_has_color,
220  mrpt::img::TColorf& pt_color) const override;
221  /** @} */
222 
224  mrpt::maps::CPointsMap::TInsertionOptions insertionOpts;
225  mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts;
227 
228 }; // End of class def.
229 
230 } // namespace maps
231 
232 #include <mrpt/opengl/pointcloud_adapters.h>
233 namespace opengl
234 {
235 /** Specialization
236  * mrpt::opengl::PointCloudAdapter<mrpt::maps::CPointsMapXYZI> \ingroup
237  * mrpt_adapters_grp */
238 template <>
240 {
241  private:
243 
244  public:
245  /** The type of each point XYZ coordinates */
246  using coords_t = float;
247  /** Has any color RGB info? */
248  static constexpr bool HAS_RGB = true;
249  /** Has native RGB info (as floats)? */
250  static constexpr bool HAS_RGBf = true;
251  /** Has native RGB info (as uint8_t)? */
252  static constexpr bool HAS_RGBu8 = false;
253 
254  /** Constructor (accept a const ref for convenience) */
256  : m_obj(*const_cast<mrpt::maps::CPointsMapXYZI*>(&obj))
257  {
258  }
259  /** Get number of points */
260  inline size_t size() const { return m_obj.size(); }
261  /** Set number of points (to uninitialized values) */
262  inline void resize(const size_t N) { m_obj.resize(N); }
263  /** Does nothing as of now */
264  inline void setDimensions(const size_t& height, const size_t& width) {}
265  /** Get XYZ coordinates of i'th point */
266  template <typename T>
267  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
268  {
269  m_obj.getPointFast(idx, x, y, z);
270  }
271  /** Set XYZ coordinates of i'th point */
272  inline void setPointXYZ(
273  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
274  {
275  m_obj.setPointFast(idx, x, y, z);
276  }
277 
278  /** Get XYZ_RGBf coordinates of i'th point */
279  template <typename T>
280  inline void getPointXYZ_RGBf(
281  const size_t idx, T& x, T& y, T& z, float& r, float& g, float& b) const
282  {
283  m_obj.getPointRGB(idx, x, y, z, r, g, b);
284  }
285  /** Set XYZ_RGBf coordinates of i'th point */
286  inline void setPointXYZ_RGBf(
287  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
288  const float r, const float g, const float b)
289  {
290  m_obj.setPointRGB(idx, x, y, z, r, g, b);
291  }
292 
293  /** Get XYZ_RGBu8 coordinates of i'th point */
294  template <typename T>
295  inline void getPointXYZ_RGBu8(
296  const size_t idx, T& x, T& y, T& z, uint8_t& r, uint8_t& g,
297  uint8_t& b) const
298  {
299  float I, Gignrd, Bignrd;
300  m_obj.getPoint(idx, x, y, z, I, Gignrd, Bignrd);
301  r = g = b = I * 255;
302  }
303  /** Set XYZ_RGBu8 coordinates of i'th point */
304  inline void setPointXYZ_RGBu8(
305  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
306  const uint8_t r, const uint8_t g, const uint8_t b)
307  {
308  m_obj.setPointRGB(idx, x, y, z, r / 255.f, g / 255.f, b / 255.f);
309  }
310 
311  /** Get RGBf color of i'th point */
312  inline void getPointRGBf(
313  const size_t idx, float& r, float& g, float& b) const
314  {
315  r = g = b = m_obj.getPointIntensity_fast(idx);
316  }
317  /** Set XYZ_RGBf coordinates of i'th point */
318  inline void setPointRGBf(
319  const size_t idx, const float r, const float g, const float b)
320  {
321  m_obj.setPointColor_fast(idx, r, g, b);
322  }
323 
324  /** Get RGBu8 color of i'th point */
325  inline void getPointRGBu8(
326  const size_t idx, uint8_t& r, uint8_t& g, uint8_t& b) const
327  {
328  float i = m_obj.getPointIntensity_fast(idx);
329  r = g = b = i * 255;
330  }
331  /** Set RGBu8 coordinates of i'th point */
332  inline void setPointRGBu8(
333  const size_t idx, const uint8_t r, const uint8_t g, const uint8_t b)
334  {
335  m_obj.setPointColor_fast(idx, r / 255.f, g / 255.f, b / 255.f);
336  }
337 
338 }; // end of PointCloudAdapter<mrpt::maps::CPointsMapXYZI>
339 } // namespace opengl
340 } // namespace mrpt
void clear()
Erase all the contents of the map.
Definition: CMetricMap.cpp:31
bool savePCDFile(const std::string &filename, bool save_as_binary) const override
Save the point cloud as a PCL PCD file, in either ASCII or binary format.
void setPointRGB(size_t index, float x, float y, float z, float R_intensity, float G_ignored, float B_ignored) override
Changes a given point from map.
PointCloudAdapter(const mrpt::maps::CPointsMapXYZI &obj)
Constructor (accept a const ref for convenience)
void getPoint(size_t index, float &x, float &y, float &z) const
Access to a given point from map, as a 2D point.
Definition: CPointsMap.cpp:203
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
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:462
void PLY_export_get_vertex(const size_t idx, mrpt::math::TPoint3Df &pt, bool &pt_has_color, mrpt::img::TColorf &pt_color) const override
In a base class, will be called after PLY_export_get_vertex_count() once for each exported point...
void setSize(size_t newLength) override
Resizes all point buffers so they can hold the given number of points, erasing all previous contents ...
GLdouble GLdouble z
Definition: glext.h:3879
void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::img::TColorf *pt_color=nullptr) override
In a base class, will be called after PLY_import_set_vertex_count() once for each loaded point...
bool hasColorPoints() const override
Returns true if the point map has a color field for each point.
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 I] Unlike setPointAllFields(), this method does not check for index out of bounds.
const double G
mrpt::aligned_std_vector< float > m_intensity
The intensity/reflectance data.
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.
#define MAP_DEFINITION_START(_CLASS_NAME_)
Add a MAP_DEFINITION_START() ...
void setFromPCLPointCloudXYZI(const POINTCLOUD &cloud)
Loads a PCL point cloud (WITH XYZI information) into this MRPT class.
void resize(const size_t N)
Set number of points (to uninitialized values)
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 insertPoint(float x, float y, float z=0)
Provides a way to insert (append) individual points into the map: the missing fields of child classes...
Definition: CPointsMap.h:625
void getPCLPointCloudXYZI(POINTCLOUD &cloud) const
Like CPointsMap::getPCLPointCloud() but for PointCloud<PointXYZI>
void setPointIntensity(size_t index, float intensity)
Changes the intensity of a given point from the map.
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
void internal_clear() override
Clear the map, erasing all the points.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
GLenum GLsizei width
Definition: glext.h:3535
void setPointRGBf(const size_t idx, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
unsigned char uint8_t
Definition: rptypes.h:44
bool loadFromKittiVelodyneFile(const std::string &filename)
Loads from a Kitti dataset Velodyne scan binary file.
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 ...
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:161
With this struct options are provided to the observation insertion process.
Definition: CPointsMap.h:219
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:65
void setPointXYZ_RGBu8(const size_t idx, const coords_t x, const coords_t y, const coords_t z, const uint8_t r, const uint8_t g, const uint8_t b)
Set XYZ_RGBu8 coordinates of i&#39;th point.
void impl_copyFrom(const CPointsMap &obj) override
Virtual assignment operator, copies as much common data (XYZ, color,...) as possible from the source ...
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.
An adapter to different kinds of point cloud object.
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...
Lightweight 3D point (float version).
void setDimensions(const size_t &height, const size_t &width)
Does nothing as of now.
float getPointIntensity_fast(size_t index) const
Like getPointColor but without checking for out-of-index erors.
GLuint index
Definition: glext.h:4068
void getPointRGB(size_t index, float &x, float &y, float &z, float &R_intensity, float &G_intensity, float &B_intensity) const override
Retrieves a point and its color (colors range is [0,1])
GLubyte g
Definition: glext.h:6372
GLubyte GLubyte b
Definition: glext.h:6372
void getPointXYZ_RGBu8(const size_t idx, T &x, T &y, T &z, uint8_t &r, uint8_t &g, uint8_t &b) const
Get XYZ_RGBu8 coordinates of i&#39;th point.
void getPCLPointCloud(POINTCLOUD &cloud) const
Use to convert this MRPT point cloud object into a PCL point cloud object (PointCloud<PointXYZ>).
Definition: CPointsMap.h:991
GLsizei const GLchar ** string
Definition: glext.h:4116
void setPointFast(size_t index, float x, float y, float z)
Changes the coordinates of the given point (0-based index), without checking for out-of-bounds and wi...
Definition: CPointsMap.h:159
void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
void getPointXYZ_RGBf(const size_t idx, T &x, T &y, T &z, float &r, float &g, float &b) const
Get XYZ_RGBf coordinates of i&#39;th point.
void setPointRGBu8(const size_t idx, const uint8_t r, const uint8_t g, const uint8_t b)
Set RGBu8 coordinates of i&#39;th point.
void insertPointRGB(float x, float y, float z, float R_intensity, float G_ignored, float B_ignored) override
Adds a new point given its coordinates and color (colors range is [0,1])
A map of 3D points with reflectance/intensity (float).
mrpt::aligned_std_vector< float > m_z
Definition: CPointsMap.h:1104
float getPointIntensity(size_t index) const
Retrieves a point intensity (range [0,1])
void setPointXYZ_RGBf(const size_t idx, const coords_t x, const coords_t y, const coords_t z, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
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...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
mrpt::aligned_std_vector< float > m_y
Definition: CPointsMap.h:1104
const float R
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Override of the default 3D scene builder to account for the individual points&#39; color.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:82
Options used when evaluating "computeObservationLikelihood" in the derived classes.
Definition: CPointsMap.h:277
A RGB color - floats in the range [0,1].
Definition: TColor.h:77
void getPointRGBf(const size_t idx, float &r, float &g, float &b) const
Get RGBf color of i&#39;th point.
float coords_t
The type of each point XYZ coordinates.
GLenum GLint GLint y
Definition: glext.h:3542
void getPointRGBu8(const size_t idx, uint8_t &r, uint8_t &g, uint8_t &b) const
Get RGBu8 color of i&#39;th point.
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 I] Unlike getPointAllFields(), this method does not check for index out of bounds.
GLenum GLint x
Definition: glext.h:3542
void insertPointFast(float x, float y, float z=0) override
The virtual method for insertPoint() without calling mark_as_modified()
GLenum GLsizei GLsizei height
Definition: glext.h:3558
mrpt::aligned_std_vector< float > m_x
The point coordinates.
Definition: CPointsMap.h:1104
#define MAP_DEFINITION_END(_CLASS_NAME_)
size_t size() const
Returns the number of stored points in the map.
Definition: CPointsMap.h:422
void setPointColor_fast(size_t index, float R, float G, float B)
Like setPointColor but without checking for out-of-index erors.
bool saveXYZI_to_text_file(const std::string &file) const
Save to a text file.
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: bef67d9c5 Mon Apr 15 00:03:11 2019 +0200 at lun abr 15 00:10:13 CEST 2019