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

Add getRGBVector3i() to every point type with RGB #450

Merged
Merged
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
110 changes: 45 additions & 65 deletions common/include/pcl/impl/point_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@
namespace pcl
{

#define PCL_ADD_POINT4D \
#define PCL_ADD_UNION_POINT4D \
union EIGEN_ALIGN16 { \
float data[4]; \
struct { \
float x; \
float y; \
float z; \
}; \
}; \
};

#define PCL_ADD_EIGEN_MAPS_POINT4D \
inline Eigen::Map<Eigen::Vector3f> getVector3fMap () { return (Eigen::Vector3f::Map (data)); } \
inline const Eigen::Map<const Eigen::Vector3f> getVector3fMap () const { return (Eigen::Vector3f::Map (data)); } \
inline Eigen::Map<Eigen::Vector4f, Eigen::Aligned> getVector4fMap () { return (Eigen::Vector4f::MapAligned (data)); } \
Expand All @@ -163,7 +165,11 @@ namespace pcl
inline Eigen::Map<Eigen::Array4f, Eigen::Aligned> getArray4fMap () { return (Eigen::Array4f::MapAligned (data)); } \
inline const Eigen::Map<const Eigen::Array4f, Eigen::Aligned> getArray4fMap () const { return (Eigen::Array4f::MapAligned (data)); }

#define PCL_ADD_NORMAL4D \
#define PCL_ADD_POINT4D \
PCL_ADD_UNION_POINT4D \
PCL_ADD_EIGEN_MAPS_POINT4D

#define PCL_ADD_UNION_NORMAL4D \
union EIGEN_ALIGN16 { \
float data_n[4]; \
float normal[3]; \
Expand All @@ -172,13 +178,19 @@ namespace pcl
float normal_y; \
float normal_z; \
}; \
}; \
};

#define PCL_ADD_EIGEN_MAPS_NORMAL4D \
inline Eigen::Map<Eigen::Vector3f> getNormalVector3fMap () { return (Eigen::Vector3f::Map (data_n)); } \
inline const Eigen::Map<const Eigen::Vector3f> getNormalVector3fMap () const { return (Eigen::Vector3f::Map (data_n)); } \
inline Eigen::Map<Eigen::Vector4f, Eigen::Aligned> getNormalVector4fMap () { return (Eigen::Vector4f::MapAligned (data_n)); } \
inline const Eigen::Map<const Eigen::Vector4f, Eigen::Aligned> getNormalVector4fMap () const { return (Eigen::Vector4f::MapAligned (data_n)); }

#define PCL_ADD_RGB \
#define PCL_ADD_NORMAL4D \
PCL_ADD_UNION_NORMAL4D \
PCL_ADD_EIGEN_MAPS_NORMAL4D

#define PCL_ADD_UNION_RGB \
union \
{ \
union \
Expand All @@ -195,6 +207,22 @@ namespace pcl
uint32_t rgba; \
};

#define PCL_ADD_EIGEN_MAPS_RGB \
inline Eigen::Vector3i getRGBVector3i () { return (Eigen::Vector3i (r, g, b)); } \
inline const Eigen::Vector3i getRGBVector3i () const { return (Eigen::Vector3i (r, g, b)); } \
inline Eigen::Vector4i getRGBVector4i () { return (Eigen::Vector4i (r, g, b, a)); } \
inline const Eigen::Vector4i getRGBVector4i () const { return (Eigen::Vector4i (r, g, b, a)); } \
inline Eigen::Vector4i getRGBAVector4i () { return (Eigen::Vector4i (r, g, b, a)); } \
inline const Eigen::Vector4i getRGBAVector4i () const { return (Eigen::Vector4i (r, g, b, a)); } \
inline Vector3cMap getBGRVector3cMap () { return (Vector3cMap (reinterpret_cast<uint8_t*> (&rgba))); } \
inline Vector3cMapConst getBGRVector3cMap () const { return (Vector3cMapConst (reinterpret_cast<const uint8_t*> (&rgba))); } \
inline Vector4cMap getBGRAVector4cMap () { return (Vector4cMap (reinterpret_cast<uint8_t*> (&rgba))); } \
inline Vector4cMapConst getBGRAVector4cMap () const { return (Vector4cMapConst (reinterpret_cast<const uint8_t*> (&rgba))); }

