在处理多边形网格时,可能会出现有多个重复的边和顶点的情况。对于那些边和顶点,如果不认为网格是不正确,则网格的连通性是不完整的。
我们可以拼接多边形网格的边界以修复某些重复的东西。它包括两个主要步骤

  1. 首先是对几何形状相同但重复的边缘进行检测和配对
  2. 然后,它们被“缝合”在一起,这样重复的边和顶点就会从网格中移除,剩下的每条边都恰好关联到两个面上。

有三个函数可以执行这样的修复操作:前两个函数可以用来缝合同一边界的半边,而第三个函数则更通用,还可以缝合位于不同边界上的半边。

  1. CGAL::Polygon_mesh_processing::stitch_boundary_cycle()
  2. CGAL::Polygon_mesh_processing::stitch_boundary_cycles()
  3. CGAL::Polygon_mesh_processing::stitch_borders() 可以处理自相交问题

【注意】输入网格应该是流形的(manifold),否则,拼接就不能保证成功。

示例

以下示例将缝合操作应用于具有重复边界边的简单四边形网格。

Polygon_mesh_processing/stitch_borders_example.cpp

  1. #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
  2. #include <CGAL/Polyhedron_3.h>
  3. #include <CGAL/Polygon_mesh_processing/stitch_borders.h>
  4. #include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
  5. #include <iostream>
  6. #include <fstream>
  7. typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
  8. typedef CGAL::Polyhedron_3<K> Polyhedron;
  9. namespace PMP = CGAL::Polygon_mesh_processing;
  10. int main(int argc, char* argv[])
  11. {
  12. const char* filename = (argc > 1) ? argv[1] : "data/full_border_quads.off";
  13. Polyhedron mesh;
  14. if(!PMP::IO::read_polygon_mesh(filename, mesh))
  15. {
  16. std::cerr << "Invalid input." << std::endl;
  17. return 1;
  18. }
  19. std::cout << "Before stitching : " << std::endl;
  20. std::cout << "\t Number of vertices :\t" << mesh.size_of_vertices() << std::endl;
  21. std::cout << "\t Number of halfedges :\t" << mesh.size_of_halfedges() << std::endl;
  22. std::cout << "\t Number of facets :\t" << mesh.size_of_facets() << std::endl;
  23. PMP::stitch_borders(mesh);
  24. std::cout << "Stitching done : " << std::endl;
  25. std::cout << "\t Number of vertices :\t" << mesh.size_of_vertices() << std::endl;
  26. std::cout << "\t Number of halfedges :\t" << mesh.size_of_halfedges() << std::endl;
  27. std::cout << "\t Number of facets :\t" << mesh.size_of_facets() << std::endl;
  28. CGAL::IO::write_polygon_mesh("mesh_stitched.off", mesh, CGAL::parameters::stream_precision(17));
  29. return 0;
  30. }

输入
image.png

此示例输出的结果与原来相同,不知道这个函数有什么作用
image.png
image.png

使用记录

GTP的合并

  1. 试图将三个左右邻接的GTP进行合并,但没有成功
  2. 试图将两个上下邻接的GTP进行合并,也没有成功