helper_testing.cpp
Go to the documentation of this file.
1 // GTest headers
2 #include <gtest/gtest.h>
3 
4 // Local headers
5 #include "alb_helper.h"
6 
8 TEST(AlbHelper, trackedClassIds)
9 {
10  EXPECT_EQ("UNKNOWN", Helper::get_object_class(0));
11  EXPECT_EQ("PERSON", Helper::get_object_class(1));
12  EXPECT_EQ("LUGGAGE", Helper::get_object_class(2));
13  EXPECT_EQ("TROLLEY", Helper::get_object_class(3));
14  EXPECT_EQ("TRUCK", Helper::get_object_class(4));
15  EXPECT_EQ("BUS", Helper::get_object_class(5));
16  EXPECT_EQ("CAR", Helper::get_object_class(6));
17  EXPECT_EQ("VAN", Helper::get_object_class(7));
18  EXPECT_EQ("TWO_WHEELER", Helper::get_object_class(8));
19  EXPECT_EQ("MASK", Helper::get_object_class(9));
20  EXPECT_EQ("NO_MASK", Helper::get_object_class(10));
21 }
22 
24 TEST(AlbHelper, poseOrientation)
25 {
26  // Identity rotation matrix.
27  geometry_msgs::Pose poseI;
28  Helper::define_pose(poseI, { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f });
29 
30  EXPECT_EQ(poseI.orientation.x, 0);
31  EXPECT_EQ(poseI.orientation.y, 0);
32  EXPECT_EQ(poseI.orientation.z, 0);
33  EXPECT_EQ(poseI.orientation.w, 1);
34 
35  // Rotation of +90degrees along X.
36  geometry_msgs::Pose poseX;
37  Helper::define_pose(poseX, { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f });
38 
39  EXPECT_NEAR(poseX.orientation.x, sqrt(2) / 2, 10e-5);
40  EXPECT_EQ(poseX.orientation.y, 0.0f);
41  EXPECT_EQ(poseX.orientation.z, 0.0f);
42  EXPECT_NEAR(poseX.orientation.w, sqrt(2) / 2, 10e-5);
43 
44  // Rotation of +90degrees along Y.
45  geometry_msgs::Pose poseY;
46  Helper::define_pose(poseY, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f });
47 
48  EXPECT_EQ(poseY.orientation.x, 0.0f);
49  EXPECT_NEAR(poseY.orientation.y, sqrt(2) / 2, 10e-5);
50  EXPECT_EQ(poseY.orientation.z, 0.0f);
51  EXPECT_NEAR(poseY.orientation.w, sqrt(2) / 2, 10e-5);
52 
53  // Rotation of +90degrees along Z.
54  geometry_msgs::Pose poseZ;
55  Helper::define_pose(poseZ, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f });
56 
57  EXPECT_EQ(poseZ.orientation.x, 0.0f);
58  EXPECT_EQ(poseZ.orientation.y, 0.0f);
59  EXPECT_NEAR(poseZ.orientation.z, sqrt(2) / 2, 10e-5);
60  EXPECT_NEAR(poseZ.orientation.w, sqrt(2) / 2, 10e-5);
61 }
62 
64 TEST(AlbHelper, unorganizedPointCloudMessage)
65 {
66  float points[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
67 
68  // Test with an unorganized point cloud.
69  sensor_msgs::PointCloud2 pointCloudUnorganized;
70  Helper::define_points_data(pointCloudUnorganized, 0, 2, points, true);
71 
72  EXPECT_EQ(pointCloudUnorganized.width, 2);
73  EXPECT_EQ(pointCloudUnorganized.height, 1);
74  EXPECT_EQ(pointCloudUnorganized.data.size(), 2 * 3 * sizeof(float));
75 
76  float *recast_points = reinterpret_cast<float *>(pointCloudUnorganized.data.data());
77  EXPECT_EQ(recast_points[0], 0.0);
78  EXPECT_EQ(recast_points[1], 1.0);
79  EXPECT_EQ(recast_points[2], 2.0);
80  EXPECT_EQ(recast_points[3], 3.0);
81  EXPECT_EQ(recast_points[4], 4.0);
82  EXPECT_EQ(recast_points[5], 5.0);
83 }
84 
85 TEST(AlbHelper, organizedPointCloudMessage)
86 {
87  float points[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
88 
89  // Test with an organized point cloud.
90  sensor_msgs::PointCloud2 pointCloudOrganized;
91  Helper::define_points_data(pointCloudOrganized, 2, 2, points, true);
92 
93  EXPECT_EQ(pointCloudOrganized.width, 1);
94  EXPECT_EQ(pointCloudOrganized.height, 2);
95  EXPECT_EQ(pointCloudOrganized.data.size(), 2 * 3 * sizeof(float));
96 }
97 
98 TEST(AlbHelper, organizedPointCloudMessageRowwiseOrdering)
99 {
100  constexpr uint32_t layers = 2;
101  constexpr uint32_t points = 6;
102  float data[points * 3]; // 3 numbers per points
103  for (int i = 0; i < points; ++i) {
104  data[3 * i] = float(i);
105  data[3 * i + 1] = float(i);
106  data[3 * i + 2] = float(i);
107  }
108 
109  // Test with an organized point cloud.
110  sensor_msgs::PointCloud2 pointCloudOrganized;
111 
112  Helper::define_points_data(pointCloudOrganized, layers, points, data, false);
113 
114  EXPECT_EQ(pointCloudOrganized.width, 3);
115  EXPECT_EQ(pointCloudOrganized.height, 2);
116  EXPECT_EQ(pointCloudOrganized.data.size(), points * 3 * sizeof(float));
117 
118  // The initial data is:
119  // 0 2 4
120  // 1 3 5
121  // Colwise we should have: 0 1 2 3 4 5
122  // Rowwise we should have: 0 2 4 1 3 5
123  float expect[points] = { 0.f, 2.f, 4.f, 1.f, 3.f, 5.f };
124  float *recast_points = reinterpret_cast<float *>(pointCloudOrganized.data.data());
125  for (int i = 0; i < points; ++i) {
126  EXPECT_EQ(recast_points[3 * i], expect[i]);
127  EXPECT_EQ(recast_points[3 * i + 1], expect[i]);
128  EXPECT_EQ(recast_points[3 * i + 2], expect[i]);
129  }
130 }
131 
133 TEST(AlbHelper, pointsFields)
134 {
135  sensor_msgs::PointCloud2 pointCloud;
136  Helper::define_point_fields(pointCloud);
137 
138  EXPECT_EQ(pointCloud.fields.size(), 3);
139 }
Helper::define_point_fields
void define_point_fields(sensor_msgs::PointCloud2 &pointCloud)
Define the point fields for the ALB PointCloud2 message.
Definition: alb_helper.cpp:27
TEST
TEST(AlbHelper, trackedClassIds)
Test to check the matching between tracked object Ids and strings.
Definition: helper_testing.cpp:8
Helper::define_points_data
void define_points_data(sensor_msgs::PointCloud2 &pointCloud, const uint32_t layers, const uint32_t points, float *pointData, bool use_colwise_order)
Define the PointCloud2 point data from raw points coming from the ALB.
Definition: alb_helper.cpp:52
alb_helper.h
Helper::get_object_class
std::string get_object_class(uint32_t classId)
Get the string class of the tracked object from the ALB.
Definition: alb_helper.cpp:289
Helper::define_pose
void define_pose(geometry_msgs::Pose &pose, const std::array< float, 3 > &position, const std::array< float, 9 > &rotation)
Define a ROS Pose message from ALB position and rotation.
Definition: alb_helper.cpp:88


outsight_alb_driver
Author(s): Outsight
autogenerated on Thu Oct 13 2022 02:21:45