How to get source and target points from Edge_iterator in CGAL

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

I tried using the following approach, but I can not compile it:

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

Compilation error in sortFunctionsaying that sourceit is not a member Edge_iterator. However, the documentation confuses me.

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

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

+3
source share
4 answers

edge_iterator std::pair . . edge_iterator . , id (i+2)%3 (i+1)%3.

triangulation.segment(edge_iterator), source() target() . .

+3

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 .

,

+1
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());
+1
source

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

Edit: I think descriptors are also similar to pointers. See if it likes it.

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

Source: https://habr.com/ru/post/1788525/


All Articles