我使用CGAL與Qt繪製Voronoi圖。我用了CGAL::Voronoi_diagram_2<DT,AT,AP>
,因爲我需要臉。這是示例代碼:CGAL,裁剪的voronoi圖侷限在一個矩形
for(Face_iterator f = VD.faces_begin(); f != VD.faces_end(); f++)
{
Ccb_halfedge_circulator ec_start = (f)->ccb();
Ccb_halfedge_circulator ec = ec_start;
do {
if (!ec->has_source())
{
}
else
QpolyF << QPointF(((Halfedge_handle)ec)->source()->point().x(), ((Halfedge_handle)ec)->source()->point().y());
} while (++ec != ec_start);
VectPolygon.push_back(QpolyF);
QpolyF.clear();}
我需要剪輯在無限遠處有源或目標的光線。如果我使用Cropped_voronoi_from_delaunay生成voronoi,它只會給出片段不是面。這些都是類型定義:
typedef K::Line_2 Line_2;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay_triangulation_2;
typedef Delaunay_triangulation_2::Face_iterator dt_Face_iterator;
typedef Delaunay_triangulation_2::Edge_circulator dt_Edge_circulator;
// typedefs for defining the adaptor
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> DT;
typedef CGAL::Delaunay_triangulation_adaptation_traits_2<DT> AT;
typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT,AT,AP> VD;
// typedef for the result type of the point location
typedef AT::Site_2 Site_2;
typedef AT::Point_2 Point_2;
typedef VD::Locate_result Locate_result;
typedef VD::Vertex_handle Vertex_handle;
typedef VD::Face_handle Face_handle;
typedef VD::Face_iterator Face_iterator;
typedef VD::Halfedge_handle Halfedge_handle;
typedef VD::Ccb_halfedge_circulator Ccb_halfedge_circulator;
爲什麼不滿意以下示例: http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Subsection_37.5.4 ? – sloriot
正如我所說我需要面孔,但CGAL中的這個例子只給出了片段。 – M4G
還有「2D範圍和鄰居搜索」,它非常接近,但我不確定它是否支持此查詢,即使通過傳遞特定的函數。 http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Point_set_2/Chapter_main.html –