Skip to content

Commit 1dd5b3f

Browse files
authored
Split point_types.hpp part into field_traits.(h|hpp) (#6375)
* Split `point_types.hpp` part into `field_traits.(h|hpp)` * Move `(H|h)as_` traits from `point_types.hpp` into `field_traits.(h|hpp)` * Add `field_traits.h` include where field traits are used * Change a MSVC compiler warning reset via `#pragma warning((push|pop))` * Add `field_traits.h` include in `point_types.h` for backward compatibility Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Fix changes according to clang-format Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Remove blank lines between namespace declarations in `field_traits.hpp` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Optimize some imports related to `pcl/point_types.h` * Remove unnecessary `pcl/point_types.h` includes in some files * Add missing `pcl/point_types.h` includes in some files Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Change license description in `pcl/field_traits.(h|hpp)` * Change license description in `pcl/field_traits.(h|hpp)` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Add missing `pcl/point_types.h` includes in `examples` * Add missing `pcl/point_types.h` includes in `examples` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Add missing `pcl/point_types.h` includes in some files * Add missing `pcl/point_types.h` includes in some files Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Add missing `cstring` include in `pcl/common/impl/copy_point.hpp` Add missing `cstring` include in `common/include/pcl/common/impl/copy_point.hpp` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Move 4661 MSVC warning configuration to CMake * Add 4661 MSVC warning configuration in CMake * Remove 4661 MSVC warning configuration from `pcl_macros.h` * Remove unused `type_traits` include from `point_types.hpp` * Use `Eigen::Map` in `boundary.h` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Move 4244 and 4267 MSVC warnings configuration to CMake * Add 4244 and 4267 MSVC warnings configuration in CMake * Remove 4244 and 4267 MSVC warnings configuration from `pcl_macros.h` Signed-off-by: Ramir Sultanov <sumir0@proton.me> * Use `Eigen/Core` in `rift.hpp` * Use `Eigen::Map` in `rift.hpp` * Add missing `pcl/point_types.h` includes in tests where `rift.h` is used Signed-off-by: Ramir Sultanov <sumir0@proton.me> --------- Signed-off-by: Ramir Sultanov <sumir0@proton.me>
1 parent 6077bbf commit 1dd5b3f

90 files changed

Lines changed: 360 additions & 188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ if(CMAKE_COMPILER_IS_MSVC)
187187
# /MANIFEST:NO") # please, don't disable manifest generation, otherwise crash at start for vs2008
188188

189189
# Disable some warnings
190-
string(APPEND CMAKE_CXX_FLAGS " /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355")
190+
# 4244 : conversion from 'type1' to 'type2', possible loss of data
191+
# 4661 : no suitable definition provided for explicit template instantiation request
192+
string(APPEND CMAKE_CXX_FLAGS " /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 /wd4244 /wd4267 /wd4661")
191193

192194
# Enable warnings, which are disabled by default (see https://learn.microsoft.com/de-de/cpp/preprocessor/compiler-warnings-that-are-off-by-default)
193195
string(APPEND CMAKE_CXX_FLAGS " /w34265")

apps/src/statistical_multiscale_interest_region_extraction_example.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <pcl/filters/extract_indices.h>
4040
#include <pcl/filters/voxel_grid.h>
4141
#include <pcl/io/pcd_io.h>
42+
#include <pcl/point_types.h>
4243

4344
using namespace pcl;
4445

benchmarks/filters/voxel_grid.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <pcl/filters/approximate_voxel_grid.h>
22
#include <pcl/filters/voxel_grid.h>
3-
#include <pcl/io/pcd_io.h> // for PCDReader
3+
#include <pcl/io/pcd_io.h> // for PCDReader
4+
#include <pcl/point_types.h> // for pcl::PointXYZ
45

56
#include <benchmark/benchmark.h>
67

common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ set(incs
5353
include/pcl/correspondence.h
5454
include/pcl/memory.h
5555
include/pcl/exceptions.h
56+
include/pcl/field_traits.h
5657
include/pcl/pcl_base.h
5758
include/pcl/pcl_exports.h
5859
include/pcl/pcl_macros.h
@@ -145,6 +146,7 @@ set(common_incs_impl
145146
)
146147

147148
set(impl_incs
149+
include/pcl/impl/field_traits.hpp
148150
include/pcl/impl/pcl_base.hpp
149151
include/pcl/impl/instantiate.hpp
150152
include/pcl/impl/point_types.hpp

common/include/pcl/common/impl/accumulators.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
#include <boost/fusion/include/as_vector.hpp>
4747
#include <boost/fusion/include/filter_if.hpp>
4848

49+
#include <pcl/field_traits.h>
4950
#include <pcl/memory.h>
5051
#include <pcl/pcl_macros.h>
51-
#include <pcl/point_types.h>
5252

5353
namespace pcl
5454
{

common/include/pcl/common/impl/copy_point.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737

3838
#pragma once
3939

40-
#include <pcl/point_types.h>
40+
#include <pcl/field_traits.h>
4141
#include <pcl/type_traits.h>
4242
#include <pcl/for_each_type.h>
4343
#include <pcl/common/concatenate.h>
4444
#include <pcl/common/copy_point.h>
4545

46+
#include <cstring> // for memcpy
4647

4748
namespace pcl
4849
{

common/include/pcl/common/point_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#pragma once
4141

42+
#include <pcl/field_traits.h>
4243
#include <pcl/point_types.h>
4344

4445
#ifdef _MSC_VER

common/include/pcl/field_traits.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

0 commit comments

Comments
 (0)