1<HTML> 2<!-- Copyright 2007 Aaron Windsor 3 4 Distributed under the Boost Software License, Version 1.0. 5 (See accompanying file LICENSE_1_0.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt) 7 8 --> 9<Head> 10<Title>Boost Graph Library: Planar Face Traversal</Title> 11<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 12 ALINK="#ff0000"> 13<IMG SRC="../../../boost.png" 14 ALT="C++ Boost" width="277" height="86"> 15 16<BR Clear> 17 18<H1>Planar Face Traversal</H1> 19 20<pre> 21template<typename Graph, typename PlanarEmbedding, typename PlanarFaceVisitor, typename EdgeIndexMap> 22void planar_face_traversal(const Graph& g, PlanarEmbedding embedding, PlanarFaceVisitor& visitor, EdgeIndexMap em); 23</pre> 24 25<p> 26A graph is <i>planar</i> if it can be drawn in two-dimensional space with no 27two of its edges crossing. Any embedding of a planar graph separates the plane 28into distinct regions that are bounded by sequences of edges in the graph. 29These regions are called <i>faces</i>. 30 31<br> 32<br> 33<table align="center" class="image"> 34<caption align="bottom"> 35<h5>A plane drawing of a graph (left), and the 8 faces defined by the planar 36embedding (right.) Each connected blue region in the image on the right is a 37face. The large blue region surrounding the graph is the <i>outer face</i>. 38</h5> 39</caption> 40<tr> 41<td> 42<img src="./figs/face_illustration.png"> 43</td> 44</tr> 45<tr></tr> 46</table> 47<br> 48 49 50A traversal of the faces of a planar graph involves iterating through all faces 51of the graph, and on each face, iterating through all vertices and edges of the 52face. The iteration through all vertices and edges of each face follows a 53path around the border of the face. 54<p> 55In a biconnected graph, like the one shown above, each face is bounded by a 56cycle and each edge belongs to exactly two faces. For this reason, when 57<tt>planar_face_traversal</tt> is called on a biconnected graph, each edge will 58be visited exactly twice: once on each of two distinct faces, and no vertex 59will be visited more than once on a particular face. The output of 60<tt>planar_face_traversal</tt> on non-biconnected graphs is less intuitive - 61for example, if the graph 62consists solely of a path of vertices (and therefore a single face), 63<tt>planar_face_traversal</tt> will iterate <i>around</i> the path, visiting 64each edge twice and visiting some vertices more than once. 65<tt>planar_face_traversal</tt> does not visit isolated vertices. 66<p> 67Like other graph traversal algorithms in the Boost Graph Library, the planar 68face traversal is a generic traversal that can be customized by the 69redefinition of certain visitor event points. By defining an appropriate 70visitor, this traversal can be 71used to enumerate the faces of a planar graph, triangulate a planar graph, or 72even construct a dual of a planar graph. 73 74<br> 75<center> 76<img src="./figs/face_traversal_example.png"> 77</center> 78<br> 79 80For example, on the above graph, an instance <tt>my_visitor</tt> of the 81following visitor: 82<pre> 83 struct output_visitor: public planar_face_traversal_visitor 84 { 85 void begin_face() { std::cout << "New face: "; } 86 template <typename Vertex> void next_vertex(Vertex v) { std::cout << v << " "; } 87 void finish_face() { std::cout << std::endl; } 88 }; 89</pre> 90can be passed to the <tt>planar_face_traversal</tt> function: 91<pre> 92 output_visitor my_visitor; 93 planar_face_traversal(g, embed, my_visitor); //embed is a planar embedding of g 94</pre> 95and might produce the output 96<pre> 97 New face: 1 2 5 4 98 New face: 2 3 4 5 99 New face: 3 0 1 4 100 New face: 1 0 3 2 101</pre> 102 103<h3>Visitor Event Points</h3> 104 105<ul> 106<li><tt>visitor.begin_traversal()</tt>: called once before any faces are 107visited. 108<li><tt>visitor.begin_face()</tt>: called once, for each face, before any 109vertex or edge on that face has been visited. 110<li><tt>visitor.end_face()</tt>: called once, for each face, after all vertices 111and all edges on that face have been visited. 112<li><tt>visitor.next_vertex(Vertex v)</tt>: called once on each vertex in the 113current face (the start and end of which are designated by calls to 114<tt>begin_face()</tt> and <tt>end_face()</tt>, respectively) in order 115according to the order established by the planar embedding. 116<li><tt>visitor.next_edge(Edge e)</tt>: called once on each edge in the current 117face (the start and end of which are designated by calls to 118<tt>begin_face()</tt> and <tt>end_face()</tt>, respectively) in order 119according to the order established by the planar embedding. 120<li><tt>visitor.end_traversal()</tt>: called once after all faces have been 121visited. 122</ul> 123 124Although <tt>next_vertex</tt> is guaranteed to be called in sequence for each 125vertex as the traversal moves around a face and <tt>next_edge</tt> is 126guaranteed to be called in sequence for each edge as the traversal moves 127around a face, there's no guarantee about the order in which 128<tt>next_vertex</tt> and <tt>next_edge</tt> are called with respect to each 129other in between calls to <tt>begin_face</tt> and <tt>end_face</tt>. These 130calls may be interleaved, all vertex visits may precede all edge visits, or 131vise-versa. 132<p> 133<tt>planar_face_traversal</tt> iterates over a copy of the edges of the input 134graph, so it is safe to add edges to the graph during visitor event points. 135 136 137<h3>Complexity</h3> 138 139If all of the visitor event points run in constant time, the traversal takes 140time <i>O(n + m)</i> for a planar graph with <i>n</i> vertices and <i>m</i> 141edges. Note that 142in a simple planar graph with <i>f</i> faces, <i>m</i> edges, and <i>n</i> 143vertices, both <i>f</i> and <i>m</i> are <i>O(n)</i>. 144 145<H3>Where Defined</H3> 146 147<P> 148<a href="../../../boost/graph/planar_face_traversal.hpp"> 149<TT>boost/graph/planar_face_traversal.hpp</TT> 150</a> 151 152<h3>Parameters</h3> 153 154IN: <tt>Graph& g</tt> 155 156<blockquote> 157An undirected graph. The graph type must 158be a model of <a href="VertexAndEdgeListGraph.html">VertexAndEdgeListGraph</a> 159</blockquote> 160 161IN: <tt>PlanarEmbedding</tt> 162 163<blockquote> 164A model of <a href="PlanarEmbedding.html">PlanarEmbedding</a>. 165</blockquote> 166 167IN: <tt>PlanarFaceVisitor</tt> 168 169<blockquote> 170A model of <a href="PlanarFaceVisitor.html">PlanarFaceVisitor</a>. 171</blockquote> 172 173IN: <tt>EdgeIndexMap vm</tt> 174 175<blockquote> 176A <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map 177</a> that maps edges from <tt>g</tt> to distinct integers in the range 178<tt>[0, num_edges(g) )</tt><br> 179<b>Default</b>: <tt>get(edge_index,g)</tt><br> 180</blockquote> 181 182 183<H3>Example</H3> 184 185<P> 186<a href="../example/planar_face_traversal.cpp"> 187<TT>examples/planar_face_traversal.cpp</TT></a> 188 189<h3>See Also</h3> 190 191<p> 192<ul> 193<li><a href="./planar_graphs.html">Planar Graphs in the Boost Graph Library</a> 194<li><a href="./PlanarFaceVisitor.html">PlanarFaceVisitor</a> concept. 195</ul> 196 197<br> 198<HR> 199Copyright © 2007 Aaron Windsor (<a href="mailto:aaron.windsor@gmail.com"> 200aaron.windsor@gmail.com</a>) 201</BODY> 202</HTML> 203