下面的例子是计算点集points,每个点设置一个索引,计算它的凸包,out中返回一个凸多边形的逆时针排序的顶点的索引
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <CGAL/Convex_hull_traits_adapter_2.h>
#include <CGAL/property_map.h>
#include <vector>
#include <numeric>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef CGAL::Convex_hull_traits_adapter_2<K,
CGAL::Pointer_property_map<Point_2>::type > Convex_hull_traits_2;
int main()
{
std::vector<Point_2> points = {
Point_2(0,0), Point_2(10,0),
Point_2(3,3), Point_2(0,10),};
std::vector<std::size_t> indices(points.size()), out;
// indices 由 iota 设置为 0,1,2,3 点在points中的下标
std::iota(indices.begin(), indices.end(),0);
CGAL::convex_hull_2(indices.begin(), indices.end(), std::back_inserter(out),
Convex_hull_traits_2(CGAL::make_property_map(points)));
// out 中为 0, 1, 3
for( std::size_t i : out){
std::cout << "points[" << i << "] = " << points[i] << std::endl;
}
return 0;
}