Using the Voxel grid method to achieve the next sampling, that is to reduce the number of points, reduce the point cloud data, while maintaining the shape of the point cloud features, in the improvement of registration, surface reconstruction, shape recognition algorithm speed is very practical.
The PCL -implemented Voxelgrid class creates a three-dimensional voxel raster from the input point cloud data (the voxel raster can be imagined as a collection of tiny three-dimensional cubes), and then within each voxel (i.e., three-dimensional cube), A bit of gravity in the voxel to approximate the other points in the voxel, so that the voxel in all points in the body with a center of gravity point of the final expression, for all voxel processing after the filtered point cloud. This method is slower than the method used to approximate the Voxel center, but it is more accurate for the representation of the corresponding surface of the sample point.
Therefore, this class is often used for the lower sampling processing of large data, especially in pre-registration and surface reconstruction, which can improve the program speed well.
Code:
#include <iostream>#include<pcl/io/pcd_io.h>#include<pcl/point_types.h>#include<pcl/filters/voxel_grid.h>#include<pcl/io/io.h>#include<pcl/visualization/cloud_viewer.h>intMainintargcChar**argv) {PCL::P ointcloud<PCL::P ointxyzi>::P TR Cloud (NewPCL::P OINTCLOUD<PCL::P ointxyzi>); PCL::P Ointcloud<PCL::P ointxyzi>::P tr cloud_filtered (NewPCL::P OINTCLOUD<PCL::P ointxyzi>); //fill in point cloud dataPcl::io::loadpcdfile ("TABLE_SCENE_LMS400.PCD", *cloud); //Creating Filter ObjectsPCL::VOXELGRID<PCL::P ointxyzi> sor;//Filter Processing ObjectsSor.setinputcloud (Cloud); Sor.setleafsize (0.01f,0.01f,0.01f);//parameters for setting the Voxel size used in filter processingSor.filter (*cloud_filtered); Std::cerr<<"Pointcloud after filtering:"<< Cloud_filtered->width * cloud_filtered->Height<<"Data points ("<< pcl::getfieldslist (*cloud_filtered) <<")."; Pcl::visualization::cloudviewer Viewer ("Cloud Viewer"); //The Showcloud function is synchronous, waiting here until the rendering is displayedViewer.showcloud (cloud_filtered); while(!viewer.wasstopped ()) { //Here you can add additional processing } return(0);}
Although the amount of data after processing is greatly reduced, it is obvious that the shape characteristics and spatial structure information are almost the same as the original point cloud.
Voxelgrid voxel Filter for the next sampling of point clouds