NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/ds3d/dataloader/realsense/realsense_config.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DS3D_DATALOADER_REALSENSE_CONFIG__H
19 #define _DS3D_DATALOADER_REALSENSE_CONFIG__H
20 
21 #include <ds3d/common/common.h>
22 #include <ds3d/common/func_utils.h>
23 
24 #include "ds3d/common/hpp/yaml_config.hpp"
25 
26 namespace ds3d { namespace impl { namespace realsense {
27 
28 constexpr const char* kDepthStream = "depth";
29 constexpr const char* kColorStream = "color";
30 constexpr const char* kPointsStream = "points";
31 
32 struct Config {
34  std::set<std::string> streams;
35  uint32_t framerate = 0;
36  bool alignImage2Depth = false;
37 
38  bool hasDepthStream() const { return streams.count(kDepthStream); }
39  bool hasColorStream() const { return streams.count(kColorStream); }
40  bool hasPointsStream() const { return streams.count(kPointsStream); }
41  bool check()
42  {
43  if (streams.empty()) {
44  streams.emplace(kDepthStream);
45  streams.emplace(kColorStream);
46  }
47  return true;
48  }
49 };
50 
51 inline ErrCode
52 parseConfig(const std::string& content, const std::string& path, Config& config)
53 {
55  config::parseComponentConfig(content, path, config.compConfig),
56  "parse dataloader component content failed");
57 
58  YAML::Node node = YAML::Load(config.compConfig.configBody);
59  auto streams = node["streams"];
60  auto framerate = node["framerate"];
61  auto alignedImage2Depth = node["aligned_image_to_depth"];
62 
63  if (streams) {
64  const static std::set<std::string> kValidStreams{kDepthStream, kColorStream, kPointsStream};
65  auto toString = [&]() {
66  std::string r("[");
67  for (auto& i : kValidStreams) {
68  r += i + ",";
69  }
70  return r + "]";
71  };
72  std::vector<std::string> strStreams = streams.as<std::vector<std::string>>();
73  for (auto& each : strStreams) {
75  kValidStreams.count(each), ErrCode::kConfig,
76  "stream must choose from " + toString());
77  config.streams.emplace(each);
78  }
79  }
80  if (framerate) {
81  uint32_t fr = framerate.as<uint32_t>();
82  config.framerate = fr;
83  }
84  if (alignedImage2Depth) {
85  config.alignImage2Depth = alignedImage2Depth.as<bool>();
86  }
87  return ErrCode::kGood;
88 }
89 
90 }}} // namespace ds3d::impl::realsense
91 
92 #endif // _DS3D_DATALOADER_REALSENSE_CONFIG__H
ds3d::impl::realsense::Config::hasPointsStream
bool hasPointsStream() const
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:40
ds3d::impl::realsense::Config
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:32
ds3d::impl::realsense::kDepthStream
constexpr const char * kDepthStream
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:28
ds3d::impl::realsense::Config::alignImage2Depth
bool alignImage2Depth
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:36
ds3d::ErrCode::kGood
@ kGood
ds3d::impl::realsense::Config::hasDepthStream
bool hasDepthStream() const
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:38
ds3d::config::parseComponentConfig
ErrCode parseComponentConfig(const std::string &yamlComp, const std::string &path, ComponentConfig &config)
Definition: includes/ds3d/common/hpp/yaml_config.hpp:57
ds3d::ErrCode
ErrCode
Definition: includes/ds3d/common/common.h:47
ds3d::impl::realsense::Config::streams
std::set< std::string > streams
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:34
ds3d::impl::realsense::kColorStream
constexpr const char * kColorStream
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:29
ds3d::impl::realsense::Config::check
bool check()
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:41
ds3d::ErrCode::kConfig
@ kConfig
ds3d::impl::realsense::kPointsStream
constexpr const char * kPointsStream
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:30
ds3d::config::ComponentConfig::configBody
std::string configBody
Definition: includes/ds3d/common/config.h:48
ds3d::impl::realsense::parseConfig
ErrCode parseConfig(const std::string &content, const std::string &path, Config &config)
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:52
DS3D_ERROR_RETURN
#define DS3D_ERROR_RETURN(code, fmt,...)
Definition: includes/ds3d/common/defines.h:77
ds3d::impl::realsense::Config::framerate
uint32_t framerate
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:35
ds3d::config::ComponentConfig
Definition: includes/ds3d/common/config.h:38
ds3d::impl::realsense::Config::hasColorStream
bool hasColorStream() const
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:39
DS3D_THROW_ERROR
#define DS3D_THROW_ERROR(statement, code, msg)
Definition: includes/ds3d/common/defines.h:83
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
ds3d::impl::realsense::Config::compConfig
config::ComponentConfig compConfig
Definition: sources/libs/ds3d/dataloader/realsense/realsense_config.h:33