CGAL::2D Arrangements-2

2.3.2 遍历Arrangement Halfedge

Arrangement的一条Halfedge是和一个 X_monotone_curve_2对象绑定,这个curve可以通过e->curve()获取。

e->source()得到源点,e->target()得到目标点,e->twin()得到半边的对边,

第个半边都有一个关联面(incident face),这个关联面在半边的左边,可以通过e->face()获取到。

e->prev()和e->next(),得到关联的上一条和下一条半边。

下面是遍历一个face的halfedge代码段:

cpp 复制代码
template <typename Arrangement>
void print_ccb(typename Arrangement::Ccb_halfedge_const_circulator circ) {
  Ccb_halfedge_const_circulator curr = circ;
  std::cout << "(" << curr->source()->point() << ")";
  do {
    typename Arrangement::Halfedge_const_handle he = curr->handle();
    std::cout << " [" << e->curve() << "] "
              << "(" << e->target()->point() << ")";
  } while (++curr != circ);
  std::cout << std::endl;
}
2.3.3 遍历Arrangement Face

一个Arrangement_2对象arr始终有一个unbounded face,通过arr.unbounded_face()可以拿到,空的Arrangement_2也有一个unbounded face。

通过f->is_unboudned()可以确定一个face是否有边界,有边界的face有一个outer CCB。

下面是遍历face的代码段:

cpp 复制代码
template <typename Arrangement>
void print_face(typename Arrangement::Face_const_handle f) {
  // Print the outer boundary.
  if (f->is_unbounded()) std::cout << "Unbounded face.\n";
  else {
    std::cout << "Outer boundary: ";
    print_ccb(f->outer_ccb());
  }
  // Print the boundary of each of the holes.
  size_t index = 1;
  for (auto hi = f->holes_begin(); hi != f->holes_end(); ++hi) {
    std::cout << " Hole #" << index++ << ": ";
    print_ccb(*hi);
  }
  // Print the isolated vertices.
  index = 1;
  for (auto iv = f->isolated_vertices_begin();
       iv != f->isolated_vertices_end(); ++iv)
  {
    std::cout << " Isolated vertex #" << index++ << ": "
              << "(" << iv->point() << ")\n";
  }
}

遍历整个Arrangement的代码段如下:

cpp 复制代码
void print_arrangement (const Arrangement_2& arr) {
  // Print the arrangement vertices.
  std::cout << arr.number_of_vertices() << " vertices:\n";
  for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) {
    std::cout << "(" << vit->point() << ")";
    if (vit->is_isolated()) std::cout << " - Isolated.\n";
    else std::cout << " - degree " << vit->degree() << std::endl;
  }
  // Print the arrangement edges.
  std::cout << arr.number_of_edges() << " edges:\n";
  for (auto eit = arr.edges_begin(); eit != arr.edges_end(); ++eit)
    std::cout << "[" << eit->curve() << "]\n";
  // Print the arrangement faces.
  std::cout << arr.number_of_faces() << " faces:\n";
  for (auto fit = arr.faces_begin(); fit != arr.faces_end(); ++fit)
    print_face(fit);
}
2.4修改Arrangement
2.5插入一对不相连的x_Monotone Curves
相关推荐
bigHead-4 分钟前
前端双屏显示与通信
开发语言·前端·javascript
richxu202510019 分钟前
Java是当今最优雅的开发语言
java·开发语言
2501_918126919 分钟前
用Python开发一个三进制程序开发工具
开发语言·汇编·python·个人开发
坐怀不乱杯魂12 分钟前
C++ 11
c++
yuuki23323313 分钟前
【C++】揭秘STL:stack与queue的底层实现
java·c++·windows
zh_xuan25 分钟前
kotlin的常见空检查
android·开发语言·kotlin
草莓熊Lotso1 小时前
Python 进阶核心:字典 / 文件操作 + 上下文管理器实战指南
数据结构·c++·人工智能·经验分享·笔记·git·python
Tony Bai8 小时前
高并发后端:坚守 Go,还是拥抱 Rust?
开发语言·后端·golang·rust
wjs20249 小时前
Swift 类型转换
开发语言