CGAL 三角剖分边迭代器包括原点

CGAL Triangulation edge iterator includes origin

我目前正在学习使用 CGAL 执行 3D 三角剖分,到目前为止,我已经通过插入和三角剖分 4 个顶点成功地创建了一个正四面体。但是当我尝试遍历四面体的边缘并获得与该边缘对应的顶点时,我将原点作为顶点或先前边缘的副本。在 2D 中一切正常,但在 3D 中出现问题。我认为这与包含 infinite/undefined 顶点有关,但我不知道如何处理。任何帮助将不胜感激。

我的代码(修改自this question):

#include <vector>
#include <iostream>
#include <cmath>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K> Delaunay;
typedef K::Point_3 Point;

 void load_points(std::vector<Point>& rPoints)
 {
  rPoints.push_back(Point(1.0, 0.0, -1.0/sqrt(2)));   // first point
  rPoints.push_back(Point(-1.0, 0.0, -1.0/sqrt(2)));   // second point
  rPoints.push_back(Point(0.0, 1.0, 1.0/sqrt(2)));   // third point
  rPoints.push_back(Point(0.0, -1.0, 1.0/sqrt(2)));   // fourth point
 }

int main()
{
 std::vector<Point> points;
 load_points(points);

 Delaunay dt;
 dt.insert(points.begin(),points.end());

 for(Delaunay::Finite_edges_iterator it = dt.finite_edges_begin(); it != dt.finite_edges_end(); ++it)
 {
   Point i1= it->first->vertex( (it->second+1)%3 )->point();
   Point i2= it->first->vertex( (it->second+2)%3 )->point();
   std::cout << "i1: " << i1 << "\t i2: " << i2 << "\n";
  }

  return 0;
}

edge 的文档表明它是一个三元组:(c,i,j) 是顶点索引为 i 和 j 的单元格 c 的边。

所以在你的代码中你应该这样写:

点i1=它->第一个->顶点(它->第二个)->点(); 点 i2= it->first->vertex( it->third )->point();