|
| 1 | +/* |
| 2 | +* SPDX-License-Identifier: BSD-3-Clause |
| 3 | +* |
| 4 | +* Point Cloud Library (PCL) - www.pointclouds.org |
| 5 | +* Copyright (c) 2025-, Open Perception Inc. |
| 6 | +* |
| 7 | +* All rights reserved |
| 8 | +*/ |
| 9 | + |
| 10 | +#pragma once |
| 11 | + |
| 12 | +#include <type_traits> // for std::enable_if |
| 13 | + |
| 14 | +namespace pcl |
| 15 | +{ |
| 16 | +namespace traits |
| 17 | +{ |
| 18 | + |
| 19 | +/** \brief Metafunction to check if a given point type has a given field. |
| 20 | + * |
| 21 | + * Example usage at run-time: |
| 22 | + * |
| 23 | + * \code |
| 24 | + * bool curvature_available = pcl::traits::has_field<PointT, pcl::fields::curvature>::value; |
| 25 | + * \endcode |
| 26 | + * |
| 27 | + * Example usage at compile-time: |
| 28 | + * |
| 29 | + * \code |
| 30 | + * BOOST_MPL_ASSERT_MSG ((pcl::traits::has_field<PointT, pcl::fields::label>::value), |
| 31 | + * POINT_TYPE_SHOULD_HAVE_LABEL_FIELD, |
| 32 | + * (PointT)); |
| 33 | + * \endcode |
| 34 | + */ |
| 35 | +template <typename PointT, typename Field> |
| 36 | +struct has_field; |
| 37 | + |
| 38 | +/** Metafunction to check if a given point type has all given fields. */ |
| 39 | +template <typename PointT, typename Field> |
| 40 | +struct has_all_fields; |
| 41 | + |
| 42 | +/** Metafunction to check if a given point type has any of the given fields. */ |
| 43 | +template <typename PointT, typename Field> |
| 44 | +struct has_any_field; |
| 45 | + |
| 46 | +/** \brief Traits defined for ease of use with common fields |
| 47 | + * |
| 48 | + * has_<fields to be detected>: struct with `value` datamember defined at compiletime |
| 49 | + * has_<fields to be detected>_v: constexpr boolean |
| 50 | + * Has<Fields to be detected>: concept modelling name alias for `enable_if` |
| 51 | + */ |
| 52 | + |
| 53 | +/** Metafunction to check if a given point type has x and y fields. */ |
| 54 | +template <typename PointT> |
| 55 | +struct has_xy; |
| 56 | + |
| 57 | +template <typename PointT> |
| 58 | +constexpr auto has_xy_v = has_xy<PointT>::value; |
| 59 | + |
| 60 | +template <typename PointT> |
| 61 | +using HasXY = std::enable_if_t<has_xy_v<PointT>, bool>; |
| 62 | + |
| 63 | +template <typename PointT> |
| 64 | +using HasNoXY = std::enable_if_t<!has_xy_v<PointT>, bool>; |
| 65 | + |
| 66 | +/** Metafunction to check if a given point type has x, y, and z fields. */ |
| 67 | +template <typename PointT> |
| 68 | +struct has_xyz; |
| 69 | + |
| 70 | +template <typename PointT> |
| 71 | +constexpr auto has_xyz_v = has_xyz<PointT>::value; |
| 72 | + |
| 73 | +template <typename PointT> |
| 74 | +using HasXYZ = std::enable_if_t<has_xyz_v<PointT>, bool>; |
| 75 | + |
| 76 | +template <typename PointT> |
| 77 | +using HasNoXYZ = std::enable_if_t<!has_xyz_v<PointT>, bool>; |
| 78 | + |
| 79 | +/** Metafunction to check if a given point type has normal_x, normal_y, and |
| 80 | + * normal_z fields. */ |
| 81 | +template <typename PointT> |
| 82 | +struct has_normal; |
| 83 | + |
| 84 | +template <typename PointT> |
| 85 | +constexpr auto has_normal_v = has_normal<PointT>::value; |
| 86 | + |
| 87 | +template <typename PointT> |
| 88 | +using HasNormal = std::enable_if_t<has_normal_v<PointT>, bool>; |
| 89 | + |
| 90 | +template <typename PointT> |
| 91 | +using HasNoNormal = std::enable_if_t<!has_normal_v<PointT>, bool>; |
| 92 | + |
| 93 | +/** Metafunction to check if a given point type has curvature field. */ |
| 94 | +template <typename PointT> |
| 95 | +struct has_curvature; |
| 96 | + |
| 97 | +template <typename PointT> |
| 98 | +constexpr auto has_curvature_v = has_curvature<PointT>::value; |
| 99 | + |
| 100 | +template <typename PointT> |
| 101 | +using HasCurvature = std::enable_if_t<has_curvature_v<PointT>, bool>; |
| 102 | + |
| 103 | +template <typename PointT> |
| 104 | +using HasNoCurvature = std::enable_if_t<!has_curvature_v<PointT>, bool>; |
| 105 | + |
| 106 | +/** Metafunction to check if a given point type has intensity field. */ |
| 107 | +template <typename PointT> |
| 108 | +struct has_intensity; |
| 109 | + |
| 110 | +template <typename PointT> |
| 111 | +constexpr auto has_intensity_v = has_intensity<PointT>::value; |
| 112 | + |
| 113 | +template <typename PointT> |
| 114 | +using HasIntensity = std::enable_if_t<has_intensity_v<PointT>, bool>; |
| 115 | + |
| 116 | +template <typename PointT> |
| 117 | +using HasNoIntensity = std::enable_if_t<!has_intensity_v<PointT>, bool>; |
| 118 | + |
| 119 | +/** Metafunction to check if a given point type has either rgb or rgba field. */ |
| 120 | +template <typename PointT> |
| 121 | +struct has_color; |
| 122 | + |
| 123 | +template <typename PointT> |
| 124 | +constexpr auto has_color_v = has_color<PointT>::value; |
| 125 | + |
| 126 | +template <typename PointT> |
| 127 | +using HasColor = std::enable_if_t<has_color_v<PointT>, bool>; |
| 128 | + |
| 129 | +template <typename PointT> |
| 130 | +using HasNoColor = std::enable_if_t<!has_color_v<PointT>, bool>; |
| 131 | + |
| 132 | +/** Metafunction to check if a given point type has label field. */ |
| 133 | +template <typename PointT> |
| 134 | +struct has_label; |
| 135 | + |
| 136 | +template <typename PointT> |
| 137 | +constexpr auto has_label_v = has_label<PointT>::value; |
| 138 | + |
| 139 | +template <typename PointT> |
| 140 | +using HasLabel = std::enable_if_t<has_label_v<PointT>, bool>; |
| 141 | + |
| 142 | +template <typename PointT> |
| 143 | +using HasNoLabel = std::enable_if_t<!has_label_v<PointT>, bool>; |
| 144 | + |
| 145 | +} // namespace traits |
| 146 | +} // namespace pcl |
| 147 | + |
| 148 | +#include <pcl/impl/field_traits.hpp> |
0 commit comments