Device.cpp
Go to the documentation of this file.
1 #include "astra_ros/Device.hpp"
3 
4 #include "util.hpp"
5 
6 
7 #include <iostream>
8 #include <sstream>
9 
10 namespace
11 {
12  const static char *const DEFAULT_URI = "device/default";
13 
14  // Wrapper for astra_*_is_available functions
15  // to make it slightly more convenient to use.
16  template<typename F, typename T>
17  bool is_available(F &&f, const T &stream)
18  {
19  bool is_available = false;
20  return f(stream, &is_available) == ASTRA_STATUS_SUCCESS && is_available;
21  }
22 
23  bool initialized = false;
24 
25  static void initialize()
26  {
27  if (initialized) return;
28  astra_initialize();
29  initialized = false;
30  }
31 }
32 
33 using namespace astra_ros;
34 
35 Device::Ptr Device::open(const Configuration &configuration)
36 {
37  return std::shared_ptr<Device>(new Device(configuration));
38 }
39 
41 {
42  // Try to fetch a new frame (this invalidates all existing frame pointers)
43  astra_status_t status = astra_update();
44  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
45 
46  bool new_frame = false;
47  astra_reader_has_new_frame(reader_, &new_frame);
48  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
49 
50  // If we don't have a new frame to process, we're done
51  if (!new_frame) return;
52 
53 
54 
55  astra_reader_frame_t astra_frame;
56 
57  status = astra_reader_open_frame(reader_, 3, &astra_frame);
58  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
59 
60  Frame frame;
61 
62  // Color Stream
63  if (color_stream_ && is_available(&astra_colorstream_is_available, *color_stream_))
64  {
65  astra_colorframe_t color_frame;
66  status = astra_frame_get_colorframe(astra_frame, &color_frame);
67  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
68 
69  Frame::Color color;
70  status = astra_colorframe_get_data_ptr(color_frame, &color.data, &color.data_length);
71  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
72 
73  astra_image_metadata_t metadata;
74  status = astra_colorframe_get_metadata(color_frame, &metadata);
75  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
76 
77  color.metadata = metadata;
78 
79  frame.color = color;
80  }
81 
82  // IR Stream
83  if (ir_stream_ && is_available(&astra_infraredstream_is_available, *ir_stream_))
84  {
85  astra_colorframe_t ir_frame;
86  status = astra_frame_get_infraredframe(astra_frame, &ir_frame);
87  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
88 
89  Frame::Ir ir;
90  status = astra_infraredframe_get_data_ptr(ir_frame, &ir.data, &ir.data_length);
91  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
92 
93  astra_image_metadata_t metadata;
94  status = astra_infraredframe_get_metadata(ir_frame, &metadata);
95  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
96 
97  ir.metadata = metadata;
98 
99  frame.ir = ir;
100  }
101 
102  // Depth Stream
103  if (depth_stream_ && is_available(&astra_depthstream_is_available, *depth_stream_))
104  {
105  astra_depthframe_t depth_frame;
106  status = astra_frame_get_depthframe(astra_frame, &depth_frame);
107  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
108 
109  Frame::Depth depth;
110  status = astra_depthframe_get_data_ptr(depth_frame, &depth.data, &depth.data_length);
111  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
112 
113  astra_image_metadata_t metadata;
114  status = astra_depthframe_get_metadata(depth_frame, &metadata);
115  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
116 
117  depth.metadata = metadata;
118 
119  status = astra_depthstream_get_hfov(*depth_stream_, &depth.horizontal_fov);
120  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
121 
122  status = astra_depthstream_get_vfov(*depth_stream_, &depth.vertical_fov);
123  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
124 
125  frame.depth = depth;
126  }
127 
128  // Body Stream
129  if (body_stream_)
130  {
131  astra_bodyframe_t body_frame;
132  status = astra_frame_get_bodyframe(astra_frame, &body_frame);
133  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
134 
135  Frame::Body body;
136  status = astra_bodyframe_body_list(body_frame, &body.body_list);
137  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
138 
139  status = astra_bodyframe_bodymask(body_frame, &body.body_mask);
140  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
141 
142  status = astra_bodyframe_floor_info_ptr(body_frame, &body.floor_info);
143  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
144 
145  frame.body = body;
146  }
147 
148  // Colorized Body Stream
149  if (colorized_body_stream_ && is_available(&astra_colorizedbodystream_is_available, *colorized_body_stream_))
150  {
151  astra_colorizedbodyframe_t colorized_body_frame;
152  status = astra_frame_get_colorizedbodyframe(astra_frame, &colorized_body_frame);
153  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
154 
155  Frame::ColorizedBody colorized_body;
156  status = astra_colorizedbodyframe_get_data_ptr(colorized_body_frame, &colorized_body.data, &colorized_body.data_length);
157  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
158 
159  astra_image_metadata_t metadata;
160  status = astra_colorizedbodyframe_get_metadata(colorized_body_frame, &metadata);
161  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
162 
163  colorized_body.metadata = metadata;
164 
165  frame.colorized_body = colorized_body;
166  }
167 
168  // Hand Stream
169  if (hand_stream_ && is_available(&astra_handstream_is_available, *hand_stream_))
170  {
171  astra_handframe_t hand_frame;
172  status = astra_frame_get_handframe(astra_frame, &hand_frame);
173  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
174 
175  Frame::Hand hand;
176  frame.hand = hand;
177  }
178 
179  // Masked Color Stream
180  if (masked_color_stream_ && is_available(&astra_maskedcolorstream_is_available, *masked_color_stream_))
181  {
182  astra_maskedcolorframe_t masked_color_frame;
183  status = astra_frame_get_maskedcolorframe(astra_frame, &masked_color_frame);
184  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
185 
186  Frame::MaskedColor masked_color;
187  status = astra_maskedcolorframe_get_data_ptr(masked_color_frame, &masked_color.data, &masked_color.data_length);
188  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
189 
190  astra_image_metadata_t metadata;
191  status = astra_maskedcolorframe_get_metadata(masked_color_frame, &metadata);
192  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
193  masked_color.metadata = metadata;
194 
195  frame.masked_color = masked_color;
196  }
197 
198  // Point Stream
199  if (point_stream_ && is_available(&astra_pointstream_is_available, *point_stream_))
200  {
201  astra_pointframe_t point_frame;
202  status = astra_frame_get_pointframe(astra_frame, &point_frame);
203  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
204 
205  Frame::Point point;
206  status = astra_pointframe_get_data_ptr(point_frame, &point.data, &point.data_length);
207  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
208  frame.point = point;
209  }
210 
211  configuration_.on_frame(frame);
212 
213  status = astra_reader_close_frame(&astra_frame);
214  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
215 }
216 
217 Device::Device(const Configuration &configuration)
218  : configuration_(configuration)
219 {
220  const char *const uri = configuration_.uri ? configuration_.uri->c_str() : DEFAULT_URI;
221 
222 
223 
224 
225  initialize();
226 
227  // The license must be registered after initialize()
229  {
230  const auto &license = configuration_.body_stream->license;
231  if (license)
232  {
233  std::cout << "Configured license" << std::endl;
234  orbbec_body_tracking_set_license(license->c_str());
235  }
236  }
237 
238  astra_status_t status = astra_streamset_open(uri, &stream_set_);
239  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
240 
241  status = astra_reader_create(stream_set_, &reader_);
242  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
243 
244  // This function is used to check the return values of all astra functions
245  // below. If there is an error, we perform appropriate cleanup before throwing.
246  const auto check_status = [this](const astra_status_t status) {
247  if (status == ASTRA_STATUS_SUCCESS) return;
248 
249  color_stream_ = boost::none;
250  ir_stream_ = boost::none;
251  depth_stream_ = boost::none;
252  body_stream_ = boost::none;
253  colorized_body_stream_ = boost::none;
254 
255  astra_reader_destroy(&reader_);
256  astra_streamset_close(&stream_set_);
257 
258  throw Exception(status);
259  };
260 
261  // Color Stream
263  {
264  astra_colorstream_t stream;
265  check_status(astra_reader_get_colorstream(reader_, &stream));
266  color_stream_ = stream;
267 
268  // Configure the mode parameter
269  auto &mode = configuration_.color_stream->mode;
270  if (mode)
271  {
272  mode->bindOnChangeHandler(&Device::onModeChange, this, stream);
273  Device::onModeChange(stream, **mode, ImageStreamMode());
274  }
275 
276  // Configure the mirrored parameter
277  auto &mirrored = configuration_.color_stream->mirrored;
278  if (mirrored)
279  {
280  mirrored->bindOnChangeHandler(&Device::onMirroredChange, this, stream);
281  astra_imagestream_set_mirroring(stream, **mirrored);
282  }
283 
284  // Configure the running parameter
285  auto &running = configuration_.color_stream->running;
286  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
287  if (*running)
288  {
289  check_status(astra_stream_start(stream));
290  }
291  }
292 
293  // IR Stream
295  {
296  astra_infraredstream_t stream;
297  check_status(astra_reader_get_infraredstream(reader_, &stream));
298  ir_stream_ = stream;
299 
300  // Configure the mode parameter
301  auto &mode = configuration_.ir_stream->mode;
302  if (mode)
303  {
304  mode->bindOnChangeHandler(&Device::onModeChange, this, stream);
305  Device::onModeChange(stream, **mode, ImageStreamMode());
306  }
307 
308  // Configure the mirrored parameter
309  auto &mirrored = configuration_.ir_stream->mirrored;
310  if (mirrored)
311  {
312  mirrored->bindOnChangeHandler(&Device::onMirroredChange, this, stream);
313  astra_imagestream_set_mirroring(stream, **mirrored);
314  }
315 
316  // Configure the running parameter
317  auto &running = configuration_.ir_stream->running;
318  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
319  if (*running)
320  {
321  check_status(astra_stream_start(stream));
322  }
323  }
324 
325  // Depth Stream
327  {
328  astra_depthstream_t stream;
329  check_status(astra_reader_get_depthstream(reader_, &stream));
330  depth_stream_ = stream;
331 
332  // Configure the mode parameter
333  auto &mode = configuration_.depth_stream->mode;
334  if (mode)
335  {
336  mode->bindOnChangeHandler(&Device::onModeChange, this, stream);
337  Device::onModeChange(stream, **mode, ImageStreamMode());
338  }
339 
340  // Configure the mirrored parameter
341  auto &mirrored = configuration_.depth_stream->mirrored;
342  if (mirrored)
343  {
344  mirrored->bindOnChangeHandler(&Device::onMirroredChange, this, stream);
345  astra_imagestream_set_mirroring(stream, **mirrored);
346  }
347 
348  // Configure the d2c mode parameter
349  auto &d2c_mode = configuration_.depth_stream->d2c_mode;
350  if (d2c_mode)
351  {
352  d2c_mode->bindOnChangeHandler(&Device::onDepthD2CModeChange, this, stream);
353  astra_depthstream_set_d2c_resolution(stream, **d2c_mode);
354  }
355 
356  // Configure the registration parameter
357  auto &registration = configuration_.depth_stream->registration;
358  if (registration)
359  {
360  registration->bindOnChangeHandler(&Device::onDepthRegistrationChange, this, stream);
361  astra_depthstream_set_registration(stream, **registration);
362  }
363 
364  // Configure the running parameter
365  auto &running = configuration_.depth_stream->running;
366  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
367  if (*running)
368  {
369  check_status(astra_stream_start(stream));
370  }
371  }
372 
373  // Body Stream
375  {
376  // Open the stream
377  astra_bodystream_t stream;
378  check_status(astra_reader_get_bodystream(reader_, &stream));
379  body_stream_ = stream;
380 
381  // Configure body orientation parameter
382  /*auto &body_orientation = configuration_.body_stream->body_orientation;
383  if (body_orientation)
384  {
385  body_orientation->bindOnChangeHandler(&Device::onBodyOrientationChange, this, stream);
386  check_status(astra_bodystream_set_body_orientation(stream, **body_orientation));
387  }
388 
389  // Configure skeleton optimization parameter
390  auto &skeleton_optimization = configuration_.body_stream->skeleton_optimization;
391  if (skeleton_optimization)
392  {
393  skeleton_optimization->bindOnChangeHandler(&Device::onBodySkeletonOptimizationChange, this, stream);
394  check_status(astra_bodystream_set_skeleton_optimization(stream, **skeleton_optimization));
395  }
396 
397  // Configure skeleton profile parameter
398  auto &skeleton_profile = configuration_.body_stream->skeleton_profile;
399  if (skeleton_profile)
400  {
401  skeleton_profile->bindOnChangeHandler(&Device::onBodySkeletonOptimizationChange, this, stream);
402  check_status(astra_bodystream_set_skeleton_optimization(stream, **skeleton_profile));
403  }*/
404 
405  // Configure the running parameter
406  auto &running = configuration_.body_stream->running;
407  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
408  if (*running)
409  {
410  check_status(astra_stream_start(stream));
411  }
412  }
413 
414  // Colorized Body Stream
416  {
417  astra_colorizedbodystream_t stream;
418  check_status(astra_reader_get_colorizedbodystream(reader_, &stream));
419  colorized_body_stream_ = stream;
420 
421  // Configure the running parameter
422  auto &running = configuration_.colorized_body_stream->running;
423  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
424  if (*running)
425  {
426  check_status(astra_stream_start(stream));
427  }
428  }
429 
430  // Hand Stream
432  {
433  astra_handstream_t stream;
434  check_status(astra_reader_get_handstream(reader_, &stream));
435  hand_stream_ = stream;
436 
437  // Configure the running parameter
438  auto &running = configuration_.hand_stream->running;
439  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
440  if (*running)
441  {
442  check_status(astra_stream_start(stream));
443  }
444 
445 
446  }
447 
448  // Point Stream
450  {
451  astra_pointstream_t stream;
452  check_status(astra_reader_get_pointstream(reader_, &stream));
453  point_stream_ = stream;
454 
455  // Configure the running parameter
456  auto &running = configuration_.point_stream->running;
457  running.bindOnChangeHandler(&Device::onStreamStartedChange, this, stream);
458  if (*running)
459  {
460  check_status(astra_stream_start(stream));
461  }
462  }
463 }
464 
465 bool Device::onStreamStartedChange(astra_streamconnection_t stream, const bool &started, const bool &started_prev)
466 {
467  // Detect how the state changed
468  const bool should_start = started && !started_prev;
469  const bool should_stop = !started && started_prev;
470 
471  if (should_start)
472  {
473  const astra_status_t status = astra_stream_start(stream);
474  if (status != ASTRA_STATUS_SUCCESS)
475  {
476  std::cerr << "astra_stream_start failed (status: " << statusToString(status) << ")" << std::endl;
477  }
478  return status == ASTRA_STATUS_SUCCESS;
479  }
480 
481  if (should_stop)
482  {
483  const astra_status_t status = astra_stream_stop(stream);
484  if (status != ASTRA_STATUS_SUCCESS)
485  {
486  std::cerr << "astra_stream_stop failed (status: " << statusToString(status) << ")" << std::endl;
487  }
488  return status == ASTRA_STATUS_SUCCESS;
489  }
490 
491  // We should never reach this point
492  return false;
493 }
494 
495 bool Device::onDepthRegistrationChange(astra_depthstream_t stream, const bool &registration, const bool &prev_registration)
496 {
497  const astra_status_t status = astra_depthstream_set_registration(stream, registration);
498  if (status != ASTRA_STATUS_SUCCESS)
499  {
500  std::cerr << "astra_depthstream_set_registration failed (status: " << statusToString(status) << ")" << std::endl;
501  }
502 
503  return status == ASTRA_STATUS_SUCCESS;
504 }
505 
506 bool Device::onDepthD2CModeChange(astra_depthstream_t stream, const int &d2c_mode, const bool &prev_d2c_mode)
507 {
508  const astra_status_t status = astra_depthstream_set_d2c_resolution(stream, d2c_mode);
509  if (status != ASTRA_STATUS_SUCCESS)
510  {
511  std::cerr << "astra_depthstream_set_d2c_resolution failed (status: " << statusToString(status) << ")" << std::endl;
512  }
513 
514  return status == ASTRA_STATUS_SUCCESS;
515 }
516 
517 
518 bool Device::onBodySkeletonOptimizationChange(astra_bodystream_t body_stream, const astra_skeleton_optimization_t &optimization, const astra_skeleton_optimization_t &prev_optimization)
519 {
520  const astra_status_t status = astra_bodystream_set_skeleton_optimization(body_stream, optimization);
521  if (status != ASTRA_STATUS_SUCCESS)
522  {
523  std::cerr << "astra_bodystream_set_skeleton_optimization failed (status: " << statusToString(status) << ")" << std::endl;
524  }
525 
526  return status == ASTRA_STATUS_SUCCESS;
527 }
528 
529 bool Device::onBodyOrientationChange(astra_bodystream_t body_stream, const astra_body_orientation_t &orientation, const astra_body_orientation_t &prev_orientation)
530 {
531  const astra_status_t status = astra_bodystream_set_body_orientation(body_stream, orientation);
532  if (status != ASTRA_STATUS_SUCCESS)
533  {
534  std::cerr << "astra_bodystream_set_body_orientation failed (status: " << statusToString(status) << ")" << std::endl;
535  }
536 
537  return status == ASTRA_STATUS_SUCCESS;
538 }
539 
540 bool Device::onBodySkeletonProfileChange(astra_bodystream_t body_stream, const astra_skeleton_profile_t &profile, const astra_skeleton_profile_t &prev_profile)
541 {
542  const astra_status_t status = astra_bodystream_set_skeleton_profile(body_stream, profile);
543  if (status != ASTRA_STATUS_SUCCESS)
544  {
545  std::cerr << "astra_bodystream_set_skeleton_profile failed (status: " << statusToString(status) << ")" << std::endl;
546  }
547 
548  return status == ASTRA_STATUS_SUCCESS;
549 }
550 
551 bool Device::onMirroredChange(astra_streamconnection_t stream, const bool &mirrored, const bool &prev_mirrored)
552 {
553  const astra_status_t status = astra_imagestream_set_mirroring(stream, mirrored);
554  if (status != ASTRA_STATUS_SUCCESS)
555  {
556  std::cerr << "astra_imagestream_set_mirroring failed (status: " << statusToString(status) << ")" << std::endl;
557  }
558 
559  return status == ASTRA_STATUS_SUCCESS;
560 }
561 
562 
563 bool Device::onModeChange(astra_streamconnection_t stream, const ImageStreamMode &mode, const ImageStreamMode &prev_mode)
564 {
565  astra_result_token_t token;
566  std::uint32_t count = 0;
567  astra_status_t status = astra_imagestream_request_modes(stream, &token, &count);
568  if (status != ASTRA_STATUS_SUCCESS)
569  {
570  std::cerr << "astra_imagestream_request_modes failed (status: " << statusToString(status) << ")" << std::endl;
571  return false;
572  }
573 
574  astra_imagestream_mode_t *const modes = new astra_imagestream_mode_t[count];
575  status = astra_imagestream_get_modes_result(stream, token, modes, count);
576  if (status != ASTRA_STATUS_SUCCESS)
577  {
578  std::cerr << "astra_imagestream_get_modes_result failed (status: " << statusToString(status) << ")" << std::endl;
579  delete[] modes;
580  return false;
581  }
582 
583  const astra_imagestream_mode_t *match = nullptr;
584  for (std::uint32_t i = 0; i < count; ++i)
585  {
586  if (
587  (!mode.fps || modes[i].fps == *mode.fps) &&
588  (!mode.width || modes[i].width == *mode.width) &&
589  (!mode.height || modes[i].height == *mode.height) &&
590  (!mode.pixel_format || modes[i].pixelFormat == *mode.pixel_format)
591  )
592  {
593  match = &modes[i];
594  break;
595  }
596  }
597 
598  if (!match)
599  {
600  // TODO: Maybe list compatible modes here?
601  std::cerr << "Failed to find compatible mode for stream" << std::endl;
602  delete[] modes;
603  return false;
604  }
605 
606  astra_imagestream_set_mode(stream, match);
607 
608  delete[] modes;
609  return true;
610 }
611 
612 orbbec_camera_params Device::getCameraParameters() const
613 {
614  orbbec_camera_params ret;
615  const astra_status_t status = astra_get_orbbec_camera_params(stream_set_, &ret);
616  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
617  return ret;
618 }
619 
620 
621 boost::optional<std::string> Device::getSerialNumber() const
622 {
623  if (!depth_stream_) return boost::none;
624 
625  // FIXME: What is the correct length here?
626  char buffer[32];
627  const astra_status_t status = astra_depthstream_get_serialnumber(*depth_stream_, buffer, sizeof(buffer));
628  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
629 
630  return std::string(buffer, buffer + sizeof(buffer));
631 }
632 
633 boost::optional<std::uint32_t> Device::getChipId() const
634 {
635  if (!depth_stream_) return boost::none;
636 
637  std::uint32_t chip_id;
638  const astra_status_t status = astra_depthstream_get_chip_id(*depth_stream_, &chip_id);
639  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
640 
641  return chip_id;
642 }
643 
644 boost::optional<astra_usb_info_t> Device::getColorUsbInfo() const
645 {
646  if (!color_stream_) return boost::none;
647 
648  astra_usb_info_t ret;
649  const astra_status_t status = astra_colorstream_get_usb_info(*color_stream_, &ret);
650  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
651  return ret;
652 }
653 
654 boost::optional<astra_usb_info_t> Device::getDepthUsbInfo() const
655 {
656  if (!depth_stream_) return boost::none;
657 
658  astra_usb_info_t ret;
659  const astra_status_t status = astra_depthstream_get_usb_info(*depth_stream_, &ret);
660  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
661  return ret;
662 }
663 
664 boost::optional<astra_usb_info_t> Device::getIrUsbInfo() const
665 {
666  if (!ir_stream_) return boost::none;
667 
668  astra_usb_info_t ret;
669  const astra_status_t status = astra_infraredstream_get_usb_info(*ir_stream_, &ret);
670  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
671  return ret;
672 }
673 
674 boost::optional<std::vector<Device::ImageStreamMode>> Device::getColorImageStreamModes() const
675 {
676  if (!color_stream_) return boost::none;
678 }
679 
680 boost::optional<std::vector<Device::ImageStreamMode>> Device::getDepthImageStreamModes() const
681 {
682  if (!depth_stream_) return boost::none;
684 }
685 
686 boost::optional<std::vector<Device::ImageStreamMode>> Device::getIrImageStreamModes() const
687 {
688  if (!ir_stream_) return boost::none;
690 }
691 
692 std::vector<Device::ImageStreamMode> Device::getImageStreamModes(astra_streamconnection_t stream) const
693 {
694  astra_result_token_t token;
695  std::uint32_t count = 0;
696  astra_status_t status = astra_imagestream_request_modes(stream, &token, &count);
697  if (status != ASTRA_STATUS_SUCCESS) throw Exception(status);
698 
699  astra_imagestream_mode_t *const modes = new astra_imagestream_mode_t[count];
700  status = astra_imagestream_get_modes_result(stream, token, modes, count);
701  if (status != ASTRA_STATUS_SUCCESS)
702  {
703  delete[] modes;
704  throw Exception(status);
705  }
706 
707  std::vector<ImageStreamMode> ret;
708  ret.reserve(count);
709  for (std::uint32_t i = 0; i < count; ++i)
710  {
711  const auto &mode = modes[i];
712  ret.push_back({
713  .width = mode.width,
714  .height = mode.height,
715  .pixel_format = mode.pixelFormat,
716  .fps = mode.fps
717  });
718  }
719 
720  return ret;
721 }
722 
723 
724 // Debugging helpers
725 namespace
726 {
727  template<typename T>
728  std::ostream &operator <<(std::ostream &o, const boost::optional<T> &value)
729  {
730  if (value)
731  {
732  return o << value.get();
733  }
734 
735  return o << "Not Present / Default";
736  }
737 
738  template<typename T>
739  std::string to_string(const T &t)
740  {
741  std::ostringstream o;
742  o << t;
743  return o.str();
744  }
745 
746  std::string indent(const std::string &str, const std::size_t spaces)
747  {
748  std::ostringstream o;
749  for (std::size_t i = 0; i < spaces; ++i) o << " ";
750  const std::string indention = o.str();
751 
752  std::ostringstream ret;
753  std::string::size_type last = 0;
754  for (std::string::size_type i = 0; i != std::string::npos; i = str.find("\n", i + 1))
755  {
756  ret << indention << str.substr(last, i - last);
757  last = i;
758  }
759 
760  return ret.str();
761  }
762 }
763 
764 std::ostream &operator <<(std::ostream &o, const Device::Configuration::ColorStream &value)
765 {
766 
767 }
768 
769 std::ostream &operator <<(std::ostream &o, const Device::Configuration::IrStream &value)
770 {
771 
772 }
773 
774 std::ostream &operator <<(std::ostream &o, const Device::Configuration::DepthStream &value)
775 {
776 
777 }
778 
779 std::ostream &operator <<(std::ostream &o, const Device::Configuration::BodyStream &value)
780 {
781 
782 }
783 
784 std::ostream &operator <<(std::ostream &o, const Device::Configuration::ColorizedBodyStream &value)
785 {
786 
787 }
788 
789 std::ostream &operator <<(std::ostream &o, const Device::Configuration::MaskedColorStream &value)
790 {
791 
792 }
793 
794 std::ostream &operator <<(std::ostream &o, const Device::Configuration &value)
795 {
796  o << "Device::Configuration {" << std::endl
797  << " URI: " << value.uri << std::endl
798  << " Color Stream: " << std::endl;
799  // << indent(to_string(value.color_stream), 4) << std::endl;
800  return o;
801 }
astra_ros::Device::Ptr
std::shared_ptr< Device > Ptr
Definition: Device.hpp:24
astra_ros::Device::Frame::MaskedColor::metadata
astra_image_metadata_t metadata
Definition: Device.hpp:128
astra_ros::Device::Configuration::MaskedColorStream
Definition: Device.hpp:308
astra_ros::Exception
Wraps a astra_status_t when an Astra SDK call fails.
Definition: Exception.hpp:14
astra_ros::Device::reader_
astra_reader_t reader_
Definition: Device.hpp:490
astra_ros::Device::Frame::Depth
Definition: Device.hpp:81
astra_ros::Device::getColorImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getColorImageStreamModes() const
Definition: Device.cpp:674
astra_ros::Device::Configuration::depth_stream
boost::optional< DepthStream > depth_stream
Definition: Device.hpp:342
astra_ros::Device::Frame::MaskedColor
Definition: Device.hpp:120
astra_ros::Device::getColorUsbInfo
boost::optional< astra_usb_info_t > getColorUsbInfo() const
Definition: Device.cpp:644
astra_ros::Device::Frame::ColorizedBody::data
astra_rgba_pixel_t * data
Definition: Device.hpp:110
astra_ros::Device::getImageStreamModes
std::vector< ImageStreamMode > getImageStreamModes(astra_streamconnection_t stream) const
Definition: Device.cpp:692
astra_ros::Device::getCameraParameters
orbbec_camera_params getCameraParameters() const
Definition: Device.cpp:612
astra_ros::Device::Frame::MaskedColor::data_length
std::uint32_t data_length
Definition: Device.hpp:122
astra_ros::Device::Frame::MaskedColor::data
astra_rgba_pixel_t * data
Definition: Device.hpp:126
astra_ros::Device::Frame::Color::metadata
astra_image_metadata_t metadata
Definition: Device.hpp:64
astra_ros::Device::update
void update()
Definition: Device.cpp:40
astra_ros::Device::getIrUsbInfo
boost::optional< astra_usb_info_t > getIrUsbInfo() const
Definition: Device.cpp:664
astra_ros::Device::Frame::Point::data_length
std::uint32_t data_length
Definition: Device.hpp:133
astra_ros::Device::Configuration::IrStream
Definition: Device.hpp:212
astra_ros::Device::Frame::Ir::data_length
std::uint32_t data_length
Definition: Device.hpp:72
astra_ros::Device::onModeChange
bool onModeChange(astra_streamconnection_t stream, const ImageStreamMode &mode, const ImageStreamMode &prev_mode)
Definition: Device.cpp:563
astra_ros::Device::Frame::Depth::horizontal_fov
float horizontal_fov
Definition: Device.hpp:83
astra_ros::Device::Frame::Color
Definition: Device.hpp:56
astra_ros::Device::Frame::masked_color
boost::optional< MaskedColor > masked_color
Definition: Device.hpp:170
astra_ros::Device::Frame::Depth::metadata
astra_image_metadata_t metadata
Definition: Device.hpp:94
astra_ros::Device::colorized_body_stream_
boost::optional< astra_colorizedbodystream_t > colorized_body_stream_
Definition: Device.hpp:496
astra_ros::statusToString
const std::string & statusToString(const astra_status_t status)
Definition: util.cpp:68
astra_ros::Device::onBodySkeletonOptimizationChange
bool onBodySkeletonOptimizationChange(astra_bodystream_t body_stream, const astra_skeleton_optimization_t &optimization, const astra_skeleton_optimization_t &prev_optimization)
Definition: Device.cpp:518
astra_ros::Device::ImageStreamMode::fps
boost::optional< std::uint8_t > fps
Definition: Device.hpp:51
astra_ros::Device::Frame::Body::floor_info
astra_floor_info_t * floor_info
Definition: Device.hpp:99
astra_ros::Device::Frame::point
boost::optional< Point > point
Definition: Device.hpp:175
astra_ros::Device::hand_stream_
boost::optional< astra_handstream_t > hand_stream_
Definition: Device.hpp:497
astra_ros::Device::Frame::Hand
Definition: Device.hpp:115
astra_ros::Device::Frame::ColorizedBody
Definition: Device.hpp:104
f
f
astra_ros::Device::open
static Ptr open(const Configuration &configuration)
Definition: Device.cpp:35
astra_ros::Device::onStreamStartedChange
bool onStreamStartedChange(astra_streamconnection_t stream, const bool &started, const bool &started_prev)
Definition: Device.cpp:465
astra_ros::Device::Frame::Depth::vertical_fov
float vertical_fov
Definition: Device.hpp:84
astra_ros::Device::Frame::ColorizedBody::data_length
std::uint32_t data_length
Definition: Device.hpp:106
astra_ros::Device::getIrImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getIrImageStreamModes() const
Definition: Device.cpp:686
astra_ros::Device::Frame::Depth::data_length
std::uint32_t data_length
Definition: Device.hpp:88
astra_ros::Device::Frame::Point::data
astra_vector3f_t * data
Definition: Device.hpp:134
astra_ros::Device::onDepthD2CModeChange
bool onDepthD2CModeChange(astra_depthstream_t stream, const int &d2c_mode, const bool &prev_d2c_mode)
Definition: Device.cpp:506
Device.hpp
astra_ros::Device::Frame::ir
boost::optional< Ir > ir
Definition: Device.hpp:145
astra_ros::Device::Frame::Color::data_length
std::uint32_t data_length
Definition: Device.hpp:58
astra_ros::Device::Frame::ColorizedBody::metadata
astra_image_metadata_t metadata
Definition: Device.hpp:112
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
operator<<
std::ostream & operator<<(std::ostream &o, const Device::Configuration::ColorStream &value)
Definition: Device.cpp:764
astra_ros::Device::Configuration::hand_stream
boost::optional< HandStream > hand_stream
Definition: Device.hpp:364
astra_ros::Device::Frame::depth
boost::optional< Depth > depth
Definition: Device.hpp:150
astra_ros::Device::configuration_
Configuration configuration_
Definition: Device.hpp:487
astra_ros::Device::onDepthRegistrationChange
bool onDepthRegistrationChange(astra_depthstream_t stream, const bool &registration, const bool &prev_registration)
Definition: Device.cpp:495
astra_ros::Device::Frame::Ir
Definition: Device.hpp:67
astra_ros::Device::depth_stream_
boost::optional< astra_depthstream_t > depth_stream_
Definition: Device.hpp:494
astra_ros::Device::ImageStreamMode
Represents a potential stream configuration.
Definition: Device.hpp:31
astra_ros::Device::Frame::Body
Definition: Device.hpp:97
astra_ros::Device::Configuration::on_frame
OnFrame on_frame
Definition: Device.hpp:323
astra_ros::Device::Configuration::ColorizedBodyStream
Definition: Device.hpp:294
astra_ros::Device::getDepthUsbInfo
boost::optional< astra_usb_info_t > getDepthUsbInfo() const
Definition: Device.cpp:654
astra_ros::Device::Configuration::DepthStream
Definition: Device.hpp:239
astra_ros::Device::Frame::hand
boost::optional< Hand > hand
Definition: Device.hpp:165
astra_ros::Device::getDepthImageStreamModes
boost::optional< std::vector< ImageStreamMode > > getDepthImageStreamModes() const
Definition: Device.cpp:680
astra_ros::Device::Configuration::body_stream
boost::optional< BodyStream > body_stream
Definition: Device.hpp:348
astra_ros::Device::Configuration::colorized_body_stream
boost::optional< ColorizedBodyStream > colorized_body_stream
Definition: Device.hpp:356
astra_ros::Device::Configuration
Definition: Device.hpp:178
astra_ros::Device::Device
Device(const Configuration &configuration)
Definition: Device.cpp:217
astra_ros::Device::Frame::Color::data
std::uint8_t * data
Definition: Device.hpp:62
astra_ros::Device::point_stream_
boost::optional< astra_pointstream_t > point_stream_
Definition: Device.hpp:499
astra_ros::Device::masked_color_stream_
boost::optional< astra_maskedcolorstream_t > masked_color_stream_
Definition: Device.hpp:498
astra_ros::Device::ImageStreamMode::width
boost::optional< std::uint32_t > width
Definition: Device.hpp:36
astra_ros::Device::onMirroredChange
bool onMirroredChange(astra_streamconnection_t stream, const bool &mirrored, const bool &prev_mirrored)
Definition: Device.cpp:551
astra_ros::Device::Configuration::ir_stream
boost::optional< IrStream > ir_stream
Definition: Device.hpp:336
astra_ros::Device::Frame::Depth::data
std::int16_t * data
Definition: Device.hpp:92
Exception.hpp
astra_ros::Device::Configuration::BodyStream
Definition: Device.hpp:271
initialize
ROSCONSOLE_DECL void initialize()
astra_ros::Device::onBodyOrientationChange
bool onBodyOrientationChange(astra_bodystream_t body_stream, const astra_body_orientation_t &orientation, const astra_skeleton_optimization_t &prev_orientation)
Definition: Device.cpp:529
astra_ros::Device::Frame
Definition: Device.hpp:54
astra_ros::Device::getSerialNumber
boost::optional< std::string > getSerialNumber() const
Definition: Device.cpp:621
astra_ros::Device::Frame::Ir::metadata
astra_image_metadata_t metadata
Definition: Device.hpp:78
astra_ros::Device::Frame::Ir::data
std::uint8_t * data
Definition: Device.hpp:76
astra_ros::Device::body_stream_
boost::optional< astra_bodystream_t > body_stream_
Definition: Device.hpp:495
astra_ros::Device::getChipId
boost::optional< std::uint32_t > getChipId() const
Definition: Device.cpp:633
astra_ros::Device::ir_stream_
boost::optional< astra_infraredstream_t > ir_stream_
Definition: Device.hpp:493
astra_ros::Device::Configuration::uri
boost::optional< std::string > uri
Definition: Device.hpp:322
astra_ros::Device::Frame::body
boost::optional< Body > body
Definition: Device.hpp:155
astra_ros::Device::Configuration::color_stream
boost::optional< ColorStream > color_stream
Definition: Device.hpp:330
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:131
astra_ros::Device::onBodySkeletonProfileChange
bool onBodySkeletonProfileChange(astra_bodystream_t body_stream, const astra_skeleton_profile_t &profile, const astra_skeleton_profile_t &prev_profile)
Definition: Device.cpp:540
astra_ros::Device::Frame::Body::body_list
astra_body_list_t body_list
Definition: Device.hpp:101
astra_ros::Device::Configuration::ColorStream
Definition: Device.hpp:187
astra_ros::Device::Configuration::point_stream
boost::optional< PointStream > point_stream
Definition: Device.hpp:380
util.hpp
astra_ros::Device::color_stream_
boost::optional< astra_colorstream_t > color_stream_
Definition: Device.hpp:492
astra_ros::Device::stream_set_
astra_streamsetconnection_t stream_set_
Definition: Device.hpp:489
astra_ros::Device::Frame::Body::body_mask
astra_bodymask_t body_mask
Definition: Device.hpp:100
astra_ros::Device::Frame::color
boost::optional< Color > color
Definition: Device.hpp:140
astra_ros
Definition: Device.hpp:14


astra_ros
Author(s): Braden McDorman
autogenerated on Wed Mar 2 2022 00:53:06