diff --git a/mainwindow.cpp b/mainwindow.cpp index 5d60010..5e523c5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,9 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include +#include +using namespace std; /* **** début de la partie à compléter **** */ void MainWindow::showSelections(MyMesh* _mesh) @@ -112,6 +115,52 @@ void MainWindow::showPath(MyMesh* _mesh, int v1, int v2) displayMesh(_mesh); } +int minimal_new(vector dist, set visited) { + long mini = LONG_MAX; + int mini_id = -1; + for (int i = 0; i < dist.size(); i++) { + if (visited.count(i) == 0 && dist[i] < mini) { + mini = dist[i]; + mini_id = i; + } + } + return mini_id; +} + +vector meinDijkstra(MyMesh *_mesh, int v1, int v2) { + set visited_nodes_id = {}; + const int nb = _mesh->n_faces(); + vector dist_min (nb, ULONG_MAX); + vector prec_hv_id (nb, -1); + dist_min[v1] = 0; + int current; + VertexHandle current_node; + uint distance; + while (visited_nodes_id.size() != nb) { + current = minimal_new(dist_min, visited_nodes_id); + visited_nodes_id.insert(current); + if (current == v2) break; + current_node = _mesh->vertex_handle(current); + for (auto voh_it = _mesh->voh_iter(current_node); voh_it.is_valid(); ++voh_it) { + distance = dist_min[current] + _mesh->valence(*voh_it); + //following = *voh_it->outgoingvertex; + if (distance < dist_min[following]) { + dist_min[successeur] = distance; + prec_hv_id[successeur] = *voh_it->idx; + } + } + } + vector path; + if (prec_hv_id[v2] != -1) { + current = v2; + while (predecesseur[current] != -1) { + path.push_back(predecesseur[current].edge); + current = path.end()->incoming_node; + } + } + return path; +} + /* **** fin de la partie à compléter **** */