在处理多边形网格时,可能会出现有多个重复的边和顶点的情况。对于那些边和顶点,如果不认为网格是不正确,则网格的连通性是不完整的。
我们可以拼接多边形网格的边界以修复某些重复的东西。它包括两个主要步骤
- 首先是对几何形状相同但重复的边缘进行检测和配对
- 然后,它们被“缝合”在一起,这样重复的边和顶点就会从网格中移除,剩下的每条边都恰好关联到两个面上。
有三个函数可以执行这样的修复操作:前两个函数可以用来缝合同一边界的半边,而第三个函数则更通用,还可以缝合位于不同边界上的半边。
CGAL::Polygon_mesh_processing::stitch_boundary_cycle()
CGAL::Polygon_mesh_processing::stitch_boundary_cycles()
CGAL::Polygon_mesh_processing::stitch_borders()
可以处理自相交问题
【注意】输入网格应该是流形的(manifold),否则,拼接就不能保证成功。
示例
以下示例将缝合操作应用于具有重复边界边的简单四边形网格。
Polygon_mesh_processing/stitch_borders_example.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> Polyhedron;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char* argv[])
{
const char* filename = (argc > 1) ? argv[1] : "data/full_border_quads.off";
Polyhedron mesh;
if(!PMP::IO::read_polygon_mesh(filename, mesh))
{
std::cerr << "Invalid input." << std::endl;
return 1;
}
std::cout << "Before stitching : " << std::endl;
std::cout << "\t Number of vertices :\t" << mesh.size_of_vertices() << std::endl;
std::cout << "\t Number of halfedges :\t" << mesh.size_of_halfedges() << std::endl;
std::cout << "\t Number of facets :\t" << mesh.size_of_facets() << std::endl;
PMP::stitch_borders(mesh);
std::cout << "Stitching done : " << std::endl;
std::cout << "\t Number of vertices :\t" << mesh.size_of_vertices() << std::endl;
std::cout << "\t Number of halfedges :\t" << mesh.size_of_halfedges() << std::endl;
std::cout << "\t Number of facets :\t" << mesh.size_of_facets() << std::endl;
CGAL::IO::write_polygon_mesh("mesh_stitched.off", mesh, CGAL::parameters::stream_precision(17));
return 0;
}
输入
此示例输出的结果与原来相同,不知道这个函数有什么作用
使用记录
GTP的合并
- 试图将三个左右邻接的GTP进行合并,但没有成功
- 试图将两个上下邻接的GTP进行合并,也没有成功