Main MRPT website > C++ reference
MRPT logo
PCL_adapters.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef mrpt_maps_PCL_adapters_H
29 #define mrpt_maps_PCL_adapters_H
30 
31 #include <mrpt/config.h>
32 #include <mrpt/utils/adapters.h>
33 
34 // NOTE: Only include this file if you have PCL installed in your system
35 // and do it only after including MRPT headers...
36 
37 // Make sure the essential PCL headers are included:
38 #include <pcl/point_types.h>
39 #include <pcl/point_cloud.h>
40 
41 namespace mrpt
42 {
43  namespace utils
44  {
45  /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > for an XYZ point cloud (without RGB) \ingroup mrpt_adapters_grp */
46  template <>
47  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > : public detail::PointCloudAdapterHelperNoRGB<pcl::PointCloud<pcl::PointXYZ>,float>
48  {
49  private:
50  pcl::PointCloud<pcl::PointXYZ> &m_obj;
51  public:
52  typedef float coords_t; //!< The type of each point XYZ coordinates
53  static const int HAS_RGB = 0; //!< Has any color RGB info?
54  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
55  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
56 
57  /** Constructor (accept a const ref for convenience) */
58  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZ> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZ>*>(&obj)) { }
59  /** Get number of points */
60  inline size_t size() const { return m_obj.points.size(); }
61  /** Set number of points (to uninitialized values) */
62  inline void resize(const size_t N) { m_obj.points.resize(N); }
63 
64  /** Get XYZ coordinates of i'th point */
65  template <typename T>
66  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
67  const pcl::PointXYZ &p=m_obj.points[idx];
68  x=p.x; y=p.y; z=p.z;
69  }
70  /** Set XYZ coordinates of i'th point */
71  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
72  pcl::PointXYZ &p=m_obj.points[idx];
73  p.x=x; p.y=y; p.z=z;
74  }
75  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> >
76 
77 
78  /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> > for an XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
79  template <>
80  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
81  {
82  private:
83  pcl::PointCloud<pcl::PointXYZRGB> &m_obj;
84  public:
85  typedef float coords_t; //!< The type of each point XYZ coordinates
86  static const int HAS_RGB = 1; //!< Has any color RGB info?
87  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
88  static const int HAS_RGBu8 = 1; //!< Has native RGB info (as uint8_t)?
89 
90  /** Constructor (accept a const ref for convenience) */
91  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGB> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGB>*>(&obj)) { }
92  /** Get number of points */
93  inline size_t size() const { return m_obj.points.size(); }
94  /** Set number of points (to uninitialized values) */
95  inline void resize(const size_t N) { m_obj.points.resize(N); }
96 
97  /** Get XYZ coordinates of i'th point */
98  template <typename T>
99  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
100  const pcl::PointXYZRGB &p=m_obj.points[idx];
101  x=p.x; y=p.y; z=p.z;
102  }
103  /** Set XYZ coordinates of i'th point */
104  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
105  pcl::PointXYZRGB &p=m_obj.points[idx];
106  p.x=x; p.y=y; p.z=z;
107  p.r=p.g=p.b=255;
108  }
109 
110  /** Get XYZ_RGBf coordinates of i'th point */
111  template <typename T>
112  inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
113  const pcl::PointXYZRGB &p=m_obj.points[idx];
114  x=p.x; y=p.y; z=p.z;
115  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
116  }
117  /** Set XYZ_RGBf coordinates of i'th point */
118  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) {
119  pcl::PointXYZRGB &p=m_obj.points[idx];
120  p.x=x; p.y=y; p.z=z;
121  p.r=r*255; p.g=g*255; p.b=b*255;
122  }
123 
124  /** Get XYZ_RGBu8 coordinates of i'th point */
125  template <typename T>
126  inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
127  const pcl::PointXYZRGB &p=m_obj.points[idx];
128  x=p.x; y=p.y; z=p.z;
129  r=p.r; g=p.g; b=p.b;
130  }
131  /** Set XYZ_RGBu8 coordinates of i'th point */
132  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) {
133  pcl::PointXYZRGB &p=m_obj.points[idx];
134  p.x=x; p.y=y; p.z=z;
135  p.r=r; p.g=g; p.b=b;
136  }
137 
138  /** Get RGBf color of i'th point */
139  inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const {
140  const pcl::PointXYZRGB &p=m_obj.points[idx];
141  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
142  }
143  /** Set XYZ_RGBf coordinates of i'th point */
144  inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) {
145  pcl::PointXYZRGB &p=m_obj.points[idx];
146  p.r=r*255; p.g=g*255; p.b=b*255;
147  }
148 
149  /** Get RGBu8 color of i'th point */
150  inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
151  const pcl::PointXYZRGB &p=m_obj.points[idx];
152  r=p.r; g=p.g; b=p.b;
153  }
154  /** Set RGBu8 coordinates of i'th point */
155  inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
156  pcl::PointXYZRGB &p=m_obj.points[idx];
157  p.r=r; p.g=g; p.b=b;
158  }
159 
160  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
161 
162 
163  /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> > for an XYZ point cloud with RGB \ingroup mrpt_adapters_grp */
164  template <>
165  class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> >
166  {
167  private:
168  pcl::PointCloud<pcl::PointXYZRGBA> &m_obj;
169  public:
170  typedef float coords_t; //!< The type of each point XYZ coordinates
171  static const int HAS_RGB = 1; //!< Has any color RGB info?
172  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
173  static const int HAS_RGBu8 = 1; //!< Has native RGB info (as uint8_t)?
174 
175  /** Constructor (accept a const ref for convenience) */
176  inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGBA> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGBA>*>(&obj)) { }
177  /** Get number of points */
178  inline size_t size() const { return m_obj.points.size(); }
179  /** Set number of points (to uninitialized values) */
180  inline void resize(const size_t N) { m_obj.points.resize(N); }
181 
182  /** Get XYZ coordinates of i'th point */
183  template <typename T>
184  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
185  const pcl::PointXYZRGBA &p=m_obj.points[idx];
186  x=p.x; y=p.y; z=p.z;
187  }
188  /** Set XYZ coordinates of i'th point */
189  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
190  pcl::PointXYZRGBA &p=m_obj.points[idx];
191  p.x=x; p.y=y; p.z=z;
192  p.r=p.g=p.b=255;
193  }
194 
195  /** Get XYZ_RGBf coordinates of i'th point */
196  template <typename T>
197  inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
198  const pcl::PointXYZRGBA &p=m_obj.points[idx];
199  x=p.x; y=p.y; z=p.z;
200  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
201  }
202  /** Set XYZ_RGBf coordinates of i'th point */
203  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) {
204  pcl::PointXYZRGBA &p=m_obj.points[idx];
205  p.x=x; p.y=y; p.z=z;
206  p.r=r*255; p.g=g*255; p.b=b*255;
207  }
208 
209  /** Get XYZ_RGBu8 coordinates of i'th point */
210  template <typename T>
211  inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
212  const pcl::PointXYZRGBA &p=m_obj.points[idx];
213  x=p.x; y=p.y; z=p.z;
214  r=p.r; g=p.g; b=p.b;
215  }
216  /** Set XYZ_RGBu8 coordinates of i'th point */
217  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) {
218  pcl::PointXYZRGBA &p=m_obj.points[idx];
219  p.x=x; p.y=y; p.z=z;
220  p.r=r; p.g=g; p.b=b;
221  }
222 
223  /** Get RGBf color of i'th point */
224  inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const {
225  const pcl::PointXYZRGBA &p=m_obj.points[idx];
226  r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
227  }
228  /** Set XYZ_RGBf coordinates of i'th point */
229  inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) {
230  pcl::PointXYZRGBA &p=m_obj.points[idx];
231  p.r=r*255; p.g=g*255; p.b=b*255;
232  }
233 
234  /** Get RGBu8 color of i'th point */
235  inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
236  const pcl::PointXYZRGBA &p=m_obj.points[idx];
237  r=p.r; g=p.g; b=p.b;
238  }
239  /** Set RGBu8 coordinates of i'th point */
240  inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
241  pcl::PointXYZRGBA &p=m_obj.points[idx];
242  p.r=r; p.g=g; p.b=b;
243  }
244 
245  }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGBA> >
246 
247  }
248 } // End of namespace
249 
250 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013