OrbbecSDK 2.6.3
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
StreamProfile.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
8#pragma once
9
10#include "Types.hpp"
12#include "libobsensor/h/Error.h"
13#include <iostream>
14#include <memory>
15
16namespace ob {
17
18class StreamProfile : public std::enable_shared_from_this<StreamProfile> {
19protected:
20 const ob_stream_profile_t *impl_ = nullptr;
21
22public:
23 StreamProfile(StreamProfile &streamProfile) = delete;
24 StreamProfile &operator=(StreamProfile &streamProfile) = delete;
25
26 StreamProfile(StreamProfile &&streamProfile) noexcept : impl_(streamProfile.impl_) {
27 streamProfile.impl_ = nullptr;
28 }
29
30 StreamProfile &operator=(StreamProfile &&streamProfile) noexcept {
31 if(this != &streamProfile) {
32 ob_error *error = nullptr;
34 Error::handle(&error);
35 impl_ = streamProfile.impl_;
36 streamProfile.impl_ = nullptr;
37 }
38 return *this;
39 }
40
41 virtual ~StreamProfile() noexcept {
42 if(impl_) {
43 ob_error *error = nullptr;
45 Error::handle(&error);
46 }
47 }
48
49 const ob_stream_profile *getImpl() const {
50 return impl_;
51 }
52
59 ob_error *error = nullptr;
61 Error::handle(&error);
62 return format;
63 }
64
71 ob_error *error = nullptr;
73 Error::handle(&error);
74 return type;
75 }
76
82 OBExtrinsic getExtrinsicTo(std::shared_ptr<StreamProfile> target) const {
83 ob_error *error = nullptr;
84 auto extrinsic = ob_stream_profile_get_extrinsic_to(impl_, const_cast<ob_stream_profile_t *>(target->getImpl()), &error);
85 Error::handle(&error);
86 return extrinsic;
87 }
88
95 void bindExtrinsicTo(std::shared_ptr<StreamProfile> target, const OBExtrinsic &extrinsic) {
96 ob_error *error = nullptr;
97 ob_stream_profile_set_extrinsic_to(const_cast<ob_stream_profile_t *>(impl_), const_cast<const ob_stream_profile_t *>(target->getImpl()), extrinsic, &error);
98 Error::handle(&error);
99 }
100
107 void bindExtrinsicTo(const OBStreamType &targetStreamType, const OBExtrinsic &extrinsic) {
108 ob_error *error = nullptr;
109 ob_stream_profile_set_extrinsic_to_type(const_cast<ob_stream_profile_t *>(impl_),targetStreamType,extrinsic, &error);
110 Error::handle(&error);
111 }
112
120 template <typename T> bool is() const;
121
129 template <typename T> std::shared_ptr<T> as() {
130 if(!is<T>()) {
131 throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
132 }
133
134 return std::dynamic_pointer_cast<T>(shared_from_this());
135 }
136
144 template <typename T> std::shared_ptr<const T> as() const {
145 if(!is<T>()) {
146 throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
147 }
148
149 return std::static_pointer_cast<const T>(shared_from_this());
150 }
151
152 // The following interfaces are deprecated and are retained here for compatibility purposes.
153 OBFormat format() const {
154 return getFormat();
155 }
156
158 return getType();
159 }
160
161protected:
162 explicit StreamProfile(const ob_stream_profile_t *impl) : impl_(impl) {}
163};
164
169public:
170 explicit VideoStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
171
172 ~VideoStreamProfile() noexcept override = default;
173
179 uint32_t getFps() const {
180 ob_error *error = nullptr;
182 Error::handle(&error);
183 return fps;
184 }
185
191 uint32_t getWidth() const {
192 ob_error *error = nullptr;
194 Error::handle(&error);
195 return width;
196 }
197
203 uint32_t getHeight() const {
204 ob_error *error = nullptr;
206 Error::handle(&error);
207 return height;
208 }
209
216 ob_error *error = nullptr;
217 auto intrinsic = ob_video_stream_profile_get_intrinsic(impl_, &error);
218 Error::handle(&error);
219 return intrinsic;
220 }
221
227 void setIntrinsic(const OBCameraIntrinsic &intrinsic) {
228 ob_error *error = nullptr;
229 ob_video_stream_profile_set_intrinsic(const_cast<ob_stream_profile_t *>(impl_), intrinsic, &error);
230 Error::handle(&error);
231 }
232
240 ob_error *error = nullptr;
241 auto distortion = ob_video_stream_profile_get_distortion(impl_, &error);
242 Error::handle(&error);
243 return distortion;
244 }
245
251 void setDistortion(const OBCameraDistortion &distortion) {
252 ob_error *error = nullptr;
253 ob_video_stream_profile_set_distortion(const_cast<ob_stream_profile_t *>(impl_), distortion, &error);
254 Error::handle(&error);
255 }
256
257public:
258 // The following interfaces are deprecated and are retained here for compatibility purposes.
259 uint32_t fps() const {
260 return getFps();
261 }
262
263 uint32_t width() const {
264 return getWidth();
265 }
266
267 uint32_t height() const {
268 return getHeight();
269 }
270};
271
276public:
277 explicit AccelStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
278
279 ~AccelStreamProfile() noexcept override = default;
280
292
299 ob_error *error = nullptr;
301 Error::handle(&error);
302 return sampleRate;
303 }
304
311 ob_error *error = nullptr;
312 auto intrinsic = ob_accel_stream_profile_get_intrinsic(impl_, &error);
313 Error::handle(&error);
314 return intrinsic;
315 }
316
317public:
318 // The following interfaces are deprecated and are retained here for compatibility purposes.
322
324 return getSampleRate();
325 }
326};
327
332public:
333 explicit GyroStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
334
335 ~GyroStreamProfile() noexcept override = default;
336
343 ob_error *error = nullptr;
345 Error::handle(&error);
346 return fullScaleRange;
347 }
348
355 ob_error *error = nullptr;
357 Error::handle(&error);
358 return sampleRate;
359 }
360
367 ob_error *error = nullptr;
368 auto intrinsic = ob_gyro_stream_get_intrinsic(impl_, &error);
369 Error::handle(&error);
370 return intrinsic;
371 }
372
373public:
374 // The following interfaces are deprecated and are retained here for compatibility purposes.
378
380 return getSampleRate();
381 }
382};
383
387
389public:
390 explicit LiDARStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
391
392 ~LiDARStreamProfile() noexcept override = default;
393
395 ob_error *error = nullptr;
396 auto rate = ob_lidar_stream_profile_get_scan_rate(impl_, &error);
397 Error::handle(&error);
398 return rate;
399 }
400};
401
402template <typename T> bool StreamProfile::is() const {
403 switch(this->getType()) {
404 case OB_STREAM_VIDEO:
405 case OB_STREAM_IR:
408 case OB_STREAM_COLOR:
409 case OB_STREAM_DEPTH:
412 return typeid(T) == typeid(VideoStreamProfile);
413 case OB_STREAM_ACCEL:
414 return typeid(T) == typeid(AccelStreamProfile);
415 case OB_STREAM_GYRO:
416 return typeid(T) == typeid(GyroStreamProfile);
417 case OB_STREAM_LIDAR:
418 return typeid(T) == typeid(LiDARStreamProfile);
419 default:
420 break;
421 }
422 return false;
423}
424
426public:
427 static std::shared_ptr<StreamProfile> create(const ob_stream_profile_t *impl) {
428 ob_error *error = nullptr;
429 const auto type = ob_stream_profile_get_type(impl, &error);
430 Error::handle(&error);
431 switch(type) {
432 case OB_STREAM_IR:
435 case OB_STREAM_DEPTH:
436 case OB_STREAM_COLOR:
437 case OB_STREAM_VIDEO:
439 return std::make_shared<VideoStreamProfile>(impl);
440 case OB_STREAM_ACCEL:
441 return std::make_shared<AccelStreamProfile>(impl);
442 case OB_STREAM_GYRO:
443 return std::make_shared<GyroStreamProfile>(impl);
444 case OB_STREAM_LIDAR:
445 return std::make_shared<LiDARStreamProfile>(impl);
446 default: {
447 ob_error *err = ob_create_error(OB_STATUS_ERROR, "Unsupported stream type.", "StreamProfileFactory::create", "", OB_EXCEPTION_TYPE_INVALID_VALUE);
448 Error::handle(&err);
449 return nullptr;
450 }
451 }
452 }
453};
454
456protected:
457 const ob_stream_profile_list_t *impl_;
458
459public:
460 explicit StreamProfileList(ob_stream_profile_list_t *impl) : impl_(impl) {}
462 ob_error *error = nullptr;
464 Error::handle(&error, false);
465 }
466
472 uint32_t getCount() const {
473 ob_error *error = nullptr;
475 Error::handle(&error);
476 return count;
477 }
478
487 std::shared_ptr<StreamProfile> getProfile(uint32_t index) const {
488 ob_error *error = nullptr;
489 auto profile = ob_stream_profile_list_get_profile(impl_, index, &error);
490 Error::handle(&error);
491 return StreamProfileFactory::create(profile);
492 }
493
505 std::shared_ptr<VideoStreamProfile> getVideoStreamProfile(int width = OB_WIDTH_ANY, int height = OB_HEIGHT_ANY, OBFormat format = OB_FORMAT_ANY,
506 int fps = OB_FPS_ANY) const {
507 ob_error *error = nullptr;
508 auto profile = ob_stream_profile_list_get_video_stream_profile(impl_, width, height, format, fps, &error);
509 Error::handle(&error);
510 auto vsp = StreamProfileFactory::create(profile);
511 return vsp->as<VideoStreamProfile>();
512 }
513
521 std::shared_ptr<AccelStreamProfile> getAccelStreamProfile(OBAccelFullScaleRange fullScaleRange, OBAccelSampleRate sampleRate) const {
522 ob_error *error = nullptr;
523 auto profile = ob_stream_profile_list_get_accel_stream_profile(impl_, fullScaleRange, sampleRate, &error);
524 Error::handle(&error);
525 auto asp = StreamProfileFactory::create(profile);
526 return asp->as<AccelStreamProfile>();
527 }
528
536 std::shared_ptr<GyroStreamProfile> getGyroStreamProfile(OBGyroFullScaleRange fullScaleRange, OBGyroSampleRate sampleRate) const {
537 ob_error *error = nullptr;
538 auto profile = ob_stream_profile_list_get_gyro_stream_profile(impl_, fullScaleRange, sampleRate, &error);
539 Error::handle(&error);
540 auto gsp = StreamProfileFactory::create(profile);
541 return gsp->as<GyroStreamProfile>();
542 }
543
551 std::shared_ptr<LiDARStreamProfile> getLiDARStreamProfile(OBLiDARScanRate scanRate, OBFormat format) const {
552 ob_error *error = nullptr;
553 auto profile = ob_stream_profile_list_get_lidar_stream_profile(impl_, scanRate, format, &error);
554 Error::handle(&error);
555 auto lsp = StreamProfileFactory::create(profile);
556 return lsp->as<LiDARStreamProfile>();
557 }
558
559public:
560 // The following interfaces are deprecated and are retained here for compatibility purposes.
561 uint32_t count() const {
562 return getCount();
563 }
564};
565
566} // namespace ob
Functions for handling errors, mainly used for obtaining error messages.
OB_EXPORT ob_error * ob_create_error(ob_status status, const char *message, const char *function, const char *args, ob_exception_type exception_type)
Create a new error object.
OBLiDARScanRate
Data structures for LiDAR scan rate.
Definition ObTypes.h:659
@ OB_STATUS_ERROR
Definition ObTypes.h:78
OBGyroFullScaleRange
Enumeration of gyroscope ranges.
Definition ObTypes.h:616
struct ob_stream_profile_t ob_stream_profile
Definition ObTypes.h:31
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:204
OBStreamType
Enumeration value describing the type of data stream.
Definition ObTypes.h:149
@ OB_STREAM_CONFIDENCE
Definition ObTypes.h:160
@ OB_STREAM_RAW_PHASE
Definition ObTypes.h:159
@ OB_STREAM_GYRO
Definition ObTypes.h:156
@ OB_STREAM_IR
Definition ObTypes.h:152
@ OB_STREAM_DEPTH
Definition ObTypes.h:154
@ OB_STREAM_IR_RIGHT
Definition ObTypes.h:158
@ OB_STREAM_IR_LEFT
Definition ObTypes.h:157
@ OB_STREAM_VIDEO
Definition ObTypes.h:151
@ OB_STREAM_ACCEL
Definition ObTypes.h:155
@ OB_STREAM_LIDAR
Definition ObTypes.h:161
@ OB_STREAM_COLOR
Definition ObTypes.h:153
enum OBIMUSampleRate OBGyroSampleRate
@ OB_EXCEPTION_TYPE_INVALID_VALUE
Definition ObTypes.h:106
OBAccelFullScaleRange
Enumeration of accelerometer ranges.
Definition ObTypes.h:634
enum OBIMUSampleRate OBAccelSampleRate
struct OBD2CTransform OBExtrinsic
#define OB_WIDTH_ANY
Definition ObTypes.h:44
#define OB_FPS_ANY
Definition ObTypes.h:46
#define OB_HEIGHT_ANY
Definition ObTypes.h:45
#define OB_FORMAT_ANY
Definition ObTypes.h:47
The stream profile related type is used to get information such as the width, height,...
OB_EXPORT ob_gyro_intrinsic ob_gyro_stream_get_intrinsic(const ob_stream_profile *profile, ob_error **error)
Get the intrinsic of the gyroscope stream.
OB_EXPORT ob_gyro_sample_rate ob_gyro_stream_profile_get_sample_rate(const ob_stream_profile *profile, ob_error **error)
Get the sampling frequency of the gyroscope stream.
OB_EXPORT ob_lidar_scan_rate ob_lidar_stream_profile_get_scan_rate(const ob_stream_profile *profile, ob_error **error)
Get the scan rate of the LiDAR stream.
OB_EXPORT ob_stream_profile * ob_stream_profile_list_get_video_stream_profile(const ob_stream_profile_list *profile_list, int width, int height, ob_format format, int fps, ob_error **error)
Match the corresponding ob_stream_profile through the passed parameters. If there are multiple matche...
OB_EXPORT ob_stream_profile * ob_stream_profile_list_get_accel_stream_profile(const ob_stream_profile_list *profile_list, ob_accel_full_scale_range full_scale_range, ob_accel_sample_rate sample_rate, ob_error **error)
Match the corresponding ob_stream_profile through the passed parameters. If there are multiple matche...
OB_EXPORT uint32_t ob_stream_profile_list_get_count(const ob_stream_profile_list *profile_list, ob_error **error)
Get the number of StreamProfile lists.
OB_EXPORT ob_stream_profile * ob_stream_profile_list_get_profile(const ob_stream_profile_list *profile_list, int index, ob_error **error)
Get the corresponding StreamProfile by subscripting.
OB_EXPORT ob_format ob_stream_profile_get_format(const ob_stream_profile *profile, ob_error **error)
Get stream profile format.
OB_EXPORT uint32_t ob_video_stream_profile_get_fps(const ob_stream_profile *profile, ob_error **error)
Get the frame rate of the video stream.
OB_EXPORT void ob_video_stream_profile_set_intrinsic(ob_stream_profile *profile, ob_camera_intrinsic intrinsic, ob_error **error)
Set the intrinsic of the video stream profile.
OB_EXPORT void ob_video_stream_profile_set_distortion(ob_stream_profile *profile, ob_camera_distortion distortion, ob_error **error)
Set the distortion of the video stream profile.
OB_EXPORT void ob_delete_stream_profile(const ob_stream_profile *profile, ob_error **error)
Delete the stream configuration.
OB_EXPORT void ob_delete_stream_profile_list(const ob_stream_profile_list *profile_list, ob_error **error)
Delete the stream profile list.
OB_EXPORT ob_accel_intrinsic ob_accel_stream_profile_get_intrinsic(const ob_stream_profile *profile, ob_error **error)
Get the intrinsic of the accelerometer stream.
OB_EXPORT uint32_t ob_video_stream_profile_get_width(const ob_stream_profile *profile, ob_error **error)
Get the width of the video stream.
OB_EXPORT ob_gyro_full_scale_range ob_gyro_stream_profile_get_full_scale_range(const ob_stream_profile *profile, ob_error **error)
Get the full-scale range of the gyroscope stream.
OB_EXPORT ob_stream_profile * ob_stream_profile_list_get_lidar_stream_profile(const ob_stream_profile_list *profile_list, ob_lidar_scan_rate scan_rate, ob_format format, ob_error **error)
Match the corresponding ob_stream_profile through the passed parameters. If there are multiple matche...
OB_EXPORT ob_accel_sample_rate ob_accel_stream_profile_get_sample_rate(const ob_stream_profile *profile, ob_error **error)
Get the sampling frequency of the accelerometer frame.
OB_EXPORT ob_stream_profile * ob_stream_profile_list_get_gyro_stream_profile(const ob_stream_profile_list *profile_list, ob_gyro_full_scale_range full_scale_range, ob_gyro_sample_rate sample_rate, ob_error **error)
Match the corresponding ob_stream_profile through the passed parameters. If there are multiple matche...
OB_EXPORT void ob_stream_profile_set_extrinsic_to(ob_stream_profile *source, const ob_stream_profile *target, ob_extrinsic extrinsic, ob_error **error)
Set the extrinsic for source stream to target stream.
OB_EXPORT void ob_stream_profile_set_extrinsic_to_type(ob_stream_profile *source, const ob_stream_type type, ob_extrinsic extrinsic, ob_error **error)
Set the extrinsic for source stream to target stream type.
OB_EXPORT uint32_t ob_video_stream_profile_get_height(const ob_stream_profile *profile, ob_error **error)
Get the height of the video stream.
OB_EXPORT ob_camera_distortion ob_video_stream_profile_get_distortion(const ob_stream_profile *profile, ob_error **error)
Get the distortion of the video stream profile.
OB_EXPORT ob_camera_intrinsic ob_video_stream_profile_get_intrinsic(const ob_stream_profile *profile, ob_error **error)
Get the intrinsic of the video stream profile.
OB_EXPORT ob_accel_full_scale_range ob_accel_stream_profile_get_full_scale_range(const ob_stream_profile *profile, ob_error **error)
Get the full-scale range of the accelerometer stream.
OB_EXPORT ob_stream_type ob_stream_profile_get_type(const ob_stream_profile *profile, ob_error **error)
Get stream profile type.
OB_EXPORT ob_extrinsic ob_stream_profile_get_extrinsic_to(const ob_stream_profile *source, ob_stream_profile *target, ob_error **error)
Get the extrinsic for source stream to target stream.
Class representing an accelerometer stream profile.
AccelStreamProfile(const ob_stream_profile_t *impl)
OBAccelIntrinsic getIntrinsic() const
get the intrinsic parameters of the stream.
OBAccelSampleRate getSampleRate() const
Return the sampling frequency.
OBAccelFullScaleRange getFullScaleRange() const
Return the full scale range.
OBAccelSampleRate sampleRate() const
~AccelStreamProfile() noexcept override=default
OBAccelFullScaleRange fullScaleRange() const
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
Class representing a gyroscope stream profile.
OBGyroFullScaleRange getFullScaleRange() const
Return the full scale range.
OBGyroSampleRate getSampleRate() const
Return the sampling frequency.
OBGyroIntrinsic getIntrinsic() const
get the intrinsic parameters of the stream.
GyroStreamProfile(const ob_stream_profile_t *impl)
~GyroStreamProfile() noexcept override=default
OBGyroSampleRate sampleRate() const
OBGyroFullScaleRange fullScaleRange() const
Class representing a LiDAR stream profile.
OBLiDARScanRate getScanRate() const
LiDARStreamProfile(const ob_stream_profile_t *impl)
~LiDARStreamProfile() noexcept override=default
static std::shared_ptr< StreamProfile > create(const ob_stream_profile_t *impl)
StreamProfile(StreamProfile &&streamProfile) noexcept
const ob_stream_profile_t * impl_
std::shared_ptr< const T > as() const
Converts object type to target type (const version).
virtual ~StreamProfile() noexcept
OBStreamType type() const
bool is() const
Check if frame object is compatible with the given type.
StreamProfile & operator=(StreamProfile &streamProfile)=delete
OBFormat format() const
OBExtrinsic getExtrinsicTo(std::shared_ptr< StreamProfile > target) const
Get the extrinsic parameters from current stream profile to the given target stream profile.
StreamProfile(StreamProfile &streamProfile)=delete
StreamProfile & operator=(StreamProfile &&streamProfile) noexcept
const ob_stream_profile * getImpl() const
void bindExtrinsicTo(const OBStreamType &targetStreamType, const OBExtrinsic &extrinsic)
Set the extrinsic parameters from current stream profile to the given target stream type.
std::shared_ptr< T > as()
Converts object type to target type.
void bindExtrinsicTo(std::shared_ptr< StreamProfile > target, const OBExtrinsic &extrinsic)
Set the extrinsic parameters from current stream profile to the given target stream profile.
OBStreamType getType() const
Get the type of stream.
OBFormat getFormat() const
Get the format of the stream.
StreamProfile(const ob_stream_profile_t *impl)
std::shared_ptr< GyroStreamProfile > getGyroStreamProfile(OBGyroFullScaleRange fullScaleRange, OBGyroSampleRate sampleRate) const
Match the corresponding gyroscope stream profile based on the passed-in parameters....
std::shared_ptr< StreamProfile > getProfile(uint32_t index) const
Return the StreamProfile object at the specified index.
uint32_t getCount() const
Return the number of StreamProfile objects.
const ob_stream_profile_list_t * impl_
std::shared_ptr< AccelStreamProfile > getAccelStreamProfile(OBAccelFullScaleRange fullScaleRange, OBAccelSampleRate sampleRate) const
Match the corresponding accelerometer stream profile based on the passed-in parameters....
std::shared_ptr< VideoStreamProfile > getVideoStreamProfile(int width=OB_WIDTH_ANY, int height=OB_HEIGHT_ANY, OBFormat format=OB_FORMAT_ANY, int fps=OB_FPS_ANY) const
Match the corresponding video stream profile based on the passed-in parameters. If multiple Match are...
std::shared_ptr< LiDARStreamProfile > getLiDARStreamProfile(OBLiDARScanRate scanRate, OBFormat format) const
Match the corresponding LiDAR stream profile based on the passed-in parameters. If multiple Match are...
uint32_t count() const
StreamProfileList(ob_stream_profile_list_t *impl)
Class representing a video stream profile.
uint32_t height() const
void setIntrinsic(const OBCameraIntrinsic &intrinsic)
Set the intrinsic parameters of the stream.
OBCameraDistortion getDistortion() const
Get the distortion parameters of the stream.
uint32_t getWidth() const
Return the width of the stream.
void setDistortion(const OBCameraDistortion &distortion)
Set the distortion parameters of the stream.
uint32_t getFps() const
Return the frame rate of the stream.
OBCameraIntrinsic getIntrinsic() const
Get the intrinsic parameters of the stream.
VideoStreamProfile(const ob_stream_profile_t *impl)
~VideoStreamProfile() noexcept override=default
uint32_t getHeight() const
Return the height of the stream.
Definition Context.hpp:22
Structure for accelerometer intrinsic parameters.
Definition ObTypes.h:412
Structure for distortion parameters.
Definition ObTypes.h:437
Structure for camera intrinsic parameters.
Definition ObTypes.h:400
Structure for gyroscope intrinsic parameters.
Definition ObTypes.h:425
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:119