11
11
#include < pcl/filters/voxel_grid.h>
12
12
#include < pcl/io/pcd_io.h>
13
13
#include < pcl/test/gtest.h>
14
+ #include < pcl/pcl_tests.h>
14
15
#include < pcl/point_types.h>
15
16
16
17
#include < cmath>
@@ -29,40 +30,23 @@ template <typename PointT>
29
30
void
30
31
EXPECT_POINT_EQ (const PointT& pt1, const PointT& pt2)
31
32
{
32
- const auto & pt1_vec = pt1.getVector4fMap ();
33
- const auto & pt_vec = pt2.getVector4fMap ();
34
- EXPECT_TRUE (pt1_vec.isApprox (pt_vec, PRECISION))
35
- << " Point1: " << pt1_vec.transpose () << " \n Point2: " << pt_vec.transpose ()
36
- << " \n norm diff: " << (pt1_vec - pt_vec).norm () << std::endl;
33
+ EXPECT_XYZ_NEAR (pt1, pt2, PRECISION);
37
34
}
38
35
39
36
template <typename >
40
37
void
41
38
EXPECT_POINT_EQ (const PointXYZRGB& pt1, const PointXYZRGB& pt2)
42
39
{
43
- const auto & pt1_vec = pt1.getVector4fMap ();
44
- const auto & pt_vec = pt2.getVector4fMap ();
45
- EXPECT_TRUE (pt1_vec.isApprox (pt_vec, PRECISION))
46
- << " Point1: " << pt1_vec.transpose () << " \n Point2: " << pt_vec.transpose ()
47
- << " \n norm diff: " << (pt1_vec - pt_vec).norm () << std::endl;
48
- EXPECT_EQ (pt1.r , pt2.r );
49
- EXPECT_EQ (pt1.g , pt2.g );
50
- EXPECT_EQ (pt1.b , pt2.b );
40
+ EXPECT_XYZ_NEAR (pt1, pt2, PRECISION);
41
+ EXPECT_RGB_EQ (pt1, pt2);
51
42
}
52
43
53
44
template <typename >
54
45
void
55
46
EXPECT_POINT_EQ (const PointXYZRGBA& pt1, const PointXYZRGBA& pt2)
56
47
{
57
- const auto & pt1_vec = pt1.getVector4fMap ();
58
- const auto & pt_vec = pt2.getVector4fMap ();
59
- EXPECT_TRUE (pt1_vec.isApprox (pt_vec, PRECISION))
60
- << " Point1: " << pt1_vec.transpose () << " \n Point2: " << pt_vec.transpose ()
61
- << " \n norm diff: " << (pt1_vec - pt_vec).norm () << std::endl;
62
- EXPECT_EQ (pt1.r , pt2.r );
63
- EXPECT_EQ (pt1.g , pt2.g );
64
- EXPECT_EQ (pt1.b , pt2.b );
65
- EXPECT_EQ (pt1.a , pt2.a );
48
+ EXPECT_XYZ_NEAR (pt1, pt2, PRECISION);
49
+ EXPECT_RGBA_EQ (pt1, pt2);
66
50
}
67
51
68
52
template <typename PointT>
@@ -79,84 +63,43 @@ EXPECT_POINTS_EQ(PointCloud<PointT> pc1, PointCloud<PointT> pc2)
79
63
std::sort (pc2.begin (), pc2.end (), pt_cmp);
80
64
81
65
for (size_t i = 0 ; i < pc1.size (); ++i)
82
- EXPECT_POINT_EQ<PointT> (pc1.at (i), pc2.at (i));
66
+ EXPECT_POINT_EQ (pc1.at (i), pc2.at (i));
83
67
}
84
68
85
69
TEST (SetUp, ExperimentalVoxelGridEquivalency)
86
70
{
87
- // PointXYZ
88
- {
89
- PointCloud<PointXYZ> new_out_cloud, old_out_cloud;
90
-
91
- experimental::VoxelGrid<PointXYZ> new_grid;
92
- pcl::VoxelGrid<PointXYZ> old_grid;
93
- new_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
94
- old_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
95
- new_grid.setInputCloud (cloud);
96
- old_grid.setInputCloud (cloud);
97
- new_grid.filter (new_out_cloud);
98
- old_grid.filter (old_out_cloud);
99
-
100
- const Eigen::Vector3i new_min_b = new_grid.getMinBoxCoordinates ();
101
- const Eigen::Vector3i old_min_b = old_grid.getMinBoxCoordinates ();
102
- EXPECT_TRUE (new_min_b.isApprox (old_min_b, PRECISION));
103
-
104
- const Eigen::Vector3i new_max_b = new_grid.getMaxBoxCoordinates ();
105
- const Eigen::Vector3i old_max_b = old_grid.getMaxBoxCoordinates ();
106
- EXPECT_TRUE (new_max_b.isApprox (old_max_b, PRECISION));
107
-
108
- const Eigen::Vector3i new_div_b = new_grid.getNrDivisions ();
109
- const Eigen::Vector3i old_div_b = old_grid.getNrDivisions ();
110
- EXPECT_TRUE (new_div_b.isApprox (old_div_b, PRECISION));
111
-
112
- const Eigen::Vector3i new_divb_mul = new_grid.getDivisionMultiplier ();
113
- const Eigen::Vector3i old_divb_mul = old_grid.getDivisionMultiplier ();
114
- EXPECT_TRUE (new_divb_mul.isApprox (old_divb_mul, PRECISION));
115
- }
116
-
117
- // PointXYZRGB
118
- {
119
- PointCloud<PointXYZRGB> new_out_cloud, old_out_cloud;
120
-
121
- // the original hashing range will overflow with leaf size of 0.02
122
- experimental::VoxelGrid<PointXYZRGB> new_grid;
123
- pcl::VoxelGrid<PointXYZRGB> old_grid;
124
- new_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
125
- old_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
126
- new_grid.setInputCloud (cloud_rgb);
127
- old_grid.setInputCloud (cloud_rgb);
128
- new_grid.filter (new_out_cloud);
129
- old_grid.filter (old_out_cloud);
130
-
131
- const Eigen::Vector3i new_min_b = new_grid.getMinBoxCoordinates ();
132
- const Eigen::Vector3i old_min_b = old_grid.getMinBoxCoordinates ();
133
- EXPECT_TRUE (new_min_b.isApprox (old_min_b, PRECISION));
134
-
135
- const Eigen::Vector3i new_max_b = new_grid.getMaxBoxCoordinates ();
136
- const Eigen::Vector3i old_max_b = old_grid.getMaxBoxCoordinates ();
137
- EXPECT_TRUE (new_max_b.isApprox (old_max_b, PRECISION));
138
-
139
- const Eigen::Vector3i new_div_b = new_grid.getNrDivisions ();
140
- const Eigen::Vector3i old_div_b = old_grid.getNrDivisions ();
141
- EXPECT_TRUE (new_div_b.isApprox (old_div_b, PRECISION));
142
-
143
- const Eigen::Vector3i new_divb_mul = new_grid.getDivisionMultiplier ();
144
- const Eigen::Vector3i old_divb_mul = old_grid.getDivisionMultiplier ();
145
- EXPECT_TRUE (new_divb_mul.isApprox (old_divb_mul, PRECISION));
146
- }
147
- }
71
+ PointCloud<PointXYZ> new_out_cloud, old_out_cloud;
148
72
149
- TEST (HashingPoint, ExperimentalVoxelGridEquivalency)
150
- {
151
- // For extracting indices
152
- PointCloud<PointXYZ> new_out_cloud;
153
73
experimental::VoxelGrid<PointXYZ> new_grid;
74
+ pcl::VoxelGrid<PointXYZ> old_grid;
154
75
new_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
76
+ old_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
155
77
new_grid.setInputCloud (cloud);
78
+ old_grid.setInputCloud (cloud);
156
79
new_grid.filter (new_out_cloud);
80
+ old_grid.filter (old_out_cloud);
81
+
82
+ const Eigen::Vector3i new_min_b = new_grid.getMinBoxCoordinates ();
83
+ const Eigen::Vector3i old_min_b = old_grid.getMinBoxCoordinates ();
84
+ EXPECT_TRUE (new_min_b.isApprox (old_min_b, PRECISION));
85
+
86
+ const Eigen::Vector3i new_max_b = new_grid.getMaxBoxCoordinates ();
87
+ const Eigen::Vector3i old_max_b = old_grid.getMaxBoxCoordinates ();
88
+ EXPECT_TRUE (new_max_b.isApprox (old_max_b, PRECISION));
89
+
90
+ const Eigen::Vector3i new_div_b = new_grid.getNrDivisions ();
91
+ const Eigen::Vector3i old_div_b = old_grid.getNrDivisions ();
92
+ EXPECT_TRUE (new_div_b.isApprox (old_div_b, PRECISION));
93
+
94
+ const Eigen::Vector3i new_divb_mul = new_grid.getDivisionMultiplier ();
95
+ const Eigen::Vector3i old_divb_mul = old_grid.getDivisionMultiplier ();
96
+ EXPECT_TRUE (new_divb_mul.isApprox (old_divb_mul, PRECISION));
97
+ }
157
98
99
+ TEST (HashingPoint, ExperimentalVoxelGridEquivalency)
100
+ {
158
101
Eigen::Vector4f min_p, max_p;
159
- getMinMax3D<PointXYZ>(*cloud, *(new_grid. getIndices ()), min_p, max_p);
102
+ getMinMax3D<PointXYZ>(*cloud, min_p, max_p);
160
103
161
104
Eigen::Vector4i min_b, max_b, div_b, divb_mul;
162
105
Eigen::Array4f inverse_leaf_size = 1 / Eigen::Array4f::Constant (0.02 );
@@ -180,9 +123,9 @@ TEST(HashingPoint, ExperimentalVoxelGridEquivalency)
180
123
181
124
for (size_t i = 0 ; i < cloud->size (); ++i) {
182
125
if (isXYZFinite (cloud->at (i))) {
183
- EXPECT_EQ ( experimental::hashPoint (
184
- cloud->at (i), inverse_leaf_size, min_b, divb_mul[1 ], divb_mul[2 ]),
185
- old_hash (cloud->at (i)));
126
+ const size_t new_hash = experimental::hashPoint (
127
+ cloud->at (i), inverse_leaf_size, min_b, divb_mul[1 ], divb_mul[2 ]);
128
+ EXPECT_EQ (new_hash, old_hash (cloud->at (i)));
186
129
}
187
130
}
188
131
}
@@ -244,84 +187,48 @@ TEST(LeafLayout, ExperimentalVoxelGridEquivalency)
244
187
}
245
188
}
246
189
247
- TEST (PointXYZ, ExperimentalVoxelGridEquivalency)
190
+ // Update to std::tuple which can get by type in C++17
191
+ template <typename PointT>
192
+ typename PointCloud<PointT>::Ptr
193
+ getCloud ();
194
+ template <>
195
+ PointCloud<PointXYZ>::Ptr
196
+ getCloud<PointXYZ>()
248
197
{
249
- PointCloud<PointXYZ> new_out, old_out;
250
-
251
- pcl::experimental::VoxelGrid<PointXYZ> new_grid;
252
- pcl::VoxelGrid<PointXYZ> old_grid;
253
- new_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
254
- old_grid.setLeafSize (0 .02f , 0 .02f , 0 .02f );
255
- new_grid.setInputCloud (cloud);
256
- old_grid.setInputCloud (cloud);
257
-
258
- new_grid.setDownsampleAllData (false );
259
- old_grid.setDownsampleAllData (false );
260
- new_grid.filter (new_out);
261
- old_grid.filter (old_out);
262
- EXPECT_POINTS_EQ (new_out, old_out);
263
- new_out.clear ();
264
- old_out.clear ();
265
-
266
- new_grid.setDownsampleAllData (true );
267
- old_grid.setDownsampleAllData (true );
268
- new_grid.filter (new_out);
269
- old_grid.filter (old_out);
270
- EXPECT_POINTS_EQ (new_out, old_out);
271
- new_out.clear ();
272
- old_out.clear ();
273
-
274
- new_grid.setMinimumPointsNumberPerVoxel (5 );
275
- old_grid.setMinimumPointsNumberPerVoxel (5 );
276
- new_grid.filter (new_out);
277
- old_grid.filter (old_out);
278
- EXPECT_POINTS_EQ (new_out, old_out);
198
+ return cloud;
279
199
}
280
-
281
- TEST (PointXYZRGB, ExperimentalVoxelGridEquivalency)
200
+ template <>
201
+ PointCloud<PointXYZRGB>::Ptr
202
+ getCloud<PointXYZRGB>()
282
203
{
283
- PointCloud<PointXYZRGB> new_out, old_out;
284
-
285
- pcl::experimental::VoxelGrid<PointXYZRGB> new_grid;
286
- pcl::VoxelGrid<PointXYZRGB> old_grid;
287
- new_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
288
- old_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
289
- new_grid.setInputCloud (cloud_rgb);
290
- old_grid.setInputCloud (cloud_rgb);
291
-
292
- new_grid.setDownsampleAllData (false );
293
- old_grid.setDownsampleAllData (false );
294
- new_grid.filter (new_out);
295
- old_grid.filter (old_out);
296
- EXPECT_POINTS_EQ (new_out, old_out);
297
- new_out.clear ();
298
- old_out.clear ();
299
-
300
- new_grid.setDownsampleAllData (true );
301
- old_grid.setDownsampleAllData (true );
302
- new_grid.filter (new_out);
303
- old_grid.filter (old_out);
304
- EXPECT_POINTS_EQ (new_out, old_out);
305
- new_out.clear ();
306
- old_out.clear ();
307
-
308
- new_grid.setMinimumPointsNumberPerVoxel (5 );
309
- old_grid.setMinimumPointsNumberPerVoxel (5 );
310
- new_grid.filter (new_out);
311
- old_grid.filter (old_out);
312
- EXPECT_POINTS_EQ (new_out, old_out);
204
+ return cloud_rgb;
205
+ }
206
+ template <>
207
+ PointCloud<PointXYZRGBA>::Ptr
208
+ getCloud<PointXYZRGBA>()
209
+ {
210
+ return cloud_rgba;
313
211
}
314
212
315
- TEST (PointXYZRGBA, ExperimentalVoxelGridEquivalency)
213
+ template <typename T>
214
+ class PointTypesTest : public ::testing::Test {};
215
+ using PointTypes = ::testing::Types<PointXYZ, PointXYZRGB, PointXYZRGBA>;
216
+ TYPED_TEST_SUITE (PointTypesTest, PointTypes);
217
+
218
+ TYPED_TEST (PointTypesTest, ExperimentalVoxelGridEquivalency)
316
219
{
317
- PointCloud<PointXYZRGBA> new_out, old_out;
220
+ using PointT = TypeParam;
221
+ using PointCloudPtr = typename PointCloud<PointT>::Ptr;
222
+
223
+ PointCloud<PointT> new_out, old_out;
224
+ PointCloudPtr cloudT = getCloud<PointT>();
318
225
319
- pcl::experimental::VoxelGrid<PointXYZRGBA > new_grid;
320
- pcl::VoxelGrid<PointXYZRGBA > old_grid;
226
+ pcl::experimental::VoxelGrid<PointT > new_grid;
227
+ pcl::VoxelGrid<PointT > old_grid;
321
228
new_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
322
229
old_grid.setLeafSize (0 .05f , 0 .05f , 0 .05f );
323
- new_grid.setInputCloud (cloud_rgba );
324
- old_grid.setInputCloud (cloud_rgba );
230
+ new_grid.setInputCloud (cloudT );
231
+ old_grid.setInputCloud (cloudT );
325
232
326
233
new_grid.setDownsampleAllData (false );
327
234
old_grid.setDownsampleAllData (false );
0 commit comments