My environment is PCL 1.11.1 and vs2019. I generated the synthetic point cloud using CloudCompare and I wanna downsample it.
So I use the following code
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPLYFile("data_path", *cloud_in);
pcl::ApproximateVoxelGrid<pcl::PointXYZ> AVG_filter;
AVG_filter.setInputCloud(cloud_in);
AVG_filter.setLeafSize(2.0f, 2.0f, 2.0f);
AVG_filter.filter(*cloud_in);
But when I visualize cloud_in after filtering, the output is weird.
Can anybody explain this phenomenon to me? It will be so helpful
I don't know what's wrong with this. I really need some help
ApproximateVoxelGrid
works best when points that are close in Euclidean space (3D space), are also stored next to each other (in cloud_in->points
). For point clouds that have been e.g. captured with a 3D camera, this is the case. On the other hand, it gives very bad results if the storage order is random, meaning that points which are stored next to each other are not close in Euclidean space. This is the case in your synthetic point cloud. I would recommend you to try VoxelGrid
instead, or to find some way to order the points. For example like this: std::sort(cloud_in->begin(), cloud_in->end(), [](auto& a, auto& b){ return (a.x < b.x); });