diff --git a/common/include/pcl/point_types.h b/common/include/pcl/point_types.h index 5e26eb8f0a4..7f5d74436b8 100644 --- a/common/include/pcl/point_types.h +++ b/common/include/pcl/point_types.h @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include /** * \file pcl/point_types.h @@ -666,6 +669,79 @@ namespace pcl } } }; + + namespace traits + { + + /** \brief Metafunction to check if a given point type has a given field. + * + * Example usage at run-time: + * + * \code + * bool curvature_available = pcl::traits::has_field::value; + * \endcode + * + * Example usage at compile-time: + * + * \code + * BOOST_MPL_ASSERT_MSG ((pcl::traits::has_field::value), + * POINT_TYPE_SHOULD_HAVE_LABEL_FIELD, + * (PointT)); + * \endcode + */ + template + struct has_field : boost::mpl::contains::type, Field>::type + { }; + + /** Metafunction to check if a given point type has all given fields. */ + template + struct has_all_fields : boost::mpl::fold, + boost::mpl::and_ > >::type + { }; + + /** Metafunction to check if a given point type has any of the given fields. */ + template + struct has_any_field : boost::mpl::fold, + boost::mpl::or_ > >::type + { }; + + /** Metafunction to check if a given point type has x, y, and z fields. */ + template + struct has_xyz : has_all_fields > + { }; + + /** Metafunction to check if a given point type has normal_x, normal_y, and + * normal_z fields. */ + template + struct has_normal : has_all_fields > + { }; + + /** Metafunction to check if a given point type has curvature field. */ + template + struct has_curvature : has_field + { }; + + /** Metafunction to check if a given point type has either rgb or rgba field. */ + template + struct has_color : has_any_field > + { }; + + /** Metafunction to check if a given point type has label field. */ + template + struct has_label : has_field + { }; + + } + } // namespace pcl #if defined _MSC_VER diff --git a/test/common/test_common.cpp b/test/common/test_common.cpp index aef71f02d7e..9444fe74a27 100644 --- a/test/common/test_common.cpp +++ b/test/common/test_common.cpp @@ -1140,6 +1140,37 @@ TEST (PCL, IsSamePointType) EXPECT_FALSE (status); } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TEST (PCL, HasField) +{ + // has_field + EXPECT_TRUE ((pcl::traits::has_field::value)); + EXPECT_FALSE ((pcl::traits::has_field::value)); + // has_all_fields + EXPECT_TRUE ((pcl::traits::has_all_fields >::value)); + EXPECT_FALSE ((pcl::traits::has_all_fields >::value)); + // has_any_field + EXPECT_TRUE ((pcl::traits::has_any_field >::value)); + EXPECT_TRUE ((pcl::traits::has_any_field >::value)); + EXPECT_FALSE ((pcl::traits::has_any_field >::value)); + // has_xyz + EXPECT_TRUE ((pcl::traits::has_xyz::value)); + EXPECT_FALSE ((pcl::traits::has_xyz::value)); + // has_normal + EXPECT_TRUE ((pcl::traits::has_normal::value)); + EXPECT_FALSE ((pcl::traits::has_normal::value)); + // has_curvature + EXPECT_TRUE ((pcl::traits::has_curvature::value)); + EXPECT_FALSE ((pcl::traits::has_curvature::value)); + // has_color + EXPECT_TRUE ((pcl::traits::has_color::value)); + EXPECT_TRUE ((pcl::traits::has_color::value)); + EXPECT_FALSE ((pcl::traits::has_color::value)); + // has_label + EXPECT_TRUE ((pcl::traits::has_label::value)); + EXPECT_FALSE ((pcl::traits::has_label::value)); +} + /* ---[ */ int main (int argc, char** argv)