diff --git a/filters/include/pcl/filters/impl/voxel_grid.hpp b/filters/include/pcl/filters/impl/voxel_grid.hpp index 6ba0bc6c9d8..669b5c6fe64 100644 --- a/filters/include/pcl/filters/impl/voxel_grid.hpp +++ b/filters/include/pcl/filters/impl/voxel_grid.hpp @@ -42,6 +42,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////////////////// template void @@ -205,6 +206,7 @@ struct cloud_point_index_idx unsigned int idx; unsigned int cloud_point_index; + cloud_point_index_idx() = default; cloud_point_index_idx (unsigned int idx_, unsigned int cloud_point_index_) : idx (idx_), cloud_point_index (cloud_point_index_) {} bool operator < (const cloud_point_index_idx &p) const { return (idx < p.idx); } }; @@ -339,8 +341,9 @@ pcl::VoxelGrid::applyFilter (PointCloud &output) // Second pass: sort the index_vector vector using value representing target cell as index // in effect all points belonging to the same output cell will be next to each other - std::sort (index_vector.begin (), index_vector.end (), std::less ()); - + auto rightshift_func = [](const cloud_point_index_idx &x, const unsigned offset) { return x.idx >> offset; }; + boost::sort::spreadsort::integer_sort(index_vector.begin(), index_vector.end(), rightshift_func); + // Third pass: count output cells // we need to skip all the same, adjacent idx values unsigned int total = 0; diff --git a/filters/src/voxel_grid.cpp b/filters/src/voxel_grid.cpp index 68e44dba0ed..92e5f71dd25 100644 --- a/filters/src/voxel_grid.cpp +++ b/filters/src/voxel_grid.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using Array4size_t = Eigen::Array; @@ -377,7 +378,8 @@ pcl::VoxelGrid::applyFilter (PCLPointCloud2 &output) // Second pass: sort the index_vector vector using value representing target cell as index // in effect all points belonging to the same output cell will be next to each other - std::sort (index_vector.begin (), index_vector.end (), std::less ()); + auto rightshift_func = [](const cloud_point_index_idx &x, const unsigned offset) { return x.idx >> offset; }; + boost::sort::spreadsort::integer_sort(index_vector.begin(), index_vector.end(), rightshift_func); // Third pass: count output cells // we need to skip all the same, adjacenent idx values @@ -549,4 +551,3 @@ PCL_INSTANTIATE(getMinMax3D, PCL_XYZ_POINT_TYPES) PCL_INSTANTIATE(VoxelGrid, PCL_XYZ_POINT_TYPES) #endif // PCL_NO_PRECOMPILE -