Point Cloud Library (PCL)  1.15.1-dev
field_traits.h
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>
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>
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>
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>
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>
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>
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>
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>
constexpr auto has_xyz_v
Definition: field_traits.h:71
std::enable_if_t< has_curvature_v< PointT >, bool > HasCurvature
Definition: field_traits.h:101
std::enable_if_t< has_normal_v< PointT >, bool > HasNormal
Definition: field_traits.h:88
std::enable_if_t< has_intensity_v< PointT >, bool > HasIntensity
Definition: field_traits.h:114
constexpr auto has_xy_v
Definition: field_traits.h:58
std::enable_if_t< has_color_v< PointT >, bool > HasColor
Definition: field_traits.h:127
std::enable_if_t<!has_normal_v< PointT >, bool > HasNoNormal
Definition: field_traits.h:91
constexpr auto has_label_v
Definition: field_traits.h:137
constexpr auto has_color_v
Definition: field_traits.h:124
constexpr auto has_intensity_v
Definition: field_traits.h:111
std::enable_if_t<!has_xyz_v< PointT >, bool > HasNoXYZ
Definition: field_traits.h:77
std::enable_if_t<!has_intensity_v< PointT >, bool > HasNoIntensity
Definition: field_traits.h:117
std::enable_if_t< has_xyz_v< PointT >, bool > HasXYZ
Definition: field_traits.h:74
std::enable_if_t<!has_curvature_v< PointT >, bool > HasNoCurvature
Definition: field_traits.h:104
std::enable_if_t<!has_color_v< PointT >, bool > HasNoColor
Definition: field_traits.h:130
std::enable_if_t<!has_xy_v< PointT >, bool > HasNoXY
Definition: field_traits.h:64
std::enable_if_t<!has_label_v< PointT >, bool > HasNoLabel
Definition: field_traits.h:143
constexpr auto has_curvature_v
Definition: field_traits.h:98
std::enable_if_t< has_xy_v< PointT >, bool > HasXY
Definition: field_traits.h:61
std::enable_if_t< has_label_v< PointT >, bool > HasLabel
Definition: field_traits.h:140
constexpr auto has_normal_v
Definition: field_traits.h:85
Metafunction to check if a given point type has all given fields.
Metafunction to check if a given point type has any of the given fields.
Metafunction to check if a given point type has either rgb or rgba field.
Metafunction to check if a given point type has curvature field.
Metafunction to check if a given point type has a given field.
Metafunction to check if a given point type has intensity field.
Metafunction to check if a given point type has label field.
Metafunction to check if a given point type has normal_x, normal_y, and normal_z fields.
Traits defined for ease of use with common fields.
Metafunction to check if a given point type has x, y, and z fields.