Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

c++ - CGAL 2D Delaunay Triangulation: How to get edges as vertex id pairs

I have a set of 2D points each with an associated id. (e.g. if the points are stored in an array, the id is the index into each point 0,....,n-1 ).

Now I create a Delaunay triangulation of these points and want to list down all the finite edges. For each edge, I would like to have the ids of the points represented by corresponding 2 vertices. Example: if there's an edge between point 0 and point 2 then (0,2). Is this possible?

#include <vector>
#include <CGALExact_predicates_inexact_constructions_kernel.h>
#include <CGALDelaunay_triangulation_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay;
typedef K::Point_2 Point;

 void load_points(std::vector<Point>& rPoints)
 {
  rPoints.push_back(Point(10,10));   // first point
  rPoints.push_back(Point(60,10));   // second point
  rPoints.push_back(Point(30,40));   // third point
  rPoints.push_back(Point(40,80));   // fourth point
 }

void main()
{
 std::vector<Point> points;
 load_points(points);

 Delaunay dt;
 dt.insert(points.begin(),points.end());

 for(Delaunay::Finite_edges_iterator it = dt.finite_edges_begin(); it != dt.finite_edges_end(); ++it)
 {
     }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First you need to use a vertex type with info as in these examples. Then an edge is a pair containing a handle to a face as well as the index of the vertex in the face that is opposite to the edge.

if you have:

Delaunay::Edge e=*it;

indices you are looking for are:

int i1= e.first->vertex( (e.second+1)%3 )->info();
int i2= e.first->vertex( (e.second+2)%3 )->info();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...