rgbd
nodelets/ros_to_rgbd.cpp
Go to the documentation of this file.
1 #include <nodelet/nodelet.h>
2 #include <nodelet/detail/callback_queue.h>
3 
4 #include <pluginlib/class_list_macros.hpp>
5 
6 #include <ros/node_handle.h>
7 #include <ros/console.h>
8 
9 #include "rgbd/client_ros_base.h"
10 #include "rgbd/image.h"
11 #include "rgbd/server.h"
12 
13 #include <memory>
14 
15 
16 namespace rgbd
17 {
18 
20 {
21 public:
22  ClientRosNodelet(ros::NodeHandle& nh) : ClientROSBase(nh)
23  {
24  }
25 
27  {
28  }
29 
30  const Image* getImage()
31  {
32  return image_ptr_;
33  }
34 
35  message_filters::Synchronizer<RGBDApproxPolicy>* getSync()
36  {
37  return sync_.get();
38  }
39 
41 
42 };
43 
44 class ROSToRGBDNodelet : public nodelet::Nodelet
45 {
46 public:
48  {
49  }
50 
51 private:
52  virtual void onInit()
53  {
54  ros::NodeHandle nh = getNodeHandle();
55  ros::NodeHandle nh_private = getPrivateNodeHandle();
56 
57  // ----- READ RGB STORAGE TYPE
58 
59  rgbd::RGBStorageType rgb_type;
60 
61  std::string rgb_type_str = "lossless";
62  nh_private.getParam("rgb_storage", rgb_type_str);
63  if (rgb_type_str == "none")
64  rgb_type = rgbd::RGB_STORAGE_NONE;
65  else if (rgb_type_str == "lossless")
66  rgb_type = rgbd::RGB_STORAGE_LOSSLESS;
67  else if (rgb_type_str == "jpg")
68  rgb_type = rgbd::RGB_STORAGE_JPG;
69  else
70  {
71  ROS_ERROR("Unknown 'rgb_storage' type: should be 'none', 'lossless', or 'jpg'.");
72  return;
73  }
74 
75  // ----- READ DEPTH STORAGE TYPE
76 
77  rgbd::DepthStorageType depth_type;
78 
79  std::string depth_type_str = "lossless";
80  nh_private.getParam("depth_storage", depth_type_str);
81  if (depth_type_str == "none")
82  depth_type = rgbd::DEPTH_STORAGE_NONE;
83  else if (depth_type_str == "lossless")
84  depth_type = rgbd::DEPTH_STORAGE_LOSSLESS;
85  else if (depth_type_str == "png")
86  depth_type = rgbd::DEPTH_STORAGE_PNG;
87  else
88  {
89  ROS_ERROR("Unknown 'depth_storage' type: should be 'none', 'lossless', or 'png'.");
90  return;
91  }
92 
93  client_ = std::make_unique<rgbd::ClientRosNodelet>(nh);
94  client_->initialize("rgb_image", "depth_image", "cam_info");
95 
96  server_ = std::make_unique<rgbd::Server>(nh);
97  server_->initialize(ros::names::resolve("rgbd"), rgb_type, depth_type);
98 
99  client_->getSync()->registerCallback(boost::bind(&ROSToRGBDNodelet::imageCallback, this, _1, _2));
100  }
101 
102  bool imageCallback(const sensor_msgs::ImageConstPtr& rgb_image_msg, const sensor_msgs::ImageConstPtr& depth_image_msg)
103  {
104  if (!client_->imageCallback(rgb_image_msg, depth_image_msg))
105  {
106  ROS_ERROR("Error during processing the image callback. See log above.");
107  return false;
108  }
109  server_->send(*client_->getImage());
110  return true;
111  }
112 
115 };
116 
117 PLUGINLIB_EXPORT_CLASS(rgbd::ROSToRGBDNodelet, nodelet::Nodelet)
118 
119 } // end namespace rgbd
std::string
rgbd::ClientROSBase::sync_
std::unique_ptr< message_filters::Synchronizer< RGBDApproxPolicy > > sync_
Definition: client_ros_base.h:75
rgbd::ClientRosNodelet
Definition: nodelets/ros_to_rgbd.cpp:19
std::unique_ptr::get
T get(T... args)
rgbd::ROSToRGBDNodelet::ROSToRGBDNodelet
ROSToRGBDNodelet()
Definition: nodelets/ros_to_rgbd.cpp:47
rgbd::ROSToRGBDNodelet
Definition: nodelets/ros_to_rgbd.cpp:44
rgbd::DepthStorageType
DepthStorageType
Definition: image.h:36
rgbd::Image
Definition: image.h:43
rgbd::RGB_STORAGE_JPG
@ RGB_STORAGE_JPG
Definition: image.h:33
rgbd::ClientRosNodelet::getSync
message_filters::Synchronizer< RGBDApproxPolicy > * getSync()
Definition: nodelets/ros_to_rgbd.cpp:35
rgbd
Definition: client.h:24
rgbd::RGBStorageType
RGBStorageType
Definition: image.h:29
rgbd::ROSToRGBDNodelet::onInit
virtual void onInit()
Definition: nodelets/ros_to_rgbd.cpp:52
rgbd::DEPTH_STORAGE_NONE
@ DEPTH_STORAGE_NONE
Definition: image.h:38
rgbd::ImageConstPtr
std::shared_ptr< const Image > ImageConstPtr
Definition: types.h:10
rgbd::ROSToRGBDNodelet::imageCallback
bool imageCallback(const sensor_msgs::ImageConstPtr &rgb_image_msg, const sensor_msgs::ImageConstPtr &depth_image_msg)
Definition: nodelets/ros_to_rgbd.cpp:102
image.h
rgbd::DEPTH_STORAGE_PNG
@ DEPTH_STORAGE_PNG
Definition: image.h:40
rgbd::ROSToRGBDNodelet::client_
std::unique_ptr< rgbd::ClientRosNodelet > client_
Definition: nodelets/ros_to_rgbd.cpp:113
memory
rgbd::ROSToRGBDNodelet::server_
std::unique_ptr< rgbd::Server > server_
Definition: nodelets/ros_to_rgbd.cpp:114
rgbd::ClientROSBase::imageCallback
bool imageCallback(const sensor_msgs::ImageConstPtr &rgb_image_msg, const sensor_msgs::ImageConstPtr &depth_image_msg)
Callback for synched rgb and depth image.
Definition: client_ros_base.cpp:71
rgbd::RGB_STORAGE_LOSSLESS
@ RGB_STORAGE_LOSSLESS
Definition: image.h:32
rgbd::ClientROSBase
Client which subscribes to regular ROS image topics.
Definition: client_ros_base.h:32
client_ros_base.h
rgbd::DEPTH_STORAGE_LOSSLESS
@ DEPTH_STORAGE_LOSSLESS
Definition: image.h:39
rgbd::ClientRosNodelet::getImage
const Image * getImage()
Definition: nodelets/ros_to_rgbd.cpp:30
rgbd::ClientRosNodelet::~ClientRosNodelet
~ClientRosNodelet()
Definition: nodelets/ros_to_rgbd.cpp:26
rgbd::RGB_STORAGE_NONE
@ RGB_STORAGE_NONE
Definition: image.h:31
rgbd::ClientRosNodelet::ClientRosNodelet
ClientRosNodelet(ros::NodeHandle &nh)
Definition: nodelets/ros_to_rgbd.cpp:22
server.h
std::unique_ptr< rgbd::ClientRosNodelet >
rgbd::ClientROSBase::image_ptr_
Image * image_ptr_
image_ptr_ Pointer to image. Image could be provided by reference or the pointer will be wrapped in a...
Definition: client_ros_base.h:89