OrbbecSDK 2.5.5
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
Sensor.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"
14#include "Error.hpp"
15#include "StreamProfile.hpp"
16#include "Device.hpp"
17#include "Frame.hpp"
18#include <functional>
19#include <memory>
20#include <vector>
21
22namespace ob {
23
24class Sensor {
25public:
31 typedef std::function<void(std::shared_ptr<Frame> frame)> FrameCallback;
32
33protected:
34 ob_sensor_t *impl_;
36
37public:
38 explicit Sensor(ob_sensor_t *impl) : impl_(impl) {}
39
40 Sensor(Sensor &&sensor) noexcept : impl_(sensor.impl_) {
41 sensor.impl_ = nullptr;
42 }
43
44 Sensor &operator=(Sensor &&sensor) noexcept {
45 if(this != &sensor) {
46 ob_error *error = nullptr;
47 ob_delete_sensor(impl_, &error);
48 Error::handle(&error);
49 impl_ = sensor.impl_;
50 sensor.impl_ = nullptr;
51 }
52 return *this;
53 }
54
55 Sensor(const Sensor &sensor) = delete;
56 Sensor &operator=(const Sensor &sensor) = delete;
57
58 virtual ~Sensor() noexcept {
59 ob_error *error = nullptr;
60 ob_delete_sensor(impl_, &error);
61 Error::handle(&error, false);
62 }
63
70 ob_error *error = nullptr;
71 auto type = ob_sensor_get_type(impl_, &error);
72 Error::handle(&error);
73 return type;
74 }
75
81 std::shared_ptr<StreamProfileList> getStreamProfileList() const {
82 ob_error *error = nullptr;
83 auto list = ob_sensor_get_stream_profile_list(impl_, &error);
84 Error::handle(&error);
85 return std::make_shared<StreamProfileList>(list);
86 }
87
93 std::vector<std::shared_ptr<Filter>> createRecommendedFilters() const {
94 ob_error *error = nullptr;
96 Error::handle(&error);
97 auto filter_count = ob_filter_list_get_count(list, &error);
98
99 std::vector<std::shared_ptr<Filter>> filters;
100 for(uint32_t i = 0; i < filter_count; i++) {
101 auto filterImpl = ob_filter_list_get_filter(list, i, &error);
102 Error::handle(&error);
103 filters.push_back(std::make_shared<Filter>(filterImpl));
104 }
105 ob_delete_filter_list(list, &error);
106 Error::handle(&error, false);
107 return filters;
108 }
109
116 void start(std::shared_ptr<StreamProfile> streamProfile, FrameCallback callback) {
117 ob_error *error = nullptr;
118 callback_ = std::move(callback);
119 ob_sensor_start(impl_, const_cast<ob_stream_profile_t *>(streamProfile->getImpl()), &Sensor::frameCallback, this, &error);
120 Error::handle(&error);
121 }
122
126 void stop() const {
127 ob_error *error = nullptr;
128 ob_sensor_stop(impl_, &error);
129 Error::handle(&error);
130 }
131
137 void switchProfile(std::shared_ptr<StreamProfile> streamProfile) {
138 ob_error *error = nullptr;
139 ob_sensor_switch_profile(impl_, const_cast<ob_stream_profile_t *>(streamProfile->getImpl()), &error);
140 Error::handle(&error);
141 }
142
143private:
144 static void frameCallback(ob_frame *frame, void *userData) {
145 auto sensor = static_cast<Sensor *>(userData);
146 sensor->callback_(std::make_shared<Frame>(frame));
147 }
148
149public:
150 // The following interfaces are deprecated and are retained here for compatibility purposes.
152 return getType();
153 }
154
155 std::vector<std::shared_ptr<Filter>> getRecommendedFilters() const {
157 }
158};
159
161private:
162 ob_sensor_list_t *impl_ = nullptr;
163
164public:
165 explicit SensorList(ob_sensor_list_t *impl) : impl_(impl) {}
166
167 ~SensorList() noexcept {
168 ob_error *error = nullptr;
169 ob_delete_sensor_list(impl_, &error);
170 Error::handle(&error, false);
171 }
172
178 uint32_t getCount() const {
179 ob_error *error = nullptr;
180 auto count = ob_sensor_list_get_count(impl_, &error);
181 Error::handle(&error);
182 return count;
183 }
184
191 OBSensorType getSensorType(uint32_t index) const {
192 ob_error *error = nullptr;
193 auto type = ob_sensor_list_get_sensor_type(impl_, index, &error);
194 Error::handle(&error);
195 return type;
196 }
197
204 std::shared_ptr<Sensor> getSensor(uint32_t index) const {
205 ob_error *error = nullptr;
206 auto sensor = ob_sensor_list_get_sensor(impl_, index, &error);
207 Error::handle(&error);
208 return std::make_shared<Sensor>(sensor);
209 }
210
217 std::shared_ptr<Sensor> getSensor(OBSensorType sensorType) const {
218 ob_error *error = nullptr;
219 auto sensor = ob_sensor_list_get_sensor_by_type(impl_, sensorType, &error);
220 Error::handle(&error);
221 return std::make_shared<Sensor>(sensor);
222 }
223
224public:
225 // The following interfaces are deprecated and are retained here for compatibility purposes.
226 uint32_t count() const {
227 return getCount();
228 }
229
230 OBSensorType type(uint32_t index) const {
231 return getSensorType(index);
232 }
233};
234
235} // namespace ob
236
Device related types, including operations such as getting and creating a device, setting and obtaini...
This file defines the Error class, which describes abnormal errors within the SDK....
The processing unit of the SDK can perform point cloud generation, format conversion and other functi...
OB_EXPORT void ob_delete_filter_list(ob_filter_list *filter_list, ob_error **error)
Delete a list of ob_filter objects.
OB_EXPORT ob_filter * ob_filter_list_get_filter(const ob_filter_list *filter_list, uint32_t index, ob_error **error)
Get the filter by index.
OB_EXPORT uint32_t ob_filter_list_get_count(const ob_filter_list *filter_list, ob_error **error)
Get the number of filter in the list.
This file contains the Filter class, which is the processing unit of the SDK that can perform point c...
Frame related type, which is mainly used to obtain frame data and frame information.
struct ob_frame_t ob_frame
Definition ObTypes.h:33
OBSensorType
Enumeration value describing the sensor type.
Definition ObTypes.h:128
Defines types related to sensors, used for obtaining stream configurations, opening and closing strea...
OB_EXPORT ob_sensor * ob_sensor_list_get_sensor(const ob_sensor_list *sensor_list, uint32_t index, ob_error **error)
Get a sensor by index number.
OB_EXPORT void ob_delete_sensor_list(ob_sensor_list *sensor_list, ob_error **error)
Delete a list of sensor objects.
OB_EXPORT void ob_sensor_stop(ob_sensor *sensor, ob_error **error)
Stop the sensor stream.
OB_EXPORT void ob_sensor_switch_profile(ob_sensor *sensor, ob_stream_profile *profile, ob_error **error)
Switch resolutions.
OB_EXPORT ob_sensor_type ob_sensor_list_get_sensor_type(const ob_sensor_list *sensor_list, uint32_t index, ob_error **error)
Get the sensor type.
OB_EXPORT ob_sensor * ob_sensor_list_get_sensor_by_type(const ob_sensor_list *sensor_list, ob_sensor_type sensorType, ob_error **error)
Get a sensor by sensor type.
OB_EXPORT void ob_delete_sensor(ob_sensor *sensor, ob_error **error)
Delete a sensor object.
OB_EXPORT uint32_t ob_sensor_list_get_count(const ob_sensor_list *sensor_list, ob_error **error)
Get the number of sensors in the sensor list.
OB_EXPORT ob_sensor_type ob_sensor_get_type(const ob_sensor *sensor, ob_error **error)
Get the type of the sensor.
OB_EXPORT ob_stream_profile_list * ob_sensor_get_stream_profile_list(const ob_sensor *sensor, ob_error **error)
Get a list of all supported stream profiles.
OB_EXPORT ob_filter_list * ob_sensor_create_recommended_filter_list(const ob_sensor *sensor, ob_error **error)
Create a list of recommended filters for the specified sensor.
OB_EXPORT void ob_sensor_start(ob_sensor *sensor, const ob_stream_profile *profile, ob_frame_callback callback, void *user_data, ob_error **error)
Open the current sensor and set the callback data frame.
The stream profile related type is used to get information such as the width, height,...
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
OBSensorType getType() const
Get the sensor type.
Definition Sensor.hpp:69
std::function< void(std::shared_ptr< Frame > frame)> FrameCallback
Callback function for frame data.
Definition Sensor.hpp:31
Sensor(ob_sensor_t *impl)
Definition Sensor.hpp:38
std::vector< std::shared_ptr< Filter > > createRecommendedFilters() const
Create a list of recommended filters for the sensor.
Definition Sensor.hpp:93
FrameCallback callback_
Definition Sensor.hpp:35
OBSensorType type() const
Definition Sensor.hpp:151
ob_sensor_t * impl_
Definition Sensor.hpp:34
void start(std::shared_ptr< StreamProfile > streamProfile, FrameCallback callback)
Open a frame data stream and set up a callback.
Definition Sensor.hpp:116
std::shared_ptr< StreamProfileList > getStreamProfileList() const
Get the list of stream profiles.
Definition Sensor.hpp:81
Sensor & operator=(Sensor &&sensor) noexcept
Definition Sensor.hpp:44
virtual ~Sensor() noexcept
Definition Sensor.hpp:58
Sensor(Sensor &&sensor) noexcept
Definition Sensor.hpp:40
Sensor & operator=(const Sensor &sensor)=delete
void stop() const
Stop the stream.
Definition Sensor.hpp:126
Sensor(const Sensor &sensor)=delete
std::vector< std::shared_ptr< Filter > > getRecommendedFilters() const
Definition Sensor.hpp:155
void switchProfile(std::shared_ptr< StreamProfile > streamProfile)
Dynamically switch resolutions.
Definition Sensor.hpp:137
uint32_t getCount() const
Get the number of sensors.
Definition Sensor.hpp:178
~SensorList() noexcept
Definition Sensor.hpp:167
uint32_t count() const
Definition Sensor.hpp:226
std::shared_ptr< Sensor > getSensor(OBSensorType sensorType) const
Get a sensor by sensor type.
Definition Sensor.hpp:217
OBSensorType getSensorType(uint32_t index) const
Get the type of the specified sensor.
Definition Sensor.hpp:191
std::shared_ptr< Sensor > getSensor(uint32_t index) const
Get a sensor by index number.
Definition Sensor.hpp:204
OBSensorType type(uint32_t index) const
Definition Sensor.hpp:230
SensorList(ob_sensor_list_t *impl)
Definition Sensor.hpp:165
Definition Context.hpp:19
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:117