Main MRPT website > C++ reference for MRPT 1.5.7
maps/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> > for an XYZ point cloud (without RGB) \ingroup mrpt_adapters_grp */
27  template <>
28  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > : public detail::PointCloudAdapterHelperNoRGB<pcl::PointCloud<pcl::PointXYZ>,float>
29  {
30  private:
31  pcl::PointCloud<pcl::PointXYZ> &m_obj;
32  public:
33  typedef float coords_t; //!< The type of each point XYZ coordinates
34  static const int HAS_RGB = 0; //!< Has any color RGB info?
35  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
36  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
37 
38  /** Constructor (accept a const ref for convenience) */
39  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZ> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZ>*>(&obj)) { }
40  /** Get number of points */
41  inline size_t size() const { return m_obj.points.size(); }
42  /** Set number of points (to uninitialized values) */
43  inline void resize(const size_t N) { m_obj.points.resize(N); }
44 
45  /** Get XYZ coordinates of i'th point */
46  template <typename T>
47  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
48  const pcl::PointXYZ &p=m_obj.points[idx];
49  x=p.x; y=p.y; z=p.z;
50  }
51  /** Set XYZ coordinates of i'th point */
52  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
53  pcl::PointXYZ &p=m_obj.points[idx];
54  p.x=x; p.y=y; p.z=z;
55  }
56 
57  /** Set Invalid Point */
58  inline void setInvalidPoint(const size_t idx)
59  {
60  pcl::PointXYZ &p=m_obj.points[idx];
61  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
62  }
63  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> >
64 
65 
66  /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> > for an XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
67  template <>
68  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
69  {
70  private:
71  pcl::PointCloud<pcl::PointXYZRGB> &m_obj;
72  public:
73  typedef float coords_t; //!< The type of each point XYZ coordinates
74  static const int HAS_RGB = 1; //!< Has any color RGB info?
75  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
76  static const int HAS_RGBu8 = 1; //!< Has native RGB info (as uint8_t)?
77 
78  /** Constructor (accept a const ref for convenience) */
79  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGB> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGB>*>(&obj)) { }
80  /** Get number of points */
81  inline size_t size() const { return m_obj.points.size(); }
82  /** Set number of points (to uninitialized values) */
83  inline void resize(const size_t N) { m_obj.points.resize(N); }
84 
85  /** Get XYZ coordinates of i'th point */
86  template <typename T>
87  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
88  const pcl::PointXYZRGB &p=m_obj.points[idx];
89  x=p.x; y=p.y; z=p.z;
90  }
91  /** Set XYZ coordinates of i'th point */
92  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
93  pcl::PointXYZRGB &p=m_obj.points[idx];
94  p.x=x; p.y=y; p.z=z;
95  p.r=p.g=p.b=255;
96  }
97 
98  /** Get XYZ_RGBf coordinates of i'th point */
99  template <typename T>
100  inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
101  const pcl::PointXYZRGB &p=m_obj.points[idx];
102  x=p.x; y=p.y; z=p.z;
103  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
104  }
105  /** Set XYZ_RGBf coordinates of i'th point */
106  inline 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) {
107  pcl::PointXYZRGB &p=m_obj.points[idx];
108  p.x=x; p.y=y; p.z=z;
109  p.r=r*255; p.g=g*255; p.b=b*255;
110  }
111 
112  /** Get XYZ_RGBu8 coordinates of i'th point */
113  template <typename T>
114  inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
115  const pcl::PointXYZRGB &p=m_obj.points[idx];
116  x=p.x; y=p.y; z=p.z;
117  r=p.r; g=p.g; b=p.b;
118  }
119  /** Set XYZ_RGBu8 coordinates of i'th point */
120  inline 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) {
121  pcl::PointXYZRGB &p=m_obj.points[idx];
122  p.x=x; p.y=y; p.z=z;
123  p.r=r; p.g=g; p.b=b;
124  }
125 
126  /** Get RGBf color of i'th point */
127  inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const {
128  const pcl::PointXYZRGB &p=m_obj.points[idx];
129  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
130  }
131  /** Set XYZ_RGBf coordinates of i'th point */
132  inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) {
133  pcl::PointXYZRGB &p=m_obj.points[idx];
134  p.r=r*255; p.g=g*255; p.b=b*255;
135  }
136 
137  /** Get RGBu8 color of i'th point */
138  inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
139  const pcl::PointXYZRGB &p=m_obj.points[idx];
140  r=p.r; g=p.g; b=p.b;
141  }
142  /** Set RGBu8 coordinates of i'th point */
143  inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
144  pcl::PointXYZRGB &p=m_obj.points[idx];
145  p.r=r; p.g=g; p.b=b;
146  }
147 
148 
149  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
150 
151 
152  /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> > for an XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
153  template <>
154  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> >
155  {
156  private:
157  pcl::PointCloud<pcl::PointXYZRGBA> &m_obj;
158  public:
159  typedef float coords_t; //!< The type of each point XYZ coordinates
160  static const int HAS_RGB = 1; //!< Has any color RGB info?
161  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
162  static const int HAS_RGBu8 = 1; //!< Has native RGB info (as uint8_t)?
163 
164  /** Constructor (accept a const ref for convenience) */
165  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGBA> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGBA>*>(&obj)) { }
166  /** Get number of points */
167  inline size_t size() const { return m_obj.points.size(); }
168  /** Set number of points (to uninitialized values) */
169  inline void resize(const size_t N) { m_obj.points.resize(N); }
170 
171  /** Get XYZ coordinates of i'th point */
172  template <typename T>
173  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
174  const pcl::PointXYZRGBA &p=m_obj.points[idx];
175  x=p.x; y=p.y; z=p.z;
176  }
177  /** Set XYZ coordinates of i'th point */
178  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
179  pcl::PointXYZRGBA &p=m_obj.points[idx];
180  p.x=x; p.y=y; p.z=z;
181  p.r=p.g=p.b=255;
182  }
183 
184  /** Set Invalid Point */
185  inline void setInvalidPoint(const size_t idx)
186  {
187  pcl::PointXYZRGBA &p=m_obj.points[idx];
188  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
189  }
190 
191  /** Get XYZ_RGBf coordinates of i'th point */
192  template <typename T>
193  inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
194  const pcl::PointXYZRGBA &p=m_obj.points[idx];
195  x=p.x; y=p.y; z=p.z;
196  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
197  }
198  /** Set XYZ_RGBf coordinates of i'th point */
199  inline 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) {
200  pcl::PointXYZRGBA &p=m_obj.points[idx];
201  p.x=x; p.y=y; p.z=z;
202  p.r=r*255; p.g=g*255; p.b=b*255;
203  }
204 
205  /** Get XYZ_RGBu8 coordinates of i'th point */
206  template <typename T>
207  inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
208  const pcl::PointXYZRGBA &p=m_obj.points[idx];
209  x=p.x; y=p.y; z=p.z;
210  r=p.r; g=p.g; b=p.b;
211  }
212  /** Set XYZ_RGBu8 coordinates of i'th point */
213  inline 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) {
214  pcl::PointXYZRGBA &p=m_obj.points[idx];
215  p.x=x; p.y=y; p.z=z;
216  p.r=r; p.g=g; p.b=b;
217  }
218 
219  /** Get RGBf color of i'th point */
220  inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const {
221  const pcl::PointXYZRGBA &p=m_obj.points[idx];
222  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
223  }
224  /** Set XYZ_RGBf coordinates of i'th point */
225  inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) {
226  pcl::PointXYZRGBA &p=m_obj.points[idx];
227  p.r=r*255; p.g=g*255; p.b=b*255;
228  }
229 
230  /** Get RGBu8 color of i'th point */
231  inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
232  const pcl::PointXYZRGBA &p=m_obj.points[idx];
233  r=p.r; g=p.g; b=p.b;
234  }
235  /** Set RGBu8 coordinates of i'th point */
236  inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
237  pcl::PointXYZRGBA &p=m_obj.points[idx];
238  p.r=r; p.g=g; p.b=b;
239  }
240 
241  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> >
242 
243  }
244 } // End of namespace
245 
246 #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.
void resize(const size_t N)
Set number of points (to uninitialized values)
GLdouble GLdouble z
Definition: glext.h:3734
float coords_t
The type of each point XYZ coordinates.
void getPointRGBf(const size_t idx, float &r, float &g, float &b) const
Get RGBf color of i&#39;th point.
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
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.
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 resize(const size_t N)
Set number of points (to uninitialized values)
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZRGB > &obj)
Constructor (accept a const ref for convenience)
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
unsigned char uint8_t
Definition: rptypes.h:43
GLubyte g
Definition: glext.h:5575
GLubyte GLubyte b
Definition: glext.h:5575
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 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 getPointRGBu8(const size_t idx, uint8_t &r, uint8_t &g, uint8_t &b) const
Get RGBu8 color of i&#39;th point.
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZ > &obj)
Constructor (accept a const ref for convenience)
void setPointRGBf(const size_t idx, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
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.
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.
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
void resize(const size_t N)
Set number of points (to uninitialized values)
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 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.
PointCloudAdapter(const pcl::PointCloud< pcl::PointXYZRGBA > &obj)
Constructor (accept a const ref for convenience)
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.
GLenum GLint GLint y
Definition: glext.h:3516
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 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.
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
GLenum GLint x
Definition: glext.h:3516
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.
void getPointRGBf(const size_t idx, float &r, float &g, float &b) const
Get RGBf color 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.
GLfloat GLfloat p
Definition: glext.h:5587
void setPointRGBf(const size_t idx, const float r, const float g, const float b)
Set XYZ_RGBf coordinates of i&#39;th point.
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019