filters.h
#ifndef FILTERS_H
#define FILTERS_H
#include <pcl/filters/passthrough.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/radius_outlier_removal.h>
#include "typedefs.h"
/* Use a PassThrough filter to remove points with depth values that are too large or too small */
PointCloudPtr
thresholdDepth (const PointCloudPtr & input, float min_depth, float max_depth)
{
pcl::PassThrough<PointT> pass_through;
pass_through.setInputCloud (input);
pass_through.setFilterFieldName ("z");
pass_through.setFilterLimits (min_depth, max_depth);
PointCloudPtr thresholded (new PointCloud);
pass_through.filter (*thresholded);
return (thresholded);
}
/* Use a VoxelGrid filter to reduce the number of points */
PointCloudPtr
downsample (const PointCloudPtr & input, float leaf_size)
{
pcl::VoxelGrid<PointT> voxel_grid;
voxel_grid.setInputCloud (input);
voxel_grid.setLeafSize (leaf_size, leaf_size, leaf_size);
PointCloudPtr downsampled (new PointCloud);
voxel_grid.filter (*downsampled);
return (downsampled);
}
/* Use a RadiusOutlierRemoval filter to remove all points with too few local neighbors */
PointCloudPtr
removeOutliers (const PointCloudPtr & input, float radius, int min_neighbors)
{
pcl::RadiusOutlierRemoval<pcl::PointXYZRGB> radius_outlier_removal;
radius_outlier_removal.setInputCloud (input);
radius_outlier_removal.setRadiusSearch (radius);
radius_outlier_removal.setMinNeighborsInRadius (min_neighbors);
PointCloudPtr inliers (new PointCloud);
radius_outlier_removal.filter (*inliers);
return (inliers);
}
/* Apply a series of filters (threshold depth, downsample, and remove outliers) */
PointCloudPtr
applyFilters (const PointCloudPtr & input, float min_depth, float max_depth, float leaf_size, float radius,
float min_neighbors)
{
PointCloudPtr filtered;
filtered = thresholdDepth (input, min_depth, max_depth);
filtered = downsample (filtered, leaf_size);
filtered = removeOutliers (filtered, radius, min_neighbors);
return (filtered);
}
#endif
pcl::PassThrough::setFilterFieldName
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: passthrough.h:111
pcl::Filter::filter
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
Definition: filter.h:132
pcl::VoxelGrid
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
Definition: voxel_grid.h:178
pcl::RadiusOutlierRemoval
RadiusOutlierRemoval filters points in a cloud based on the number of neighbors they have...
Definition: radius_outlier_removal.h:72
pcl::RadiusOutlierRemoval::setRadiusSearch
void setRadiusSearch(double radius)
Set the radius of the sphere that will determine which points are neighbors.
Definition: radius_outlier_removal.h:104
pcl::PassThrough::setFilterLimits
void setFilterLimits(const float &limit_min, const float &limit_max)
Set the numerical limits for the field for filtering data.
Definition: passthrough.h:131
pcl::PassThrough
PassThrough passes points in a cloud based on constraints for one particular field of the point type...
Definition: passthrough.h:80
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::FilterIndices::filter
void filter(PointCloud &output)
Definition: filter_indices.h:103
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:66
pcl::RadiusOutlierRemoval::setMinNeighborsInRadius
void setMinNeighborsInRadius(int min_pts)
Set the number of neighbors that need to be present in order to be classified as an inlier...
Definition: radius_outlier_removal.h:126
pcl::VoxelGrid::setLeafSize
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
Definition: voxel_grid.h:223