Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7505486
Use multithreaded executor so layers can use different callback groups
JustusBraun Mar 5, 2025
38c2bd2
Create LayerManager to load, initialize and handle layers
JustusBraun Mar 12, 2025
96f8552
WIP: Layer updates
JustusBraun Mar 16, 2025
d2f041e
Ensure layer updates are not published before initialization finished
JustusBraun Mar 16, 2025
de7f7ff
Add notifyChanged call in combination layers
JustusBraun Mar 17, 2025
de87afd
Add readLock() and writeLock() functions to layer interface for
JustusBraun Mar 23, 2025
6440206
Switch map_ptr_ to std::weak_ptr to prevent cyclic dependencies.
JustusBraun Mar 23, 2025
d37d9b6
Add LayerTimer to allow layers to log locking, update and notifyChange
JustusBraun Mar 23, 2025
fae057a
Unique logger for each layer provided by AbstractLayer
JustusBraun Mar 24, 2025
46156b1
Add dynamic_obstacle_layer to implement optimizations
JustusBraun Mar 25, 2025
c978366
Remove weak_ptr overhead and in loop vector allocations
JustusBraun Mar 25, 2025
a1bec6c
Downcast Mesh and remove vector field publish
JustusBraun Mar 25, 2025
3d19157
Reduce the number of faces checkd for each neighbour vertex
JustusBraun Mar 25, 2025
f747a34
Remove unused vertex maps, set log levels to debug
JustusBraun Mar 25, 2025
8aef90d
Add check if downcast was successful
JustusBraun Mar 25, 2025
0ea8330
Improve default layer update performance by updating only changed
JustusBraun Mar 26, 2025
f3acf8f
Changed writeLock to a protected function. The only logic that should…
JustusBraun Mar 28, 2025
660c10d
The layer update can now be done without needing the writeLock for the
JustusBraun Mar 28, 2025
13a2be2
Added check to detect if a Non-Manifold Mesh was used as input
JustusBraun Apr 6, 2025
0ea1471
Switch log msg to debug
JustusBraun Apr 7, 2025
0c9cfb9
Set cost of lethal vertices to 1.0 and enable OpenMP for faster
JustusBraun Apr 11, 2025
a7c05f7
Fix vertex color loading and publishing
JustusBraun May 27, 2025
e97557f
Add check if the edge_weights map contains the keys
JustusBraun May 27, 2025
09b4b87
Handle non-manifold meshes during Map load
JustusBraun May 30, 2025
6b7ab87
Fix combination layer lethal vertex handling
JustusBraun Jul 13, 2025
e093a9e
Remove explicit initialization for all map values
JustusBraun Jul 14, 2025
ea5776a
Propagate timestamps through notifyChanged and updateInput calls
JustusBraun Jul 16, 2025
c1442bf
Post merge clean up and fixes
JustusBraun Aug 8, 2025
230e8bf
Apply runtime improvements from dynamic_inflation_layer to inflation_…
JustusBraun Aug 8, 2025
aad1e2e
Remove DynamicInflationLayer
JustusBraun Aug 8, 2025
a496eb6
Add note why we do not normalize the combined costs
JustusBraun Aug 11, 2025
17d48d0
Add note on why we use a multithreaded executor
JustusBraun Aug 13, 2025
cb2ccc3
Change AbstractLayer::costs() and AbstractLayer::lethals() to return
JustusBraun Aug 13, 2025
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
5 changes: 4 additions & 1 deletion mbf_mesh_nav/src/mbf_mesh_nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <signal.h>
#include <tf2_ros/transform_listener.h>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/executors/multi_threaded_executor.hpp>

mbf_mesh_nav::MeshNavigationServer::Ptr mesh_nav_srv_ptr;
rclcpp::Node::SharedPtr node;
Expand Down Expand Up @@ -66,7 +67,9 @@ int main(int argc, char** argv)

signal(SIGINT, sigintHandler);

rclcpp::spin(node);
rclcpp::executors::MultiThreadedExecutor exec;
exec.add_node(node);
exec.spin();
Comment thread
JustusBraun marked this conversation as resolved.

