rgbd
client_rgbd.cpp
Go to the documentation of this file.
1 #include "rgbd/client_rgbd.h"
2 
3 #include "rgbd/types.h"
4 #include "rgbd/ros/conversions.h"
5 
6 namespace rgbd {
7 
8 // ----------------------------------------------------------------------------------------
9 
10 ClientRGBD::ClientRGBD() : image_ptr_(nullptr)
11 {
12 }
13 
14 // ----------------------------------------------------------------------------------------
15 
17 {
18 }
19 
20 // ----------------------------------------------------------------------------------------
21 
22 bool ClientRGBD::initialize(const std::string& server_name)
23 {
24  ros::NodeHandle nh;
25  ros::SubscribeOptions sub_options =
26  ros::SubscribeOptions::create<rgbd_msgs::RGBD>(
27  server_name, 1, boost::bind(&ClientRGBD::rgbdImageCallback, this, _1), ros::VoidPtr(), &cb_queue_);
28 
29  sub_image_ = nh.subscribe(sub_options);
30 
31  return true;
32 }
33 
34 // ----------------------------------------------------------------------------------------
35 
37 {
38  sub_image_ = ros::Subscriber(); // Old subscriber is deleted, so it unsubscribes. New subsriber is not subscribed to anything.
39  return true;
40 }
41 
42 // ----------------------------------------------------------------------------------------
43 
45 {
46  new_image_ = false;
47  image_ptr_ = &image;
48  cb_queue_.callAvailable();
49  return new_image_;
50 }
51 
52 // ----------------------------------------------------------------------------------------
53 
55 {
56  new_image_ = false;
57  image_ptr_ = nullptr;
58  cb_queue_.callAvailable();
59  if (!new_image_)
60  {
61  delete image_ptr_; // Needs to be deleted, because caller doesn't get a shared ptr to this raw pointer.
62  return nullptr;
63  }
64  return ImagePtr(image_ptr_);
65 }
66 
67 // ----------------------------------------------------------------------------------------
68 
69 void ClientRGBD::rgbdImageCallback(const rgbd_msgs::RGBD::ConstPtr& msg)
70 {
72 }
73 
74 }
rgbd::ClientRGBD::new_image_
bool new_image_
Track if image is updated in a callback.
Definition: client_rgbd.h:80
std::string
std::shared_ptr
types.h
rgbd::ClientRGBD::~ClientRGBD
virtual ~ClientRGBD()
Destructor.
Definition: client_rgbd.cpp:16
client_rgbd.h
conversions.h
rgbd::ClientRGBD::image_ptr_
Image * image_ptr_
Pointer to the Image being written in the NextImage calls. Either set to the address of the provided ...
Definition: client_rgbd.h:87
rgbd::Image
Definition: image.h:43
rgbd
Definition: client.h:24
rgbd::ClientRGBD::initialize
bool initialize(const std::string &server_name)
Initialize the client.
Definition: client_rgbd.cpp:22
rgbd::ClientRGBD::sub_image_
ros::Subscriber sub_image_
Definition: client_rgbd.h:74
rgbd::ClientRGBD::deinitialize
bool deinitialize()
Clears the subscriber. initialized will now return false.
Definition: client_rgbd.cpp:36
rgbd::ClientRGBD::rgbdImageCallback
void rgbdImageCallback(const rgbd_msgs::RGBD::ConstPtr &msg)
Definition: client_rgbd.cpp:69
rgbd::ClientRGBD::cb_queue_
ros::CallbackQueue cb_queue_
Definition: client_rgbd.h:75
rgbd::convert
bool convert(const cv::Mat &image, sensor_msgs::Image &image_msg)
Convert either a rgb or depth image, cv::Mat, to an image message.
Definition: conversions.cpp:32
rgbd::ImagePtr
std::shared_ptr< Image > ImagePtr
Definition: types.h:8
rgbd::ClientRGBD::nextImage
ImagePtr nextImage()
Get a new Image. If no new image has been received since the last call, The ImagePtr will be a nullpt...
Definition: client_rgbd.cpp:54
rgbd::ClientRGBD::ClientRGBD
ClientRGBD()
Constructor.
Definition: client_rgbd.cpp:10