#define PCL_ADD_RGB \
PCL_ADD_UNION_RGB \
PCL_ADD_EIGEN_MAPS_RGB

#define PCL_ADD_INTENSITY \
struct \
{ \
Expand Down Expand Up @@ -222,6 +250,13 @@ namespace pcl
typedef Eigen::Map<Eigen::Vector4f, Eigen::Aligned> Vector4fMap;
typedef const Eigen::Map<const Eigen::Vector4f, Eigen::Aligned> Vector4fMapConst;

typedef Eigen::Matrix<uint8_t, 3, 1> Vector3c;
typedef Eigen::Map<Vector3c> Vector3cMap;
typedef const Eigen::Map<const Vector3c> Vector3cMapConst;
typedef Eigen::Matrix<uint8_t, 4, 1> Vector4c;
typedef Eigen::Map<Vector4c, Eigen::Aligned> Vector4cMap;
typedef const Eigen::Map<const Vector4c, Eigen::Aligned> Vector4cMapConst;


struct _PointXYZ
{
Expand Down Expand Up @@ -506,17 +541,7 @@ namespace pcl
r = g = b = 0;
a = 255;
}
inline Eigen::Vector3i getRGBVector3i ()
{
return (Eigen::Vector3i (r, g, b));
}
inline const Eigen::Vector3i getRGBVector3i () const { return (Eigen::Vector3i (r, g, b)); }
inline Eigen::Vector4i getRGBVector4i ()
{
return (Eigen::Vector4i (r, g, b, a));
}
inline const Eigen::Vector4i getRGBVector4i () const { return (Eigen::Vector4i (r, g, b, a)); }


friend std::ostream& operator << (std::ostream& os, const PointXYZRGBA& p);
};

Expand Down Expand Up @@ -592,18 +617,6 @@ namespace pcl
a = 0;
}

inline Eigen::Vector3i getRGBVector3i ()
{
return (Eigen::Vector3i (r, g, b));
}
inline const Eigen::Vector3i getRGBVector3i () const { return (Eigen::Vector3i (r, g, b)); }
inline Eigen::Vector4i getRGBVector4i ()
{
return (Eigen::Vector4i (r, g, b, a));
}
inline const Eigen::Vector4i getRGBVector4i () const { return (Eigen::Vector4i (r, g, b, a)); }


friend std::ostream& operator << (std::ostream& os, const PointXYZRGB& p);
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
Expand Down Expand Up @@ -859,23 +872,12 @@ namespace pcl
{
struct
{
// RGB union
union
{
struct
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
};
float rgb;
uint32_t rgba;
};
PCL_ADD_UNION_RGB;
float curvature;
};
float data_c[4];
};
PCL_ADD_EIGEN_MAPS_RGB;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

Expand Down Expand Up @@ -928,17 +930,6 @@ namespace pcl
curvature = 0;
}

inline Eigen::Vector3i getRGBVector3i ()
{
return (Eigen::Vector3i (r, g, b));
}
inline const Eigen::Vector3i getRGBVector3i () const { return (Eigen::Vector3i (r, g, b)); }
inline Eigen::Vector4i getRGBVector4i ()
{
return (Eigen::Vector4i (r, g, b, a));
}
inline const Eigen::Vector4i getRGBVector4i () const { return (Eigen::Vector4i (r, g, b, a)); }

friend std::ostream& operator << (std::ostream& os, const PointXYZRGBNormal& p);
};

Expand Down Expand Up @@ -1475,25 +1466,14 @@ namespace pcl
{
struct
{
// RGB union
union
{
struct
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
};
float rgb;
uint32_t rgba;
};
PCL_ADD_UNION_RGB;
float radius;
float confidence;
float curvature;
};
float data_c[4];
};
PCL_ADD_EIGEN_MAPS_RGB;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

