Downsampling#

Principle#

To act on a cloud, the total number of points is a key variable which, if reduced, can greatly speed up other applied treatments.
During the process of aligning multiple clouds together, if clouds are big, it is greatly recommended to downsample them, calculate translation and rotation matrix thanks to them, and apply those final transformations onto input clouds directly.

Voxel downsampling#

For each voxel (think about it as tiny 3D boxes aligned in space), all points it contains are approximated by their centroid. Beware that this method deforms the cloud.

Voxel downsampling

Voxel downsampling principle (2D representation) - blue points will be approximated with the red one#

The corresponding method is the following :

 1/**
 2 * @brief Downsample given cloud to ds_cloud, following voxel centering method
 3 * @tparam PointT Should be a pcl::PointXYZxxx
 4 * @param cloud Input clout
 5 * @param ds_cloud Output downsampled cloud
 6 * @param box_ridge Voxel ridge size
 7 * @param verbose If has to output debug on console
 8 * @example
 9 * pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
10 * getAndCenterCloud<pcl::PointXYZ>(cloud,true);
11 * pcl::PointCloud<pcl::PointXYZRGB>::Ptr ds_cloud(new pcl::PointCloud <pcl::PointXYZRGB>);
12 * downsampleCloudVoxel<pcl::PointXYZRGB>(cloud, ds_cloud, 0.1f, true);
13*/
14template <typename PointT>
15void downsampleCloudVoxel(typename pcl::PointCloud<PointT>::Ptr& cloud, typename pcl::PointCloud<PointT>::Ptr& ds_cloud, float box_ridge, bool verbose = false);
The parameter we can modify is box_ridge, corresponding to the voxel ridge.
To use it, do as follow :
1downsampleCloudVoxel<pcl::PointXYZ>(mynewcloud, mynewcloud_downsampled, 0.5 /*voxel ridge size, bigger = less points and more deformation*/);

Random sampling#

To get the desired number of points, it is possible to sample the cloud with a random based uniform probability filter.
The principle is easy : random points are removed from the cloud on a uniform basis.
This method preserves the cloud shape (if the number of samples is big enough), but it may lead to a loss of information if single points are distributed in space.

The corresponding method is the following :

 1/**
 2 * @brief Downsample given cloud to ds_cloud, following random sampling method
 3 * @tparam PointT Should be a pcl::PointXYZxxx
 4 * @param cloud Input clout
 5 * @param ds_cloud Output downsampled cloud
 6 * @param samples Number of samples to keep
 7 * @param verbose If has to output debug on console
 8*/
 9template <typename PointT>
10void downsampleCloudSample(typename pcl::PointCloud<PointT>::Ptr& cloud, typename pcl::PointCloud<PointT>::Ptr& ds_cloud, unsigned int samples, bool verbose = false);

The parameter we can modify is samples, corresponding to the number of points we want to have in the end. To use it, do as follow :

1downsampleCloudSample<pcl::PointXYZ>(mynewcloud, mynewcloud_downsampled, 50000 /*number of points to keep*/);

Algorithm 3D Algorithm PCL Point Cloud