Skip to content

Instantly share code, notes, and snippets.

@universax
Last active February 2, 2019 10:00
Show Gist options
  • Save universax/2d5d75957a9ff8733039a565ce3b8107 to your computer and use it in GitHub Desktop.
Save universax/2d5d75957a9ff8733039a565ce3b8107 to your computer and use it in GitHub Desktop.
PCL filter implementation example
void PCLManager::edgeRmoveFilter(pcl::PointCloud<PointType>::Ptr cloud) {
pcl::PointCloud<PointNormalType>::Ptr normal = createNormals(cloud);
vector<int> removeIndex;
for (int i = 0; i < cloud->points.size(); i++)
{
if (abs(normal->points[i].normal_x / normal->points[i].normal_z) > 0.1)
{
removeIndex.push_back(i);
}
}
for (int i = 0; i < removeIndex.size(); i++)
{
cloud->erase(cloud->points.begin() + removeIndex[i] - i);
}
}
void PCLManager::statisticalOutlierFilter(pcl::PointCloud<PointType>::Ptr cloud)
{
pcl::StatisticalOutlierRemoval<PointType> sor;
sor.setInputCloud(cloud);
sor.setMeanK(10);
sor.setStddevMulThresh(1.0);
pcl::PointCloud<PointType>::Ptr cloud_filtered(new pcl::PointCloud<PointType>);
sor.filter(*cloud_filtered);
pcl::copyPointCloud(*cloud_filtered, *cloud);
cloud_filtered.reset();
}
void PCLManager::voxelGridFilter(float leaf, pcl::PointCloud<PointType>::Ptr cloud)
{
//VoxelGrid
pcl::VoxelGrid<PointType> grid;
grid.setLeafSize(leaf, leaf, leaf);
grid.setInputCloud(cloud);
pcl::PointCloud<PointType>::Ptr cloud_filtered(new pcl::PointCloud<PointType>());
grid.filter(*cloud_filtered);
pcl::copyPointCloud(*cloud_filtered, *cloud);
cloud_filtered.reset();
}
void PCLManager::extractIndices(pcl::PointCloud<PointType>::Ptr cloud, pcl::PointIndices::Ptr inliners)
{
pcl::PointCloud<PointType>::Ptr tmp(new pcl::PointCloud<PointType>());
pcl::copyPointCloud(*cloud, *tmp);
pcl::ExtractIndices<PointType> extract;
extract.setInputCloud(tmp);
extract.setIndices(inliners);
extract.setNegative(true);
extract.filter(*cloud);
}
void PCLManager::radiusOutlinerFilter(pcl::PointCloud<PointType>::Ptr cloud) {
pcl::RadiusOutlierRemoval<PointType> ror;
ror.setInputCloud(cloud);
ror.setRadiusSearch(0.05);
ror.setMinNeighborsInRadius(2);
pcl::PointCloud<PointType>::Ptr filterdCloud(new pcl::PointCloud<PointType>());
ror.filter(*filterdCloud);
*cloud = *filterdCloud;
filterdCloud.reset();
}
void PCLManager::passThroughFilter(pcl::PointCloud<PointType>::Ptr inputCloud, const string &fieldName, float min, float max) {
pcl::PassThrough<PointType> pass;
pass.setInputCloud(inputCloud);
pass.setFilterFieldName(fieldName);
pass.setFilterLimits(min, max);
pcl::PointCloud<PointType>::Ptr filterdCloud(new pcl::PointCloud<PointType>());
pass.filter(*filterdCloud);
*inputCloud = *filterdCloud;
}
void PCLManager::nanRemovalFilter(pcl::PointCloud<PointType>::Ptr cloud) {
std::vector<int> indices;
pcl::removeNaNFromPointCloud(*cloud, *cloud, indices);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment