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代码段:

template 
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的代码段:

template 
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的代码段如下:

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

你可能感兴趣的:(c++,开发语言)