1 执行结果
原始点云可视化
搜索半径设置为0.1m
搜索半径设置为0.05m
2 代码实现
// boundary
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/boundary.h>
#include <pcl/io/file_io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/io.h>
using namespace std;
int main() {
// 加载点云数据
std::cout << "Process start" << endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//pcl::io::loadPCDFile<pcl::PointXYZ>(".\\input\\KuangshanCut_S85_cp30.pcd", *cloud);
//数据输入路径
pcl::io::loadPCDFile<pcl::PointXYZ>(".\\input\\cloud_in.pcd", *cloud);
//auto start_tm = std::chrono::high_resolution_clock::now();
// 估计法线
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud(cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
ne.setSearchMethod(tree);
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
ne.setRadiusSearch(0.08);
ne.compute(*normals);
std::cout << " Wait... " << endl;
// 计算边界
pcl::PointCloud<pcl::Boundary>::Ptr boundaries(new pcl::PointCloud<pcl::Boundary>);
pcl::PointCloud<pcl::PointXYZ>::Ptr boundary_points(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::Normal>::Ptr boundary_normals(new pcl::PointCloud<pcl::Normal>);
pcl::PointCloud<pcl::PointXYZ>::Ptr non_boundary_points(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::Normal>::Ptr non_boundary_normals(new pcl::PointCloud<pcl::Normal>);
pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> est;
est.setInputCloud(cloud);
est.setInputNormals(normals);
est.setRadiusSearch(0.1);
est.setSearchMethod(tree);
est.compute(*boundaries);
// 获取边界点和法线
for (size_t i = 0; i < cloud->size(); ++i) {
if (boundaries->points[i].boundary_point) {
boundary_points->push_back(cloud->points[i]);
boundary_normals->push_back(normals->points[i]);
}
else {
non_boundary_points->push_back(cloud->points[i]);
non_boundary_normals->push_back(normals->points[i]);
}
}
// 保存边界点云和非边界点云,数据输出路径
pcl::io::savePCDFile<pcl::PointXYZ>(".\\output\\cloud_out_boundary_r01_points.pcd", *boundary_points);
pcl::io::savePCDFile<pcl::PointXYZ>(".\\output\\cloud_out_nonboundary_r01_points.pcd", *non_boundary_points);
//计算程序执行时间
/*auto end_tm = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> dura = end_tm - start_tm;
double execu_tm = dura.count();
std::cout<<" The time of software executionTime"<<execu_tm<<" s"<<endl;*/
std::cout << "Process Done!" << endl;
return 0;
}