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



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN:Unversioned directory at Sun May 1 08:45:24 UTC 2016