diff --git a/BGL/examples/BGL_surface_mesh/shortest_path.cpp b/BGL/examples/BGL_surface_mesh/shortest_path.cpp index f85d41b3a7e..ab568ee5eff 100644 --- a/BGL/examples/BGL_surface_mesh/shortest_path.cpp +++ b/BGL/examples/BGL_surface_mesh/shortest_path.cpp @@ -57,7 +57,8 @@ int main(int argc, char** argv) } std::vector halfedge_sequence; - CGAL::shortest_path_between_two_vertices(vs, vt, sm, halfedge_sequence); + CGAL::shortest_path_between_two_vertices(vs, vt, sm, + std::back_inserter(halfedge_sequence)); // dump std::cout << "Shortest path between vertices " << i0 << " and " << i1 diff --git a/BGL/include/CGAL/boost/graph/shortest_path.h b/BGL/include/CGAL/boost/graph/shortest_path.h index 349f1279c31..e48e3256386 100644 --- a/BGL/include/CGAL/boost/graph/shortest_path.h +++ b/BGL/include/CGAL/boost/graph/shortest_path.h @@ -14,6 +14,9 @@ #include +#include +#include + #include #include #include @@ -64,12 +67,15 @@ namespace internal { * @param mesh the mesh * @param halfedge_sequence the sequence of halfedges that form the shortest path on `mesh` */ -template -void shortest_path_between_two_vertices( +template +OutputIterator shortest_path_between_two_vertices( const typename boost::graph_traits::vertex_descriptor vs,//source const typename boost::graph_traits::vertex_descriptor vt,//target const Mesh& mesh, - std::vector::halfedge_descriptor>& halfedge_sequence) + OutputIterator halfedge_sequence_oit, + const NamedParameters& np = parameters::default_values()) { using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; @@ -87,10 +93,7 @@ void shortest_path_between_two_vertices( boost::dijkstra_shortest_paths(mesh, vs, boost::predecessor_map(pred_pmap).visitor(vis)); } - catch (const std::exception& e) - { - std::cout << e.what() << std::endl; - } + catch (const std::exception& e){} // Walk back from target to source and collect vertices along the way struct vertex_on_path @@ -128,8 +131,9 @@ void shortest_path_between_two_vertices( const std::pair h = halfedge((path_it + 1)->vertex, path_it->vertex, mesh); if (h.second) - halfedge_sequence.push_back(h.first); + *halfedge_sequence_oit++ = h.first; } + return halfedge_sequence_oit; } } // namespace CGAL