本文主要是介绍pcl三角面片拼接和PCL库的bug修复,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PCL面片拼接代码如下,我使用的1.10.1PCL,这个版本的库存在问题会导致输出的结果错误,在cc会报错: An error occurred while loading ‘combined mesh’
// 读取第一个PLY文件pcl::PolygonMesh mesh1;pcl::io::loadPLYFile("hole.ply", mesh1);// 读取第二个PLY文件pcl::PolygonMesh mesh2;pcl::io::loadPLYFile("no_hole.ply", mesh2);// 创建一个新的PolygonMeshpcl::PolygonMesh combinedMesh;pcl::PolygonMesh::concatenate(mesh1, mesh2, combinedMesh);// 将结果保存为PLY文件pcl::io::savePLYFile("combined_mesh.ply", combinedMesh);
在PolygonMesh.h中原始函数定义如下,其中计算point_offset 调用过晚,只需要把它剪切到
bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);之前即可
bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);if (success == false) {return false;}// Make the resultant polygon mesh take the newest stampmesh1.header.stamp = std::max(mesh1.header.stamp, mesh2.header.stamp);const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;std::transform(mesh2.polygons.begin (),mesh2.polygons.end (),std::back_inserter (mesh1.polygons),[point_offset](auto polygon){std::transform(polygon.vertices.begin (),polygon.vertices.end (),polygon.vertices.begin (),[point_offset](auto& point_idx){return point_idx + point_offset;});return polygon;});return true;
这篇关于pcl三角面片拼接和PCL库的bug修复的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!