版权声明:本文为博主newston原创文章,允许转载,但转载必须保留原创链接。 https://blog.csdn.net/newston/article/details/78691513
环境说明
centos7.2 1511版本,直接使用eclipse IDE可执行文件。eclipse版本:eclipse-cpp-neon-1a-linux-gtk-x86_64.tar.gz
Eclipse IDE for C/C++ Developers
Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
Centos7.2安装CGAL请查看之前文章
打开eclipse创建C++可执行文件工程
新建main.cpp文件,使用官网example:
#include "print.h"
typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
typedef K::Point_2 Point ;
typedef CGAL::Polygon_2<K> Polygon_2 ;
typedef CGAL::Straight_skeleton_2<K> Ss ;
typedef boost::shared_ptr<Ss> SsPtr ;
int main()
{
Polygon_2 poly ;
poly.push_back( Point(-1,-1) ) ;
poly.push_back( Point(0,-12) ) ;
poly.push_back( Point(1,-1) ) ;
poly.push_back( Point(12,0) ) ;
poly.push_back( Point(1,1) ) ;
poly.push_back( Point(0,12) ) ;
poly.push_back( Point(-1,1) ) ;
poly.push_back( Point(-12,0) ) ;
// You can pass the polygon via an iterator pair
SsPtr iss = CGAL::create_interior_straight_skeleton_2(poly.vertices_begin(), poly.vertices_end());
// Or you can pass the polygon directly, as below.
// To create an exterior straight skeleton you need to specify a maximum offset.
double lMaxOffset = 5 ;
SsPtr oss = CGAL::create_exterior_straight_skeleton_2(lMaxOffset, poly);
print_straight_skeleton(*iss);
print_straight_skeleton(*oss);
return 0;
}
1.编译提示无法找到print.h文件:
从./cgal-releases-CGAL-4.7/Straight_skeleton_2/examples/Straight_skeleton_2目录下复制该文件到工程源文件夹下,与main.cpp文件在一起。
2.编译提示缺少库:
3.编译成功后运行结果:
Straight skeleton with 10 vertices, 34 halfedges and 8 faces
(-12,0)->(-1,-1) contour
(-1,-1)->(-12,0) contour
(-1,-1)->(0,-12) contour
(0,-12)->(-1,-1) contour
(0,-12)->(1,-1) contour
(1,-1)->(0,-12) contour
(1,-1)->(12,0) contour
(12,0)->(1,-1) contour
(12,0)->(1,1) contour
(1,1)->(12,0) contour
(1,1)->(0,12) contour
(0,12)->(1,1) contour
(0,12)->(-1,1) contour
(-1,1)->(0,12) contour
(-1,1)->(-12,0) contour
(-12,0)->(-1,1) contour
(-1,-1)->(5.3871e-17,-1.23134e-16) bisector
(5.3871e-17,-1.23134e-16)->(-1,-1) bisector
(0,-12)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(0,-12) bisector
(1,-1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(1,-1) bisector
(12,0)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(12,0) bisector
(1,1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(1,1) bisector
(0,12)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(0,12) bisector
(-1,1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(-1,1) bisector
(-12,0)->(5.3871e-17,-1.23134e-16) bisector
(5.3871e-17,-1.23134e-16)->(-12,0) bisector
(5.3871e-17,-1.23134e-16)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(5.3871e-17,-1.23134e-16) bisector
修改输出骨架点skeleton vertex
在print.h文件中添加输出函数:
template<class K>
void print_straight_skeleton_vertex( CGAL::Straight_skeleton_2<K> const& ss )
{
typedef CGAL::Straight_skeleton_2<K> Ss ;
typedef typename Ss::Vertex_const_handle Vertex_const_handle ;
typedef typename Ss::Vertex_const_iterator Vertex_const_iterator;
typedef typename Ss::Halfedge_const_handle Halfedge_const_handle ;
typedef typename Ss::Halfedge_const_iterator Halfedge_const_iterator ;
Halfedge_const_handle null_halfedge ;
Vertex_const_handle null_vertex ;
std::cout << "Straight skeleton with " << ss.size_of_vertices()
<< " vertices, " << ss.size_of_halfedges()
<< " halfedges and " << ss.size_of_faces()
<< " faces" << std::endl ;
for ( Halfedge_const_iterator i = ss.halfedges_begin(); i != ss.halfedges_end(); ++i )
{
print_point(i->opposite()->vertex()->point()) ;
std::cout << "->" ;
print_point(i->vertex()->point());
std::cout << " " << ( i->is_bisector() ? "bisector" : "contour" ) << std::endl;
}
for ( Vertex_const_iterator j = ss.vertices_begin(); j != ss.vertices_end(); ++j )
{
print_point(j->point());
std::cout << ( j->is_skeleton() ? "skeleton vertex" : "contour vertex" )<< std::endl;
}
}
输出为:
Straight skeleton with 10 vertices, 34 halfedges and 8 faces
(-12,0)->(-1,-1) contour
(-1,-1)->(-12,0) contour
(-1,-1)->(0,-12) contour
(0,-12)->(-1,-1) contour
(0,-12)->(1,-1) contour
(1,-1)->(0,-12) contour
(1,-1)->(12,0) contour
(12,0)->(1,-1) contour
(12,0)->(1,1) contour
(1,1)->(12,0) contour
(1,1)->(0,12) contour
(0,12)->(1,1) contour
(0,12)->(-1,1) contour
(-1,1)->(0,12) contour
(-1,1)->(-12,0) contour
(-12,0)->(-1,1) contour
(-1,-1)->(5.3871e-17,-1.23134e-16) bisector
(5.3871e-17,-1.23134e-16)->(-1,-1) bisector
(0,-12)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(0,-12) bisector
(1,-1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(1,-1) bisector
(12,0)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(12,0) bisector
(1,1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(1,1) bisector
(0,12)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(0,12) bisector
(-1,1)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(-1,1) bisector
(-12,0)->(5.3871e-17,-1.23134e-16) bisector
(5.3871e-17,-1.23134e-16)->(-12,0) bisector
(5.3871e-17,-1.23134e-16)->(-1.23134e-16,-1.07742e-16) bisector
(-1.23134e-16,-1.07742e-16)->(5.3871e-17,-1.23134e-16) bisector
(-1,-1)contour vertex
(0,-12)contour vertex
(1,-1)contour vertex
(12,0)contour vertex
(1,1)contour vertex
(0,12)contour vertex
(-1,1)contour vertex
(-12,0)contour vertex
(5.3871e-17,-1.23134e-16)skeleton vertex
(-1.23134e-16,-1.07742e-16)skeleton vertex
说明:
实验代码中只运行了 create_interior_straight_skeleton_2