Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

using namespace pcl;

Expand Down
3 changes: 2 additions & 1 deletion benchmarks/filters/voxel_grid.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/pcd_io.h> // for PCDReader
#include <pcl/io/pcd_io.h> // for PCDReader
#include <pcl/point_types.h> // for pcl::PointXYZ

#include <benchmark/benchmark.h>

Expand Down
2 changes: 2 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set(incs
include/pcl/correspondence.h
include/pcl/memory.h
include/pcl/exceptions.h
include/pcl/field_traits.h
include/pcl/pcl_base.h
include/pcl/pcl_exports.h
include/pcl/pcl_macros.h
Expand Down Expand Up @@ -145,6 +146,7 @@ set(common_incs_impl
)

set(impl_incs
include/pcl/impl/field_traits.hpp
include/pcl/impl/pcl_base.hpp
include/pcl/impl/instantiate.hpp
include/pcl/impl/point_types.hpp
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/common/impl/accumulators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
#include <boost/fusion/include/as_vector.hpp>
#include <boost/fusion/include/filter_if.hpp>

#include <pcl/field_traits.h>
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>

namespace pcl
{
Expand Down
3 changes: 2 additions & 1 deletion common/include/pcl/common/impl/copy_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@

#pragma once

#include <pcl/point_types.h>
#include <pcl/field_traits.h>
#include <pcl/type_traits.h>
#include <pcl/for_each_type.h>
#include <pcl/common/concatenate.h>
#include <pcl/common/copy_point.h>

#include <cstring> // for memcpy

namespace pcl
{
Expand Down
1 change: 1 addition & 0 deletions common/include/pcl/common/point_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#pragma once

#include <pcl/field_traits.h>
#include <pcl/point_types.h>

#ifdef _MSC_VER
Expand Down
148 changes: 148 additions & 0 deletions common/include/pcl/field_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2025-, Open Perception Inc.
*
* All rights reserved
*/

#pragma once

#include <type_traits> // for std::enable_if

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<PointT, pcl::fields::curvature>::value;
* \endcode
*
* Example usage at compile-time:
*
* \code
* BOOST_MPL_ASSERT_MSG ((pcl::traits::has_field<PointT, pcl::fields::label>::value),
* POINT_TYPE_SHOULD_HAVE_LABEL_FIELD,
* (PointT));
* \endcode
*/
template <typename PointT, typename Field>
struct has_field;

/** Metafunction to check if a given point type has all given fields. */
template <typename PointT, typename Field>
struct has_all_fields;

/** Metafunction to check if a given point type has any of the given fields. */
template <typename PointT, typename Field>
struct has_any_field;

/** \brief Traits defined for ease of use with common fields
*
* has_<fields to be detected>: struct with `value` datamember defined at compiletime
* has_<fields to be detected>_v: constexpr boolean
* Has<Fields to be detected>: concept modelling name alias for `enable_if`
*/

/** Metafunction to check if a given point type has x and y fields. */
template <typename PointT>
struct has_xy;

template <typename PointT>
constexpr auto has_xy_v = has_xy<PointT>::value;

template <typename PointT>
using HasXY = std::enable_if_t<has_xy_v<PointT>, bool>;

template <typename PointT>
using HasNoXY = std::enable_if_t<!has_xy_v<PointT>, bool>;

/** Metafunction to check if a given point type has x, y, and z fields. */
template <typename PointT>
struct has_xyz;

template <typename PointT>
constexpr auto has_xyz_v = has_xyz<PointT>::value;

template <typename PointT>
using HasXYZ = std::enable_if_t<has_xyz_v<PointT>, bool>;

template <typename PointT>
using HasNoXYZ = std::enable_if_t<!has_xyz_v<PointT>, bool>;

/** Metafunction to check if a given point type has normal_x, normal_y, and
* normal_z fields. */
template <typename PointT>
struct has_normal;

template <typename PointT>
constexpr auto has_normal_v = has_normal<PointT>::value;

template <typename PointT>
using HasNormal = std::enable_if_t<has_normal_v<PointT>, bool>;

template <typename PointT>
using HasNoNormal = std::enable_if_t<!has_normal_v<PointT>, bool>;

/** Metafunction to check if a given point type has curvature field. */
template <typename PointT>
struct has_curvature;

template <typename PointT>
constexpr auto has_curvature_v = has_curvature<PointT>::value;

template <typename PointT>
using HasCurvature = std::enable_if_t<has_curvature_v<PointT>, bool>;

template <typename PointT>
using HasNoCurvature = std::enable_if_t<!has_curvature_v<PointT>, bool>;

/** Metafunction to check if a given point type has intensity field. */
template <typename PointT>
struct has_intensity;

template <typename PointT>
constexpr auto has_intensity_v = has_intensity<PointT>::value;

template <typename PointT>
using HasIntensity = std::enable_if_t<has_intensity_v<PointT>, bool>;

template <typename PointT>
using HasNoIntensity = std::enable_if_t<!has_intensity_v<PointT>, bool>;

/** Metafunction to check if a given point type has either rgb or rgba field. */
template <typename PointT>
struct has_color;

template <typename PointT>
constexpr auto has_color_v = has_color<PointT>::value;

template <typename PointT>
using HasColor = std::enable_if_t<has_color_v<PointT>, bool>;

template <typename PointT>
using HasNoColor = std::enable_if_t<!has_color_v<PointT>, bool>;

/** Metafunction to check if a given point type has label field. */
template <typename PointT>
struct has_label;

template <typename PointT>
constexpr auto has_label_v = has_label<PointT>::value;

template <typename PointT>
using HasLabel = std::enable_if_t<has_label_v<PointT>, bool>;

template <typename PointT>
using HasNoLabel = std::enable_if_t<!has_label_v<PointT>, bool>;

} // namespace traits
} // namespace pcl

#include <pcl/impl/field_traits.hpp>
99 changes: 99 additions & 0 deletions common/include/pcl/impl/field_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2025-, Open Perception Inc.
*
* All rights reserved
*/

#pragma once

#include <pcl/point_struct_traits.h> // for pcl::traits::fieldList

// Forward declarations of common pcl field types
namespace pcl
{
namespace fields
{
struct x;
struct y;
struct z;
struct normal_x;
struct normal_y;
struct normal_z;
struct curvature;
struct intensity;
struct rgb;
struct rgba;
struct label;
} // namespace fields
} // namespace pcl

#include <boost/mpl/and.hpp> // for boost::mpl::and_
#include <boost/mpl/bool.hpp> // for boost::mpl::bool_
#include <boost/mpl/contains.hpp> // for boost::mpl::contains
#include <boost/mpl/fold.hpp> // for boost::mpl::fold
#include <boost/mpl/or.hpp> // for boost::mpl::or_
#include <boost/mpl/placeholders.hpp> // for boost::mpl::_1, boost::mpl::_2
#include <boost/mpl/vector.hpp> // for boost::mpl::vector

namespace pcl
{
namespace traits
{

template <typename PointT, typename Field>
struct has_field : boost::mpl::contains<typename pcl::traits::fieldList<PointT>::type, Field>::type
{ };

template <typename PointT, typename Field>
struct has_all_fields : boost::mpl::fold<Field,
boost::mpl::bool_<true>,
boost::mpl::and_<boost::mpl::_1,
has_field<PointT, boost::mpl::_2> > >::type
{ };

template <typename PointT, typename Field>
struct has_any_field : boost::mpl::fold<Field,
boost::mpl::bool_<false>,
boost::mpl::or_<boost::mpl::_1,
has_field<PointT, boost::mpl::_2> > >::type
{ };

template <typename PointT>
struct has_xy : has_all_fields<PointT, boost::mpl::vector<pcl::fields::x,
pcl::fields::y> >
{ };

template <typename PointT>
struct has_xyz : has_all_fields<PointT, boost::mpl::vector<pcl::fields::x,
pcl::fields::y,
pcl::fields::z> >
{ };

template <typename PointT>
struct has_normal : has_all_fields<PointT, boost::mpl::vector<pcl::fields::normal_x,
pcl::fields::normal_y,
pcl::fields::normal_z> >
{ };

template <typename PointT>
struct has_curvature : has_field<PointT, pcl::fields::curvature>
{ };

template <typename PointT>
struct has_intensity : has_field<PointT, pcl::fields::intensity>
{ };

template <typename PointT>
struct has_color : has_any_field<PointT, boost::mpl::vector<pcl::fields::rgb,
pcl::fields::rgba> >
{ };

template <typename PointT>
struct has_label : has_field<PointT, pcl::fields::label>
{ };

} // namespace traits
} // namespace pcl
Loading