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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019