Getting a vertex_handle from an edge_iterator
Asked Answered
C

1

11

I'm having quite some difficulty getting a vertex_handle for each of the end points of an edge in a Delaunay triangulation. Since I hammered my head against this for several hours I thought maybe one of you guys could help me out with this apparently trivial problem:

#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();
  }
}

According to the documentation dereferencing an Edge_iterator I should get an Edge_handle and Edge_handle should have members source() and target() to simply get the endpoints, but it won't compile and seems to be wrong. Derefencing like above will give me a pair<> which doesn't have those member functions.

Any idea what I'm doing wrong?

Cadelle answered 29/1, 2011 at 13:43 Comment(2)
Where's the compilation failing?Afra
It's that (ei*) is of type pair which obviously does not have a source().Cadelle
B
12

Dereferencing an Edge_iterator will give you an Edge according to the documentation.

Edge is definded as follows: typedef std::pair<Face_handle,int> Edge;

Dereferencing the Face_handle will give you a Face.

The two vertices that the edge joins can be accessed by:

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

I don't know if it is helpful for you quest, but is access the points like this:

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

The CGAL documentation is confusing to me... I am curious where you found the eh->source() and eh->target() calls, I could not find it :-)

Babysit answered 29/1, 2011 at 15:32 Comment(2)
It should be handles rather than vertices in your first solution Vertex_handle vs and Vertex_handle vt.Electrometallurgy
tangentially related: So the most direct way to get the adjacent faces for an Edge_iterator would be to dereference it, then dereference the Face_handle to get one face, and then find the index of the edge to finally get it with neighbor(index) ? Edit: Just found mirror_edge which makes this a tad easierMeuse

© 2022 - 2024 — McMap. All rights reserved.