15#include <lagrange/Mesh.h>
16#include <lagrange/legacy/inline.h>
17#include <lagrange/utils/assert.h>
42template <
typename MeshType,
typename DistFunc,
typename ProcessFunc>
45 const std::vector<typename MeshType::Index>& seed_vertices,
46 const std::vector<typename MeshType::Scalar>& seed_vertex_dist,
47 typename MeshType::Scalar radius,
49 const ProcessFunc& process)
51 using Scalar =
typename MeshType::Scalar;
52 using Index =
typename MeshType::Index;
55 mesh.get_vertex_per_facet() == 3,
56 "Only triangle meshes are supported for now.");
58 mesh.is_connectivity_initialized(),
59 "BSF requires mesh connectivity to be initialized.");
62 radius = std::numeric_limits<Scalar>::max();
65 const Index num_vertices = mesh.get_num_vertices();
67 using Entry = std::pair<Index, Scalar>;
68 auto comp = [](
const Entry& e1,
const Entry& e2) {
return e1.second > e2.second; };
69 std::priority_queue<Entry, std::vector<Entry>,
decltype(comp)> Q(comp);
70 std::vector<bool> visited(num_vertices,
false);
72 size_t num_seeds = seed_vertices.size();
74 num_seeds == seed_vertex_dist.size(),
75 "Inconsistent number of seed distances.");
76 for (
size_t i = 0; i < num_seeds; i++) {
78 Q.push({seed_vertices[i], seed_vertex_dist[i]});
82 Entry entry = Q.top();
85 Index vi = entry.first;
86 Scalar di = entry.second;
88 if (visited[vi])
continue;
90 bool done = process(vi, di);
94 const auto& adj_vertices = mesh.get_vertices_adjacent_to_vertex(entry.first);
95 for (
const auto& vj : adj_vertices) {
96 Scalar dj = di + dist(vi, vj);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
void dijkstra(SurfaceMesh< Scalar, Index > &mesh, span< const Index > seed_vertices, span< const Scalar > seed_vertex_dist, Scalar radius, const function_ref< Scalar(Index, Index)> &dist, const function_ref< bool(Index, Scalar)> &process)
Traverse the mesh based on Dijkstra's algorithm with customized distance metric and process functions...
Definition: dijstra.cpp:24
Main namespace for Lagrange.
Definition: AABBIGL.h:30