MRPT  2.0.0
PCL_adapters.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-2020, 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/config.h>
13 
14 // NOTE: Only include this file if you have PCL installed in your system
15 // and do it only after including MRPT headers...
16 
17 // Make sure the essential PCL headers are included:
18 #include <pcl/point_cloud.h>
19 #include <pcl/point_types.h>
20 
21 namespace mrpt::opengl
22 {
23 /** Specialization
24  * mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > for an XYZ
25  * point cloud (without RGB) \ingroup mrpt_adapters_grp */
26 template <>
27 class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ>>
28 {
29  private:
30  pcl::PointCloud<pcl::PointXYZ>& m_obj;
31 
32  public:
33  /** The type of each point XYZ coordinates */
34  using coords_t = float;
35  /** Has any color RGB info? */
36  static constexpr bool HAS_RGB = false;
37  /** Has native RGB info (as floats)? */
38  static constexpr bool HAS_RGBf = false;
39  /** Has native RGB info (as uint8_t)? */
40  static constexpr bool HAS_RGBu8 = false;
41 
42  /** Constructor (accept a const ref for convenience) */
43  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZ>& obj)
44  : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZ>*>(&obj))
45  {
46  }
47  /** Get number of points */
48  inline size_t size() const { return m_obj.points.size(); }
49  /** Set number of points (to uninitialized values) */
50  inline void resize(const size_t N) { m_obj.points.resize(N); }
51  /** Set height and width (for organized) */
52  inline void setDimensions(size_t height, size_t width)
53  {
54  m_obj.height = height;
55  m_obj.width = width;
56  }
57  /** Get XYZ coordinates of i'th point */
58  template <typename T>
59  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
60  {
61  const pcl::PointXYZ& p = m_obj.points[idx];
62  x = p.x;
63  y = p.y;
64  z = p.z;
65  }
66  /** Set XYZ coordinates of i'th point */
67  inline void setPointXYZ(
68  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
69  {
70  pcl::PointXYZ& p = m_obj.points[idx];
71  p.x = x;
72  p.y = y;
73  p.z = z;
74  }
75 
76  /** Set Invalid Point */
77  inline void setInvalidPoint(const size_t idx)
78  {
79  pcl::PointXYZ& p = m_obj.points[idx];
80  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
81  }
82 }; // end of mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> >
83 
84 /** Specialization
85  * mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> > for an
86  * XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
87 template <>
88 class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB>>
89 {
90  private:
91  pcl::PointCloud<pcl::PointXYZRGB>& m_obj;
92 
93  public:
94  /** The type of each point XYZ coordinates */
95  using coords_t = float;
96  /** Has any color RGB info? */
97  static constexpr bool HAS_RGB = true;
98  /** Has native RGB info (as floats)? */
99  static constexpr bool HAS_RGBf = false;
100  /** Has native RGB info (as uint8_t)? */
101  static constexpr bool HAS_RGBu8 = true;
102 
103  /** Constructor (accept a const ref for convenience) */
104  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGB>& obj)
105  : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGB>*>(&obj))
106  {
107  }
108  /** Get number of points */
109  inline size_t size() const { return m_obj.points.size(); }
110  /** Set number of points (to uninitialized values) */
111  inline void resize(const size_t N) { m_obj.points.resize(N); }
112  /** Set height and width (for organized) */
113  inline void setDimensions(size_t height, size_t width)
114  {
115  m_obj.height = height;
116  m_obj.width = width;
117  }
118 
119  /** Get XYZ coordinates of i'th point */
120  template <typename T>
121  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
122  {
123  const pcl::PointXYZRGB& p = m_obj.points[idx];
124  x = p.x;
125  y = p.y;
126  z = p.z;
127  }
128  /** Set XYZ coordinates of i'th point */
129  inline void setPointXYZ(
130  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
131  {
132  pcl::PointXYZRGB& p = m_obj.points[idx];
133  p.x = x;
134  p.y = y;
135  p.z = z;
136  p.r = p.g = p.b = 255;
137  }
138 
139  /** Get XYZ_RGBf coordinates of i'th point */
140  template <typename T>
141  inline void getPointXYZ_RGBf(
142  const size_t idx, T& x, T& y, T& z, float& r, float& g, float& b) const
143  {
144  const pcl::PointXYZRGB& p = m_obj.points[idx];
145  x = p.x;
146  y = p.y;
147  z = p.z;
148  r = p.r / 255.f;
149  g = p.g / 255.f;
150  b = p.b / 255.f;
151  }
152  /** Set XYZ_RGBf coordinates of i'th point */
153  inline void setPointXYZ_RGBf(
154  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
155  const float r, const float g, const float b)
156  {
157  pcl::PointXYZRGB& p = m_obj.points[idx];
158  p.x = x;
159  p.y = y;
160  p.z = z;
161  p.r = r * 255;
162  p.g = g * 255;
163  p.b = b * 255;
164  }
165 
166  /** Get XYZ_RGBu8 coordinates of i'th point */
167  template <typename T>
168  inline void getPointXYZ_RGBu8(
169  const size_t idx, T& x, T& y, T& z, uint8_t& r, uint8_t& g,
170  uint8_t& b) const
171  {
172  const pcl::PointXYZRGB& p = m_obj.points[idx];
173  x = p.x;
174  y = p.y;
175  z = p.z;
176  r = p.r;
177  g = p.g;
178  b = p.b;
179  }
180  /** Set XYZ_RGBu8 coordinates of i'th point */
181  inline void setPointXYZ_RGBu8(
182  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
183  const uint8_t r, const uint8_t g, const uint8_t b)
184  {
185  pcl::PointXYZRGB& p = m_obj.points[idx];
186  p.x = x;
187  p.y = y;
188  p.z = z;
189  p.r = r;
190  p.g = g;
191  p.b = b;
192  }
193 
194  /** Get RGBf color of i'th point */
195  inline void getPointRGBf(
196  const size_t idx, float& r, float& g, float& b) const
197  {
198  const pcl::PointXYZRGB& p = m_obj.points[idx];
199  r = p.r / 255.f;
200  g = p.g / 255.f;
201  b = p.b / 255.f;
202  }
203  /** Set XYZ_RGBf coordinates of i'th point */
204  inline void setPointRGBf(
205  const size_t idx, const float r, const float g, const float b)
206  {
207  pcl::PointXYZRGB& p = m_obj.points[idx];
208  p.r = r * 255;
209  p.g = g * 255;
210  p.b = b * 255;
211  }
212 
213  /** Get RGBu8 color of i'th point */
214  inline void getPointRGBu8(
215  const size_t idx, uint8_t& r, uint8_t& g, uint8_t& b) const
216  {
217  const pcl::PointXYZRGB& p = m_obj.points[idx];
218  r = p.r;
219  g = p.g;
220  b = p.b;
221  }
222  /** Set RGBu8 coordinates of i'th point */
223  inline void setPointRGBu8(
224  const size_t idx, const uint8_t r, const uint8_t g, const uint8_t b)
225  {
226  pcl::PointXYZRGB& p = m_obj.points[idx];
227  p.r = r;
228  p.g = g;
229  p.b = b;
230  }
231 
232 }; // end of mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB>
233 // >
234 
235 /** Specialization
236  * mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> > for an
237  * XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
238 template <>
239 class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA>>
240 {
241  private:
242  pcl::PointCloud<pcl::PointXYZRGBA>& m_obj;
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 = false;
251  /** Has native RGB info (as uint8_t)? */
252  static constexpr bool HAS_RGBu8 = true;
253 
254  /** Constructor (accept a const ref for convenience) */
255  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGBA>& obj)
256  : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGBA>*>(&obj))
257  {
258  }
259  /** Get number of points */
260  inline size_t size() const { return m_obj.points.size(); }
261  /** Set number of points (to uninitialized values) */
262  inline void resize(const size_t N) { m_obj.points.resize(N); }
263  /** Set height and width (for organized) */
264  inline void setDimensions(size_t height, size_t width)
265  {
266  m_obj.height = height;
267  m_obj.width = width;
268  }
269 
270  /** Get XYZ coordinates of i'th point */
271  template <typename T>
272  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
273  {
274  const pcl::PointXYZRGBA& p = m_obj.points[idx];
275  x = p.x;
276  y = p.y;
277  z = p.z;
278  }
279  /** Set XYZ coordinates of i'th point */
280  inline void setPointXYZ(
281  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
282  {
283  pcl::PointXYZRGBA& p = m_obj.points[idx];
284  p.x = x;
285  p.y = y;
286  p.z = z;
287  p.r = p.g = p.b = 255;
288  }
289 
290  /** Set Invalid Point */
291  inline void setInvalidPoint(const size_t idx)
292  {
293  pcl::PointXYZRGBA& p = m_obj.points[idx];
294  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
295  }
296 
297  /** Get XYZ_RGBf coordinates of i'th point */
298  template <typename T>
299  inline void getPointXYZ_RGBf(
300  const size_t idx, T& x, T& y, T& z, float& r, float& g, float& b) const
301  {
302  const pcl::PointXYZRGBA& p = m_obj.points[idx];
303  x = p.x;
304  y = p.y;
305  z = p.z;
306  r = p.r / 255.f;
307  g = p.g / 255.f;
308  b = p.b / 255.f;
309  }
310  /** Set XYZ_RGBf coordinates of i'th point */
311  inline void setPointXYZ_RGBf(
312  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
313  const float r, const float g, const float b)
314  {
315  pcl::PointXYZRGBA& p = m_obj.points[idx];
316  p.x = x;
317  p.y = y;
318  p.z = z;
319  p.r = r * 255;
320  p.g = g * 255;
321  p.b = b * 255;
322  }
323 
324  /** Get XYZ_RGBu8 coordinates of i'th point */
325  template <typename T>
326  inline void getPointXYZ_RGBu8(
327  const size_t idx, T& x, T& y, T& z, uint8_t& r, uint8_t& g,
328  uint8_t& b) const
329  {
330  const pcl::PointXYZRGBA& p = m_obj.points[idx];
331  x = p.x;
332  y = p.y;
333  z = p.z;
334  r = p.r;
335  g = p.g;
336  b = p.b;
337  }
338  /** Set XYZ_RGBu8 coordinates of i'th point */
339  inline void setPointXYZ_RGBu8(
340  const size_t idx, const coords_t x, const coords_t y, const coords_t z,
341  const uint8_t r, const uint8_t g, const uint8_t b)
342  {
343  pcl::PointXYZRGBA& p = m_obj.points[idx];
344  p.x = x;
345  p.y = y;
346  p.z = z;
347  p.r = r;
348  p.g = g;
349  p.b = b;
350  }
351 
352  /** Get RGBf color of i'th point */
353  inline void getPointRGBf(
354  const size_t idx, float& r, float& g, float& b) const
355  {
356  const pcl::PointXYZRGBA& p = m_obj.points[idx];
357  r = p.r / 255.f;
358  g = p.g / 255.f;
359  b = p.b / 255.f;
360  }
361  /** Set XYZ_RGBf coordinates of i'th point */
362  inline void setPointRGBf(
363  const size_t idx, const float r, const float g, const float b)
364  {
365  pcl::PointXYZRGBA& p = m_obj.points[idx];
366  p.r = r * 255;
367  p.g = g * 255;
368  p.b = b * 255;
369  }
370 
371  /** Get RGBu8 color of i'th point */
372  inline void getPointRGBu8(
373  const size_t idx, uint8_t& r, uint8_t& g, uint8_t& b) const
374  {
375  const pcl::PointXYZRGBA& p = m_obj.points[idx];
376  r = p.r;
377  g = p.g;
378  b = p.b;
379  }
380  /** Set RGBu8 coordinates of i'th point */
381  inline void setPointRGBu8(
382  const size_t idx, const uint8_t r, const uint8_t g, const uint8_t b)
383  {
384  pcl::PointXYZRGBA& p = m_obj.points[idx];
385  p.r = r;
386  p.g = g;
387  p.b = b;
388  }
389 
390 }; // end of mrpt::opengl::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA>
391 // >
392 } // namespace mrpt::opengl
void setPointRGBf(const size_t idx, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
Definition: PCL_adapters.h:204
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZRGBA > &obj)
Constructor (accept a const ref for convenience)
Definition: PCL_adapters.h:255
void getPointRGBu8(const size_t idx, uint8_t &r, uint8_t &g, uint8_t &b) const
Get RGBu8 color of i&#39;th point.
Definition: PCL_adapters.h:372
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.
Definition: PCL_adapters.h:223
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.
Definition: PCL_adapters.h:299
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.
Definition: PCL_adapters.h:326
void setDimensions(size_t height, size_t width)
Set height and width (for organized)
Definition: PCL_adapters.h:113
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.
Definition: PCL_adapters.h:280
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.
Definition: PCL_adapters.h:181
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
Definition: PCL_adapters.h:59
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
Definition: PCL_adapters.h:121
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.
Definition: PCL_adapters.h:129
void setPointRGBf(const size_t idx, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
Definition: PCL_adapters.h:362
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: PCL_adapters.h:111
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.
Definition: PCL_adapters.h:67
An adapter to different kinds of point cloud object.
float coords_t
The type of each point XYZ coordinates.
Definition: PCL_adapters.h:246
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: PCL_adapters.h:262
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.
Definition: PCL_adapters.h:339
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.
Definition: PCL_adapters.h:141
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZ > &obj)
Constructor (accept a const ref for convenience)
Definition: PCL_adapters.h:43
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.
Definition: PCL_adapters.h:311
void setDimensions(size_t height, size_t width)
Set height and width (for organized)
Definition: PCL_adapters.h:264
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
Definition: PCL_adapters.h:272
float coords_t
The type of each point XYZ coordinates.
Definition: PCL_adapters.h:95
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: PCL_adapters.h:50
void getPointRGBu8(const size_t idx, uint8_t &r, uint8_t &g, uint8_t &b) const
Get RGBu8 color of i&#39;th point.
Definition: PCL_adapters.h:214
void getPointRGBf(const size_t idx, float &r, float &g, float &b) const
Get RGBf color of i&#39;th point.
Definition: PCL_adapters.h:195
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void setDimensions(size_t height, size_t width)
Set height and width (for organized)
Definition: PCL_adapters.h:52
void getPointRGBf(const size_t idx, float &r, float &g, float &b) const
Get RGBf color of i&#39;th point.
Definition: PCL_adapters.h:353
void setInvalidPoint(const size_t idx)
Set Invalid Point.
Definition: PCL_adapters.h:77
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.
Definition: PCL_adapters.h:168
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.
Definition: PCL_adapters.h:153
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZRGB > &obj)
Constructor (accept a const ref for convenience)
Definition: PCL_adapters.h:104
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.
Definition: PCL_adapters.h:381
float coords_t
The type of each point XYZ coordinates.
Definition: PCL_adapters.h:34



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020