首页 > 其他分享 >CGAL类柱面(管状)点云曲面生成+两端封口

CGAL类柱面(管状)点云曲面生成+两端封口

时间:2024-10-11 13:21:05浏览次数:3  
标签:std 封口 return CGAL bound mesh max 点云 hole

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/Face_filtered_graph.h>
#include<CGAL/Advancing_front_surface_reconstruction.h>
#include <CGAL/Polygon_mesh_processing/repair.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor     face_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<Mesh>::vertex_descriptor   vertex_descriptor;

// 参见 https://doc.cgal.org/latest/Advancing_front_surface_reconstruction/Advancing_front_surface_reconstruction_2reconstruction_fct_8cpp-example.html
struct Perimeter {

    double bound;

    Perimeter(double bound)
        : bound(bound)
    {}

    template <typename AdvancingFront, typename Cell_handle>
    double operator() (const AdvancingFront& adv, Cell_handle& c,
        const int& index) const
    {
        // bound == 0 is better than bound < infinity
        // as it avoids the distance computations
        if (bound == 0) {
            // smallest_radius_delaunay_sphere是指在给定的点集中,找到一个最小半径的球体,
            // 该球体是 Delaunay 三角剖分的一部分。
            return adv.smallest_radius_delaunay_sphere(c, index);
        }

        // If perimeter > bound, return infinity so that facet is not used
        // 保证生成的facet的每条边长度都不超过bound
        double d = 0;
        d = sqrt(squared_distance(c->vertex((index + 1) % 4)->point(),
            c->vertex((index + 2) % 4)->point()));
        if (d > bound) return adv.infinity();
        d += sqrt(squared_distance(c->vertex((index + 2) % 4)->point(),
            c->vertex((index + 3) % 4)->point()));
        if (d > bound) return adv.infinity();
        d += sqrt(squared_distance(c->vertex((index + 1) % 4)->point(),
            c->vertex((index + 3) % 4)->point()));
        if (d > bound) return adv.infinity();

        // Otherwise, return usual priority value: smallest radius of
        // delaunay sphere
        return adv.smallest_radius_delaunay_sphere(c, index);
    }
};

bool is_small_hole(halfedge_descriptor h, Mesh& mesh,
    double max_hole_diam, int max_num_hole_edges)
{
    int num_hole_edges = 0;
    CGAL::Bbox_3 hole_bbox;
    for (halfedge_descriptor hc : CGAL::halfedges_around_face(h, mesh))
    {
        const Point& p = mesh.point(target(hc, mesh));

        hole_bbox += p.bbox();
        ++num_hole_edges;

        // Exit early, to avoid unnecessary traversal of large holes
        if (num_hole_edges > max_num_hole_edges) return false;
        if (hole_bbox.xmax() - hole_bbox.xmin() > max_hole_diam) return false;
        if (hole_bbox.ymax() - hole_bbox.ymin() > max_hole_diam) return false;
        if (hole_bbox.zmax() - hole_bbox.zmin() > max_hole_diam) return false;
    }

    return true;
}

int main()
{
    std::vector<Kernel::Point_3> result; // 【输入】类柱面(管状)点云
    ...
    typedef std::array<std::size_t, 3> Facet; // Triple of indices
    std::vector<Facet> facets;

    Perimeter perimeter(5.0); // 生成的面片应满足任意edge长度不超过5.0

    CGAL::advancing_front_surface_reconstruction(result.begin(),
        result.end(),
        std::back_inserter(facets), perimeter);

    // copy points for random access
    std::vector<Point> vertices;
    vertices.reserve(points.size());
    std::copy(result.begin(), result.end(), std::back_inserter(vertices));
   
    CGAL::Surface_mesh<Point> output_mesh;
    CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(vertices, facets, output_mesh);

    // 以下两个参数用于筛选出mesh中符合条件的边缘
    double max_hole_diam = 1000.0;  // 某一端闭合边缘最大半径
    int max_num_hole_edges = 1000;  // 某一端闭合边缘最多包含的Edge数量

    std::vector<halfedge_descriptor> border_cycles;
    // collect one halfedge per boundary cycle
    PMP::extract_boundary_cycles(output_mesh, std::back_inserter(border_cycles));
    for (halfedge_descriptor h : border_cycles)
    {
        if (max_hole_diam > 0 && max_num_hole_edges > 0 &&
            !is_small_hole(h, output_mesh, max_hole_diam, max_num_hole_edges))
            continue;
        PMP::triangulate_hole(output_mesh, h);
    }
    
    // 【输出】
    std::ofstream f("out_af.off");
    f << output_mesh;
    f.close();
    ...
}

