【问题标题】:Getting a vertex_handle from an edge_iterator从 edge_iterator 获取 vertex_handle
【发布时间】:2011-06-17 18:07:01
【问题描述】:

我很难为 Delaunay 三角剖分中的每个边的端点获取 vertex_handle。由于我为此苦苦思考了几个小时,我想也许你们中的一个人可以帮助我解决这个看似微不足道的问题:

#include <iostream>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>

using namespace std;

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
typedef Triangulation::Edge_iterator Edge_iterator;
typedef Triangulation::Vertex_handle Vertex;

int main(){
  Point p;
  Triangulation t;
  while(cin >> p)
    t.insert(p);

  // Iterate over edges
  for(Edge_iterator ei=t.finite_edges_begin();ei!=t.finite_edges_end(); ei++){
    // Get a vertex from the edge
    Vertex vs = ei->source();
  }
}

根据取消引用 Edge_iterator 的文档,我应该得到一个 Edge_handle 和 Edge_handle 应该有成员 source() 和 target() 来简单地获取端点,但它不会编译并且似乎是错误的。像上面这样的取消引用会给我一个没有这些成员函数的对。

知道我做错了什么吗?

【问题讨论】:

  • 哪里编译失败了?
  • 就是 (ei*) 是 pair 类型,显然没有 source()。

标签: c++ triangulation cgal delaunay


【解决方案1】:

根据documentation,取消引用Edge_iterator 将为您提供Edge

Edge 定义如下:typedef std::pair&lt;Face_handle,int&gt; Edge;

取消对Face_handle 的引用将为您提供Face

可以通过以下方式访问边连接的两个顶点:

  for(Edge_iterator ei=t.finite_edges_begin();ei!=t.finite_edges_end(); ei++){
    // Get a vertex from the edge
    Triangulation::Face& f = *(ei->first);
    int i = ei->second;
    Vertex vs = f.vertex(f.cw(i));
    Vertex vt = f.vertex(f.ccw(i));
  }

我不知道它是否对你的任务有帮助,但是像这样访问点:

for (Edge_iterator it = m_tri.edges_begin(); it != m_tri.edges_end(); ++it)
{
    Triangulation::Segment seg = m_tri.segment( *it );

    Triangulation::Point p0 = seg.point(0);
    Triangulation::Point p1 = seg.point(1);
    // ...
}

CGAL 文档让我感到困惑......我很好奇你在哪里找到了 eh-&gt;source()eh-&gt;target() 调用,我找不到它:-)

【讨论】:

  • 在您的第一个解决方案Vertex_handle vsVertex_handle vt 中,它应该是句柄而不是顶点。
  • 切向相关:因此,获取Edge_iterator 的相邻面的最直接方法是取消引用它,然后取消引用Face_handle 以获取一张面,然后找到最终通过neighbor(index) 获得它?编辑:刚刚找到mirror_edge,这让这变得更容易了
猜你喜欢
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-29
  • 2022-07-22
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
相关资源
最近更新 更多