diff --git a/common/include/pcl/impl/point_types.hpp b/common/include/pcl/impl/point_types.hpp index 9b05cfd5609..1121ca7a2a6 100644 --- a/common/include/pcl/impl/point_types.hpp +++ b/common/include/pcl/impl/point_types.hpp @@ -145,7 +145,7 @@ namespace pcl { -#define PCL_ADD_POINT4D \ +#define PCL_ADD_UNION_POINT4D \ union EIGEN_ALIGN16 { \ float data[4]; \ struct { \ @@ -153,7 +153,9 @@ namespace pcl float y; \ float z; \ }; \ - }; \ + }; + +#define PCL_ADD_EIGEN_MAPS_POINT4D \ inline Eigen::Map getVector3fMap () { return (Eigen::Vector3f::Map (data)); } \ inline const Eigen::Map getVector3fMap () const { return (Eigen::Vector3f::Map (data)); } \ inline Eigen::Map getVector4fMap () { return (Eigen::Vector4f::MapAligned (data)); } \ @@ -163,7 +165,11 @@ namespace pcl inline Eigen::Map getArray4fMap () { return (Eigen::Array4f::MapAligned (data)); } \ inline const Eigen::Map 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]; \ @@ -172,13 +178,19 @@ namespace pcl float normal_y; \ float normal_z; \ }; \ - }; \ + }; + +#define PCL_ADD_EIGEN_MAPS_NORMAL4D \ inline Eigen::Map getNormalVector3fMap () { return (Eigen::Vector3f::Map (data_n)); } \ inline const Eigen::Map getNormalVector3fMap () const { return (Eigen::Vector3f::Map (data_n)); } \ inline Eigen::Map getNormalVector4fMap () { return (Eigen::Vector4f::MapAligned (data_n)); } \ inline const Eigen::Map 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 \ @@ -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 (&rgba))); } \ + inline Vector3cMapConst getBGRVector3cMap () const { return (Vector3cMapConst (reinterpret_cast (&rgba))); } \ + inline Vector4cMap getBGRAVector4cMap () { return (Vector4cMap (reinterpret_cast (&rgba))); } \ + inline Vector4cMapConst getBGRAVector4cMap () const { return (Vector4cMapConst (reinterpret_cast (&rgba))); } + +#define PCL_ADD_RGB \ + PCL_ADD_UNION_RGB \ + PCL_ADD_EIGEN_MAPS_RGB + #define PCL_ADD_INTENSITY \ struct \ { \ @@ -222,6 +250,13 @@ namespace pcl typedef Eigen::Map Vector4fMap; typedef const Eigen::Map Vector4fMapConst; + typedef Eigen::Matrix Vector3c; + typedef Eigen::Map Vector3cMap; + typedef const Eigen::Map Vector3cMapConst; + typedef Eigen::Matrix Vector4c; + typedef Eigen::Map Vector4cMap; + typedef const Eigen::Map Vector4cMapConst; + struct _PointXYZ { @@ -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); }; @@ -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 }; @@ -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 }; @@ -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); }; @@ -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 }; diff --git a/test/common/test_common.cpp b/test/common/test_common.cpp index aef71f02d7e..63b1b2972f4 100644 --- a/test/common/test_common.cpp +++ b/test/common/test_common.cpp @@ -297,6 +297,72 @@ TEST (PCL, PointTypes) EXPECT_EQ (__alignof (PointXYZRGBNormal), 16); } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template class XYZPointTypesTest : public ::testing::Test { }; +typedef ::testing::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 class NormalPointTypesTest : public ::testing::Test { }; +typedef ::testing::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 class RGBPointTypesTest : public ::testing::Test { }; +typedef ::testing::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) {