OrbbecSDK 2.5.5
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
119 template <typename T> bool is() const;
120
127 template <typename T> std::shared_ptr<T> as() {
128 if(!is<T>()) {
129 throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
130 }
131
132 return std::dynamic_pointer_cast<T>(shared_from_this());
133 }
134
141 template <typename T> std::shared_ptr<const T> as() const {
142 if(!is<T>()) {
143 throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
144 }
145
146 return std::static_pointer_cast<const T>(shared_from_this());
147 }
148
149 // The following interfaces are deprecated and are retained here for compatibility purposes.
150 OBFormat format() const {
151 return getFormat();
152 }
153
155 return getType();
156 }
157
158protected:
159 explicit StreamProfile(const ob_stream_profile_t *impl) : impl_(impl) {}
160};
161
166public:
167 explicit VideoStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
168
169 ~VideoStreamProfile() noexcept override = default;
170
176 uint32_t getFps() const {
177 ob_error *error = nullptr;
179 Error::handle(&error);
180 return fps;
181 }
182
188 uint32_t getWidth() const {
189 ob_error *error = nullptr;
191 Error::handle(&error);
192 return width;
193 }
194
200 uint32_t getHeight() const {
201 ob_error *error = nullptr;
203 Error::handle(&error);
204 return height;
205 }
206
213 ob_error *error = nullptr;
214 auto intrinsic = ob_video_stream_profile_get_intrinsic(impl_, &error);
215 Error::handle(&error);
216 return intrinsic;
217 }
218
224 void setIntrinsic(const OBCameraIntrinsic &intrinsic) {
225 ob_error *error = nullptr;
226 ob_video_stream_profile_set_intrinsic(const_cast<ob_stream_profile_t *>(impl_), intrinsic, &error);
227 Error::handle(&error);
228 }
229
237 ob_error *error = nullptr;
238 auto distortion = ob_video_stream_profile_get_distortion(impl_, &error);
239 Error::handle(&error);
240 return distortion;
241 }
242
248 void setDistortion(const OBCameraDistortion &distortion) {
249 ob_error *error = nullptr;
250 ob_video_stream_profile_set_distortion(const_cast<ob_stream_profile_t *>(impl_), distortion, &error);
251 Error::handle(&error);
252 }
253
254public:
255 // The following interfaces are deprecated and are retained here for compatibility purposes.
256 uint32_t fps() const {
257 return getFps();
258 }
259
260 uint32_t width() const {
261 return getWidth();
262 }
263
264 uint32_t height() const {
265 return getHeight();
266 }
267};
268
273public:
274 explicit AccelStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
275
276 ~AccelStreamProfile() noexcept override = default;
277
289
296 ob_error *error = nullptr;
298 Error::handle(&error);
299 return sampleRate;
300 }
301
308 ob_error *error = nullptr;
309 auto intrinsic = ob_accel_stream_profile_get_intrinsic(impl_, &error);
310 Error::handle(&error);
311 return intrinsic;
312 }
313
314public:
315 // The following interfaces are deprecated and are retained here for compatibility purposes.
319
321 return getSampleRate();
322 }
323};
324
329public:
330 explicit GyroStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
331
332 ~GyroStreamProfile() noexcept override = default;
333
340 ob_error *error = nullptr;
342 Error::handle(&error);
343 return fullScaleRange;
344 }
345
352 ob_error *error = nullptr;
354 Error::handle(&error);
355 return sampleRate;
356 }
357
364 ob_error *error = nullptr;
365 auto intrinsic = ob_gyro_stream_get_intrinsic(impl_, &error);
366 Error::handle(&error);
367 return intrinsic;
368 }
369
370public:
371 // The following interfaces are deprecated and are retained here for compatibility purposes.
375
377 return getSampleRate();
378 }
379};
380
381template <typename T> bool StreamProfile::is() const {
382 switch(this->getType()) {
383 case OB_STREAM_VIDEO:
384 case OB_STREAM_IR:
387 case OB_STREAM_COLOR:
388 case OB_STREAM_DEPTH:
391 return typeid(T) == typeid(VideoStreamProfile);
392 case OB_STREAM_ACCEL:
393 return typeid(T) == typeid(AccelStreamProfile);
394 case OB_STREAM_GYRO:
395 return typeid(T) == typeid(GyroStreamProfile);
396 default:
397 break;
398 }
399 return false;
400}
401
403public:
404 static std::shared_ptr<StreamProfile> create(const ob_stream_profile_t *impl) {
405 ob_error *error = nullptr;
406 const auto type = ob_stream_profile_get_type(impl, &error);
407 Error::handle(&error);
408 switch(type) {
409 case OB_STREAM_IR:
412 case OB_STREAM_DEPTH:
413 case OB_STREAM_COLOR:
414 case OB_STREAM_VIDEO:
416 return std::make_shared<VideoStreamProfile>(impl);
417 case OB_STREAM_ACCEL:
418 return std::make_shared<AccelStreamProfile>(impl);
419 case OB_STREAM_GYRO:
420 return std::make_shared<GyroStreamProfile>(impl);
421 default: {
422 ob_error *err = ob_create_error(OB_STATUS_ERROR, "Unsupported stream type.", "StreamProfileFactory::create", "", OB_EXCEPTION_TYPE_INVALID_VALUE);
423 Error::handle(&err);
424 return nullptr;
425 }
426 }
427 }
428};
429
431protected:
432 const ob_stream_profile_list_t *impl_;
433
434public:
435 explicit StreamProfileList(ob_stream_profile_list_t *impl) : impl_(impl) {}
437 ob_error *error = nullptr;
439 Error::handle(&error, false);
440 }
441
447 uint32_t getCount() const {
448 ob_error *error = nullptr;
450 Error::handle(&error);
451 return count;
452 }
453
460 std::shared_ptr<StreamProfile> getProfile(uint32_t index) const {
461 ob_error *error = nullptr;
462 auto profile = ob_stream_profile_list_get_profile(impl_, index, &error);
463 Error::handle(&error);
464 return StreamProfileFactory::create(profile);
465 }
466
477 std::shared_ptr<VideoStreamProfile> getVideoStreamProfile(int width = OB_WIDTH_ANY, int height = OB_HEIGHT_ANY, OBFormat format = OB_FORMAT_ANY,
478 int fps = OB_FPS_ANY) const {
479 ob_error *error = nullptr;
480 auto profile = ob_stream_profile_list_get_video_stream_profile(impl_, width, height, format, fps, &error);
481 Error::handle(&error);
482 auto vsp = StreamProfileFactory::create(profile);
483 return vsp->as<VideoStreamProfile>();
484 }
485
493 std::shared_ptr<AccelStreamProfile> getAccelStreamProfile(OBAccelFullScaleRange fullScaleRange, OBAccelSampleRate sampleRate) const {
494 ob_error *error = nullptr;
495 auto profile = ob_stream_profile_list_get_accel_stream_profile(impl_, fullScaleRange, sampleRate, &error);
496 Error::handle(&error);
497 auto asp = StreamProfileFactory::create(profile);
498 return asp->as<AccelStreamProfile>();
499 }
500
508 std::shared_ptr<GyroStreamProfile> getGyroStreamProfile(OBGyroFullScaleRange fullScaleRange, OBGyroSampleRate sampleRate) const {
509 ob_error *error = nullptr;
510 auto profile = ob_stream_profile_list_get_gyro_stream_profile(impl_, fullScaleRange, sampleRate, &error);
511 Error::handle(&error);
512 auto gsp = StreamProfileFactory::create(profile);
513 return gsp->as<GyroStreamProfile>();
514 }
515
516public:
517 // The following interfaces are deprecated and are retained here for compatibility purposes.
518 uint32_t count() const {
519 return getCount();
520 }
521};
522
523} // 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.
@ OB_STATUS_ERROR
Definition ObTypes.h:77
OBGyroFullScaleRange
Enumeration of gyroscope ranges.
Definition ObTypes.h:604
struct ob_stream_profile_t ob_stream_profile
Definition ObTypes.h:31
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:199
OBStreamType
Enumeration value describing the type of data stream.
Definition ObTypes.h:146
@ OB_STREAM_CONFIDENCE
Definition ObTypes.h:157
@ OB_STREAM_RAW_PHASE
Definition ObTypes.h:156
@ OB_STREAM_GYRO
Definition ObTypes.h:153
@ OB_STREAM_IR
Definition ObTypes.h:149
@ OB_STREAM_DEPTH
Definition ObTypes.h:151
@ OB_STREAM_IR_RIGHT
Definition ObTypes.h:155
@ OB_STREAM_IR_LEFT
Definition ObTypes.h:154
@ OB_STREAM_VIDEO
Definition ObTypes.h:148
@ OB_STREAM_ACCEL
Definition ObTypes.h:152
@ OB_STREAM_COLOR
Definition ObTypes.h:150
enum OBIMUSampleRate OBGyroSampleRate
@ OB_EXCEPTION_TYPE_INVALID_VALUE
Definition ObTypes.h:105
OBAccelFullScaleRange
Enumeration of accelerometer ranges.
Definition ObTypes.h:622
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_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_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
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...
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:19
Structure for accelerometer intrinsic parameters.
Definition ObTypes.h:400
Structure for distortion parameters.
Definition ObTypes.h:425
Structure for camera intrinsic parameters.
Definition ObTypes.h:388
Structure for gyroscope intrinsic parameters.
Definition ObTypes.h:413
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:117