inline void planar_face_traversal(const Graph& g, PlanarEmbedding embedding, Visitor& visitor ) { planar_face_traversal(g, embedding, visitor, get(edge_index, g)); }
void CPlanarGraph::DetectFaces() { // Based on the example in (http://www.boost.org/doc/libs/1_47_0/libs/graph/example/planar_face_traversal.cpp) int numOfNodes = GetNumOfNodes(); Graph g(numOfNodes); int numOfEdges = GetNumOfEdges(); for ( int i=0; i<numOfEdges; i++ ) { int idx0 = GetEdge(i).GetIdx0(); int idx1 = GetEdge(i).GetIdx1(); add_edge(idx0, idx1, g); } // Initialize the interior edge index property_map<Graph, edge_index_t>::type e_index = get(edge_index, g); graph_traits<Graph>::edges_size_type edge_count = 0; graph_traits<Graph>::edge_iterator ei, ei_end; for ( boost::tuples::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei ) { put(e_index, *ei, edge_count++); } typedef std::vector< graph_traits<Graph>::edge_descriptor > vec_t; std::vector<vec_t> embedding(num_vertices(g)); #if 0 // Test for planarity - we know it is planar, we just want to // compute the planar embedding as a side-effect if ( boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g, boyer_myrvold_params::embedding = &embedding[0] ) ) { std::cout << "Input graph is planar" << std::endl; } else { std::cout << "Input graph is not planar" << std::endl; } #else // Compute the planar embedding based on node positions... VertexIterator vi, vi_end; for ( boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; ++vi ) { OutEdgeIterator ei, ei_end; std::vector<EdgeDescriptor> adjacentEdges; for ( boost::tie(ei, ei_end) = boost::out_edges(*vi, g); ei != ei_end; ++ei ) { VertexDescriptor v1 = boost::source(*ei, g); VertexDescriptor v2 = boost::target(*ei, g); adjacentEdges.push_back(*ei); } SortAdjacentVertices(g, *vi, adjacentEdges); for(int i = 0; i < adjacentEdges.size(); ++i) { std::cout << *vi << " -> " << adjacentEdges[i] << std::endl; } if(adjacentEdges.size()>0) std::cout << std::endl; embedding[*vi] = adjacentEdges; } #endif std::cout << std::endl << "Vertices on the faces: " << std::endl; vertex_output_visitor v_vis; planar_face_traversal(g, &embedding[0], v_vis); std::cout << std::endl << "Edges on the faces: " << std::endl; edge_output_visitor e_vis; planar_face_traversal(g, &embedding[0], e_vis); RemoveTheOutsideFace(); }