rgbd_camera_publisher.cpp
Go to the documentation of this file.
4 
5 namespace camera_throttle
6 {
7 
9 {
10  Impl() : unadvertised(false), hasPcl(false)
11  {
12  }
13 
15  {
16  shutdown();
17  }
18 
19  bool isValid() const
20  {
21  return !this->unadvertised;
22  }
23 
24  void shutdown()
25  {
26  if (!this->unadvertised) {
27  this->unadvertised = true;
28  this->rgbPub.shutdown();
29  this->rgbInfoPub.shutdown();
30  this->depthPub.shutdown();
31  this->depthInfoPub.shutdown();
32  if (this->hasPcl)
33  this->pclPub.shutdown();
34  }
35  }
36 
43  bool hasPcl;
44 };
45 
47  const std::string& rgb_base_topic, const std::string& depth_base_topic, size_t queue_size,
48  const image_transport::SubscriberStatusCallback& rgb_connect_cb,
49  const image_transport::SubscriberStatusCallback& rgb_disconnect_cb,
50  const image_transport::SubscriberStatusCallback& depth_connect_cb,
51  const image_transport::SubscriberStatusCallback& depth_disconnect_cb,
52  const ros::SubscriberStatusCallback& rgb_info_connect_cb,
53  const ros::SubscriberStatusCallback& rgb_info_disconnect_cb,
54  const ros::SubscriberStatusCallback& depth_info_connect_cb,
55  const ros::SubscriberStatusCallback& depth_info_disconnect_cb,
56  const ros::VoidPtr& tracked_object, bool latch)
57  : impl(new Impl)
58 {
59  this->impl->hasPcl = false;
60 
61  // Explicitly resolve name here so we compute the correct CameraInfo topic when the
62  // image topic is remapped
63  const auto rgb_image_topic = rgb_nh.resolveName(rgb_base_topic);
64  const auto rgb_info_topic = image_transport::getCameraInfoTopic(rgb_image_topic);
65  const auto depth_image_topic = depth_nh.resolveName(depth_base_topic);
66  const auto depth_info_topic = image_transport::getCameraInfoTopic(depth_image_topic);
67 
68  this->impl->rgbPub = image_it.advertise(
69  rgb_image_topic, queue_size, rgb_connect_cb, rgb_disconnect_cb, tracked_object, latch);
70  this->impl->rgbInfoPub = rgb_nh.advertise<sensor_msgs::CameraInfo>(
71  rgb_info_topic, queue_size, rgb_info_connect_cb, rgb_info_disconnect_cb, tracked_object, latch);
72  this->impl->depthPub = image_it.advertise(
73  depth_image_topic, queue_size, depth_connect_cb, depth_disconnect_cb, tracked_object, latch);
74  this->impl->depthInfoPub = depth_nh.advertise<sensor_msgs::CameraInfo>(
75  depth_info_topic, queue_size, depth_info_connect_cb, depth_info_disconnect_cb, tracked_object, latch);
76 }
77 
79  const std::string& rgb_base_topic, const std::string& depth_base_topic, const std::string& pcl_topic,
80  size_t queue_size,
81  const image_transport::SubscriberStatusCallback& rgb_connect_cb,
82  const image_transport::SubscriberStatusCallback& rgb_disconnect_cb,
83  const image_transport::SubscriberStatusCallback& depth_connect_cb,
84  const image_transport::SubscriberStatusCallback& depth_disconnect_cb,
85  const ros::SubscriberStatusCallback& pcl_connect_cb,
86  const ros::SubscriberStatusCallback& pcl_disconnect_cb,
87  const ros::SubscriberStatusCallback& rgb_info_connect_cb,
88  const ros::SubscriberStatusCallback& rgb_info_disconnect_cb,
89  const ros::SubscriberStatusCallback& depth_info_connect_cb,
90  const ros::SubscriberStatusCallback& depth_info_disconnect_cb,
91  const ros::VoidPtr& tracked_object, bool latch)
92  : impl(new Impl)
93 {
94  this->impl->hasPcl = true;
95 
96  // Explicitly resolve name here so we compute the correct CameraInfo topic when the
97  // image topic is remapped
98  const auto rgb_image_topic = rgb_nh.resolveName(rgb_base_topic);
99  const auto rgb_info_topic = image_transport::getCameraInfoTopic(rgb_image_topic);
100  const auto depth_image_topic = depth_nh.resolveName(depth_base_topic);
101  const auto depth_info_topic = image_transport::getCameraInfoTopic(depth_image_topic);
102 
103  this->impl->rgbPub = image_it.advertise(
104  rgb_image_topic, queue_size, rgb_connect_cb, rgb_disconnect_cb, tracked_object, latch);
105  this->impl->rgbInfoPub = rgb_nh.advertise<sensor_msgs::CameraInfo>(
106  rgb_info_topic, queue_size, rgb_info_connect_cb, rgb_info_disconnect_cb, tracked_object, latch);
107  this->impl->depthPub = image_it.advertise(
108  depth_image_topic, queue_size, depth_connect_cb, depth_disconnect_cb, tracked_object, latch);
109  this->impl->depthInfoPub = depth_nh.advertise<sensor_msgs::CameraInfo>(
110  depth_info_topic, queue_size, depth_info_connect_cb, depth_info_disconnect_cb, tracked_object, latch);
111  this->impl->pclPub = pcl_nh.advertise<sensor_msgs::PointCloud2>(
112  pcl_topic, queue_size, pcl_connect_cb, pcl_disconnect_cb, tracked_object, latch);
113 }
114 
116 {
117  if (impl && impl->isValid())
118  return std::max(std::max(
119  std::max(impl->rgbPub.getNumSubscribers(), impl->rgbInfoPub.getNumSubscribers()),
120  std::max(impl->depthPub.getNumSubscribers(), impl->depthInfoPub.getNumSubscribers())
121  ), (this->impl->hasPcl ? impl->pclPub.getNumSubscribers() : 0));
122  return 0;
123 }
124 
126 {
127  if (impl) return impl->rgbPub.getTopic();
128  return {};
129 }
130 
132 {
133  if (impl) return impl->rgbInfoPub.getTopic();
134  return {};
135 }
136 
138 {
139  if (impl) return impl->depthPub.getTopic();
140  return {};
141 }
142 
144 {
145  if (impl) return impl->depthInfoPub.getTopic();
146  return {};
147 }
148 
150 {
151  if (impl && impl->hasPcl) return impl->pclPub.getTopic();
152  return {};
153 }
154 
155 void RgbdCameraPublisher::publish(const sensor_msgs::Image& rgb_image, const sensor_msgs::CameraInfo& rgb_info,
156  const sensor_msgs::Image& depth_image, const sensor_msgs::CameraInfo& depth_info) const
157 {
158  if (!impl || !impl->isValid() || impl->hasPcl) {
159  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
160  return;
161  }
162 
163  impl->rgbPub.publish(rgb_image);
164  impl->rgbInfoPub.publish(rgb_info);
165 
166  impl->depthPub.publish(depth_image);
167  impl->depthInfoPub.publish(depth_info);
168 }
169 
170 void RgbdCameraPublisher::publish(const sensor_msgs::Image& rgb_image, const sensor_msgs::CameraInfo& rgb_info,
171  const sensor_msgs::Image& depth_image, const sensor_msgs::CameraInfo& depth_info,
172  const sensor_msgs::PointCloud2& pcl) const
173 {
174  if (!impl || !impl->isValid() || !impl->hasPcl) {
175  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
176  return;
177  }
178 
179  impl->rgbPub.publish(rgb_image);
180  impl->rgbInfoPub.publish(rgb_info);
181 
182  impl->depthPub.publish(depth_image);
183  impl->depthInfoPub.publish(depth_info);
184 
185  impl->pclPub.publish(pcl);
186 }
187 
188 void RgbdCameraPublisher::publish(const sensor_msgs::ImageConstPtr& rgb_image, const sensor_msgs::CameraInfoConstPtr& rgb_info,
189  const sensor_msgs::ImageConstPtr& depth_image, const sensor_msgs::CameraInfoConstPtr& depth_info) const
190 {
191  if (!impl || !impl->isValid() || impl->hasPcl) {
192  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
193  return;
194  }
195 
196  impl->rgbPub.publish(rgb_image);
197  impl->rgbInfoPub.publish(rgb_info);
198 
199  impl->depthPub.publish(depth_image);
200  impl->depthInfoPub.publish(depth_info);
201 }
202 
203 void RgbdCameraPublisher::publish(const sensor_msgs::ImageConstPtr& rgb_image, const sensor_msgs::CameraInfoConstPtr& rgb_info,
204  const sensor_msgs::ImageConstPtr& depth_image, const sensor_msgs::CameraInfoConstPtr& depth_info,
205  const sensor_msgs::PointCloud2ConstPtr& pcl) const
206 {
207  if (!impl || !impl->isValid() || !impl->hasPcl) {
208  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
209  return;
210  }
211 
212  impl->rgbPub.publish(rgb_image);
213  impl->rgbInfoPub.publish(rgb_info);
214 
215  impl->depthPub.publish(depth_image);
216  impl->depthInfoPub.publish(depth_info);
217 
218  impl->pclPub.publish(pcl);
219 }
220 
221 void RgbdCameraPublisher::publish(sensor_msgs::Image& rgb_image, sensor_msgs::CameraInfo& rgb_info,
222  sensor_msgs::Image& depth_image, sensor_msgs::CameraInfo& depth_info, ros::Time stamp) const
223 {
224  if (!impl || !impl->isValid() || impl->hasPcl) {
225  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
226  return;
227  }
228 
229  rgb_image.header.stamp = stamp;
230  rgb_info.header.stamp = stamp;
231  depth_image.header.stamp = stamp;
232  depth_info.header.stamp = stamp;
233 
234  this->publish(rgb_image, rgb_info, depth_image, depth_info);
235 }
236 
237 void RgbdCameraPublisher::publish(sensor_msgs::Image& rgb_image, sensor_msgs::CameraInfo& rgb_info,
238  sensor_msgs::Image& depth_image, sensor_msgs::CameraInfo& depth_info,
239  sensor_msgs::PointCloud2& pcl, ros::Time stamp) const
240 {
241  if (!impl || !impl->isValid() || !impl->hasPcl) {
242  ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::RgbdCameraPublisher");
243  return;
244  }
245 
246  rgb_image.header.stamp = stamp;
247  rgb_info.header.stamp = stamp;
248  depth_image.header.stamp = stamp;
249  depth_info.header.stamp = stamp;
250  pcl.header.stamp = stamp;
251 
252  this->publish(rgb_image, rgb_info, depth_image, depth_info, stamp);
253 }
254 
256 {
257  if (impl) {
258  impl->shutdown();
259  impl.reset();
260  }
261 }
262 
263 RgbdCameraPublisher::operator void*() const
264 {
265  return (impl && impl->isValid()) ? (void*)1 : (void*)0;
266 }
267 
268 }
camera_throttle::RgbdCameraPublisher::Impl::isValid
bool isValid() const
Definition: rgbd_camera_publisher.cpp:19
camera_throttle::RgbdCameraPublisher::Impl::hasPcl
bool hasPcl
Definition: rgbd_camera_publisher.cpp:43
image_transport::getCameraInfoTopic
IMAGE_TRANSPORT_DECL std::string getCameraInfoTopic(const std::string &base_topic)
camera_throttle::RgbdCameraPublisher::shutdown
void shutdown()
Shutdown the advertisements associated with this Publisher.
Definition: rgbd_camera_publisher.cpp:255
ros::Publisher
boost::shared_ptr< void >
camera_throttle::RgbdCameraPublisher::getDepthInfoTopic
std::string getDepthInfoTopic() const
Returns the depth camera info topic of this CameraPublisher.
Definition: rgbd_camera_publisher.cpp:143
camera_throttle::RgbdCameraPublisher::Impl::depthInfoPub
ros::Publisher depthInfoPub
Definition: rgbd_camera_publisher.cpp:40
camera_throttle::RgbdCameraPublisher::getPclTopic
std::string getPclTopic() const
Get the topic of the pointcloud (can be empty if pointcloud is not processed).
Definition: rgbd_camera_publisher.cpp:149
rgbd_camera_publisher.h
camera_throttle::RgbdCameraPublisher::Impl::pclPub
ros::Publisher pclPub
Definition: rgbd_camera_publisher.cpp:41
camera_throttle::RgbdCameraPublisher::Impl::rgbInfoPub
ros::Publisher rgbInfoPub
Definition: rgbd_camera_publisher.cpp:38
ros::SubscriberStatusCallback
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
camera_throttle::RgbdCameraPublisher::publish
void publish(const sensor_msgs::Image &rgb_image, const sensor_msgs::CameraInfo &rgb_info, const sensor_msgs::Image &depth_image, const sensor_msgs::CameraInfo &depth_info) const
Publish an RGB and depth (image, info) pair on the topics associated with this RgbdCameraPublisher.
Definition: rgbd_camera_publisher.cpp:155
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
camera_throttle::RgbdCameraPublisher::Impl::Impl
Impl()
Definition: rgbd_camera_publisher.cpp:10
camera_throttle::RgbdCameraPublisher::Impl::shutdown
void shutdown()
Definition: rgbd_camera_publisher.cpp:24
image_transport::ImageTransport::advertise
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle::resolveName
std::string resolveName(const std::string &name, bool remap=true) const
rgbd_image_transport.h
ros::Publisher::shutdown
void shutdown()
camera_throttle::RgbdCameraPublisher::Impl::rgbPub
image_transport::Publisher rgbPub
Definition: rgbd_camera_publisher.cpp:37
camera_throttle::RgbdCameraPublisher::Impl::~Impl
~Impl()
Definition: rgbd_camera_publisher.cpp:14
camera_throttle::RgbdCameraPublisher::getRGBTopic
std::string getRGBTopic() const
Returns the RGB base (image) topic of this CameraPublisher.
Definition: rgbd_camera_publisher.cpp:125
ROS_ASSERT_MSG
#define ROS_ASSERT_MSG(cond,...)
camera_throttle::RgbdCameraPublisher::Impl::depthPub
image_transport::Publisher depthPub
Definition: rgbd_camera_publisher.cpp:39
image_transport::Publisher::shutdown
void shutdown()
camera_throttle::RgbdCameraPublisher::getRGBInfoTopic
std::string getRGBInfoTopic() const
Returns the RGB camera info topic of this CameraPublisher.
Definition: rgbd_camera_publisher.cpp:131
camera_common.h
camera_throttle::RgbdCameraPublisher::Impl
Definition: rgbd_camera_publisher.cpp:8
camera_throttle::RgbdCameraPublisher::Impl::unadvertised
bool unadvertised
Definition: rgbd_camera_publisher.cpp:42
ros::Time
camera_throttle::RgbdCameraPublisher::getDepthTopic
std::string getDepthTopic() const
Returns the depth base (image) topic of this CameraPublisher.
Definition: rgbd_camera_publisher.cpp:137
image_transport::Publisher
camera_throttle
Definition: camera_throttle.h:11
image_transport::SubscriberStatusCallback
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
camera_throttle::RgbdCameraPublisher::impl
std::shared_ptr< Impl > impl
Definition: rgbd_camera_publisher.h:154
camera_throttle::RgbdCameraPublisher::RgbdCameraPublisher
RgbdCameraPublisher()=default
camera_throttle::RgbdImageTransport
Definition: rgbd_image_transport.h:10
ros::NodeHandle
camera_throttle::RgbdCameraPublisher::getNumSubscribers
size_t getNumSubscribers() const
Returns the number of subscribers that are currently connected to this CameraPublisher.
Definition: rgbd_camera_publisher.cpp:115


camera_throttle
Author(s): Martin Pecka
autogenerated on Sat Dec 14 2024 03:51:15