#include #include #include #include #include #include #include #include typedef CGAL::Cartesian Kernel; typedef Kernel::Point_3 Point; typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; typedef boost::graph_traits::vertex_iterator vertex_iterator; int main() { int i=0; Polyhedron P; std::ifstream in("cube.off"); in >> P ; // associate indices to the vertices using the "id()" field of the vertex. vertex_iterator vb, ve; int index = 0; // boost::tie assigns the first and second element of the std::pair // returned by boost::vertices to the variables vit and ve for(boost::tie(vb,ve)=boost::vertices(P); vb!=ve; ++vb ){ vertex_descriptor vd = *vb; vd->id() = index++; } // This is the vector where the distance gets written to std::vector distance(P.size_of_vertices()); // Here we start at an arbitrary vertex // Any other vertex could be the starting point boost::tie(vb,ve)=boost::vertices(P); vertex_descriptor vd = *vb; std::cout << "We compute distances to " << vd->point() << std::endl; // bfs = breadth first search explores the graph // Just as the distance_recorder there is a way to record the predecessor of a vertex boost::breadth_first_search(P, vd, visitor(boost::make_bfs_visitor(boost::record_distances(make_iterator_property_map(distance.begin(), get(boost::vertex_index, P)), boost::on_tree_edge())))); // Traverse all vertices and show at what distance they are for(boost::tie(vb,ve)=boost::vertices(P); vb!=ve; ++vb ){ vd = *vb; std::cout << vd->point() << " is " << distance[vd->id()] << " hops away" << std::endl; } return 0; }