diff --git a/BGL/examples/BGL_surface_mesh/shortest_path.cpp b/BGL/examples/BGL_surface_mesh/shortest_path.cpp index 988e7c618f6..24a62a8ab5b 100644 --- a/BGL/examples/BGL_surface_mesh/shortest_path.cpp +++ b/BGL/examples/BGL_surface_mesh/shortest_path.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) } } - std::vector halfedge_sequence; + std::list halfedge_sequence; CGAL::dijkstra_shortest_path(vs, vt, sm, std::back_inserter(halfedge_sequence)); @@ -68,12 +68,13 @@ int main(int argc, char** argv) auto vpmap = get(CGAL::vertex_point, sm); std::ofstream out("shortest_path.polylines.txt"); + out << halfedge_sequence.size() << " " << get(vpmap, source(halfedge_sequence.front(),sm)); for (const halfedge_descriptor he : halfedge_sequence) { - const vertex_descriptor v0 = source(he, sm); - const vertex_descriptor v1 = target(he, sm); - out << "2 " << get(vpmap, v0) << " " << get(vpmap, v1) << std::endl; + const vertex_descriptor v = target(he, sm); + out << " " << get(vpmap, v); } + out << std::endl; out.close(); return EXIT_SUCCESS; diff --git a/BGL/include/CGAL/boost/graph/dijkstra_shortest_path.h b/BGL/include/CGAL/boost/graph/dijkstra_shortest_path.h index f6f16921914..f417ce510aa 100644 --- a/BGL/include/CGAL/boost/graph/dijkstra_shortest_path.h +++ b/BGL/include/CGAL/boost/graph/dijkstra_shortest_path.h @@ -146,42 +146,14 @@ OutputIterator dijkstra_shortest_path( } catch (const internal::Dijkstra_end_exception& ){} - // Walk back from target to source and collect vertices along the way - struct vertex_on_path - { - vertex_descriptor vertex; - bool is_constrained; - }; - - std::vector constrained_vertices = { vs }; + std::list path; vertex_descriptor t = vt; - std::vector path; - do - { - const bool is_new_vertex = (constrained_vertices.end() - == std::find(constrained_vertices.begin(), constrained_vertices.end(), t)); - - vertex_on_path vop; - vop.vertex = t; - vop.is_constrained = !is_new_vertex; - path.push_back(vop); - + do { + path.push_front(halfedge(relaxed_edges_map[t],g)); t = get(pred_pmap, t); - } - while (t != vs); - - // Add the last vertex - vertex_on_path vop; - vop.vertex = constrained_vertices.back(); - vop.is_constrained = true; - path.push_back(vop); - - // Display path - for (auto path_it = path.begin(); path_it != path.end() - 1; ++path_it) - { - const auto map_it = vis.relaxed_edges.find(path_it->vertex); - if (map_it != vis.relaxed_edges.end()) - *halfedge_sequence_oit++ = halfedge(map_it->second, g); + }while (t != vs); + for(auto he : path){ + *halfedge_sequence_oit++ = he; } return halfedge_sequence_oit; }