PCL+CGAL进行2D delaunay重建

发布时间:2023年12月22日

把pcl的点云转成CGAL支持的点云格式,重建后再转回PCL的三角面片格式,info就是pts里面pair的第二个参数,有需要也可以换成其他的,我这里是填入的索引,便于转成PCL支持的格式

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <fstream>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include<pcl/io/ply_io.h>

using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Vb = CGAL::Triangulation_vertex_base_with_info_2<std::size_t, K>;
using Tds = CGAL::Triangulation_data_structure_2<Vb>;
using Delaunay = CGAL::Delaunay_triangulation_2<K, Tds>;
using cgalPoint = Delaunay::Point;

typedef pcl::PointXYZ PointT;
typedef pcl::PointCloud<PointT> CloudT;
typedef CloudT::Ptr CP;

pcl::PolygonMesh delaunay2D(CP cloud)
{
    std::vector< std::pair<cgalPoint, std::size_t > > pts;
    pts.reserve(cloud->size());
    for (int i = 0; i < cloud->size(); i++)
    {
        PointT p = cloud->points[i];
        pts.emplace_back(cgalPoint(p.x, p.y), i);
    }
    Delaunay triangulation;
    triangulation.insert(pts.begin(), pts.end());

    pcl::PolygonMesh triangles;
    for (auto f = triangulation.faces_begin(); f != triangulation.faces_end(); ++f) {
        pcl::Vertices face_vertices;
        face_vertices.vertices.push_back(f->vertex(0)->info()); 
        face_vertices.vertices.push_back(f->vertex(1)->info()); 
        face_vertices.vertices.push_back(f->vertex(2)->info()); 
        triangles.polygons.push_back(face_vertices);
    }

    pcl::toPCLPointCloud2(*cloud, triangles.cloud);
    return triangles;
}

文章来源:https://blog.csdn.net/qq_39494059/article/details/135147851
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。