Expand Down
66 changes: 66 additions & 0 deletions test/common/test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,72 @@ TEST (PCL, PointTypes)
EXPECT_EQ (__alignof (PointXYZRGBNormal), 16);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template <typename T> class XYZPointTypesTest : public ::testing::Test { };
typedef ::testing::Types<BOOST_PP_SEQ_ENUM(PCL_XYZ_POINT_TYPES)> XYZPointTypes;
TYPED_TEST_CASE(XYZPointTypesTest, XYZPointTypes);
TYPED_TEST(XYZPointTypesTest, GetVectorXfMap)
{
TypeParam pt;
for (size_t i = 0; i < 3; ++i)
EXPECT_EQ (&pt.data[i], &pt.getVector3fMap () (i));
for (size_t i = 0; i < 4; ++i)
EXPECT_EQ (&pt.data[i], &pt.getVector4fMap () (i));
}

TYPED_TEST(XYZPointTypesTest, GetArrayXfMap)
{
TypeParam pt;
for (size_t i = 0; i < 3; ++i)
EXPECT_EQ (&pt.data[i], &pt.getArray3fMap () (i));
for (size_t i = 0; i < 4; ++i)
EXPECT_EQ (&pt.data[i], &pt.getArray4fMap () (i));
}

template <typename T> class NormalPointTypesTest : public ::testing::Test { };
typedef ::testing::Types<BOOST_PP_SEQ_ENUM(PCL_NORMAL_POINT_TYPES)> NormalPointTypes;
TYPED_TEST_CASE(NormalPointTypesTest, NormalPointTypes);
TYPED_TEST(NormalPointTypesTest, GetNormalVectorXfMap)
{
TypeParam pt;
for (size_t i = 0; i < 3; ++i)
EXPECT_EQ (&pt.data_n[i], &pt.getNormalVector3fMap () (i));
for (size_t i = 0; i < 4; ++i)
EXPECT_EQ (&pt.data_n[i], &pt.getNormalVector4fMap () (i));
}

template <typename T> class RGBPointTypesTest : public ::testing::Test { };
typedef ::testing::Types<BOOST_PP_SEQ_ENUM(PCL_RGB_POINT_TYPES)> RGBPointTypes;
TYPED_TEST_CASE(RGBPointTypesTest, RGBPointTypes);
TYPED_TEST(RGBPointTypesTest, GetRGBVectorXi)
{
TypeParam pt; pt.r = 1; pt.g = 2; pt.b = 3; pt.a = 4;
EXPECT_EQ (pt.r, pt.getRGBVector3i () (0));
EXPECT_EQ (pt.g, pt.getRGBVector3i () (1));
EXPECT_EQ (pt.b, pt.getRGBVector3i () (2));
EXPECT_EQ (pt.r, pt.getRGBVector4i () (0));
EXPECT_EQ (pt.g, pt.getRGBVector4i () (1));
EXPECT_EQ (pt.b, pt.getRGBVector4i () (2));
EXPECT_EQ (pt.a, pt.getRGBVector4i () (3));
EXPECT_EQ (pt.r, pt.getRGBAVector4i () (0));
EXPECT_EQ (pt.g, pt.getRGBAVector4i () (1));
EXPECT_EQ (pt.b, pt.getRGBAVector4i () (2));
EXPECT_EQ (pt.a, pt.getRGBAVector4i () (3));
}

TYPED_TEST(RGBPointTypesTest, GetBGRVectorXcMap)
{
TypeParam pt;
EXPECT_EQ (&pt.b, &pt.getBGRVector3cMap () (0));
EXPECT_EQ (&pt.g, &pt.getBGRVector3cMap () (1));
EXPECT_EQ (&pt.r, &pt.getBGRVector3cMap () (2));
EXPECT_EQ (&pt.b, &pt.getBGRAVector4cMap () (0));
EXPECT_EQ (&pt.g, &pt.getBGRAVector4cMap () (1));
EXPECT_EQ (&pt.r, &pt.getBGRAVector4cMap () (2));
EXPECT_EQ (&pt.a, &pt.getBGRAVector4cMap () (3));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, Intersections)
{
Expand Down