Point Cloud Library (PCL)  1.15.1-dev
field_traits.hpp
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 <pcl/point_struct_traits.h> // for pcl::traits::fieldList
13 
14 // Forward declarations of common pcl field types
15 namespace pcl
16 {
17 namespace fields
18 {
19 struct x;
20 struct y;
21 struct z;
22 struct normal_x;
23 struct normal_y;
24 struct normal_z;
25 struct curvature;
26 struct intensity;
27 struct rgb;
28 struct rgba;
29 struct label;
30 } // namespace fields
31 } // namespace pcl
32 
33 #include <boost/mpl/and.hpp> // for boost::mpl::and_
34 #include <boost/mpl/bool.hpp> // for boost::mpl::bool_
35 #include <boost/mpl/contains.hpp> // for boost::mpl::contains
36 #include <boost/mpl/fold.hpp> // for boost::mpl::fold
37 #include <boost/mpl/or.hpp> // for boost::mpl::or_
38 #include <boost/mpl/placeholders.hpp> // for boost::mpl::_1, boost::mpl::_2
39 #include <boost/mpl/vector.hpp> // for boost::mpl::vector
40 
41 namespace pcl
42 {
43 namespace traits
44 {
45 
46 template <typename PointT, typename Field>
47 struct has_field : boost::mpl::contains<typename pcl::traits::fieldList<PointT>::type, Field>::type
48 { };
49 
50 template <typename PointT, typename Field>
51 struct has_all_fields : boost::mpl::fold<Field,
52  boost::mpl::bool_<true>,
53  boost::mpl::and_<boost::mpl::_1,
54  has_field<PointT, boost::mpl::_2> > >::type
55 { };
56 
57 template <typename PointT, typename Field>
58 struct has_any_field : boost::mpl::fold<Field,
59  boost::mpl::bool_<false>,
60  boost::mpl::or_<boost::mpl::_1,
61  has_field<PointT, boost::mpl::_2> > >::type
62 { };
63 
64 template <typename PointT>
65 struct has_xy : has_all_fields<PointT, boost::mpl::vector<pcl::fields::x,
66  pcl::fields::y> >
67 { };
68 
69 template <typename PointT>
70 struct has_xyz : has_all_fields<PointT, boost::mpl::vector<pcl::fields::x,
71  pcl::fields::y,
72  pcl::fields::z> >
73 { };
74 
75 template <typename PointT>
76 struct has_normal : has_all_fields<PointT, boost::mpl::vector<pcl::fields::normal_x,
77  pcl::fields::normal_y,
78  pcl::fields::normal_z> >
79 { };
80 
81 template <typename PointT>
82 struct has_curvature : has_field<PointT, pcl::fields::curvature>
83 { };
84 
85 template <typename PointT>
86 struct has_intensity : has_field<PointT, pcl::fields::intensity>
87 { };
88 
89 template <typename PointT>
90 struct has_color : has_any_field<PointT, boost::mpl::vector<pcl::fields::rgb,
91  pcl::fields::rgba> >
92 { };
93 
94 template <typename PointT>
95 struct has_label : has_field<PointT, pcl::fields::label>
96 { };
97 
98 } // namespace traits
99 } // namespace pcl
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.