NavMap
Loading...
Searching...
No Matches
DistanceField.hpp
Go to the documentation of this file.
1// Copyright 2026 Intelligent Robotics Lab
2//
3// This file is part of the project Easy Navigation (EasyNav in short)
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
21
22#ifndef NAVMAP_CORE__DISTANCEFIELD_HPP_
23#define NAVMAP_CORE__DISTANCEFIELD_HPP_
24
25#include <cstdint>
26#include <limits>
27#include <unordered_map>
28#include <utility>
29#include <vector>
30
32
33namespace navmap
34{
35
51{
52public:
59 const NavMap & nm, bool from_boundary,
60 float max_distance = std::numeric_limits<float>::infinity());
61
63 void compute(const std::vector<NavCelId> & seed_cells);
64
69 void update(const std::vector<NavCelId> & added, const std::vector<NavCelId> & removed);
70
71 const std::vector<float> & distances() const {return dist_;}
72 float operator[](NavCelId cid) const {return dist_[cid];}
73
75 const std::vector<NavCelId> & changed() const {return changed_;}
76
78 bool is_seed(NavCelId cid) const {return cid < seed_of_.size() && seed_of_[cid] != kNoSeed;}
79
80private:
81 static constexpr std::uint32_t kNoSeed = std::numeric_limits<std::uint32_t>::max();
82 struct Seed
83 {
84 Eigen::Vector3f a, b;
85 NavCelId cell;
86 bool alive;
87 };
88
89 float distance_to(NavCelId c, std::uint32_t seed) const;
90 void touch(NavCelId c);
91 void begin_operation();
92 void finish();
93 template<class F>
94 void flood(std::uint32_t seed, F && f);
95 void splat(std::uint32_t seed);
96 std::uint32_t new_point_seed(NavCelId c);
97 static std::int64_t bucket_key(int bx, int by, int bz);
98 void index_seed(std::uint32_t seed, bool insert);
99
100 const NavMap & nm_;
101 bool from_boundary_;
102 float max_distance_;
103 float bucket_{1.0f};
104 std::unordered_map<std::int64_t, std::vector<std::uint32_t>> buckets_;
105 std::vector<Eigen::Vector3f> centroid_;
106 std::vector<Seed> seeds_;
107 std::size_t n_boundary_{0};
108 std::vector<std::uint32_t> boundary_start_;
109 std::vector<std::uint32_t> seed_of_;
110 std::vector<std::uint32_t> nearest_;
111 std::vector<float> dist_;
112 std::vector<std::uint32_t> free_seed_slots_;
113 // Cells touched by the current operation and their previous distance
114 std::vector<NavCelId> touched_;
115 std::vector<float> before_;
116 std::vector<std::uint32_t> touched_stamp_;
117 std::uint32_t stamp_{0};
118 std::vector<NavCelId> changed_;
119 // Flood buffers
120 std::vector<NavCelId> flood_;
121 std::vector<std::uint32_t> flood_stamp_;
122 std::uint32_t flood_id_{0};
123};
124
125} // namespace navmap
126
127#endif // NAVMAP_CORE__DISTANCEFIELD_HPP_
Core container and data structures for EasyNav navigable meshes.
void update(const std::vector< NavCelId > &added, const std::vector< NavCelId > &removed)
Incremental update: NavCels that became seeds and NavCels that stopped being seeds since the last com...
Definition DistanceField.cpp:223
DistanceField(const NavMap &nm, bool from_boundary, float max_distance=std::numeric_limits< float >::infinity())
Definition DistanceField.cpp:34
void compute(const std::vector< NavCelId > &seed_cells)
Full computation from these seed cells.
Definition DistanceField.cpp:185
float operator[](NavCelId cid) const
Definition DistanceField.hpp:72
const std::vector< NavCelId > & changed() const
NavCels whose distance changed in the last compute() / update().
Definition DistanceField.hpp:75
DistanceField(const NavMap &nm, bool from_boundary, float max_distance=std::numeric_limits< float >::infinity())
Definition DistanceField.cpp:34
bool is_seed(NavCelId cid) const
Whether cid is currently a seed cell.
Definition DistanceField.hpp:78
const std::vector< float > & distances() const
Definition DistanceField.hpp:71
Definition NavMap.hpp:561
Definition Combine.hpp:39
uint32_t NavCelId
Index of a triangle (NavCel) within the global mesh.
Definition NavMap.hpp:59
uint32_t NavCelId
Index of a triangle (NavCel) within the global mesh.
Definition NavMap.hpp:59