如何从CGAL中的Edge_iterator获取源点和目标点
我对某些点进行了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
edge_iterator
是面和顶点索引的std::pair
。可以通过该面参考访问边的源顶点和目标顶点。 edge_iterator 中的顶点索引与相反的顶点一致。因此,另外两个的 ID 为(i+2)%3
和(i+1)%3
。其他一些解决方案是通过 triangulation.segment(edge_iterator) 获取段,然后使用 source() 和 target() 函数获取直接给分。但是,您无法以这种方式访问顶点句柄。
The
edge_iterator
is astd::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 thesource()
andtarget()
functions to get to the points directly. However, you cannot get access to the vertex handles that way.访问端点的 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
迭代器的行为应该有点像指向实际元素的指针,因此您需要在访问任何成员之前取消引用它。尝试将其更改为
a->source().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.