]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/planar_face_traversal.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / graph / example / planar_face_traversal.cpp
1 //=======================================================================
2 // Copyright 2007 Aaron Windsor
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8 #include <iostream>
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/graph/properties.hpp>
11 #include <boost/graph/graph_traits.hpp>
12 #include <boost/property_map/property_map.hpp>
13 #include <boost/ref.hpp>
14 #include <vector>
15
16 #include <boost/graph/planar_face_traversal.hpp>
17 #include <boost/graph/boyer_myrvold_planar_test.hpp>
18
19
20 using namespace boost;
21
22
23
24 // Some planar face traversal visitors that will
25 // print the vertices and edges on the faces
26
27 struct output_visitor : public planar_face_traversal_visitor
28 {
29 void begin_face() { std::cout << "New face: "; }
30 void end_face() { std::cout << std::endl; }
31 };
32
33
34
35 struct vertex_output_visitor : public output_visitor
36 {
37 template <typename Vertex>
38 void next_vertex(Vertex v)
39 {
40 std::cout << v << " ";
41 }
42 };
43
44
45
46 struct edge_output_visitor : public output_visitor
47 {
48 template <typename Edge>
49 void next_edge(Edge e)
50 {
51 std::cout << e << " ";
52 }
53 };
54
55
56 int main(int argc, char** argv)
57 {
58
59 typedef adjacency_list
60 < vecS,
61 vecS,
62 undirectedS,
63 property<vertex_index_t, int>,
64 property<edge_index_t, int>
65 >
66 graph;
67
68 // Create a graph - this is a biconnected, 3 x 3 grid.
69 // It should have four small (four vertex/four edge) faces and
70 // one large face that contains all but the interior vertex
71 graph g(9);
72
73 add_edge(0,1,g);
74 add_edge(1,2,g);
75
76 add_edge(3,4,g);
77 add_edge(4,5,g);
78
79 add_edge(6,7,g);
80 add_edge(7,8,g);
81
82
83 add_edge(0,3,g);
84 add_edge(3,6,g);
85
86 add_edge(1,4,g);
87 add_edge(4,7,g);
88
89 add_edge(2,5,g);
90 add_edge(5,8,g);
91
92
93 // Initialize the interior edge index
94 property_map<graph, edge_index_t>::type e_index = get(edge_index, g);
95 graph_traits<graph>::edges_size_type edge_count = 0;
96 graph_traits<graph>::edge_iterator ei, ei_end;
97 for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
98 put(e_index, *ei, edge_count++);
99
100
101 // Test for planarity - we know it is planar, we just want to
102 // compute the planar embedding as a side-effect
103 typedef std::vector< graph_traits<graph>::edge_descriptor > vec_t;
104 std::vector<vec_t> embedding(num_vertices(g));
105 if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
106 boyer_myrvold_params::embedding =
107 &embedding[0]
108 )
109 )
110 std::cout << "Input graph is planar" << std::endl;
111 else
112 std::cout << "Input graph is not planar" << std::endl;
113
114
115 std::cout << std::endl << "Vertices on the faces: " << std::endl;
116 vertex_output_visitor v_vis;
117 planar_face_traversal(g, &embedding[0], v_vis);
118
119 std::cout << std::endl << "Edges on the faces: " << std::endl;
120 edge_output_visitor e_vis;
121 planar_face_traversal(g, &embedding[0], e_vis);
122
123 return 0;
124 }