OrbbecSDK 2.10.6
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
ApplicationConfig.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "Device.hpp"
7#include "StreamProfile.hpp"
8#include "Error.hpp"
11
12#include <memory>
13#include <stdexcept>
14#include <vector>
15
16namespace ob {
17
19public:
21
23 return sensorType_;
24 }
25
26 void enableStream(bool enabled) {
27 streamEnabled_ = enabled;
28 }
29
30 bool isStreamEnabled() const {
31 return streamEnabled_;
32 }
33
34 void setStreamProfile(const std::shared_ptr<StreamProfile> &profile) {
35 streamProfile_ = profile;
36 }
37
38 std::shared_ptr<StreamProfile> streamProfile() const {
39 return streamProfile_;
40 }
41
42 void enableUndistortion(bool enabled) {
43 undistortionEnabled_ = enabled;
44 }
45
46 bool isUndistortionEnabled() const {
47 return undistortionEnabled_;
48 }
49
50private:
51 OBSensorType sensorType_{ OB_SENSOR_UNKNOWN };
52 bool streamEnabled_ = { false };
53 std::shared_ptr<StreamProfile> streamProfile_;
54 bool undistortionEnabled_ = { false };
55};
56
58public:
59 void enable(bool enabled) {
60 enabled_ = enabled;
61 }
62
63 bool isEnabled() const {
64 return enabled_;
65 }
66
68 format_ = format;
69 }
70
71 OBFormat format() const {
72 return format_;
73 }
74
75 void setDecimationFactor(int32_t factor) {
76 decimationFactor_ = factor;
77 }
78
79 int32_t decimationFactor() const {
80 return decimationFactor_;
81 }
82
84 alignMode_ = mode;
85 }
86
88 return alignMode_;
89 }
90
91 void enableFrameSync(bool enabled) {
92 frameSync_ = enabled;
93 }
94
95 bool isFrameSyncEnabled() const {
96 return frameSync_;
97 }
98
99 void setAllFrameTypeRequired(bool enabled) {
100 allFrameTypeRequired_ = enabled;
101 }
102
104 return allFrameTypeRequired_;
105 }
106
107 void enableMatchTargetResolution(bool enabled) {
108 matchTargetResolution_ = enabled;
109 }
110
112 return matchTargetResolution_;
113 }
114
115private:
116 bool enabled_{ false };
117 OBFormat format_{ OB_FORMAT_POINT };
118 int32_t decimationFactor_{ 0 };
119 OBAlignMode alignMode_{ ALIGN_DISABLE };
120 bool frameSync_{ false };
121 bool allFrameTypeRequired_{ false };
122 bool matchTargetResolution_{ false };
123};
124
126public:
127 void enable(bool enabled) {
128 enabled_ = enabled;
129 }
130
131 bool isEnabled() const {
132 return enabled_;
133 }
134
135 void enableIR(bool enabled) {
136 enableIRforHDR_ = enabled;
137 }
138
139 bool isIREnabled() const {
140 return enableIRforHDR_;
141 }
142
143private:
144 bool enabled_{ false };
145 bool enableIRforHDR_{ true };
146};
147
149public:
150 void enable(bool enabled) {
151 enabled_ = enabled;
152 }
153
154 bool isEnabled() const {
155 return enabled_;
156 }
157
159 config_ = config;
160 }
161
163 return config_;
164 }
165
166private:
167 bool enabled_{ false };
169};
170
172public:
173 static bool isSupported(const std::shared_ptr<Device> &device) {
174 ob_error *error = nullptr;
175 auto ret = ob_device_is_application_config_supported(device->getImpl(), &error);
176 Error::handle(&error);
177 return ret;
178 }
179
180 static std::shared_ptr<ApplicationConfig> get(const std::shared_ptr<Device> &device) {
181 ob_error *error = nullptr;
182 auto handle = ob_device_get_application_config(device->getImpl(), &error);
183 Error::handle(&error);
184 return std::make_shared<ApplicationConfig>(handle);
185 }
186
191 static std::shared_ptr<ApplicationConfig> get(const std::shared_ptr<Device> &device, const std::string &presetName) {
192 ob_error *error = nullptr;
193 auto handle = ob_device_get_application_config_by_preset(device->getImpl(), presetName.c_str(), &error);
194 Error::handle(&error);
195 if(!handle) {
196 return nullptr;
197 }
198 return std::make_shared<ApplicationConfig>(handle);
199 }
200
202
204 if(handle_) {
205 ob_error *error = nullptr;
206 ob_delete_application_config(handle_, &error);
207 Error::handle(&error, false);
208 }
209 }
210
212 return handle_;
213 }
214
215 void reset() {
216 ob_error *error = nullptr;
217 ob_application_config_reset(handle_, &error);
218 Error::handle(&error);
219 }
220
221 std::vector<std::shared_ptr<ApplicationSensorConfig>> sensors() const {
222 std::vector<std::shared_ptr<ApplicationSensorConfig>> result;
223 ob_error *error = nullptr;
224 auto count = ob_application_config_get_count(handle_, OB_APP_CONFIG_SENSORS, &error);
225 Error::handle(&error);
226 for(uint32_t i = 0; i < count; ++i) {
227 auto sensorType = static_cast<OBSensorType>(ob_application_config_get_int(handle_, OB_APP_CONFIG_ARRAY_ITEM(OB_APP_CONFIG_SENSOR_TYPE, i), &error));
228 Error::handle(&error);
229 auto sensorConfig = std::make_shared<ApplicationSensorConfig>(sensorType);
230 // enable
232 Error::handle(&error);
233 sensorConfig->enableStream(enable);
234 // profile
236 Error::handle(&error);
237 sensorConfig->setStreamProfile(StreamProfileFactory::create(profile));
238 result.emplace_back(sensorConfig);
239 // undistortion
241 Error::handle(&error, false); // optional
242 sensorConfig->enableUndistortion(enable);
243 }
244 return result;
245 }
246
247 void setSensors(const std::vector<std::shared_ptr<ApplicationSensorConfig>> &sensors) {
248 for(const auto &sensor: sensors) {
249 setSensor(sensor);
250 }
251 }
252
253 void setSensor(const std::shared_ptr<ApplicationSensorConfig> &sensor) {
254 if(!sensor) {
255 return;
256 }
257 ob_error *error = nullptr;
258 auto index = sensorIndex(sensor->sensorType());
259 // enable
260 ob_application_config_set_bool(handle_, OB_APP_CONFIG_ARRAY_ITEM(OB_APP_CONFIG_STREAM_ENABLED, index), sensor->isStreamEnabled(), &error);
261 Error::handle(&error);
262 // profile
263 auto profile = sensor->streamProfile();
264 if(!profile) {
265 throw std::runtime_error("ApplicationSensorConfig: stream profile must not be null");
266 }
268 Error::handle(&error);
269 // undistortion
270 ob_application_config_set_bool(handle_, OB_APP_CONFIG_ARRAY_ITEM(OB_APP_CONFIG_UNDISTORTION_ENABLED, index), sensor->isUndistortionEnabled(), &error);
271 Error::handle(&error);
272 }
273
274 std::shared_ptr<ApplicationDevDecimationConfig> deviceDecimation() const {
275 auto cfg = std::make_shared<ApplicationDevDecimationConfig>();
276 ob_error *error = nullptr;
277 // enable
279 Error::handle(&error);
280 cfg->enable(enable);
281 if(enable) {
282 // Preset resolution
285 Error::handle(&error);
286 cfg->setPresetResolutionConfig(config);
287 }
288 return cfg;
289 }
290
291 void setDeviceDecimation(const std::shared_ptr<ApplicationDevDecimationConfig> &config) {
292 if(!config) {
293 return;
294 }
295 ob_error *error = nullptr;
297 Error::handle(&error);
298 auto presetResConfig = config->presetResolutionConfig();
299 ob_application_config_set_struct(handle_, OB_APP_CONFIG_ITEM(OB_APP_CONFIG_DEVICE_DECIMATION), &presetResConfig, sizeof(presetResConfig), &error);
300 Error::handle(&error);
301 }
302
303 std::shared_ptr<ApplicationPointCloudConfig> pointCloud() const {
304 auto cfg = std::make_shared<ApplicationPointCloudConfig>();
305 ob_error *error = nullptr;
306 // enable
308 Error::handle(&error);
309 cfg->enable(enable);
310 // format
312 Error::handle(&error);
313 cfg->setFormat(static_cast<OBFormat>(value));
314 // decimation factor
316 Error::handle(&error);
317 cfg->setDecimationFactor(value);
318 // align mode
320 Error::handle(&error);
321 cfg->setAlignMode(static_cast<OBAlignMode>(value));
322 // frame sync
324 Error::handle(&error);
325 cfg->enableFrameSync(enable);
326 // frame aggregate mode
328 Error::handle(&error);
329 cfg->setAllFrameTypeRequired(enable);
330 // match target resolution
332 Error::handle(&error);
333 cfg->enableMatchTargetResolution(enable);
334 return cfg;
335 }
336
337 void setPointCloud(const std::shared_ptr<ApplicationPointCloudConfig> &config) {
338 if(!config) {
339 return;
340 }
341 ob_error *error = nullptr;
343 Error::handle(&error);
344 ob_application_config_set_int(handle_, OB_APP_CONFIG_ITEM(OB_APP_CONFIG_POINTCLOUD_FORMAT), static_cast<int32_t>(config->format()), &error);
345 Error::handle(&error);
347 Error::handle(&error);
348 ob_application_config_set_int(handle_, OB_APP_CONFIG_ITEM(OB_APP_CONFIG_POINTCLOUD_ALIGN_MODE), static_cast<int32_t>(config->alignMode()), &error);
349 Error::handle(&error);
350 ob_application_config_set_bool(handle_, OB_APP_CONFIG_ITEM(OB_APP_CONFIG_POINTCLOUD_FRAME_SYNC), config->isFrameSyncEnabled(), &error);
351 Error::handle(&error);
353 Error::handle(&error);
355 &error);
356 Error::handle(&error);
357 }
358
359 std::shared_ptr<ApplicationHDRMergeConfig> hdrMerge() const {
360 auto cfg = std::make_shared<ApplicationHDRMergeConfig>();
361 ob_error *error = nullptr;
362 // enable
364 Error::handle(&error);
365 cfg->enable(enable);
366 // IR enable
368 Error::handle(&error);
369 cfg->enableIR(enable);
370 return cfg;
371 }
372
373 void setHDRMerge(const std::shared_ptr<ApplicationHDRMergeConfig> &config) {
374 if(!config) {
375 return;
376 }
377 ob_error *error = nullptr;
379 Error::handle(&error);
381 Error::handle(&error);
382 }
383
384private:
385 uint32_t sensorIndex(OBSensorType sensorType) const {
386 ob_error *error = nullptr;
387 auto count = ob_application_config_get_count(handle_, OB_APP_CONFIG_SENSORS, &error);
388 Error::handle(&error);
389 for(uint32_t i = 0; i < count; ++i) {
390 auto current = static_cast<OBSensorType>(ob_application_config_get_int(handle_, OB_APP_CONFIG_ARRAY_ITEM(OB_APP_CONFIG_SENSOR_TYPE, i), &error));
391 Error::handle(&error);
392 if(current == sensorType) {
393 return i;
394 }
395 }
396 throw std::runtime_error("Application sensor config not found");
397 }
398
399 ob_application_config *handle_ = nullptr;
400};
401
402using ApplicationConfigPtr = std::shared_ptr<ApplicationConfig>;
403
404} // namespace ob
OB_EXPORT uint32_t ob_application_config_get_count(const ob_application_config *config, OBAppConfigKey key, ob_error **error)
Get the number of items in an array key.
OB_EXPORT int32_t ob_application_config_get_int(const ob_application_config *config, OBAppConfigItem item, ob_error **error)
Get an int32_t value.
OB_EXPORT void ob_delete_application_config(ob_application_config *config, ob_error **error)
Delete an application configuration object.
OB_EXPORT ob_application_config * ob_device_get_application_config_by_preset(ob_device *device, const char *preset_name, ob_error **error)
Get the application configuration carried by an externally imported preset, by preset name.
OB_EXPORT void ob_application_config_reset(ob_application_config *config, ob_error **error)
Reset an application configuration object to default values.
OB_EXPORT ob_stream_profile * ob_application_config_get_profile(const ob_application_config *config, OBAppConfigItem item, ob_error **error)
Get the stream profile from a sensor item.
OB_EXPORT void ob_application_config_set_profile(ob_application_config *config, OBAppConfigItem item, const ob_stream_profile *profile, ob_error **error)
Set the stream profile for a sensor item.
OB_EXPORT void ob_application_config_set_int(ob_application_config *config, OBAppConfigItem item, int32_t value, ob_error **error)
Set an int32_t value.
OB_EXPORT void ob_application_config_get_struct(const ob_application_config *config, OBAppConfigItem item, void *value, uint32_t valueSize, ob_error **error)
Get a fixed-size SDK structure value.
OB_EXPORT ob_application_config * ob_device_get_application_config(ob_device *device, ob_error **error)
Get the application runtime configuration cache for the device.
OB_EXPORT bool ob_device_is_application_config_supported(ob_device *device, ob_error **error)
Check whether the current device supports application runtime configuration import/export.
OB_EXPORT void ob_application_config_set_struct(ob_application_config *config, OBAppConfigItem item, const void *value, uint32_t valueSize, ob_error **error)
Set a fixed-size SDK structure value.
@ OB_APP_CONFIG_HDR_MERGE_IR_ENABLED
@ OB_APP_CONFIG_POINTCLOUD_ALIGN_MODE
@ OB_APP_CONFIG_DEVICE_DECIMATION
@ OB_APP_CONFIG_POINTCLOUD_ALL_FRAME_TYPE_REQUIRED
@ OB_APP_CONFIG_POINTCLOUD_MATCH_TARGET_RESOLUTION
@ OB_APP_CONFIG_STREAM_PROFILE
@ OB_APP_CONFIG_UNDISTORTION_ENABLED
@ OB_APP_CONFIG_POINTCLOUD_FRAME_SYNC
@ OB_APP_CONFIG_DEVICE_DECIMATION_ENABLED
@ OB_APP_CONFIG_SENSORS
@ OB_APP_CONFIG_POINTCLOUD_FORMAT
@ OB_APP_CONFIG_SENSOR_TYPE
@ OB_APP_CONFIG_STREAM_ENABLED
@ OB_APP_CONFIG_POINTCLOUD_ENABLED
@ OB_APP_CONFIG_POINTCLOUD_DECIMATION_FACTOR
@ OB_APP_CONFIG_HDR_MERGE_ENABLED
#define OB_APP_CONFIG_ARRAY_ITEM(key, index)
OB_EXPORT void ob_application_config_set_bool(ob_application_config *config, OBAppConfigItem item, bool value, ob_error **error)
Set a bool value.
OB_EXPORT bool ob_application_config_get_bool(const ob_application_config *config, OBAppConfigItem item, ob_error **error)
Get a bool value.
#define OB_APP_CONFIG_ITEM(key)
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....
OBSensorType
Enumeration value describing the sensor type.
Definition ObTypes.h:182
@ OB_SENSOR_UNKNOWN
Definition ObTypes.h:183
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:262
@ OB_FORMAT_POINT
Definition ObTypes.h:282
struct ob_application_config_t ob_application_config
Definition ObTypes.h:38
OBAlignMode
Alignment mode.
Definition ObTypes.h:584
@ ALIGN_DISABLE
Definition ObTypes.h:585
The stream profile related type is used to get information such as the width, height,...
std::shared_ptr< ApplicationHDRMergeConfig > hdrMerge() const
void setSensors(const std::vector< std::shared_ptr< ApplicationSensorConfig > > &sensors)
void setHDRMerge(const std::shared_ptr< ApplicationHDRMergeConfig > &config)
std::shared_ptr< ApplicationPointCloudConfig > pointCloud() const
void setDeviceDecimation(const std::shared_ptr< ApplicationDevDecimationConfig > &config)
void setPointCloud(const std::shared_ptr< ApplicationPointCloudConfig > &config)
ob_application_config * handle() const
std::vector< std::shared_ptr< ApplicationSensorConfig > > sensors() const
void setSensor(const std::shared_ptr< ApplicationSensorConfig > &sensor)
static bool isSupported(const std::shared_ptr< Device > &device)
std::shared_ptr< ApplicationDevDecimationConfig > deviceDecimation() const
static std::shared_ptr< ApplicationConfig > get(const std::shared_ptr< Device > &device)
ApplicationConfig(ob_application_config *handle)
static std::shared_ptr< ApplicationConfig > get(const std::shared_ptr< Device > &device, const std::string &presetName)
Get the application config carried by an externally imported preset, by preset name.
const OBPresetResolutionConfig & presetResolutionConfig() const
void setPresetResolutionConfig(const OBPresetResolutionConfig &config)
void setAlignMode(OBAlignMode mode)
void setDecimationFactor(int32_t factor)
void enableMatchTargetResolution(bool enabled)
std::shared_ptr< StreamProfile > streamProfile() const
ApplicationSensorConfig(OBSensorType sensorType)
OBSensorType sensorType() const
void enableUndistortion(bool enabled)
void setStreamProfile(const std::shared_ptr< StreamProfile > &profile)
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
static std::shared_ptr< StreamProfile > create(const ob_stream_profile_t *impl)
std::shared_ptr< ApplicationConfig > ApplicationConfigPtr
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:162