我想使用cgal的骨架方法计算与中间轴变换非常接近的值。我基于cgal的计算框架示例编写了一个非常简单的代码。
包括:
#include<boost/shared_ptr.hpp>
#include<CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include<CGAL/Polygon_2.h>
#include<CGAL/create_straight_skeleton_2.h>
#include<CGAL/Polygon_with_holes_2.h>
#include<CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
typedef K::Point_2 Point ;
typedef CGAL::Polygon_2<K> Polygon_2 ;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes ;
typedef CGAL::Straight_skeleton_2<K> Ss ;
typedef boost::shared_ptr<Ss> SsPtr ;
typedef Ss::Vertex_const_handle Vertex_const_handle ;
typedef Ss::Vertex_const_iterator Vertex_const_iterator ;
typedef Ss::Halfedge_const_handle Halfedge_const_handle ;
typedef Ss::Halfedge_const_iterator Halfedge_const_iterator ;
代码
Polygon_2 outer ;
outer.push_back( Point(-1,-1) ) ;
outer.push_back( Point(0,-12) ) ;
outer.push_back( Point(1,-1) ) ;
outer.push_back( Point(12,0) ) ;
outer.push_back( Point(1,1) ) ;
outer.push_back( Point(0,12) ) ;
outer.push_back( Point(-1,1) ) ;
outer.push_back( Point(-12,0) ) ;
Polygon_2 hole ;
hole.push_back( Point(-1,0) ) ;
hole.push_back( Point(0,1 ) ) ;
hole.push_back( Point(1,0 ) ) ;
hole.push_back( Point(0,-1) ) ;
Polygon_with_holes poly( outer ) ;
poly.add_hole( hole ) ;
// You can pass the polygon via an iterator pair
SsPtr ss = CGAL::create_interior_straight_skeleton_2(poly);
然后我迭代计算出的骨架的边缘:
for ( Halfedge_const_iterator i = (*ss).halfedges_begin(); i != (*ss).halfedges_end(); ++i )
{
if (i->is_inner_bisector())
{
cout << i->opposite()->vertex()->point() << "->" << i->vertex()->point() << endl;
}
}
结果是完全错误的骨架。输入是一个有孔的多边形。计算出的骨架与该孔相交,其总体形状是完全错误的。
请帮助我为它计算正确的骨架。
谢谢。