Files
OrbbecSDK_ROS2/orbbec_camera/src/image_publisher.cpp
T

61 lines
2.3 KiB
C++
Raw Normal View History

2024-09-23 20:22:23 +08:00
// Copyright 2023 Intel Corporation. All Rights Reserved.
//
// 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.
#include "orbbec_camera/image_publisher.h"
namespace orbbec_camera {
// --- image_rcl_publisher implementation ---
image_rcl_publisher::image_rcl_publisher(rclcpp::Node& node, const std::string& topic_name,
const rmw_qos_profile_t& qos) {
image_publisher_impl = node.create_publisher<sensor_msgs::msg::Image>(
topic_name, rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(qos), qos));
}
void image_rcl_publisher::publish(sensor_msgs::msg::Image::UniquePtr image_ptr) {
image_publisher_impl->publish(std::move(image_ptr));
}
size_t image_rcl_publisher::get_subscription_count() const {
return image_publisher_impl->get_subscription_count();
}
// --- image_transport_publisher implementation ---
image_transport_publisher::image_transport_publisher(rclcpp::Node& node,
const std::string& topic_name,
const rmw_qos_profile_t& qos) {
2026-07-28 21:06:41 +08:00
image_publisher_impl =
std::make_shared<image_transport::Publisher>(image_transport::create_publisher(
#ifdef ORBBEC_IMAGE_TRANSPORT_USES_REQUIRED_INTERFACES
2026-05-27 13:08:33 +02:00
image_transport::RequiredInterfaces{node},
#else
&node,
#endif
topic_name,
2026-07-28 21:06:41 +08:00
#ifdef ORBBEC_IMAGE_TRANSPORT_USES_REQUIRED_INTERFACES
2026-05-27 13:08:33 +02:00
rclcpp::QoS{rclcpp::QoSInitialization::from_rmw(qos), qos}
#else
qos
#endif
2026-07-28 21:06:41 +08:00
));
2024-09-23 20:22:23 +08:00
}
void image_transport_publisher::publish(sensor_msgs::msg::Image::UniquePtr image_ptr) {
image_publisher_impl->publish(*image_ptr);
}
size_t image_transport_publisher::get_subscription_count() const {
return image_publisher_impl->getNumSubscribers();
}
2026-07-28 21:06:41 +08:00
} // namespace orbbec_camera