Lagrange
Loading...
Searching...
No Matches
dijkstra.h
1/*
2 * Copyright 2022 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
15 #include <lagrange/legacy/internal/dijkstra.h>
16#endif
17
18#include <lagrange/SurfaceMesh.h>
19#include <lagrange/utils/function_ref.h>
20#include <lagrange/utils/span.h>
21
22#include <Eigen/Core>
23
24#include <queue>
25#include <vector>
26
27namespace lagrange::internal {
28
33template <typename Scalar, typename Index>
35{
36 using Entry = std::pair<Scalar, Index>;
37 std::priority_queue<Entry, std::vector<Entry>, std::greater<Entry>> queue;
38 std::vector<bool> visited;
39 std::vector<bool> visited_edges;
40 std::vector<bool> chord_bridged;
41 std::vector<Index> edge_indices;
42};
43
47template <typename Scalar>
49{
54
59
61 Eigen::Vector3<Scalar> seed_position = Eigen::Vector3<Scalar>::Zero();
62};
63
82template <typename Scalar, typename Index>
83void dijkstra(
85 span<const Index> seed_vertices,
86 span<const Scalar> seed_vertex_dist,
87 const DijkstraOptions<Scalar>& dijkstra_options,
88 const function_ref<Scalar(Index, Index)>& dist,
89 const function_ref<void(Index, Scalar)>& process,
90 DijkstraCache<Scalar, Index>* cache = nullptr);
91
92} // namespace lagrange::internal
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
A lightweight non-owning reference to a callable.
Definition function_ref.h:47
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
void dijkstra(SurfaceMesh< Scalar, Index > &mesh, span< const Index > seed_vertices, span< const Scalar > seed_vertex_dist, const DijkstraOptions< Scalar > &dijkstra_options, const function_ref< Scalar(Index, Index)> &dist, const function_ref< void(Index, Scalar)> &process, DijkstraCache< Scalar, Index > *cache=nullptr)
Traverse the mesh based on Dijkstra's algorithm with customized distance metric and process functions...
Definition dijkstra.cpp:254
Reusable scratch buffers for Dijkstra traversal.
Definition dijkstra.h:35
Options for the Dijkstra traversal.
Definition dijkstra.h:49
Eigen::Vector3< Scalar > seed_position
Center of the Euclidean ball. Required when euclidean_radius > 0.
Definition dijkstra.h:61
Scalar euclidean_radius
Maximum Euclidean distance from seed_position.
Definition dijkstra.h:58
Scalar geodesic_radius
Maximum geodesic distance from the seed.
Definition dijkstra.h:53