CGAL:在定期三角剖分中使用边缘迭代器访问每个顶点的邻居的问题



我在我的代码中使用cgal中的定期delaunay三角剖分,并为每个顶点生成所有相邻的顶点。为此,我使用Edge Iterator,因为就我而言,它将比顶点迭代器快得多。这是代码片段,

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Periodic_2_triangulation_traits_2<Kernel> Gt;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned int, Gt> Vb;
typedef CGAL::Periodic_2_triangulation_face_base_2<Gt> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Periodic_2_Delaunay_triangulation_2<Gt, Tds> Triangulation;
typedef Triangulation::Iso_rectangle Iso_rectangle;
typedef Triangulation::Edge_iterator Edge_iterator;
typedef Triangulation::Vertex_handle Vertex_handle;
typedef Triangulation::Point Point;
typedef vector<pair<Point, unsigned> > Vector_Paired;
Vector_Paired points;
Iso_rectangle domain(0,0,L,L);
for(int iat = 0; iat < N; iat++)
    {
 points.push_back(make_pair(Point(r_tot[iat][0],r_tot[iat][1]),iat));
    }
Triangulation T(points.begin(), points.end(), domain);
for(Edge_iterator ei=T.finite_edges_begin(); ei!=T.finite_edges_end(); ei++)
    {
      Triangulation::Face& f = *(ei->first);
      int ii = ei->second;
      Vertex_handle vi = f.vertex(f.cw(ii));     
      Vertex_handle vj = f.vertex(f.ccw(ii));    
      int iat = vi->info();
      int jat = vj->info();
      VecInd[iat].push_back(jat);
      VecInd[jat].push_back(iat);
    }

但是,有时我会为每个顶点一个特殊的邻居,而我得到8或9或...同一邻居的副本。例如,在Vecind中,这是一个包含相邻索引的2D向量,我得到了这样的东西:vecind [0] = [2,2,2,2,2,4,4,4,...]

我找不到使用CGAL网站中的Edge Iterator的示例,而在Stackoverflow中没有任何相关性。我想知道该实施是否正确?我应该添加到我的代码中,以便每个邻居获得一个副本,我可以使用stl :: sets,但是我想知道问题的来源。

这是Mael的Cgal-Discuss邮件列表上发布的答案:


如果您的点集在几何学上的间隔不佳,则这些点的三角剖分可能不会在平坦的圆环上形成简单的复合物(换句话说,三角剖分中有短周期(。在这种情况下,该算法使用8份三角剖分来人为地创建一个简单的复合物。您可以使用函数is_triangulation_in_1_sheet()检查是否是这种情况,并在用户手册中阅读有关这些机制的更多信息。

当使用副本时,边缘上的迭代确实会为您提供基础数据结构所具有的完全:每个边缘的9个实体。为了获得唯一的,您可以通过查看边缘顶点的偏移来过滤9中的8个。这就是返回独特的周期性细分的迭代器中所做的。不幸的是,您想要边缘,并且此迭代器直接转换为边缘的几何形状(段(。但是,您可以简单地使用该迭代器的主要过滤功能,即:is_canonical()。此功能将查看边缘两个顶点的偏移,并仅保留在域的第一个副本中至少具有一个顶点的偏移,这足以使其独一无二。

最新更新