Main MRPT website > C++ reference
MRPT logo
PCL_adapters.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef mrpt_maps_PCL_adapters_H
00029 #define mrpt_maps_PCL_adapters_H
00030 
00031 #include <mrpt/config.h>
00032 #include <mrpt/utils/adapters.h>
00033 
00034 // NOTE: Only include this file if you have PCL installed in your system
00035 //        and do it only after including MRPT headers...
00036 
00037 // Make sure the essential PCL headers are included:
00038 #include <pcl/point_types.h>
00039 #include <pcl/point_cloud.h>
00040 
00041 namespace mrpt
00042 {
00043         namespace utils
00044         {
00045                 /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > for an XYZ point cloud (without RGB) \ingroup mrpt_adapters_grp */
00046                 template <>
00047                 class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> > :  public detail::PointCloudAdapterHelperNoRGB<pcl::PointCloud<pcl::PointXYZ>,float>
00048                 {
00049                 private:
00050                         pcl::PointCloud<pcl::PointXYZ> &m_obj;
00051                 public:
00052                         typedef float  coords_t;         //!< The type of each point XYZ coordinates
00053                         static const int HAS_RGB   = 0;  //!< Has any color RGB info?
00054                         static const int HAS_RGBf  = 0;  //!< Has native RGB info (as floats)?
00055                         static const int HAS_RGBu8 = 0;  //!< Has native RGB info (as uint8_t)?
00056 
00057                         /** Constructor (accept a const ref for convenience) */
00058                         inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZ> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZ>*>(&obj)) { }
00059                         /** Get number of points */
00060                         inline size_t size() const { return m_obj.points.size(); }
00061                         /** Set number of points (to uninitialized values) */
00062                         inline void resize(const size_t N) { m_obj.points.resize(N); }
00063 
00064                         /** Get XYZ coordinates of i'th point */
00065                         template <typename T>
00066                         inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00067                                 const pcl::PointXYZ &p=m_obj.points[idx];
00068                                 x=p.x; y=p.y; z=p.z;
00069                         }
00070                         /** Set XYZ coordinates of i'th point */
00071                         inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00072                                 pcl::PointXYZ &p=m_obj.points[idx];
00073                                 p.x=x; p.y=y; p.z=z;
00074                         }
00075                 }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZ> >
00076 
00077 
00078                 /** Specialization mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> > for an XYZ point cloud with RGB  \ingroup mrpt_adapters_grp */
00079                 template <>
00080                 class PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
00081                 {
00082                 private:
00083                         pcl::PointCloud<pcl::PointXYZRGB> &m_obj;
00084                 public:
00085                         typedef float  coords_t;         //!< The type of each point XYZ coordinates
00086                         static const int HAS_RGB   = 1;  //!< Has any color RGB info?
00087                         static const int HAS_RGBf  = 0;  //!< Has native RGB info (as floats)?
00088                         static const int HAS_RGBu8 = 1;  //!< Has native RGB info (as uint8_t)?
00089 
00090                         /** Constructor (accept a const ref for convenience) */
00091                         inline PointCloudAdapter(const pcl::PointCloud<pcl::PointXYZRGB> &obj) : m_obj(*const_cast<pcl::PointCloud<pcl::PointXYZRGB>*>(&obj)) { }
00092                         /** Get number of points */
00093                         inline size_t size() const { return m_obj.points.size(); }
00094                         /** Set number of points (to uninitialized values) */
00095                         inline void resize(const size_t N) { m_obj.points.resize(N); }
00096 
00097                         /** Get XYZ coordinates of i'th point */
00098                         template <typename T>
00099                         inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
00100                                 const pcl::PointXYZRGB &p=m_obj.points[idx];
00101                                 x=p.x; y=p.y; z=p.z;
00102                         }
00103                         /** Set XYZ coordinates of i'th point */
00104                         inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
00105                                 pcl::PointXYZRGB &p=m_obj.points[idx];
00106                                 p.x=x; p.y=y; p.z=z;
00107                                 p.r=p.g=p.b=255;
00108                         }
00109 
00110                         /** Get XYZ_RGBf coordinates of i'th point */
00111                         template <typename T>
00112                         inline void getPointXYZ_RGBf(const size_t idx, T &x,T &y, T &z, float &r,float &g,float &b) const {
00113                                 const pcl::PointXYZRGB &p=m_obj.points[idx];
00114                                 x=p.x; y=p.y; z=p.z;
00115                                 r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
00116                         }
00117                         /** Set XYZ_RGBf coordinates of i'th point */
00118                         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) {
00119                                 pcl::PointXYZRGB &p=m_obj.points[idx];
00120                                 p.x=x; p.y=y; p.z=z;
00121                                 p.r=r*255; p.g=g*255; p.b=b*255;
00122                         }
00123 
00124                         /** Get XYZ_RGBu8 coordinates of i'th point */
00125                         template <typename T>
00126                         inline void getPointXYZ_RGBu8(const size_t idx, T &x,T &y, T &z, uint8_t &r,uint8_t &g,uint8_t &b) const {
00127                                 const pcl::PointXYZRGB &p=m_obj.points[idx];
00128                                 x=p.x; y=p.y; z=p.z;
00129                                 r=p.r; g=p.g; b=p.b;
00130                         }
00131                         /** Set XYZ_RGBu8 coordinates of i'th point */
00132                         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) {
00133                                 pcl::PointXYZRGB &p=m_obj.points[idx];
00134                                 p.x=x; p.y=y; p.z=z;
00135                                 p.r=r; p.g=g; p.b=b;
00136                         }
00137 
00138                         /** Get RGBf color of i'th point */
00139                         inline void getPointRGBf(const size_t idx, float &r,float &g,float &b) const {
00140                                 const pcl::PointXYZRGB &p=m_obj.points[idx];
00141                                 r=p.r/255.f; g=p.g/255.f; b=p.b/255.f;
00142                         }
00143                         /** Set XYZ_RGBf coordinates of i'th point */
00144                         inline void setPointRGBf(const size_t idx, const float r,const float g,const float b) {
00145                                 pcl::PointXYZRGB &p=m_obj.points[idx];
00146                                 p.r=r*255; p.g=g*255; p.b=b*255;
00147                         }
00148 
00149                         /** Get RGBu8 color of i'th point */
00150                         inline void getPointRGBu8(const size_t idx, uint8_t &r,uint8_t &g,uint8_t &b) const {
00151                                 const pcl::PointXYZRGB &p=m_obj.points[idx];
00152                                 r=p.r; g=p.g; b=p.b;
00153                         }
00154                         /** Set RGBu8 coordinates of i'th point */
00155                         inline void setPointRGBu8(const size_t idx,const uint8_t r,const uint8_t g,const uint8_t b) {
00156                                 pcl::PointXYZRGB &p=m_obj.points[idx];
00157                                 p.r=r; p.g=g; p.b=b;
00158                         }
00159 
00160                 }; // end of mrpt::utils::PointCloudAdapter<pcl::PointCloud<pcl::PointXYZRGB> >
00161 
00162         }
00163 } // End of namespace
00164 
00165 #endif



Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 Hosted on:
SourceForge.net Logo