PCL+CGAL进行2D delaunay重建

把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;
}

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值