astra_ros
Device.hpp
1 #ifndef _ASTRA_ROS_DEVICE_HPP_
2 #define _ASTRA_ROS_DEVICE_HPP_
3 
4 #include <string>
5 #include <memory>
6 #include <iostream>
7 #include <vector>
8 #include <boost/optional.hpp>
9 
10 #include "Parameter.hpp"
11 
12 #include <astra/capi/astra.h>
13 
14 namespace astra_ros
15 {
21  class Device
22  {
23  public:
24  typedef std::shared_ptr<Device> Ptr;
25  typedef std::shared_ptr<const Device> ConstPtr;
26 
32  {
36  boost::optional<std::uint32_t> width;
37 
41  boost::optional<std::uint32_t> height;
42 
46  boost::optional<astra_pixel_format_t> pixel_format;
47 
51  boost::optional<std::uint8_t> fps;
52  };
53 
54  struct Frame
55  {
56  struct Color
57  {
58  std::uint32_t data_length;
59 
60  // The image data for the color stream (use metadata to understand the content).
61  // This pointer is only valid until the next update().
62  std::uint8_t *data;
63 
64  astra_image_metadata_t metadata;
65  };
66 
67  struct Ir
68  {
69  float horizontal_fov;
70  float vertical_fov;
71 
72  std::uint32_t data_length;
73 
74  // The image data for the IR stream (use metadata to understand the content).
75  // This pointer is only valid until the next update().
76  std::uint8_t *data;
77 
78  astra_image_metadata_t metadata;
79  };
80 
81  struct Depth
82  {
83  float horizontal_fov;
84  float vertical_fov;
85 
86  bool registered;
87 
88  std::uint32_t data_length;
89 
90  // The image data for the depth stream (use metadata to understand the content).
91  // This pointer is only valid until the next update().
92  std::int16_t *data;
93 
94  astra_image_metadata_t metadata;
95  };
96 
97  struct Body
98  {
99  astra_floor_info_t *floor_info;
100  astra_bodymask_t body_mask;
101  astra_body_list_t body_list;
102  };
103 
105  {
106  std::uint32_t data_length;
107 
108  // The pixel data for the colorized body stream.
109  // This pointer is only valid until the next update().
110  astra_rgba_pixel_t *data;
111 
112  astra_image_metadata_t metadata;
113  };
114 
115  struct Hand
116  {
117 
118  };
119 
120  struct MaskedColor
121  {
122  std::uint32_t data_length;
123 
124  // The pixel data for the masked color stream.
125  // This pointer is only valid until the next update().
126  astra_rgba_pixel_t *data;
127 
128  astra_image_metadata_t metadata;
129  };
130 
131  struct Point
132  {
133  std::uint32_t data_length;
134  astra_vector3f_t *data;
135  };
136 
140  boost::optional<Color> color;
141 
145  boost::optional<Ir> ir;
146 
150  boost::optional<Depth> depth;
151 
155  boost::optional<Body> body;
156 
160  boost::optional<ColorizedBody> colorized_body;
161 
165  boost::optional<Hand> hand;
166 
170  boost::optional<MaskedColor> masked_color;
171 
175  boost::optional<Point> point;
176  };
177 
179  {
180  typedef std::function<void (const Frame &frame)> OnFrame;
181 
182  struct ColorStream
183  {
184  typedef Parameter<bool> Running;
185  typedef Parameter<bool> Mirrored;
186 
188 
189  Running running;
190 
194  boost::optional<Mirrored> mirrored;
195 
199  boost::optional<Mode> mode;
200  };
201 
202  struct IrStream
203  {
204  typedef Parameter<bool> Running;
205  typedef Parameter<bool> Mirrored;
206 
208 
211 
212  Running running;
213 
217  boost::optional<Mirrored> mirrored;
218 
222  boost::optional<Mode> mode;
223 
224  boost::optional<Gain> gain;
225  boost::optional<Exposure> exposure;
226 
227  };
228 
229  struct DepthStream
230  {
231  typedef Parameter<bool> Running;
232  typedef Parameter<bool> Mirrored;
233 
235 
237  typedef Parameter<int> D2CMode;
238 
239  Running running;
240 
244  boost::optional<Mirrored> mirrored;
245 
249  boost::optional<Mode> mode;
250 
254  boost::optional<Registration> registration;
255 
256 
257  boost::optional<D2CMode> d2c_mode;
258 
259  };
260 
261  struct BodyStream
262  {
263  typedef Parameter<bool> Running;
268 
272  boost::optional<std::string> license;
273 
274  Running running;
275 
276  boost::optional<BodyOrientation> body_orientation;
277  boost::optional<SkeletonOptimization> skeleton_optimization;
278  boost::optional<SkeletonProfile> skeleton_profile;
279  boost::optional<BodyFeatures> default_body_features;
280  };
281 
283  {
284  typedef Parameter<bool> Running;
285  typedef Parameter<bool> Mirrored;
286 
287  Running running;
288  };
289 
290  struct HandStream
291  {
292  typedef Parameter<bool> Running;
293  Running running;
294  };
295 
297  {
298  typedef Parameter<bool> Running;
299  typedef Parameter<bool> Mirrored;
300 
301  Running running;
302  };
303 
304  struct PointStream
305  {
306  typedef Parameter<bool> Running;
307  Running running;
308  };
309 
310  boost::optional<std::string> uri;
311  OnFrame on_frame;
312 
313 
318  boost::optional<ColorStream> color_stream;
319 
324  boost::optional<IrStream> ir_stream;
325 
330  boost::optional<DepthStream> depth_stream;
331 
336  boost::optional<BodyStream> body_stream;
337 
342  boost::optional<ColorizedBodyStream> colorized_body_stream;
343 
348  boost::optional<HandStream> hand_stream;
349 
354  boost::optional<MaskedColorStream> masked_color_stream;
355 
360  boost::optional<PointStream> point_stream;
361  };
362 
368  static Ptr open(const Configuration &configuration);
369 
373  void update();
374 
378  inline const Configuration &getConfiguration() const noexcept
379  {
380  return configuration_;
381  }
382 
386  inline Configuration &getConfiguration() noexcept
387  {
388  return configuration_;
389  }
390 
394  orbbec_camera_params getCameraParameters() const;
395 
399  boost::optional<std::string> getSerialNumber() const;
400 
404  boost::optional<std::uint32_t> getChipId() const;
405 
409  boost::optional<astra_usb_info_t> getColorUsbInfo() const;
410 
414  boost::optional<astra_usb_info_t> getDepthUsbInfo() const;
415 
419  boost::optional<astra_usb_info_t> getIrUsbInfo() const;
420 
426  boost::optional<std::vector<ImageStreamMode>> getColorImageStreamModes() const;
427 
433  boost::optional<std::vector<ImageStreamMode>> getDepthImageStreamModes() const;
434 
440  boost::optional<std::vector<ImageStreamMode>> getIrImageStreamModes() const;
441 
442  private:
443  Device(const Configuration &configuration);
444 
445  bool onStreamStartedChange(astra_streamconnection_t stream, const bool &started, const bool &started_prev);
446  bool onDepthRegistrationChange(astra_depthstream_t stream, const bool &registration, const bool &prev_registration);
447  bool onDepthD2CModeChange(astra_depthstream_t stream, const int &d2c_mode, const bool &prev_d2c_mode);
448  bool onBodyOrientationChange(astra_bodystream_t body_stream, const astra_body_orientation_t &orientation, const astra_skeleton_optimization_t &prev_orientation);
449  bool onBodySkeletonOptimizationChange(astra_bodystream_t body_stream, const astra_skeleton_optimization_t &optimization, const astra_skeleton_optimization_t &prev_optimization);
450  bool onBodySkeletonProfileChange(astra_bodystream_t body_stream, const astra_skeleton_profile_t &profile, const astra_skeleton_profile_t &prev_profile);
451  bool onModeChange(astra_streamconnection_t stream, const ImageStreamMode &mode, const ImageStreamMode &prev_mode);
452  bool onMirroredChange(astra_streamconnection_t stream, const bool &mirrored, const bool &prev_mirrored);
453 
454  std::vector<ImageStreamMode> getImageStreamModes(astra_streamconnection_t stream) const;
455 
456  Configuration configuration_;
457 
458  astra_streamsetconnection_t stream_set_;
459  astra_reader_t reader_;
460 
461  boost::optional<astra_colorstream_t> color_stream_;
462  boost::optional<astra_infraredstream_t> ir_stream_;
463  boost::optional<astra_depthstream_t> depth_stream_;
464  boost::optional<astra_bodystream_t> body_stream_;
465  boost::optional<astra_colorizedbodystream_t> colorized_body_stream_;
466  boost::optional<astra_handstream_t> hand_stream_;
467  boost::optional<astra_maskedcolorstream_t> masked_color_stream_;
468  boost::optional<astra_pointstream_t> point_stream_;
469  };
470 }
471 
472 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::ColorStream &value);
473 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::IrStream &value);
474 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::DepthStream &value);
475 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::BodyStream &value);
476 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::ColorizedBodyStream &value);
477 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration::MaskedColorStream &value);
478 std::ostream &operator <<(std::ostream &o, const astra_ros::Device::Configuration &value);
479 
480 #endif
astra_ros::Device::Configuration::MaskedColorStream
Definition: Device.hpp:297
astra_ros::Device::Frame::Depth
Definition: Device.hpp:82
astra_ros::Device::getConfiguration
const Configuration & getConfiguration() const noexcept
Definition: Device.hpp:378
astra_ros::Device::Configuration::depth_stream
boost::optional< DepthStream > depth_stream
Definition: Device.hpp:330
astra_ros::Device::getChipId
boost::optional< std::uint32_t > getChipId() const
astra_ros::Device::Configuration::ColorStream::mirrored
boost::optional< Mirrored > mirrored
Definition: Device.hpp:194
astra_ros::Device::Frame::MaskedColor
Definition: Device.hpp:121
astra_ros::Device::Configuration::PointStream
Definition: Device.hpp:305
astra_ros::Device::Configuration::hand_stream
boost::optional< HandStream > hand_stream
Definition: Device.hpp:348
astra_ros::Device::Configuration::IrStream
Definition: Device.hpp:203
astra_ros::Device::Frame::Color
Definition: Device.hpp:57
astra_ros::Device::Frame::masked_color
boost::optional< MaskedColor > masked_color
Definition: Device.hpp:170
astra_ros::Device::ImageStreamMode::fps
boost::optional< std::uint8_t > fps
Definition: Device.hpp:51
astra_ros::Device::getIrImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getIrImageStreamModes() const
astra_ros::Device::Frame::point
boost::optional< Point > point
Definition: Device.hpp:175
astra_ros::Device::Frame::Hand
Definition: Device.hpp:116
astra_ros::Device::Configuration::DepthStream::mirrored
boost::optional< Mirrored > mirrored
Definition: Device.hpp:244
astra_ros::Device::Frame::ColorizedBody
Definition: Device.hpp:105
astra_ros::Device::Configuration::DepthStream::mode
boost::optional< Mode > mode
Definition: Device.hpp:249
astra_ros::Device::Configuration::HandStream
Definition: Device.hpp:291
astra_ros::Device::Frame::ir
boost::optional< Ir > ir
Definition: Device.hpp:145
astra_ros::Parameter< bool >
astra_ros::Device::Configuration::DepthStream::registration
boost::optional< Registration > registration
Definition: Device.hpp:254
astra_ros::Device::update
void update()
astra_ros::Device::Frame::colorized_body
boost::optional< ColorizedBody > colorized_body
Definition: Device.hpp:160
astra_ros::Device::ImageStreamMode::height
boost::optional< std::uint32_t > height
Definition: Device.hpp:41
astra_ros::Device::Configuration::BodyStream::license
boost::optional< std::string > license
Definition: Device.hpp:272
astra_ros::Device::Configuration::colorized_body_stream
boost::optional< ColorizedBodyStream > colorized_body_stream
Definition: Device.hpp:342
astra_ros::Device::Frame::depth
boost::optional< Depth > depth
Definition: Device.hpp:150
astra_ros::Device::Configuration::IrStream::mirrored
boost::optional< Mirrored > mirrored
Definition: Device.hpp:217
astra_ros::Device::getColorImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getColorImageStreamModes() const
astra_ros::Device::Frame::Ir
Definition: Device.hpp:68
astra_ros::Device::ImageStreamMode
Represents a potential stream configuration.
Definition: Device.hpp:32
astra_ros::Device::Frame::Body
Definition: Device.hpp:98
astra_ros::Device::Configuration::ColorizedBodyStream
Definition: Device.hpp:283
astra_ros::Device::Configuration::DepthStream
Definition: Device.hpp:230
astra_ros::Device::Frame::hand
boost::optional< Hand > hand
Definition: Device.hpp:165
astra_ros::Device::Configuration::body_stream
boost::optional< BodyStream > body_stream
Definition: Device.hpp:336
astra_ros::Device::Configuration
Definition: Device.hpp:179
astra_ros::Device::getDepthImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getDepthImageStreamModes() const
astra_ros::Device::Configuration::ColorStream::mode
boost::optional< Mode > mode
Definition: Device.hpp:199
astra_ros::Device::open
static Ptr open(const Configuration &configuration)
astra_ros::Device::getConfiguration
Configuration & getConfiguration() noexcept
Definition: Device.hpp:386
astra_ros::Device::getCameraParameters
orbbec_camera_params getCameraParameters() const
astra_ros::Device::Configuration::masked_color_stream
boost::optional< MaskedColorStream > masked_color_stream
Definition: Device.hpp:354
astra_ros::Device::ImageStreamMode::width
boost::optional< std::uint32_t > width
Definition: Device.hpp:36
astra_ros::Device::Configuration::IrStream::mode
boost::optional< Mode > mode
Definition: Device.hpp:222
astra_ros::Device::Configuration::ir_stream
boost::optional< IrStream > ir_stream
Definition: Device.hpp:324
astra_ros::Device::Configuration::BodyStream
Definition: Device.hpp:262
astra_ros::Device::getColorUsbInfo
boost::optional< astra_usb_info_t > getColorUsbInfo() const
astra_ros::Device::Frame
Definition: Device.hpp:55
astra_ros::Device::Configuration::point_stream
boost::optional< PointStream > point_stream
Definition: Device.hpp:360
astra_ros::Device::getIrUsbInfo
boost::optional< astra_usb_info_t > getIrUsbInfo() const
astra_ros::Device::Frame::body
boost::optional< Body > body
Definition: Device.hpp:155
astra_ros::Device::getSerialNumber
boost::optional< std::string > getSerialNumber() const
astra_ros::Device::Configuration::color_stream
boost::optional< ColorStream > color_stream
Definition: Device.hpp:318
astra_ros::Device::getDepthUsbInfo
boost::optional< astra_usb_info_t > getDepthUsbInfo() const
astra_ros::Device::ImageStreamMode::pixel_format
boost::optional< astra_pixel_format_t > pixel_format
Definition: Device.hpp:46
astra_ros::Device::Frame::Point
Definition: Device.hpp:132
astra_ros::Device::Configuration::ColorStream
Definition: Device.hpp:183
astra_ros::Device
An agnostic C++ wrapper for the C Astra SDK. This object is wrapped by RosDevice.
Definition: Device.hpp:22
astra_ros::Device::Frame::color
boost::optional< Color > color
Definition: Device.hpp:140