mirror of https://github.com/CGAL/cgal
simplify the code
This commit is contained in:
parent
94801e8826
commit
8a749c5b61
|
|
@ -56,7 +56,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<halfedge_descriptor> halfedge_sequence;
|
||||
std::list<halfedge_descriptor> 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;
|
||||
|
|
|
|||
|
|
@ -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<vertex_descriptor> constrained_vertices = { vs };
|
||||
std::list<halfedge_descriptor> path;
|
||||
vertex_descriptor t = vt;
|
||||
std::vector<vertex_on_path> 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue