Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions navmap_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_library(${PROJECT_NAME} SHARED
src/${PROJECT_NAME}/Descriptors.cpp
src/${PROJECT_NAME}/Combine.cpp
src/${PROJECT_NAME}/Simplify.cpp
src/${PROJECT_NAME}/Subdivide.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
3 changes: 3 additions & 0 deletions navmap_core/include/navmap_core/Simplify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct SimplifyParams
/// Layers left out of the above (e.g. per-cell geometry such as "elevation"). They are carried
/// from the NavCel that survives, so recompute them if they depend on its shape.
std::vector<std::string> ignore_layers;
/// Vertices (ids of the input map) that are never removed: other vertices may collapse onto
/// them, they never collapse. E.g. where the borders of maps simplified apart must meet.
std::vector<PointId> keep_vertices;
};

/// Sizes before and after simplify().
Expand Down
89 changes: 89 additions & 0 deletions navmap_core/include/navmap_core/Subdivide.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2026 Intelligent Robotics Lab
//
// This file is part of the project Easy Navigation (EasyNav in short)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file Subdivide.hpp
* @brief Splitting NavCels: along straight lines (cut_along_lines) and around points (refine).
*
* Both keep the mesh conforming (every edge is shared whole by the NavCels on both sides: no
* cracks) and carry what the NavCels hold: each new NavCel has the layer values and the surface
* of the NavCel it comes from. New vertices interpolate the position and the vertex colours.
* NavCel ids change; geometry accelerations are rebuilt.
*/

#ifndef NAVMAP_CORE__SUBDIVIDE_HPP_
#define NAVMAP_CORE__SUBDIVIDE_HPP_

#include <cstddef>
#include <functional>
#include <vector>

#include "navmap_core/NavMap.hpp"

namespace navmap
{

/// Sizes before and after a subdivision.
struct SubdivideStats
{
std::size_t navcels_before{0}, navcels_after{0};
std::size_t vertices_before{0}, vertices_after{0};
};

/// Lines in the map frame: x = xs[i] and y = ys[j] (m).
struct CutLines
{
std::vector<float> xs;
std::vector<float> ys;
};

/**
* @brief Split the NavCels the lines cross, so that none crosses one.
*
* E.g. to cut a map into tiles along a grid. A vertex within @p snap (m) of a line is moved onto
* it, and the new vertices are put exactly on it: every vertex on a line has exactly the line's
* coordinate. A link keeps its ends on the first piece of each.
*/
SubdivideStats cut_along_lines(NavMap & nm, const CutLines & lines, float snap = 1e-4f);

/**
* @brief Refine the NavCels under @p points until none of them has an edge longer than
* @p max_edge (m).
*
* Longest-edge bisection: an edge is split at its middle in every NavCel that has it, after
* splitting first, if needed, the longer edges of its neighbours (so the NavCels keep their
* shape and the mesh stays conforming). The refinement spreads a little around each point.
* Points off the map are ignored; NavCels at the end of a link are not split, nor any edge they
* have (the refinement stops short there).
*/
SubdivideStats refine(NavMap & nm, const std::vector<Eigen::Vector3f> & points, float max_edge);

/// The largest edge (m) a NavCel with these vertices may have; not finite or <= 0: no bound.
using EdgeSizeAt = std::function<float(
const Eigen::Vector3f &, const Eigen::Vector3f &, const Eigen::Vector3f &)>;

/**
* @brief Refine until no NavCel has an edge longer than @p max_edge_at says for it.
*
* The same longest-edge bisection, for a region instead of points (e.g. every NavCel within
* some distance of an obstacle, or a size that grows with the distance to a robot): the NavCels
* split are asked again, so the result meets the bound everywhere, in one pass over the map.
* If no NavCel is too large the map is left as it is (its accelerations too).
*/
SubdivideStats refine(NavMap & nm, const EdgeSizeAt & max_edge_at);

} // namespace navmap

#endif // NAVMAP_CORE__SUBDIVIDE_HPP_
3 changes: 3 additions & 0 deletions navmap_core/src/navmap_core/Simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class Simplifier
}
}
}
for (const PointId x : p_.keep_vertices) {
if (x < nv) {locked_[x] = 1;}
}
for (uint32_t u = 0; u < nv; ++u) {
if (VT_[u].empty()) {dead_[u] = 1;}
}
Expand Down
Loading
Loading