PCL 无序点云的快速三角剖分
这个程序可以把3D点云里的点组合成很多三角形然后把这些三角形拼接生成连续表面。先看看输入的3D点云程序运行后会显示生成的连续表面输入bun0.pcd输出没有保存输出结果运行编译后直接双击即可运行代码#include pcl/point_types.h #include pcl/io/pcd_io.h #include pcl/search/kdtree.h // for KdTree #include pcl/features/normal_3d.h #include pcl/surface/gp3.h int main () { // Load input file into a PointCloudT with an appropriate type pcl::PointCloudpcl::PointXYZ::Ptr cloud (new pcl::PointCloudpcl::PointXYZ); pcl::PCLPointCloud2 cloud_blob; pcl::io::loadPCDFile (bun0.pcd, cloud_blob); pcl::fromPCLPointCloud2 (cloud_blob, *cloud); //* the data should be available in cloud // Normal estimation* pcl::NormalEstimationpcl::PointXYZ, pcl::Normal n; pcl::PointCloudpcl::Normal::Ptr normals (new pcl::PointCloudpcl::Normal); pcl::search::KdTreepcl::PointXYZ::Ptr tree (new pcl::search::KdTreepcl::PointXYZ); tree-setInputCloud (cloud); n.setInputCloud (cloud); n.setSearchMethod (tree); n.setKSearch (20); n.compute (*normals); //* normals should not contain the point normals surface curvatures // Concatenate the XYZ and normal fields* pcl::PointCloudpcl::PointNormal::Ptr cloud_with_normals (new pcl::PointCloudpcl::PointNormal); pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); //* cloud_with_normals cloud normals // Create search tree* pcl::search::KdTreepcl::PointNormal::Ptr tree2 (new pcl::search::KdTreepcl::PointNormal); tree2-setInputCloud (cloud_with_normals); // Initialize objects pcl::GreedyProjectionTriangulationpcl::PointNormal gp3; pcl::PolygonMesh triangles; // Set the maximum distance between connected points (maximum edge length) gp3.setSearchRadius (0.025); // Set typical values for the parameters gp3.setMu (2.5); gp3.setMaximumNearestNeighbors (100); gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees gp3.setMinimumAngle(M_PI/18); // 10 degrees gp3.setMaximumAngle(2*M_PI/3); // 120 degrees gp3.setNormalConsistency(false); // Get result gp3.setInputCloud (cloud_with_normals); gp3.setSearchMethod (tree2); gp3.reconstruct (triangles); // Additional vertex information std::vectorint parts gp3.getPartIDs(); std::vectorint states gp3.getPointStates(); // Finish return (0); }参考Fast triangulation of unordered point clouds — Point Cloud Library 0.0 documentation