-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pcl.cpp
233 lines (194 loc) · 6.96 KB
/
test_pcl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <algorithm>
#include <cstdint>
#include <filesystem>
#include <memory>
#include <string>
#include <vector>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <h5_bridge.hpp>
#include <h5b_sensor_msgs.hpp>
#include <gtest/gtest.h>
namespace fs = std::filesystem;
auto h5_infile_ = []()->std::string
{
auto tmp_dir = fs::temp_directory_path();
return tmp_dir.native() + std::string("/h5b_sensor_msgs_pcl_test.h5");
};
const std::string H5_INFILE = h5_infile_();
struct EIGEN_ALIGN16 PointOS
{
PCL_ADD_POINT4D;
float intensity;
std::uint32_t t;
std::uint16_t reflectivity;
std::uint8_t ring;
std::uint16_t noise;
std::uint32_t range;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
static inline PointOS make(
float x, float y, float z, float intensity,
std::uint32_t t, std::uint16_t reflectivity,
std::uint8_t ring, std::uint8_t col,
std::uint16_t noise, std::uint32_t range)
{
return {x, y, z, 0.0, intensity, t, reflectivity, ring, noise, range};
}
};
POINT_CLOUD_REGISTER_POINT_STRUCT(PointOS,
(float, x, x)
(float, y, y)
(float, z, z)
(float, intensity, intensity)
(std::uint32_t, t, t)
(std::uint16_t, reflectivity, reflectivity)
(std::uint8_t, ring, ring)
(std::uint16_t, noise, noise)
(std::uint32_t, range, range)
)
TEST(pcl, Cleanup)
{
EXPECT_NO_THROW(fs::remove(fs::path(H5_INFILE)));
}
TEST(pcl, PointXYZ)
{
auto h5 = std::make_unique<h5_bridge::H5File>(H5_INFILE, "a");
std::vector<int> rows_list{16, 32, 64, 128};
int cols = 2048;
for (int rows : rows_list)
{
int npts = rows * cols;
auto vec_x = h5_bridge::random_vec<float>(npts);
auto vec_y = h5_bridge::random_vec<float>(npts);
auto vec_z = h5_bridge::random_vec<float>(npts);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
cloud->height = rows;
cloud->width = cols;
cloud->points.resize(cloud->width * cloud->height);
for (std::size_t i = 0; i < npts; ++i)
{
cloud->points[i].x = vec_x[i];
cloud->points[i].y = vec_y[i];
cloud->points[i].z = vec_z[i];
}
sensor_msgs::msg::PointCloud2 msg;
EXPECT_NO_THROW(pcl::toROSMsg(*cloud, msg));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/xyz/0/" + std::to_string(rows), msg));
sensor_msgs::msg::PointCloud2 msg2;
EXPECT_NO_THROW(
msg2 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/xyz/0/" + std::to_string(rows)));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/xyz/1/" + std::to_string(rows), msg2));
sensor_msgs::msg::PointCloud2 msg3;
EXPECT_NO_THROW(
msg3 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/xyz/1/" + std::to_string(rows)));
EXPECT_TRUE(msg2 == msg3);
}
}
TEST(pcl, PointXYZI)
{
auto h5 = std::make_unique<h5_bridge::H5File>(H5_INFILE, "a");
std::vector<int> rows_list{16, 32, 64, 128};
int cols = 2048;
for (int rows : rows_list)
{
int npts = rows * cols;
auto vec_x = h5_bridge::random_vec<float>(npts);
auto vec_y = h5_bridge::random_vec<float>(npts);
auto vec_z = h5_bridge::random_vec<float>(npts);
auto vec_i = h5_bridge::random_vec<float>(npts);
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZI>);
cloud->height = rows;
cloud->width = cols;
cloud->points.resize(cloud->width * cloud->height);
for (std::size_t i = 0; i < npts; ++i)
{
cloud->points[i].x = vec_x[i];
cloud->points[i].y = vec_y[i];
cloud->points[i].z = vec_z[i];
cloud->points[i].intensity = vec_i[i];
}
sensor_msgs::msg::PointCloud2 msg;
EXPECT_NO_THROW(pcl::toROSMsg(*cloud, msg));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/xyzi/0/" + std::to_string(rows), msg));
sensor_msgs::msg::PointCloud2 msg2;
EXPECT_NO_THROW(
msg2 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/xyzi/0/" + std::to_string(rows)));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/xyzi/1/" + std::to_string(rows), msg2));
sensor_msgs::msg::PointCloud2 msg3;
EXPECT_NO_THROW(
msg3 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/xyzi/1/" + std::to_string(rows)));
EXPECT_TRUE(msg2 == msg3);
}
}
TEST(pcl, PointOuster)
{
auto h5 = std::make_unique<h5_bridge::H5File>(H5_INFILE, "a");
std::vector<int> rows_list{16, 32, 64, 128};
int cols = 2048;
for (int rows : rows_list)
{
int npts = rows * cols;
auto vec_x = h5_bridge::random_vec<float>(npts);
auto vec_y = h5_bridge::random_vec<float>(npts);
auto vec_z = h5_bridge::random_vec<float>(npts);
auto vec_i = h5_bridge::random_vec<float>(npts);
auto vec_t = h5_bridge::random_vec<std::uint32_t>(npts);
auto vec_reflectivity = h5_bridge::random_vec<std::uint16_t>(npts);
auto vec_ring_ = h5_bridge::random_vec<std::uint8_t>(npts);
auto vec_noise = h5_bridge::random_vec<std::uint16_t>(npts);
auto vec_range = h5_bridge::random_vec<std::uint32_t>(npts);
std::vector<std::uint8_t> vec_ring;
std::transform(vec_ring_.begin(), vec_ring_.end(),
std::back_inserter(vec_ring),
[rows](std::uint8_t r) -> std::uint8_t
{ return r % rows; });
pcl::PointCloud<PointOS>::Ptr cloud(new pcl::PointCloud<PointOS>);
cloud->height = rows;
cloud->width = cols;
cloud->points.resize(npts);
for (std::size_t i = 0; i < npts; ++i)
{
cloud->points[i].x = vec_x[i];
cloud->points[i].y = vec_y[i];
cloud->points[i].z = vec_z[i];
cloud->points[i].intensity = vec_i[i];
cloud->points[i].t = vec_t[i];
cloud->points[i].reflectivity = vec_reflectivity[i];
cloud->points[i].ring = vec_ring[i];
cloud->points[i].noise = vec_noise[i];
cloud->points[i].range = vec_range[i];
}
sensor_msgs::msg::PointCloud2 msg;
EXPECT_NO_THROW(pcl::toROSMsg(*cloud, msg));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/ouster/0/" + std::to_string(rows), msg));
sensor_msgs::msg::PointCloud2 msg2;
EXPECT_NO_THROW(
msg2 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/ouster/0/" + std::to_string(rows)));
EXPECT_NO_THROW(
h5b_sensor_msgs::write(
h5.get(), "/pcl/ouster/1/" + std::to_string(rows), msg2));
sensor_msgs::msg::PointCloud2 msg3;
EXPECT_NO_THROW(
msg3 = h5b_sensor_msgs::read<sensor_msgs::msg::PointCloud2>(
h5.get(), "/pcl/ouster/1/" + std::to_string(rows)));
EXPECT_TRUE(msg2 == msg3);
}
}