@@ -75,14 +75,14 @@ struct compute_key_functor {
7575};
7676
7777template <int Index, class ... Args>
78- struct normalize_and_devide_tuple_functor
78+ struct normalize_and_divide_tuple_functor
7979 : public thrust::binary_function<const thrust::tuple<Args...>,
8080 const int ,
8181 thrust::tuple<Args...>> {
8282 __host__ __device__ thrust::tuple<Args...> operator ()(
8383 const thrust::tuple<Args...> &x, const int &y) const {
8484 thrust::tuple<Args...> ans = x;
85- devide_tuple_impl (ans, y,
85+ divide_tuple_impl (ans, y,
8686 thrust::make_index_sequence<sizeof ...(Args)>{});
8787 thrust::get<Index>(ans).normalize ();
8888 return ans;
@@ -211,8 +211,17 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
211211 };
212212 if (!has_normals && !has_colors) {
213213 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;
216225 auto output_begins = make_tuple_begin (output->points_ );
217226 thrust::transform (output_begins, output_begins + n_out, counts.begin (),
218227 output_begins, dv_func);
@@ -223,7 +232,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
223232 auto begin =
224233 make_tuple_begin (output->points_ , output->normals_ , counts);
225234 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>
227236 dv_func;
228237 auto output_begins =
229238 make_tuple_begin (output->points_ , output->normals_ );
@@ -235,7 +244,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
235244 resize_all (n, output->colors_ );
236245 auto begin = make_tuple_begin (output->points_ , output->colors_ , counts);
237246 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;
239248 auto output_begins = make_tuple_begin (output->points_ , output->colors_ );
240249 thrust::transform (output_begins, output_begins + n_out, counts.begin (),
241250 output_begins, dv_func);
@@ -247,7 +256,7 @@ std::shared_ptr<PointCloud> PointCloud::VoxelDownSample(
247256 auto begin = make_tuple_begin (output->points_ , output->normals_ ,
248257 output->colors_ , counts);
249258 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,
251260 Eigen::Vector3f>
252261 dv_func;
253262 auto output_begins = make_tuple_begin (output->points_ , output->normals_ ,
@@ -397,7 +406,7 @@ PointCloud::RemoveStatisticalOutliers(size_t nb_neighbors,
397406 auto mean_and_count = thrust::transform_reduce (
398407 utility::exec_policy (0 ), avg_distances.begin (),
399408 avg_distances.end (),
400- [] __device__ (float const &x) {
409+ [] __device__ (float const &x) -> thrust::tuple< float , size_t > {
401410 return thrust::make_tuple (max (x, 0 .0f ), (size_t )(x >= 0.0 ));
402411 },
403412 thrust::make_tuple (0 .0f , size_t (0 )),
@@ -412,8 +421,8 @@ PointCloud::RemoveStatisticalOutliers(size_t nb_neighbors,
412421 const float sq_sum = thrust::transform_reduce (
413422 utility::exec_policy (0 ), avg_distances.begin (),
414423 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 ;
417426 },
418427 0.0 , thrust::plus<float >());
419428 // Bessel's correction
0 commit comments