Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new color traits in point_types.hpp #4761

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
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 @@ -136,7 +136,7 @@ namespace pcl
{

// Requires that point type has rgb or rgba field
using IsCompatible = pcl::traits::has_color<boost::mpl::_1>;
using IsCompatible = pcl::traits::has_rgb<boost::mpl::_1>;

// Storage
float r = 0, g = 0, b = 0, a = 0;
Expand Down
4 changes: 2 additions & 2 deletions common/include/pcl/common/impl/copy_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ struct CopyPointHelper<PointInT, PointOutT, std::enable_if_t<std::is_same<PointI
template <typename PointInT, typename PointOutT>
struct CopyPointHelper<PointInT, PointOutT,
std::enable_if_t<boost::mpl::and_<boost::mpl::not_<std::is_same<PointInT, PointOutT>>,
boost::mpl::or_<boost::mpl::not_<pcl::traits::has_color<PointInT>>,
boost::mpl::not_<pcl::traits::has_color<PointOutT>>,
boost::mpl::or_<boost::mpl::not_<pcl::traits::has_rgb<PointInT>>,
boost::mpl::not_<pcl::traits::has_rgb<PointOutT>>,
boost::mpl::and_<pcl::traits::has_field<PointInT, pcl::fields::rgb>,
pcl::traits::has_field<PointOutT, pcl::fields::rgb>>,
boost::mpl::and_<pcl::traits::has_field<PointInT, pcl::fields::rgba>,
Expand Down
75 changes: 70 additions & 5 deletions common/include/pcl/impl/point_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2402,20 +2402,85 @@ namespace traits
template <typename PointT>
using HasNoIntensity = std::enable_if_t<!has_intensity_v<PointT>, bool>;

/** Metafunction to check if a given point type has L*a*b* fields. */
template <typename PointT>
struct has_Lab : has_all_fields<PointT, boost::mpl::vector<pcl::fields::L,
pcl::fields::a,
pcl::fields::b> >
{ };

template <typename PointT>
constexpr auto has_Lab_v = has_Lab<PointT>::value;

template <typename PointT>
using HasLab = std::enable_if_t<has_Lab_v<PointT>, bool>;

template <typename PointT>
using HasNoLab = std::enable_if_t<!has_Lab_v<PointT>, bool>;

/** Metafunction to check if a given point type has HSV color space fields. */
template <typename PointT>
struct has_HSV : has_all_fields<PointT, boost::mpl::vector<pcl::fields::h,
pcl::fields::s,
pcl::fields::v> >
{ };

template <typename PointT>
constexpr auto has_HSV_v = has_HSV<PointT>::value;

template <typename PointT>
using HasHSV = std::enable_if_t<has_HSV_v<PointT>, bool>;

template <typename PointT>
using HasNoHSV = std::enable_if_t<!has_HSV_v<PointT>, bool>;

/** Metafunction to check if a given point type has either rgb or rgba field. */
template <typename PointT>
struct has_color : has_any_field<PointT, boost::mpl::vector<pcl::fields::rgb,
pcl::fields::rgba> >
struct has_rgb : has_any_field<PointT, boost::mpl::vector<pcl::fields::rgb,
pcl::fields::rgba> >
{ };

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

template <typename PointT>
using HasRGB = std::enable_if_t<has_rgb_v<PointT>, bool>;

template <typename PointT>
using HasNoRGB = std::enable_if_t<!has_rgb_v<PointT>, bool>;

/** Metafunction to check if a given point type has any color (e.g. rgb, rgba, hsv, lab) field. */
template <typename PointT>
constexpr auto has_any_color_v = has_rgb_v<PointT> || has_HSV_v<PointT> || has_Lab_v<PointT> || has_intensity_v<PointT>;

template <typename PointT>
using HasAnyColor = std::enable_if_t<has_any_color_v<PointT>, bool>;

// There should be a `HasNoAnyColor` implementation which exactly means no color fields in point types,
// but the name seems to be obscure, so we decide to change the behavior of `HasNoColor` for this purpose
// as soon as the deprecation of `has_color` families in PCL 1.15.
// See here: https://github.com/PointCloudLibrary/pcl/pull/4761#discussion_r646427755
kunaltyagi marked this conversation as resolved.
Show resolved Hide resolved

/** Deprecated: Metafunction to check if a given point type has either rgb or rgba field. */
/*
Deprecations contain has_color, has_color_v, HasColor, HasNoColor. And they will be
removed in PCL 1.15. Please use has_rgb, has_rgb_v, HasRGB, HasNoRGB respectively.
*/
template <typename PointT>
using has_color PCL_DEPRECATED(1, 15, "Please use has_rgb instead.")
= has_rgb<PointT>;

template <typename PointT>
PCL_DEPRECATED(1, 15, "Please use has_rgb_v instead.")
constexpr auto has_color_v = has_rgb<PointT>::value;

template <typename PointT>
using HasColor = std::enable_if_t<has_color_v<PointT>, bool>;
using HasColor PCL_DEPRECATED(1, 15, "Please use HasRGB instead.")
= HasRGB<PointT>;

template <typename PointT>
using HasNoColor = std::enable_if_t<!has_color_v<PointT>, bool>;
using HasNoColor PCL_DEPRECATED(1, 15, "Please use HasNoRGB instead.")
ueqri marked this conversation as resolved.
Show resolved Hide resolved
= HasNoRGB<PointT>;

/** Metafunction to check if a given point type has label field. */
template <typename PointT>
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/point_types_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace pcl
* \param[in] in the input XYZRGB(XYZRGBA, XYZRGBL, etc.) point
* \param[out] out the output XYZLAB point
*/
template <typename PointT, traits::HasColor<PointT> = true>
template <typename PointT, traits::HasRGB<PointT> = true>
inline void
PointXYZRGBtoXYZLAB (const PointT& in,
PointXYZLAB& out)
Expand Down
58 changes: 58 additions & 0 deletions test/common/test_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,74 @@ TEST (TypeTraits, HasIntensity)
"has_intensity<> should detect intensity field");
}

