@@ -75,14 +75,14 @@ struct compute_key_functor {
75
75
};
76
76
77
77
template <int Index, class ... Args>
78
- struct normalize_and_devide_tuple_functor
78
+ struct normalize_and_divide_tuple_functor
79
79
: public thrust::binary_function<const thrust::tuple<Args...>,
80
80
const int ,
81
81
thrust::tuple<Args...>> {
82
82
__host__ __device__ thrust::tuple<Args...> operator ()(
83
83
const thrust::tuple<Args...> &x, const int &y) const {
84
84
thrust::tuple<Args...> ans = x;
85
- devide_tuple_impl (ans, y,
85
+ divide_tuple_impl (ans, y,
86
86
thrust::make_index_sequence<sizeof ...(Args)>{});
87
87
thrust::get<Index>(ans).normalize ();
88
88
return ans;
@@ -211,8 +211,17 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
211
211
};
212
212
if (!has_normals && !has_colors) {
213
213
auto begin = make_tuple_begin (output->points_ , counts);
214
- int n_out = runs (begin, sorted_points);
215
- devide_tuple_functor<Eigen::Vector3f> dv_func;
214
+ thrust::sort_by_key (
215
+ utility::exec_policy (0 ), keys.begin (), keys.end (),
216
+ sorted_points.begin ());
217
+ add_tuple_functor<Eigen::Vector3f, int > add_func;
218
+ auto end = thrust::reduce_by_key (
219
+ utility::exec_policy (0 ), keys.begin (), keys.end (),
220
+ make_tuple_iterator (sorted_points.begin (),
221
+ thrust::make_constant_iterator (1 )),
222
+ thrust::make_discard_iterator (), begin, binary_pred, add_func);
223
+ int n_out = thrust::distance (begin, end.second );
224
+ divide_tuple_functor<Eigen::Vector3f> dv_func;
216
225
auto output_begins = make_tuple_begin (output->points_ );
217
226
thrust::transform (output_begins, output_begins + n_out, counts.begin (),
218
227
output_begins, dv_func);
@@ -223,7 +232,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
223
232
auto begin =
224
233
make_tuple_begin (output->points_ , output->normals_ , counts);
225
234
int n_out = runs (begin, sorted_points, sorted_normals);
226
- normalize_and_devide_tuple_functor <1 , Eigen::Vector3f, Eigen::Vector3f>
235
+ normalize_and_divide_tuple_functor <1 , Eigen::Vector3f, Eigen::Vector3f>
227
236
dv_func;
228
237
auto output_begins =
229
238
make_tuple_begin (output->points_ , output->normals_ );
@@ -235,7 +244,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
235
244
resize_all (n, output->colors_ );
236
245
auto begin = make_tuple_begin (output->points_ , output->colors_ , counts);
237
246
int n_out = runs (begin, sorted_points, sorted_colors);
238
- devide_tuple_functor <Eigen::Vector3f, Eigen::Vector3f> dv_func;
247
+ divide_tuple_functor <Eigen::Vector3f, Eigen::Vector3f> dv_func;
239
248
auto output_begins = make_tuple_begin (output->points_ , output->colors_ );
240
249
thrust::transform (output_begins, output_begins + n_out, counts.begin (),
241
250
output_begins, dv_func);
@@ -247,7 +256,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
247
256
auto begin = make_tuple_begin (output->points_ , output->normals_ ,
248
257
output->colors_ , counts);
249
258
int n_out = runs (begin, sorted_points, sorted_normals, sorted_colors);
250
- normalize_and_devide_tuple_functor <1 , Eigen::Vector3f, Eigen::Vector3f,
259
+ normalize_and_divide_tuple_functor <1 , Eigen::Vector3f, Eigen::Vector3f,
251
260
Eigen::Vector3f>
252
261
dv_func;
253
262
auto output_begins = make_tuple_begin (output->points_ , output->normals_ ,
@@ -397,7 +406,7 @@ PointCloud::RemoveStatisticalOutliers(size_t nb_neighbors,
397
406
auto mean_and_count = thrust::transform_reduce (
398
407
utility::exec_policy (0 ), avg_distances.begin (),
399
408
avg_distances.end (),
400
- [] __device__ (float const &x) {
409
+ [] __device__ (float const &x) -> thrust::tuple< float , size_t > {
401
410
return thrust::make_tuple (max (x, 0 .0f ), (size_t )(x >= 0.0 ));
402
411
},
403
412
thrust::make_tuple (0 .0f , size_t (0 )),
@@ -412,8 +421,8 @@ PointCloud::RemoveStatisticalOutliers(size_t nb_neighbors,
412
421
const float sq_sum = thrust::transform_reduce (
413
422
utility::exec_policy (0 ), avg_distances.begin (),
414
423
avg_distances.end (),
415
- [cloud_mean] __device__ (const float x) {
416
- return (x > 0 ) ? (x - cloud_mean) * (x - cloud_mean) : 0 ;
424
+ [cloud_mean] __device__ (const float x) -> float {
425
+ return (x > 0 ) ? (x - cloud_mean) * (x - cloud_mean) : 0 . 0f ;
417
426
},
418
427
0.0 , thrust::plus<float >());
419
428
// Bessel's correction
0 commit comments