#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
int
main(int argc, char** argv)
{
pcl::PointCloud< pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud< pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = 5;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (auto& point : *cloud)
{
point.x = 1024 * rand() / (RAND_MAX + 1.0f);
point.y = 1024 * rand() / (RAND_MAX + 1.0f);
point.z = 1024 * rand() / (RAND_MAX + 1.0f);
}
std::cerr << "Cloud before filtering : " << std::endl;
for (const auto& p: *cloud)
{
std::cerr << " " << p.x << " "
<< p.y << " "
<< p.z << " "<<std::endl;
}
pcl::PassThrough < pcl::PointXYZ> pass;
pass.setInputCloud(cloud);
//多次设置 前面的设置会失效,按最后一个设置来滤波
pass.setFilterFieldName("z");
pass.setFilterLimits(0.0, 500.0);
//下面的会生效 上面的会失效
pass.setFilterFieldName("x");
pass.setFilterLimits(0.0, 500.0);
pass.filter(*cloud_filtered);
std::cerr << "Cloud after filtering : " << std::endl;
for (const auto& p : *cloud_filtered)
{
std::cerr << " " << p.x << " "
<< p.y << " "
<< p.z << " " << std::endl;
}
std::cerr << "end of main procedure" << std::endl;
return 0;
}
PCL滤波--passthrough
最新推荐文章于 2023-02-23 15:50:43 发布