标签:std,封口,return,CGAL,bound,mesh,max,点云,hole
From: https://blog.csdn.net/xmyzqs1212/article/details/142815425

相关文章

  • PCL 使用八叉树进行点云变化检测
    目录一、概述二、代码三、结果一、概述  PCL中的pcl::octree::OctreePointCloudChangeDetector函数能够实现同时构建八叉树并完成空间变化检测。二、代码#include<iostream>#include<pcl/io/pcd_io.h>#include<pcl/point_types.h>#include<pcl/octree/oc......
  • 三维点云使用pcl实现RANSAC平面分割
    小白每日一练!点云分割分割是将点云划分为多个部分的过程,每个部分代表不同的物体或表面。在这里,我们使用RANSAC算法来识别和分离平面。(以ModelNet40为例)完整代码放在最后面啦!!测试好了可以直接使用!!RANSAC算法RANSAC算法是一种用于从一组包含异常数据的观测数据中估计数学模......
  • 一些点云的小知识,从官方文档中发现的例子
    1、判断点云的点是否是有效的 pcl::PointXYZp_valid; p_valid.x=0; p_valid.y=0; p_valid.z=0; std::cout<<"Isp_validvalid?"<<pcl::isFinite(p_valid)<<std::endl; //IfanycomponentisNaN,thepointisnotfinite. pcl::Poi......
  • Open3D 点云分割之最小图割算法(C++)
    文章目录一、原理概述1.1基本原理1.2最小割算法二、实现代码三、实现代码参考资料一、原理概述1.1基本原理(1)首先用一个无向图G=<V,E>来表示要分割的点云,V和E分别是顶点和边的集合(构建无向图),其中每条边均有着相应的权重。不同于普通的图结构,GraphCuts图......
  • PCL 点云中的数学
    函数求导方差&协方差矩阵基本概念方差(Variance)衡量的是单个随机变量的变化(比如一个人在群体中的身高),概率论中方差用来度量随机变量和其数学期望(即均值)之间的偏离程度。标准差(StandardDeviation)是方差的算术平方根,用σ表示。标准差能反映一个数据集的离散程度。协方......
  • PCL 点云表面法线估算
    估算点云表面法线表面法线是几何表面的重要属性,在许多领域(例如计算机图形应用程序)中大量使用,以应用正确的光源以产生阴影和其他视觉效果。给定一个几何表面,通常很难将表面某个点的法线方向推断为垂直于该点表面的向量。但是,由于我们获取的点云数据集是真实表面上的一组点......
  • PCL 计算点云距离
    文章目录一、简介二、实现代码三、实现效果参考资料一、简介顾名思义,这个就是计算点云中每个点到另一个点云最近的距离,之后我们可以基于这些距离做一些预处理工作。思路其实很简单,通过对点云构建kdtree并采用并行的方式实现该计算过程。二、实现代码ColorR......
  • TPAMI 2024 | 点云分割领域自适应的组合语义混合
    CompositionalSemanticMixforDomainAdaptationinPointCloudSegmentation点云分割领域自适应的组合语义混合CristianoSaltori,FabioGalasso,GiuseppeFiameni,NicuSebe,FabioPoiesi,ElisaRicci代码:https://github.com/saltoricristiano/cosmix-uda摘......
  • PointNet++改进策略 :模块改进 | SWA| PVT,融入Transformer的点云与体素的模块同时提升
    目录介绍PVT原理PVT的核心思想和结构PVT模块结构体素分支点分支代码实现论文题目:PVT:Point-VoxelTransformerforPointCloudLearning发布期刊:InternationalJournalofIntelligentSystems通讯地址:杭州电子科技大学&伦敦大学学院代码地址:https://github.com/......
  • 【LVI-SAM】激光点云如何辅助视觉特征深度提取
    LVI-SAM激光点云辅助视觉特征深度提取1.坐标系转换2.构建单位球面坐标系下的图像特征点和激光点云3.构建深度直方图并过滤激光点云4.最近邻搜索与深度估计5.深度投影与可视化总结这段代码的核心任务是将激光点云中的点与图像上的特征点进行对应,并计算图像特征......