return EXIT_SUCCESS;
}
15 changes: 15 additions & 0 deletions mesh_layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif()
find_package(ament_cmake_ros REQUIRED)
find_package(mesh_map REQUIRED)
find_package(LVR2 REQUIRED)
find_package(OpenMP)
add_definitions(${LVR2_DEFINITIONS})

pluginlib_export_plugin_description_file(mesh_map mesh_layers.xml)
Expand All @@ -23,6 +24,7 @@ add_library(${PROJECT_NAME}
src/steepness_layer.cpp
src/ridge_layer.cpp
src/clearance_layer.cpp
src/combination_layer.cpp
)
include_directories(
include
Expand All @@ -38,6 +40,7 @@ ament_target_dependencies(${PROJECT_NAME} mesh_map LVR2)
target_compile_definitions(${PROJECT_NAME} PRIVATE "MESH_LAYERS_BUILDING_LIBRARY")
target_link_libraries(${PROJECT_NAME}
${LVR2_LIBRARIES}
OpenMP::OpenMP_CXX
)

install(DIRECTORY include/
Expand All @@ -51,6 +54,18 @@ install(TARGETS
RUNTIME DESTINATION bin
)

if (BUILD_TESTING)
# Add GTest tests
find_package(ament_cmake_gtest REQUIRED)

ament_add_gtest(${PROJECT_NAME}_inflation_layer_test test/inflation_layer_test.cpp)
target_include_directories(${PROJECT_NAME}_inflation_layer_test PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(${PROJECT_NAME}_inflation_layer_test ${PROJECT_NAME})
endif()

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(mesh_map)
Expand Down
8 changes: 0 additions & 8 deletions mesh_layers/include/mesh_layers/border_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ class BorderLayer : public mesh_map::AbstractLayer
return lethal_vertices_;
}

/**
* @brief update set of lethal vertices by adding and removing vertices
*
* @param added_lethal vertices to be marked as lethal
* @param removed_lethal vertices to be removed from the set of lethal vertices
*/
virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal) override {};

/**
* @brief initializes this layer plugin
*
Expand Down
8 changes: 0 additions & 8 deletions mesh_layers/include/mesh_layers/clearance_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ class ClearanceLayer : public mesh_map::AbstractLayer
return lethal_vertices_;
}

/**
* @brief update set of lethal vertices by adding and removing vertices
*
* @param added_lethal vertices to be marked as lethal
* @param removed_lethal vertices to be removed from the set of lethal vertices
*/
virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal) override {};

/**
* @brief initializes this layer plugin
*
Expand Down
128 changes: 128 additions & 0 deletions mesh_layers/include/mesh_layers/combination_layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2025, Justus Braun
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* authors:
* Justus Braun <jubraun@uni-osnabrueck.de>
*
*/
#pragma once

#include <mesh_map/abstract_layer.h>
#include <rclcpp/rclcpp.hpp>

