Centos7.2 eclipse使用CGAL求主骨架

环境说明

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.编译提示缺少库:

添加CGAL基础库

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值