6262#include " mesh_msgs/msg/mesh_vertex_colors.hpp"
6363#include " mesh_msgs/msg/mesh_vertex_colors_stamped.hpp"
6464#include " mesh_msgs/msg/mesh_vertex_costs_stamped.hpp"
65+ #include " mesh_msgs/msg/mesh_vertex_costs_sparse_stamped.hpp"
6566#include " mesh_msgs/msg/mesh_vertex_tex_coords.hpp"
6667#include " mesh_msgs/msg/mesh_material.hpp"
6768#include " mesh_msgs/msg/mesh_texture.hpp"
@@ -224,6 +225,31 @@ inline const mesh_msgs::msg::MeshVertexCosts toVertexCosts(
224225 return costs_msg;
225226}
226227
228+ inline const mesh_msgs::msg::MeshVertexCostsSparse toVertexCostsSparse (
229+ const lvr2::VertexMap<float >& costs,
230+ const float default_value
231+ )
232+ {
233+ mesh_msgs::msg::MeshVertexCostsSparse costs_msg;
234+ costs_msg.vertices .resize (costs.numValues ());
235+ costs_msg.costs .resize (costs.numValues ());
236+ costs_msg.default_value = default_value;
237+
238+ std::transform (costs.begin (), costs.end (), costs_msg.vertices .begin (),
239+ [](const lvr2::VertexHandle& v)
240+ {
241+ return v.idx ();
242+ }
243+ );
244+ std::transform (costs_msg.vertices .begin (), costs_msg.vertices .end (), costs_msg.costs .begin (),
245+ [&costs](const uint32_t idx)
246+ {
247+ return costs[lvr2::VertexHandle (idx)];
248+ }
249+ );
250+ return costs_msg;
251+ }
252+
227253inline const mesh_msgs::msg::MeshVertexCostsStamped toVertexCostsStamped (
228254 const lvr2::VertexMap<float >& costs,
229255 const size_t num_values,
@@ -243,6 +269,24 @@ inline const mesh_msgs::msg::MeshVertexCostsStamped toVertexCostsStamped(
243269 return mesh_msg;
244270}
245271
272+ inline const mesh_msgs::msg::MeshVertexCostsSparseStamped toVertexCostsSparseStamped (
273+ const lvr2::VertexMap<float >& costs,
274+ const float default_value,
275+ const std::string& name,
276+ const std::string& frame_id,
277+ const std::string& uuid,
278+ const rclcpp::Time& stamp = rclcpp::Time()
279+ )
280+ {
281+ mesh_msgs::msg::MeshVertexCostsSparseStamped msg;
282+ msg.mesh_vertex_costs = toVertexCostsSparse (costs, default_value);
283+ msg.uuid = uuid;
284+ msg.type = name;
285+ msg.header .frame_id = frame_id;
286+ msg.header .stamp = stamp;
287+ return msg;
288+ }
289+
246290inline const mesh_msgs::msg::MeshVertexCosts toVertexCosts (
247291 const lvr2::DenseVertexMap<float >& costs)
248292{
0 commit comments