namespace mesh_layers
{

class MaxCombinationLayer
: public mesh_map::AbstractLayer
{
public:

bool readLayer() override {return false;}
bool writeLayer() override {return true;}
float defaultValue() override {return 0.0;}
float threshold() override {return 1.0;}
lvr2::VertexMap<float>& costs() override {return costs_;}
std::set<lvr2::VertexHandle>& lethals() override {return lethals_;}

/**
* @brief Combines the configured layers
*/
bool computeLayer() override;

/**
* @brief Process a change in a lower layer
*/
virtual void onInputChanged(
const rclcpp::Time& timestamp,
const std::set<lvr2::VertexHandle>& changed
) override;

/**
* @brief Initialize the layer
*/
bool initialize() override;

private:
// Combined costs
lvr2::DenseVertexMap<float> costs_;

// Combined lethal vertices
std::set<lvr2::VertexHandle> lethals_;

// Configured layers; use weak_ptr to prevent shared_ptr cycles
std::vector<std::weak_ptr<mesh_map::AbstractLayer>> inputs_;
};


class CombinationLayer
: public mesh_map::AbstractLayer
{
public:

bool readLayer() override {return false;}
bool writeLayer() override {return true;}
float defaultValue() override {return 0.0;}
float threshold() override {return 1.0;}
lvr2::VertexMap<float>& costs() override {return costs_;}
std::set<lvr2::VertexHandle>& lethals() override {return lethals_;}

/**
* @brief Combines the configured layers
*/
bool computeLayer() override;

/**
* @brief Process a change in a lower layer
*/
virtual void onInputChanged(
const rclcpp::Time& timestamp,
const std::set<lvr2::VertexHandle>& changed
) override;

/**
* @brief Initialize the layer
*/
bool initialize() override;

private:
// Combined costs
lvr2::DenseVertexMap<float> costs_;

// Combined lethal vertices
std::set<lvr2::VertexHandle> lethals_;

// Configured layers; use weak_ptr to prevent shared_ptr cycles
std::vector<std::weak_ptr<mesh_map::AbstractLayer>> inputs_;
};

} // namespace mesh_map
8 changes: 0 additions & 8 deletions mesh_layers/include/mesh_layers/height_diff_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ class HeightDiffLayer : public mesh_map::AbstractLayer
return lethal_vertices_;
}

/**
* @brief update set of lethal vertices by adding and removing vertices
*
* @param added_lethal vertices to be marked as lethal
* @param removed_lethal vertices to be removed from the set of lethal vertices
*/
virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal) override {};

