2017-09-08 72 views
3

我想使用Voronoi圖提取邊緣點(點位於凸包的邊界邊緣上)。我知道一個無界單元格包含一個邊界站點點,但是如何使用迭代器訪問該信息?使用CGAL的Voronoi圖:僅提取邊緣點(凸包)

解決方案

VD vd; 
//initialise your voronoi diagram 
VD::Face_iterator it = vd.faces_begin(), beyond = vd.faces_end(); 
for (int f = 0; it != beyond; ++f, ++it) 
{ 
    std::cout << "Face " << f << ": \n"; 
    if (it->is_unbounded()) 
    { 
    // it's a boundary point 
    } 
} 

回答

0

閱讀CGAL 2D Delaunay Triangulation: How to get edges as vertex id pairs,並銘記維諾和德勞內的關係檢查這個example

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL/Delaunay_triangulation_2.h> 
#include <fstream> 
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 
typedef CGAL::Delaunay_triangulation_2<K> Triangulation; 
typedef Triangulation::Edge_iterator Edge_iterator; 
typedef Triangulation::Point   Point; 
int main() 
{ 
    std::ifstream in("data/voronoi.cin"); 
    std::istream_iterator<Point> begin(in); 
    std::istream_iterator<Point> end; 
    Triangulation T; 
    T.insert(begin, end); 
    int ns = 0; 
    int nr = 0; 
    Edge_iterator eit =T.edges_begin(); 
    for (; eit !=T.edges_end(); ++eit) { 
    CGAL::Object o = T.dual(eit); 
    if (CGAL::object_cast<K::Segment_2>(&o)) {++ns;} 
    else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;} 
    } 
    std::cout << "The Voronoi diagram has " << ns << " finite edges " 
     << " and " << nr << " rays" << std::endl; 
    return 0; 
} 

如果這不回答你的問題,然後得到啓發通過它並玩耍。