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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020