/**
* @brief initializes this layer plugin
*
Expand Down
59 changes: 36 additions & 23 deletions mesh_layers/include/mesh_layers/inflation_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define MESH_MAP__INFLATION_LAYER_H

#include <mesh_map/abstract_layer.h>
#include <lvr2/geometry/PMPMesh.hpp>
#include <rclcpp/rclcpp.hpp>

namespace mesh_layers
Expand All @@ -50,6 +51,7 @@ const float EPSILON = 1e-9;
*/
class InflationLayer : public mesh_map::AbstractLayer
{
public:
/**
* @brief try read layer from map file
*
Expand Down Expand Up @@ -81,13 +83,17 @@ class InflationLayer : public mesh_map::AbstractLayer
*/
virtual float threshold() override;

inline float computeUpdateSethianMethod(const float& d1, const float& d2, const float& a, const float& b,
const float& dot, const float& F);
inline float computeUpdateSethianMethod(
const float& d1, const float& d2,
const float& a, const float& b,
const float& dot, const float& F
) const;

/**
* @brief updates the wavefront
*
* @param distances current distances from the start vertices
* @param vector_map buffer to store new vectors towards the source in
* @param predecessors current predecessors of vertices visited during the wave front propagation
* @param max_distance max distance of propagation
* @param edge_weights weights of the edges
Expand All @@ -99,11 +105,14 @@ class InflationLayer : public mesh_map::AbstractLayer
*
* @return true if successful; else false
*/
inline bool waveFrontUpdate(lvr2::DenseVertexMap<float>& distances,
lvr2::DenseVertexMap<lvr2::VertexHandle>& predecessors, const float& max_distance,
const lvr2::DenseEdgeMap<float>& edge_weights, const lvr2::FaceHandle& fh,
const lvr2::BaseVector<float>& normal, const lvr2::VertexHandle& v1,
const lvr2::VertexHandle& v2, const lvr2::VertexHandle& v3);
bool waveFrontUpdate(
const lvr2::PMPMesh<mesh_map::Vector>& mesh,
lvr2::DenseVertexMap<float>& distances,
lvr2::DenseVertexMap<mesh_map::Vector>& vector_map,
const float& max_distance,
const lvr2::DenseEdgeMap<float>& edge_weights,
const lvr2::VertexHandle& v1, const lvr2::VertexHandle& v2, const lvr2::VertexHandle& v3
) const;

/**
* @brief fade cost value based on lethal and inscribed area
Expand All @@ -118,13 +127,22 @@ class InflationLayer : public mesh_map::AbstractLayer
* @brief inflate around lethal vertices by using an wave front propagation and assign riskiness values to vertices
*
* @param lethals set of current lethal vertices
* @param[out] costs buffer to write the costs to
* @param[out] vectors buffer to write the vectors to
* @param inflation_radius radius of inflation
* @param inscribed_radius rarius of inscribed area
* @param inscribed_value value assigned to inscribed vertices
* @param lethal_value value of lethal vertices
*/
void waveCostInflation(const std::set<lvr2::VertexHandle>& lethals, const float inflation_radius,
const float inscribed_radius, const float inscribed_value, const float lethal_value);
void waveCostInflation(
const std::set<lvr2::VertexHandle>& lethals,
lvr2::DenseVertexMap<float>& costs,
lvr2::DenseVertexMap<mesh_map::Vector>& vectors,
const float inflation_radius,
const float inscribed_radius,
const float inscribed_value,
const float lethal_value
);

/**
* @brief returns repulsive vector at a given position inside a face
Expand All @@ -134,7 +152,7 @@ class InflationLayer : public mesh_map::AbstractLayer
*
* @return vector of the current vectorfield
*/
lvr2::BaseVector<float> vectorAt(const std::array<lvr2::VertexHandle, 3>& vertices,
mesh_map::Vector vectorAt(const std::array<lvr2::VertexHandle, 3>& vertices,
const std::array<float, 3>& barycentric_coords);

/**
Expand All @@ -144,14 +162,14 @@ class InflationLayer : public mesh_map::AbstractLayer
*
* @return vector of vectorfield at requested vertex
*/
lvr2::BaseVector<float> vectorAt(const lvr2::VertexHandle& vertex);
mesh_map::Vector vectorAt(const lvr2::VertexHandle& vertex);

/**
* @brief delivers the current repulsive vectorfield
*
* @return repulsive vectorfield
*/
const boost::optional<lvr2::VertexMap<lvr2::BaseVector<float>>&> vectorMap()
const boost::optional<lvr2::VertexMap<mesh_map::Vector>&> vectorMap()
{
return vector_map_;
}
Expand All @@ -165,7 +183,7 @@ class InflationLayer : public mesh_map::AbstractLayer
*/
void backToSource(const lvr2::VertexHandle& current_vertex,
const lvr2::DenseVertexMap<lvr2::VertexHandle>& predecessors,
lvr2::DenseVertexMap<lvr2::BaseVector<float>>& vector_map);
lvr2::DenseVertexMap<mesh_map::Vector>& vector_map);

/**
* @brief calculate the values of this layer
Expand All @@ -191,13 +209,10 @@ class InflationLayer : public mesh_map::AbstractLayer
return lethal_vertices_;
} // TODO remove... layer types

/**
* @brief update set of lethal vertices by adding and removing vertices
*
* @param added_lethal vertices to be marked as lethal
* @param removed_lethal vertices to be removed from the set of lethal vertices
*/
virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal);
virtual void onInputChanged(
const rclcpp::Time& timestamp,
const std::set<lvr2::VertexHandle>& changed
) override;

/**
* @brief initializes this layer plugin
Expand All @@ -215,9 +230,7 @@ class InflationLayer : public mesh_map::AbstractLayer

lvr2::DenseVertexMap<float> direction_;

lvr2::DenseVertexMap<lvr2::FaceHandle> cutting_faces_;

lvr2::DenseVertexMap<lvr2::BaseVector<float>> vector_map_;
lvr2::DenseVertexMap<mesh_map::Vector> vector_map_;

lvr2::DenseVertexMap<float> distances_;

Expand Down
8 changes: 0 additions & 8 deletions mesh_layers/include/mesh_layers/ridge_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,6 @@ class RidgeLayer : public mesh_map::AbstractLayer
return lethal_vertices_;
}

/**
* @brief update set of lethal vertices by adding and removing vertices
*
* @param added_lethal vertices to be marked as lethal
* @param removed_lethal vertices to be removed from the set of lethal vertices
*/
virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal) override {};

/**
* @brief initializes this layer plugin
*
Expand Down
Loading
Loading