Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
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
1 change: 1 addition & 0 deletions common/include/pcl/common/impl/accumulators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#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>
Expand Down
1 change: 1 addition & 0 deletions common/include/pcl/common/impl/copy_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#pragma once

#include <pcl/field_traits.h>
#include <pcl/point_types.h>
#include <pcl/type_traits.h>
#include <pcl/for_each_type.h>
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
176 changes: 176 additions & 0 deletions common/include/pcl/field_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2025-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#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>
127 changes: 127 additions & 0 deletions common/include/pcl/impl/field_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2025-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#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