如何从CGAL中的Edge_iterator获取源点和目标点

发布于 2024-10-14 22:39:38 字数 1328 浏览 1 评论 0原文

我对某些点进行了 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() 来访问这些点。

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

I have a Delaunay triangulation over some points and want to iterate over all of the edges in it in length-ascending order in order to build a minimum spanning thread.

I've tried with the following approach but cannot get it to compile:

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);
...

The compilation fails in the sortFunction, saying that source is no member of Edge_iterator. However, the documentation confuses me here.

CGAL documentation says that the value type of the edge iterator is a halfedge.
There it is said that I can use source() and target() to access the points.

However, this does not seem to be the case. What am I messing up here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的背包 2024-10-21 22:39:38

edge_iterator 是面和顶点索引的 std::pair。可以通过该面参考访问边的源顶点和目标顶点。 edge_iterator 中的顶点索引与相反的顶点一致。因此,另外两个的 ID 为 (i+2)%3(i+1)%3

其他一些解决方案是通过 triangulation.segment(edge_iterator) 获取段,然后使用 source() 和 target() 函数获取直接给分。但是,您无法以这种方式访问​​顶点句柄。

The edge_iterator is a std::pair of a face and a vertex index. The edge's source and target vertices can be accessed over this face reference. The vertex index in the edge_iterator conforms to the opposite vertex. So, the other two have id's (i+2)%3 and (i+1)%3.

Some other solution is getting to the segment via triangulation.segment(edge_iterator) and then using the source() and target() functions to get to the points directly. However, you cannot get access to the vertex handles that way.

落墨 2024-10-21 22:39:38

访问端点的 vertex_handle

您可以通过T::Vertex_handle sVertex = a->first->vertex(T::cw(a->second));

T::Vertex_handle fVertex = a->第一个->顶点(T::ccw(a->第二个));

等等..从每个 Vertex_handle 您可以使用 point 方法恢复点的坐标..

希望它能有所帮助

you can access to vertex_handle of the endpoints by

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

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

an so on.. From each Vertex_handle you can recover point's coordinates by using the point method..

Hope it can help

少女净妖师 2024-10-21 22:39:38
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());
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());
杀お生予夺 2024-10-21 22:39:38

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

编辑:我猜句柄也是类似指针的。看看它是否喜欢这个。

la = CGAL::squared_distance(a->source()->point(), a->target()->point());
lb = CGAL::squared_distance(b->source()->point(), b->target()->point());

Iterators should act a bit like pointers to the actual elements, so you need to dereference it before accessing any members. Try changing it to a->source().point()

Edit: I guess handles are also pointerlike. See if it likes this.

la = CGAL::squared_distance(a->source()->point(), a->target()->point());
lb = CGAL::squared_distance(b->source()->point(), b->target()->point());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文