|
NavMap
|
#include <NavMap.hpp>

Classes | |
| struct | LocateOpts |
| Options for the locate functions. More... | |
Public Member Functions | |
| template<typename T> | |
| std::shared_ptr< LayerView< T > > | add_layer (const std::string &name, const std::string &description, const std::string &unit, const std::string &src_layer) |
| Create (or get) a typed per-NavCel layer, initialized from another layer. | |
| template<typename T> | |
| std::shared_ptr< LayerView< T > > | add_layer (const std::string &name, const std::string &description={}, const std::string &unit={}, T default_value=T{}) |
| Create (or get) a typed per-NavCel layer with a default value. | |
| std::size_t | add_link (NavCelId from, NavCelId to, LinkType type=LinkType::GENERIC, float length=-1.0f, bool bidirectional=true) |
Add a link from from to to. | |
| NavCelId | add_navcel (uint32_t v0, uint32_t v1, uint32_t v2) |
| Append a triangle (NavCel) and return its id. | |
| void | add_navcel_to_surface (std::size_t surface_index, NavCelId cid) |
| Add an existing nav cell id to a surface. | |
| std::size_t | add_surface (const Surface &s) |
| Append an existing Surface (by value). | |
| std::size_t | add_surface (Surface &&s) |
| Add a Surface by move (avoids copy). | |
| uint32_t | add_vertex (const Eigen::Vector3f &p) |
| Append a vertex and return its index. | |
| void | build_adjacency () |
| Build topological adjacency between neighboring NavCels. | |
| void | clear_links () |
| bool | closest_navcel (const Eigen::Vector3f &p_world, size_t &surface_idx, NavCelId &cid, Eigen::Vector3f &closest_point, float &sqdist, int restrict_surface=-1) const |
| Find the closest triangle to a point. | |
| std::size_t | create_surface (std::string frame_id) |
| Create a new empty Surface and append it to the map. | |
| Surface | create_surface_obj (const std::string &frame_id) const |
| Create a standalone Surface object (not yet added to the map). | |
| std::vector< float > | distance_field (const std::vector< NavCelId > &seed_cells, bool from_boundary, float max_distance=std::numeric_limits< float >::infinity()) const |
| Distance (m, 3D) from each NavCel centroid to the nearest seed. | |
| std::uint64_t | geometry_id () const |
| Fingerprint of the geometry (vertex positions and triangles), 64-bit FNV-1a. | |
| std::optional< LayerMeta > | get_layer_meta (const std::string &name) const |
| Return metadata for a layer if present (implementation-defined). | |
| std::array< NavCelId, 3 > | get_neighbors (NavCelId cid) const |
Return the three neighbor NavCel ids of triangle cid. | |
| bool | has_layer (const std::string &name) const |
Check whether a layer named name exists. | |
| bool | has_same_geometry (const NavMap &other) const |
| Fast check for identical geometry (vertices and NavCel indices). | |
| bool | is_unknown (const std::string &name, NavCelId cid) const |
Whether layer name holds its unknown value at cid (false if it has none). | |
| template<typename T> | |
| void | layer_clear (const std::string &name, T value=T{}) |
| Reset all values in a layer to a given value. | |
| template<typename T> | |
| bool | layer_copy (const std::string &src, const std::string &dst) |
| Copy values from one layer into another. | |
| template<typename T> | |
| T | layer_get (const std::string &name, NavCelId cid, T def=T{}) const |
| Get a per-cell value as the requested type. | |
| template<typename T> | |
| void | layer_set (const std::string &name, NavCelId cid, T value) |
| Set a per-cell value (creates/retypes the layer if needed). | |
| std::size_t | layer_size (const std::string &name) const |
| Number of entries in a layer (should equal navcels.size()). | |
| std::string | layer_type_name (const std::string &name) const |
| Human-readable type name for a layer ("float", "double", "uint8", ...). | |
| const std::vector< SurfaceLink > & | links () const |
| const std::vector< std::uint32_t > & | links_from (NavCelId cid) const |
Indices of the links that can be taken from cid (both ends of bidirectional ones). | |
| std::vector< std::string > | list_layers () const |
| List all layer names currently stored. | |
| bool | locate_navcel (const Eigen::Vector3f &p_world, size_t &surface_idx, NavCelId &cid, Eigen::Vector3f &bary, Eigen::Vector3f *hit_pt) const |
| Locate the triangle under / near a world point (convenience). | |
| bool | locate_navcel (const Eigen::Vector3f &p_world, size_t &surface_idx, NavCelId &cid, Eigen::Vector3f &bary, Eigen::Vector3f *hit_pt, const LocateOpts &opts) const |
| Locate the triangle under / near a world point. | |
| bool | locate_navcel_core (const Eigen::Vector3f &p_world, std::size_t &surface_idx, NavCelId &cid, Eigen::Vector3f &bary, Eigen::Vector3f *hit_pt, const LocateOpts &opts) const |
| Forward to the existing low-level locator (implemented in .cpp). | |
| void | mark_vertex_updated (PointId) |
| Mark a vertex as updated (reserved for future cache invalidation). | |
| Eigen::Vector3f | navcel_centroid (NavCelId cid) const |
| Triangle centroid (computed on the fly). | |
| std::vector< NavCelId > | navcel_neighbors (NavCelId cid) const |
| Return up to 3 neighbor cell ids (skips invalid entries). | |
| template<typename T> | |
| T | navcel_value (NavCelId cid, const LayerView< T > &layer) const |
Read the value of a typed per-NavCel layer at triangle cid. | |
| NavMap () | |
| Copy constructor: deep copy of geometry, surfaces, layers and metadata. | |
| NavMap (const NavMap &other) | |
| Copy constructor: deep copy of geometry, surfaces, layers and metadata. | |
| std::size_t | nonmanifold_edges () const |
| Edges shared by more than two NavCels in the last adjacency build. | |
| NavMap & | operator= (const NavMap &other) |
| Copy assignment optimized to avoid geometry duplication. | |
| NavMap & | operator= (NavMap &&other) noexcept |
| Move assignment. | |
| bool | raycast (const Eigen::Vector3f &o, const Eigen::Vector3f &d, NavCelId &hit_cid, float &t, Eigen::Vector3f &hit_pt) const |
| Raycast against all surfaces to find the closest hit. | |
| void | raycast_many (const std::vector< Ray > &rays, std::vector< RayHit > &out, bool first_hit_only=true) const |
| Batched raycast. | |
| void | rebuild_geometry_accels () |
| Recompute derived geometry and acceleration structures. | |
| bool | remove_link (std::size_t index) |
Remove link index (the last link takes its index). False if out of range. | |
| bool | remove_surface (std::size_t surface_index) |
| Remove a Surface by index. | |
| double | sample_layer_at (const std::string &name, const Eigen::Vector3f &p_world, double def=std::numeric_limits< double >::quiet_NaN()) const |
| Sample a per-NavCel layer at a world position. | |
| template<typename T> | |
| bool | set_area (const Eigen::Vector3f &p_world, T value, const std::string &layer_name, AreaShape shape, float size) |
| Set a per-NavCel layer to a constant value over a 2D area. | |
| void | set_layer_unknown (const std::string &name, double value) |
Declare the value of layer name that means "not observed" (NaN allowed). | |
| std::size_t | surface_of (NavCelId cid) const |
Index of the surface owning cid, or kNoSurface. | |
Public Attributes | |
| std::optional< Colors > | colors |
| Optional per-vertex colors. | |
| std::unordered_map< std::string, LayerMeta > | layer_meta |
| Optional metadata per layer. | |
| LayerRegistry | layers |
| Per-NavCel layers (runtime registry). | |
| std::vector< NavCel > | navcels |
| All triangles (global indexing). | |
| Positions | positions |
| Vertex positions (SoA). | |
| std::vector< Surface > | surfaces |
| Surfaces (partitions of navcels). | |
Static Public Attributes | |
| static constexpr std::size_t | kInvalidLink = std::numeric_limits<std::size_t>::max() |
| Value returned by add_link() when a NavCel id is out of range. | |
| static constexpr std::size_t | kNoSurface = std::numeric_limits<std::size_t>::max() |
| Value returned by surface_of() for a NavCel in no surface. | |
| NavMap | ( | ) |
Copy constructor: deep copy of geometry, surfaces, layers and metadata.
Copy constructor: deep copy of geometry, surfaces, layers and metadata.
| std::shared_ptr< LayerView< T > > add_layer | ( | const std::string & | name, |
| const std::string & | description, | ||
| const std::string & | unit, | ||
| const std::string & | src_layer ) |
Create (or get) a typed per-NavCel layer, initialized from another layer.
If a layer with name exists, it is returned (size preserved). If the size differs from navcels.size(), it is resized. If the source layer src_layer exists, its values are copied into the destination using layer_copy(), performing type conversion if necessary. If the source layer does not exist, the destination is left with defaults.
| T | Storage type. |
| name | Layer name. |
| description | Human-readable description (optional). |
| unit | Unit (e.g., "m", "deg", "%"), optional. |
| src_layer | Source layer name to initialize from. |
| std::shared_ptr< LayerView< T > > add_layer | ( | const std::string & | name, |
| const std::string & | description = {}, | ||
| const std::string & | unit = {}, | ||
| T | default_value = T{} ) |
Create (or get) a typed per-NavCel layer with a default value.
If a layer with name exists, it is returned (size preserved). If the size differs from navcels.size(), values are reinitialized to default_value.
| T | Storage type. |
| name | Layer name. |
| description | Human-readable description (optional). |
| unit | Unit (e.g., "m", "deg", "%"), optional. |
| default_value | Initial value for all triangles. |
| std::size_t add_link | ( | NavCelId | from, |
| NavCelId | to, | ||
| LinkType | type = LinkType::GENERIC, | ||
| float | length = -1.0f, | ||
| bool | bidirectional = true ) |
Add a link from from to to.
A negative length takes the distance between their centroids.
| NavCelId add_navcel | ( | uint32_t | v0, |
| uint32_t | v1, | ||
| uint32_t | v2 ) |
Append a triangle (NavCel) and return its id.
| v0 | Index of vertex 0. |
| v1 | Index of vertex 1. |
| v2 | Index of vertex 2. |
| void add_navcel_to_surface | ( | std::size_t | surface_index, |
| NavCelId | cid ) |
Add an existing nav cell id to a surface.
| std::size_t add_surface | ( | const Surface & | s | ) |
| std::size_t add_surface | ( | Surface && | s | ) |
| uint32_t add_vertex | ( | const Eigen::Vector3f & | p | ) |
Append a vertex and return its index.
| void build_adjacency | ( | ) |
Build topological adjacency between neighboring NavCels.
Two triangles are neighbors if they share an undirected edge and no other triangle uses it; edges shared by more than two (non-manifold) stay open. Called by rebuild_geometry_accels().
| void clear_links | ( | ) |
| bool closest_navcel | ( | const Eigen::Vector3f & | p_world, |
| size_t & | surface_idx, | ||
| NavCelId & | cid, | ||
| Eigen::Vector3f & | closest_point, | ||
| float & | sqdist, | ||
| int | restrict_surface = -1 ) const |
Find the closest triangle to a point.
Traverses per-surface BVHs with distance lower-bounds; returns the closest triangle, the closest point on it, and the squared distance.
| p_world | Query point in world coordinates. | |
| [out] | surface_idx | Surface index of the closest triangle. |
| [out] | cid | NavCel id of the closest triangle. |
| [out] | closest_point | Closest point on that triangle. |
| [out] | sqdist | Squared distance to p_world. |
| restrict_surface | If >= 0, restrict search to this surface. |
| std::size_t create_surface | ( | std::string | frame_id | ) |
| Surface create_surface_obj | ( | const std::string & | frame_id | ) | const |
| std::vector< float > distance_field | ( | const std::vector< NavCelId > & | seed_cells, |
| bool | from_boundary, | ||
| float | max_distance = std::numeric_limits<float>::infinity() ) const |
Distance (m, 3D) from each NavCel centroid to the nearest seed.
Seeds are the centroids of seed_cells and, if from_boundary, the open edges of the mesh (edges without a neighbor: walls, drops, unmapped space). The nearest seed is propagated over adjacency and the distance is measured straight to it, so it never jumps between disconnected surfaces (e.g. stacked floors).
| seed_cells | Seed NavCels (out-of-range ids are ignored). |
| from_boundary | Also seed the open edges. |
| max_distance | Stop beyond this distance; farther or unreachable cells get +inf. |
| std::uint64_t geometry_id | ( | ) | const |
Fingerprint of the geometry (vertex positions and triangles), 64-bit FNV-1a.
Equal maps have equal ids, so a layer update can name the geometry it belongs to. Recomputed lazily after add_vertex(), add_navcel() or rebuild_geometry_accels(); call the latter after editing positions or navcels directly.
| std::optional< LayerMeta > get_layer_meta | ( | const std::string & | name | ) | const |
Return metadata for a layer if present (implementation-defined).
| name | Layer name. |
| bool has_layer | ( | const std::string & | name | ) | const |
Check whether a layer named name exists.
| bool has_same_geometry | ( | const NavMap & | other | ) | const |
Fast check for identical geometry (vertices and NavCel indices).
| bool is_unknown | ( | const std::string & | name, |
| NavCelId | cid ) const |
Whether layer name holds its unknown value at cid (false if it has none).
| void layer_clear | ( | const std::string & | name, |
| T | value = T{} ) |
Reset all values in a layer to a given value.
| T | Expected storage type of the layer. |
| name | Layer name. |
| value | Value to assign to all entries. |
| bool layer_copy | ( | const std::string & | src, |
| const std::string & | dst ) |
Copy values from one layer into another.
Both layers must have the same type and size.
| T | Storage type (e.g. float, uint8_t). |
| src | Name of source layer. |
| dst | Name of destination layer. |
| T layer_get | ( | const std::string & | name, |
| NavCelId | cid, | ||
| T | def = T{} ) const |
Get a per-cell value as the requested type.
If the stored type matches T, returns directly. Otherwise falls back to conversion vía double: floating → static_cast<T>, integral → clamp [0,max(T)] y redondeo (llround).
Si la capa no existe o cid está fuera de rango, devuelve def.
| T | uint8_t, int16_t, float, or double |
| name | Layer name |
| cid | Triangle id |
| def | Default value on failure |
def | void layer_set | ( | const std::string & | name, |
| NavCelId | cid, | ||
| T | value ) |
Set a per-cell value (creates/retypes the layer if needed).
| T | Storage type. |
| name | Layer name. |
| cid | Triangle id. |
| value | Value to write. |
| std::size_t layer_size | ( | const std::string & | name | ) | const |
Number of entries in a layer (should equal navcels.size()).
| std::string layer_type_name | ( | const std::string & | name | ) | const |
Human-readable type name for a layer ("float", "double", "uint8", ...).
| const std::vector< SurfaceLink > & links | ( | ) | const |
| const std::vector< std::uint32_t > & links_from | ( | NavCelId | cid | ) | const |
Indices of the links that can be taken from cid (both ends of bidirectional ones).
| std::vector< std::string > list_layers | ( | ) | const |
List all layer names currently stored.
| bool locate_navcel | ( | const Eigen::Vector3f & | p_world, |
| size_t & | surface_idx, | ||
| NavCelId & | cid, | ||
| Eigen::Vector3f & | bary, | ||
| Eigen::Vector3f * | hit_pt ) const |
Locate the triangle under / near a world point (convenience).
Uses default LocateOpts. See the full overload for details.
| p_world | Query point in world coordinates. | |
| [out] | surface_idx | Surface index owning the located triangle. |
| [out] | cid | Located NavCel id. |
| [out] | bary | Barycentric coordinates of the hit. |
| [out] | hit_pt | Optional: projected point on the surface. |
| bool locate_navcel | ( | const Eigen::Vector3f & | p_world, |
| size_t & | surface_idx, | ||
| NavCelId & | cid, | ||
| Eigen::Vector3f & | bary, | ||
| Eigen::Vector3f * | hit_pt, | ||
| const LocateOpts & | opts ) const |
Locate the triangle under / near a world point.
Strategy: 1) If hint_cid is provided, try walking neighbors. 2) Else, try a per-surface 2D seed grid near (x,y) with planar test. 3) If still not found, vertical raycast (downward or upward).
| p_world | Query point in world coordinates. | |
| [out] | surface_idx | Surface index owning the located triangle. |
| [out] | cid | Located NavCel id. |
| [out] | bary | Barycentric coordinates of the hit. |
| [out] | hit_pt | Optional: projected point on the surface. |
| opts | Tuning options (see LocateOpts). |
| bool locate_navcel_core | ( | const Eigen::Vector3f & | p_world, |
| std::size_t & | surface_idx, | ||
| NavCelId & | cid, | ||
| Eigen::Vector3f & | bary, | ||
| Eigen::Vector3f * | hit_pt, | ||
| const LocateOpts & | opts ) const |
Forward to the existing low-level locator (implemented in .cpp).
This hook should call your original, detailed locator implementation. The robust overload above will fall back to vertical rays if needed.
| void mark_vertex_updated | ( | PointId | ) |
Mark a vertex as updated (reserved for future cache invalidation).
| pid | Vertex id (unused for now). |
| Eigen::Vector3f navcel_centroid | ( | NavCelId | cid | ) | const |
Triangle centroid (computed on the fly).
Return up to 3 neighbor cell ids (skips invalid entries).
Read the value of a typed per-NavCel layer at triangle cid.
| T | Layer storage type (must match the layer). |
| cid | NavCel id. |
| layer | Typed layer view. |
cid. | std::size_t nonmanifold_edges | ( | ) | const |
Edges shared by more than two NavCels in the last adjacency build.
Copy assignment optimized to avoid geometry duplication.
If both maps share identical geometry (same vertex arrays and NavCel indices), layers are synchronized by name/type (copy-on-difference) and destination-only layers are removed. Otherwise, a full deep copy is performed.
Move assignment.
Transfers ownership of geometry, surfaces, layers and metadata.
| bool raycast | ( | const Eigen::Vector3f & | o, |
| const Eigen::Vector3f & | d, | ||
| NavCelId & | hit_cid, | ||
| float & | t, | ||
| Eigen::Vector3f & | hit_pt ) const |
| void raycast_many | ( | const std::vector< Ray > & | rays, |
| std::vector< RayHit > & | out, | ||
| bool | first_hit_only = true ) const |
Batched raycast.
| rays | Input rays. | |
| [out] | out | Output hits (parallel to rays). |
| first_hit_only | If true, stop at the first surface that hits. |
| void rebuild_geometry_accels | ( | ) |
Recompute derived geometry and acceleration structures.
Computes triangle normals and areas, builds adjacency between neighbors, and builds per-surface BVHs. Layer sizes are not changed automatically; call resize_all() if you modified navcels.
| bool remove_link | ( | std::size_t | index | ) |
Remove link index (the last link takes its index). False if out of range.
| bool remove_surface | ( | std::size_t | surface_index | ) |
| double sample_layer_at | ( | const std::string & | name, |
| const Eigen::Vector3f & | p_world, | ||
| double | def = std::numeric_limits<double>::quiet_NaN() ) const |
Sample a per-NavCel layer at a world position.
Locates the containing triangle and returns its layer value.
| name | Layer name. |
| p_world | World-space query. |
| def | Default value if not found. |
def if missing. | bool set_area | ( | const Eigen::Vector3f & | p_world, |
| T | value, | ||
| const std::string & | layer_name, | ||
| AreaShape | shape, | ||
| float | size ) |
Set a per-NavCel layer to a constant value over a 2D area.
The center is the ground projection of p_world. If the projected NavCel cannot be determined, returns false. Supports U8/F32/F64 layers.
Efficiency: BFS from the seed NavCel with XY AABB pruning against the circumscribed square of the area. Inclusion test by triangle centroid.
| T | uint8_t, int16_t, float, or double |
| p_world | 3D point in world coordinates (projected to ground) |
| value | Value to set in the layer |
| layer_name | Target layer name |
| shape | CIRCULAR or RECTANGULAR |
| size | Radius (CIRCULAR) or side length (RECTANGULAR) |
| void set_layer_unknown | ( | const std::string & | name, |
| double | value ) |
Declare the value of layer name that means "not observed" (NaN allowed).
Travels with the map (message and file) and is kept by add_layer().
| std::size_t surface_of | ( | NavCelId | cid | ) | const |
Index of the surface owning cid, or kNoSurface.
| std::optional<Colors> colors |
Optional per-vertex colors.
|
staticconstexpr |
Value returned by add_link() when a NavCel id is out of range.
|
staticconstexpr |
Value returned by surface_of() for a NavCel in no surface.
| std::unordered_map<std::string, LayerMeta> layer_meta |
Optional metadata per layer.
| LayerRegistry layers |
Per-NavCel layers (runtime registry).
| std::vector<NavCel> navcels |
All triangles (global indexing).
| Positions positions |
Vertex positions (SoA).