TEST (TypeTraits, HasLab)
{
static_assert(!pcl::traits::has_Lab_v<pcl::PointXYZ>,
"has_Lab<> should detect lack of CIELAB field");
static_assert(!pcl::traits::has_Lab_v<pcl::PointXYZRGB>,
"has_Lab<> should detect lack of CIELAB field");
static_assert(!pcl::traits::has_Lab_v<pcl::PointXYZHSV>,
"has_Lab<> should detect lack of CIELAB field");
static_assert(pcl::traits::has_Lab_v<pcl::PointXYZLAB>,
"has_Lab<> should detect CIELAB field");
}

TEST (TypeTraits, HasHSV)
{
static_assert(!pcl::traits::has_HSV_v<pcl::PointXYZ>,
"has_HSV<> should detect lack of HSV field");
static_assert(!pcl::traits::has_HSV_v<pcl::PointXYZRGB>,
"has_HSV<> should detect lack of HSV field");
static_assert(!pcl::traits::has_HSV_v<pcl::PointXYZLAB>,
"has_HSV<> should detect lack of HSV field");
static_assert(pcl::traits::has_HSV_v<pcl::PointXYZHSV>,
"has_HSV<> should detect HSV field");
}

TEST (TypeTraits, HasColor)
{
static_assert(!pcl::traits::has_color_v<pcl::PointXYZ>,
"has_color<> should detect lack of rgb field");
static_assert(!pcl::traits::has_color_v<pcl::PointXYZLAB>,
"has_color<> should detect lack of rgb field");
static_assert(!pcl::traits::has_color_v<pcl::PointXYZHSV>,
"has_color<> should detect lack of rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGB>,
"has_color<> should detect rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGBA>,
"has_color<> should detect rgb field");
}

TEST (TypeTraits, HasRGB)
{
static_assert(!pcl::traits::has_rgb_v<pcl::PointXYZ>,
"has_rgb<> should detect lack of rgb field");
static_assert(!pcl::traits::has_rgb_v<pcl::PointXYZLAB>,
"has_rgb<> should detect lack of rgb field");
static_assert(!pcl::traits::has_rgb_v<pcl::PointXYZHSV>,
"has_rgb<> should detect lack of rgb field");
static_assert(pcl::traits::has_rgb_v<pcl::PointXYZRGB>,
"has_rgb<> should detect rgb field");
static_assert(pcl::traits::has_rgb_v<pcl::PointXYZRGBA>,
"has_rgb<> should detect rgb field");
}

TEST (TypeTraits, HasAnyColor)
{
static_assert(!pcl::traits::has_any_color_v<pcl::PointXYZ>,
"has_any_color<> should detect lack of color field");
static_assert(pcl::traits::has_any_color_v<pcl::PointXYZLAB>,
"has_any_color<> should detect color field");
static_assert(pcl::traits::has_any_color_v<pcl::PointXYZHSV>,
"has_any_color<> should detect color field");
static_assert(pcl::traits::has_any_color_v<pcl::PointXYZRGB>,
"has_any_color<> should detect color field");
static_assert(pcl::traits::has_any_color_v<pcl::PointXYZRGBA>,
"has_any_color<> should detect color field");
static_assert(pcl::traits::has_any_color_v<pcl::PointXYZI>,
"has_any_color<> should detect color field");
}

TEST (TypeTraits, HasLabel)
{
static_assert(!pcl::traits::has_label_v<pcl::PointXYZRGB>,
Expand Down
2 changes: 1 addition & 1 deletion tools/real_sense_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class RealSenseViewer
print_info (" Hz ");
print_value ("%dx%d ", mode.depth_width, mode.depth_height);
print_info ("Depth");
if (pcl::traits::has_color<PointT>::value)
if (pcl::traits::has_rgb<PointT>::value)
{
print_value (" %dx%d ", mode.color_width, mode.color_height);
print_info ("Color");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pcl::visualization::PCLVisualizer::addPointCloud (
return (false);
}

if (pcl::traits::has_color<PointT>())
if (pcl::traits::has_rgb<PointT>())
{
PointCloudColorHandlerRGBField<PointT> color_handler_rgb_field (cloud);
return (fromHandlersToScreen (geometry_handler, color_handler_rgb_field, id, viewport, cloud->sensor_origin_, cloud->sensor_orientation_));
Expand Down