4

我对某些点进行了 Delaunay 三角剖分,并希望按长度升序遍历其中的所有边,以构建最小跨度线程。

我尝试了以下方法,但无法编译:

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> T;
typedef K::Point_2 P;
typedef T::Vertex_handle Vh;
typedef T::Vertex_iterator Vi;
typedef T::Edge_iterator Ei;

bool sortFunction (Ei a, Ei b) {
    K::FT la, lb;
    la = CGAL::squared_distance(a.source().point(), a.target().point());
    lb = CGAL::squared_distance(b.source().point(), b.target().point());
    return la < lb;
}

...
T g;
...
std::vector<Ei> edges;
for (Ei ei = g.edges_begin(); ei != g.edges_end(); ei++) {
    edges.push_back(ei);
}
std::sort(edges.begin(), edges.end(), sortFunction);
...

在 中编译失败sortFunction,说source是没有成员Edge_iterator。但是,文档在这里让我感到困惑。

CGAL 文档说边迭代器的值类型是半边。 据说我可以使用source()访问target()积分。

然而,情况似乎并非如此。我在这里搞砸了什么?

4

4 回答 4

4

edge_iteratorstd::pair一个面和一个顶点索引。可以通过此面参考访问边的源顶点和目标顶点。edge_iterator 中的顶点索引符合相反的顶点。所以,另外两个有 id(i+2)%3(i+1)%3.

其他一些解决方案是通过 到达该段triangulation.segment(edge_iterator),然后使用source()andtarget()函数直接到达要点。但是,您无法通过这种方式访问​​顶点句柄。

于 2011-02-02T21:34:49.320 回答
2
Triangulation::Edge e;
//TODO: get e
Triangulation::Vertex_handle v1 = e.first->vertex((e.second + 1) % 3);
Triangulation::Vertex_handle v2 = e.first->vertex((e.second + 2) % 3);
K::FT squared_distance = CGAL::squared_distance(v1->point(), v2->point());
于 2013-11-03T13:47:37.257 回答
1

您可以通过以下方式访问端点的 vertex_handle

T::Vertex_handle sVertex = a->first->vertex(T::cw(a->second));

T::Vertex_handle fVertex = a->first->vertex(T::ccw(a->second));

依此类推..从每个 Vertex_handle 您可以使用 point 方法恢复点的坐标..

希望它可以帮助

于 2013-10-09T17:37:24.163 回答
-1

迭代器应该有点像指向实际元素的指针,因此您需要在访问任何成员之前取消引用它。尝试将其更改为a->source().point()

编辑:我猜句柄也是指针式的。看看它喜不喜欢这个。

la = CGAL::squared_distance(a->source()->point(), a->target()->point());
lb = CGAL::squared_distance(b->source()->point(), b->target()->point());
于 2011-01-28T17:09:35.150 回答