-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditional_filtering.cpp
44 lines (32 loc) · 1.79 KB
/
conditional_filtering.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <pcl/point_types.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/io/pcd_io.h>
using namespace std;
int main(int argc, char* argv[]){
if (argc != 3)
{
cout << "Usage: " << argv[0] << " <input.pcd> <output.pcd>" << endl;
return -1;
}
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>());
if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) == -1){
PCL_ERROR("Could not read input file \n");
return -1;
}
cout << "Loaded " << cloud->points.size() << " points from " << argv[1] << endl;
pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond(new pcl::ConditionAnd<pcl::PointXYZ>());
range_cond->addComparison(pcl::FieldComparison<pcl::PointXYZ>::ConstPtr(new pcl::FieldComparison<pcl::PointXYZ>("x", pcl::ComparisonOps::GT, -30)));
range_cond->addComparison(pcl::FieldComparison<pcl::PointXYZ>::ConstPtr(new pcl::FieldComparison<pcl::PointXYZ>("x", pcl::ComparisonOps::LT, 30)));
range_cond->addComparison(pcl::FieldComparison<pcl::PointXYZ>::ConstPtr(new pcl::FieldComparison<pcl::PointXYZ>("y", pcl::ComparisonOps::GT, -30)));
range_cond->addComparison(pcl::FieldComparison<pcl::PointXYZ>::ConstPtr(new pcl::FieldComparison<pcl::PointXYZ>("y", pcl::ComparisonOps::LT, 30)));
pcl::ConditionalRemoval<pcl::PointXYZ> condrem;
condrem.setCondition(range_cond);
condrem.setInputCloud(cloud);
condrem.setKeepOrganized(true);
condrem.filter(*cloud_filtered);
cout << "Filtered cloud contains" << cloud_filtered->points.size() << "points." << endl;
pcl::io::savePCDFileASCII(argv[2], *cloud_filtered);
cout << "Saved filtered point cloud to" << argv[2] << endl;
return 0;
}