2012-03-13 32 views
5

我有一組2D點,每個點都有一個關聯的ID。 (例如,如果點存儲在數組中,則id是到每個點0,...,n-1的索引)。CGAL 2D Delaunay三角剖分:如何將邊緣作爲頂點ID對

現在我創建這些點的Delaunay三角剖分,並希望列出所有有限邊緣。對於每個邊,我希望有相應的2個頂點表示的點的ID。例如:如果在點0和點2之間存在邊緣,則(0,2)。這可能嗎?

#include <vector> 
#include <CGAL\Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL\Delaunay_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) 
{ 
    } 
} 

回答

7

首先,你需要使用與信息頂點類型爲these examples。然後一個邊是一對包含一個面的句柄以及與邊相對的面的頂點索引。

如果您有:

Delaunay::Edge e=*it; 

指數你正在尋找的是:

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

sloriot:非常有幫助。謝謝。 – 911 2012-03-25 04:50:28

+0

太清楚了!謝謝。 – LoveMeow 2014-12-27 18:22:16

相關問題