emersonmx

CGAL_arr_printer

Jan 12th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.92 KB | None | 0 0
  1. #ifndef _PRINT_ARR_H_
  2. #define _PRINT_ARR_H_
  3.  
  4. //-----------------------------------------------------------------------------
  5. // Print all neighboring vertices to a given arrangement vertex.
  6. //
  7. template<class Arrangement>
  8. void print_neighboring_vertices (typename Arrangement::Vertex_const_handle v)
  9. {
  10.   if (v->is_isolated())
  11.   {
  12.     std::cout << "The vertex (" << v->point() << ") is isolated" << std::endl;
  13.     return;
  14.   }
  15.  
  16.   typename Arrangement::Halfedge_around_vertex_const_circulator  first, curr;
  17.   typename Arrangement::Vertex_const_handle                      u;
  18.  
  19.   std::cout << "The neighbors of the vertex (" << v->point() << ") are:";
  20.   first = curr = v->incident_halfedges();
  21.   do
  22.   {
  23.     // Note that the current halfedge is (u -> v):
  24.     u = curr->source();
  25.     std::cout << " (" << u->point() << ")";
  26.  
  27.     ++curr;
  28.   } while (curr != first);
  29.   std::cout << std::endl;
  30.  
  31.   return;
  32. }
  33.  
  34. //-----------------------------------------------------------------------------
  35. // Print all vertices (points) and edges (curves) along a connected component
  36. // boundary.
  37. //
  38. template<class Arrangement>
  39. void print_ccb (typename Arrangement::Ccb_halfedge_const_circulator circ)
  40. {
  41.   typename Arrangement::Ccb_halfedge_const_circulator  curr = circ;
  42.   typename Arrangement::Halfedge_const_handle          he;
  43.  
  44.   std::cout << "(" << curr->source()->point() << ")";
  45.   do
  46.   {
  47.     he = curr;
  48.     std::cout << "   [" << he->curve() << "]   "
  49.               << "(" << he->target()->point() << ")";
  50.  
  51.     ++curr;
  52.   } while (curr != circ);
  53.   std::cout << std::endl;
  54.  
  55.   return;
  56. }
  57.  
  58. //-----------------------------------------------------------------------------
  59. // Print the boundary description of an arrangement face.
  60. //
  61. template<class Arrangement>
  62. void print_face (typename Arrangement::Face_const_handle f)
  63. {
  64.   // Print the outer boundary.
  65.   if (f->is_unbounded())
  66.   {
  67.     std::cout << "Unbounded face. " << std::endl;
  68.   }
  69.   else
  70.   {
  71.     std::cout << "Outer boundary: ";
  72.     print_ccb<Arrangement> (f->outer_ccb());
  73.   }
  74.  
  75.   // Print the boundary of each of the holes.
  76.   typename Arrangement::Hole_const_iterator  hole;
  77.   int                                         index = 1;
  78.  
  79.   for (hole = f->holes_begin(); hole != f->holes_end(); ++hole, ++index)
  80.   {
  81.     std::cout << "    Hole #" << index << ": ";
  82.     print_ccb<Arrangement> (*hole);
  83.   }
  84.  
  85.   // Print the isolated vertices.
  86.   typename Arrangement::Isolated_vertex_const_iterator  iv;
  87.  
  88.   for (iv = f->isolated_vertices_begin(), index = 1;
  89.        iv != f->isolated_vertices_end(); ++iv, ++index)
  90.   {
  91.     std::cout << "    Isolated vertex #" << index << ": "
  92.               << "(" << iv->point() << ")" << std::endl;
  93.   }
  94.  
  95.   return;
  96. }
  97.  
  98. //-----------------------------------------------------------------------------
  99. // Print the given arrangement.
  100. //
  101. template<class Arrangement>
  102. void print_arrangement (const Arrangement& arr)
  103. {
  104.   CGAL_precondition (arr.is_valid());
  105.  
  106.   // Print the arrangement vertices.
  107.   typename Arrangement::Vertex_const_iterator  vit;
  108.  
  109.   std::cout << arr.number_of_vertices() << " vertices:" << std::endl;
  110.   for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit)
  111.   {
  112.     std::cout << "(" << vit->point() << ")";
  113.     if (vit->is_isolated())
  114.       std::cout << " - Isolated." << std::endl;
  115.     else
  116.       std::cout << " - degree " << vit->degree() << std::endl;
  117.   }
  118.  
  119.   // Print the arrangement edges.
  120.   typename Arrangement::Edge_const_iterator    eit;
  121.  
  122.   std::cout << arr.number_of_edges() << " edges:" << std::endl;
  123.   for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit)
  124.     std::cout << "[" << eit->curve() << "]" << std::endl;
  125.  
  126.   // Print the arrangement faces.
  127.   typename Arrangement::Face_const_iterator    fit;
  128.  
  129.   std::cout << arr.number_of_faces() << " faces:" << std::endl;
  130.   for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit)
  131.     print_face<Arrangement> (fit);
  132.  
  133.   return;
  134. }
  135.  
  136. #endif
Advertisement
Add Comment
Please, Sign In to add comment