Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: point_traits.h 1380 2011-06-19 11:34:29Z bouffa $ 00035 * 00036 */ 00037 00038 #ifndef PCL_ROS_POINT_TRAITS_H_ 00039 #define PCL_ROS_POINT_TRAITS_H_ 00040 00041 #include <std_msgs/Header.h> 00042 #include <sensor_msgs/PointField.h> 00043 #include <boost/type_traits/remove_all_extents.hpp> 00044 #include <boost/type_traits/is_same.hpp> 00045 #include <boost/mpl/assert.hpp> 00046 00047 namespace pcl 00048 { 00049 00050 namespace fields 00051 { 00052 // Tag types get put in this namespace 00053 } 00054 00055 namespace traits 00056 { 00057 // Metafunction to return enum value representing a type 00058 template<typename T> struct asEnum {}; 00059 template<> struct asEnum<int8_t> { static const uint8_t value = sensor_msgs::PointField::INT8; }; 00060 template<> struct asEnum<uint8_t> { static const uint8_t value = sensor_msgs::PointField::UINT8; }; 00061 template<> struct asEnum<int16_t> { static const uint8_t value = sensor_msgs::PointField::INT16; }; 00062 template<> struct asEnum<uint16_t> { static const uint8_t value = sensor_msgs::PointField::UINT16; }; 00063 template<> struct asEnum<int32_t> { static const uint8_t value = sensor_msgs::PointField::INT32; }; 00064 template<> struct asEnum<uint32_t> { static const uint8_t value = sensor_msgs::PointField::UINT32; }; 00065 template<> struct asEnum<float> { static const uint8_t value = sensor_msgs::PointField::FLOAT32; }; 00066 template<> struct asEnum<double> { static const uint8_t value = sensor_msgs::PointField::FLOAT64; }; 00067 00068 // Metafunction to return type of enum value 00069 template<int> struct asType {}; 00070 template<> struct asType<sensor_msgs::PointField::INT8> { typedef int8_t type; }; 00071 template<> struct asType<sensor_msgs::PointField::UINT8> { typedef uint8_t type; }; 00072 template<> struct asType<sensor_msgs::PointField::INT16> { typedef int16_t type; }; 00073 template<> struct asType<sensor_msgs::PointField::UINT16> { typedef uint16_t type; }; 00074 template<> struct asType<sensor_msgs::PointField::INT32> { typedef int32_t type; }; 00075 template<> struct asType<sensor_msgs::PointField::UINT32> { typedef uint32_t type; }; 00076 template<> struct asType<sensor_msgs::PointField::FLOAT32> { typedef float type; }; 00077 template<> struct asType<sensor_msgs::PointField::FLOAT64> { typedef double type; }; 00078 00079 // Metafunction to decompose a type (possibly of array of any number of dimensions) into 00080 // its scalar type and total number of elements. 00081 template<typename T> struct decomposeArray 00082 { 00083 typedef typename boost::remove_all_extents<T>::type type; 00084 static const uint32_t value = sizeof(T) / sizeof(type); 00085 }; 00086 00087 // For non-POD point types, this is specialized to return the corresponding POD type. 00088 template<typename PointT> struct POD 00089 { 00090 typedef PointT type; 00091 }; 00092 00093 // name 00094 /* This really only depends on Tag, but we go through some gymnastics to avoid ODR violations. 00095 We template it on the point type PointT to avoid ODR violations when registering multiple 00096 point types with shared tags. 00097 The dummy parameter is so we can partially specialize name on PointT and Tag but leave it 00098 templated on dummy. Each specialization declares a static char array containing the tag 00099 name. The definition of the static member would conflict when linking multiple translation 00100 units that include the point type registration. But when the static member definition is 00101 templated (on dummy), we sidestep the ODR issue. 00102 */ 00103 template<class PointT, typename Tag, int dummy = 0> 00104 struct name : name<typename POD<PointT>::type, Tag, dummy> 00105 { 00106 // Contents of specialization: 00107 // static const char value[]; 00108 00109 // Avoid infinite compile-time recursion 00110 BOOST_MPL_ASSERT_MSG((!boost::is_same<PointT, typename POD<PointT>::type>::value), 00111 POINT_TYPE_NOT_PROPERLY_REGISTERED, (PointT&)); 00112 }; 00113 00114 // offset 00115 template<class PointT, typename Tag> 00116 struct offset : offset<typename POD<PointT>::type, Tag> 00117 { 00118 // Contents of specialization: 00119 // static const size_t value; 00120 00121 // Avoid infinite compile-time recursion 00122 BOOST_MPL_ASSERT_MSG((!boost::is_same<PointT, typename POD<PointT>::type>::value), 00123 POINT_TYPE_NOT_PROPERLY_REGISTERED, (PointT&)); 00124 }; 00125 00126 // datatype 00127 template<class PointT, typename Tag> 00128 struct datatype : datatype<typename POD<PointT>::type, Tag> 00129 { 00130 // Contents of specialization: 00131 // typedef ... type; 00132 // static const uint8_t value; 00133 // static const uint32_t size; 00134 00135 // Avoid infinite compile-time recursion 00136 BOOST_MPL_ASSERT_MSG((!boost::is_same<PointT, typename POD<PointT>::type>::value), 00137 POINT_TYPE_NOT_PROPERLY_REGISTERED, (PointT&)); 00138 }; 00139 00140 // fields 00141 template<typename PointT> 00142 struct fieldList : fieldList<typename POD<PointT>::type> 00143 { 00144 // Contents of specialization: 00145 // typedef boost::mpl::vector<...> type; 00146 00147 // Avoid infinite compile-time recursion 00148 BOOST_MPL_ASSERT_MSG((!boost::is_same<PointT, typename POD<PointT>::type>::value), 00149 POINT_TYPE_NOT_PROPERLY_REGISTERED, (PointT&)); 00150 }; 00151 00152 } //namespace traits 00153 } 00154 00155 #endif //#ifndef PCL_ROS_POINT_TRAITS_H_