CGAL三角化边缘迭代器包括原点

时间:2016-06-23 16:48:55

标签: c++ cgal

我目前正在学习使用CGAL进行3D三角测量,到目前为止,我已经设法通过插入和三角化4个顶点来创建一个正四面体。但是当我尝试遍历四面体的边缘并获得对应于该边缘的顶点时,我将原点作为顶点或先前边缘的副本。在2D中它一切正常,但在3D中出问题。我认为这与包含的无限/未定义顶点有关,但我不知道如何处理这个问题。任何帮助将不胜感激。

我的代码(从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;
}

1 个答案:

答案 0 :(得分:2)

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

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

点i1 = it-&gt; first-&gt; vertex(it-&gt; second) - &gt; point(); 点i2 = it-&gt; first-&gt; vertex(it-&gt; third) - &gt; point();