@@ -84,22 +84,6 @@ namespace fs = std::filesystem;
8484namespace mesh_map
8585{
8686
87- // std::shared_ptr<lvr2::BaseMesh<Vector> > createHemByName(std::string hem_impl, lvr2::MeshBufferPtr mesh_buffer)
88- // {
89- // if(hem_impl == "pmp")
90- // {
91- // return std::make_shared<lvr2::PMPMesh<Vector> >(mesh_buffer);
92- // }
93- // else if(hem_impl == "lvr")
94- // {
95- // return std::make_shared<lvr2::HalfEdgeMesh<Vector> >(mesh_buffer);
96- // }
97-
98- // std::stringstream error_msg;
99- // error_msg << "'" << hem_impl << "' not known." << std::endl;
100- // throw std::runtime_error(error_msg.str());
101- // }
102-
10387using HDF5MeshIO = lvr2::Hdf5Build<lvr2::hdf5features::MeshIO>;
10488
10589MeshMap::MeshMap (tf2_ros::Buffer& tf, const rclcpp::Node::SharedPtr& node)
@@ -147,6 +131,17 @@ MeshMap::MeshMap(tf2_ros::Buffer& tf, const rclcpp::Node::SharedPtr& node)
147131 marker_pub = node->create_publisher <visualization_msgs::msg::Marker>(" ~/marker" , 100 );
148132 mesh_geometry_pub = node->create_publisher <mesh_msgs::msg::MeshGeometryStamped>(" ~/mesh" , rclcpp::QoS (1 ).transient_local ());
149133 vertex_costs_pub = node->create_publisher <mesh_msgs::msg::MeshVertexCostsStamped>(" ~/vertex_costs" , rclcpp::QoS (1 ).transient_local ());
134+ // we dont want to publish static costs all the time.
135+ // therefore we have to check if someone newly subscribed to the topic
136+ vertex_costs_subscribe_checker_ = node->create_wall_timer (std::chrono::milliseconds (200 ), [this , node]{
137+ const size_t count = vertex_costs_pub->get_subscription_count () + vertex_costs_pub->get_intra_process_subscription_count ();
138+ if (count > vertex_costs_sub_count_)
139+ {
140+ RCLCPP_INFO (node->get_logger (), " New cost layer subscriber detected. Publishing vertex costs once..." );
141+ publishCostLayers (node->now ());
142+ }
143+ vertex_costs_sub_count_ = count;
144+ });
150145 vertex_costs_update_pub_ = node->create_publisher <mesh_msgs::msg::MeshVertexCostsSparseStamped>(std::string (vertex_costs_pub->get_topic_name ()) + " /updates" , rclcpp::QoS (10 ).transient_local ());
151146 vertex_colors_pub = node->create_publisher <mesh_msgs::msg::MeshVertexColorsStamped>(" ~/vertex_colors" , rclcpp::QoS (1 ).transient_local ());
152147 vector_field_pub = node->create_publisher <visualization_msgs::msg::Marker>(" ~/vector_field" , rclcpp::QoS (1 ).transient_local ());
0 commit comments