From 5e4252da7e69a45ec6182693c6116a60153155cc Mon Sep 17 00:00:00 2001 From: DylanVsn <43576618+DylanVsn@users.noreply.github.com> Date: Wed, 4 Mar 2020 21:43:20 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A7a=20marche/compile=20pas=20parce=20que=20?= =?UTF-8?q?j'ai=20pas=20trouv=C3=A9=20comment=20passer=20d'un=20halfedge?= =?UTF-8?q?=20au=20sommet=20de=20d=C3=A9part/arriv=C3=A9e=20et=20du=20half?= =?UTF-8?q?edge=20au=20edge=20associ=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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 **** */