NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/ds3d/datarender/gl3d/render_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_DATARENDER_GL3D_RENDER_CONFIG__H
19 #define _DS3D_DATARENDER_GL3D_RENDER_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 render {
27 
28 constexpr uint32_t kDefaultWidth = 1280;
29 constexpr uint32_t kDefaultHeight = 720;
30 constexpr float kMinDepth = 0.3f;
31 constexpr float kMaxDepth = 5.0f;
32 
33 constexpr const char* kDepthStream = "depth";
34 constexpr const char* kColorStream = "color";
35 constexpr const char* kPointStream = "points";
36 constexpr const char* kLidarStream = "lidardata";
37 
38 static vec3b kDefaultMinDepthColor{{255, 255, 0}};
39 static vec3b kDefaultMaxDepthColor{{0, 0, 0}};
40 
41 struct Config {
43  std::set<std::string> streams;
44  uint32_t width = kDefaultWidth;
45  uint32_t height = kDefaultHeight;
46  std::string title = "data-render";
47  bool block = false;
48 
49  bool hasDepthStream() const { return streams.count(kDepthStream); }
50  bool hasColorStream() const { return streams.count(kColorStream); }
51  bool hasPointsStream() const { return streams.count(kPointStream); }
52 
53  bool check()
54  {
55  if (streams.empty()) {
56  streams.emplace(kDepthStream);
57  streams.emplace(kColorStream);
58  }
59  if (!width) {
61  }
62  if (!height) {
64  }
65 
66  return true;
67  }
68 };
69 
70 struct DepthConfig : public Config {
75 };
76 
77 struct PointsConfig : public Config {
78  vec3f viewPosition{{0.0f, 0.0f, 0.0f}};
79  vec3f viewTarget{{0.0f, 0.0f, -1.0f}};
80  vec3f viewUp{{0.0f, 1.0f, 0.0f}};
81  float near = 0.3f;
82  float far = 10.0f;
83  float fov = 60.0f; // angle degree
84  bool coordYOpposite = true;
85  bool positiveZOnly = false;
86 };
87 
88 struct LidarConfig : public PointsConfig {
89  uint32_t elementSize = 4;
90  std::string lidarDataKey = kLidarXYZI;
92  vec3b lidarColor = {{0, 255, 0}}; // RGB
93  bool enableLabel = false;
94 };
95 
96 inline ErrCode
97 parseBaseConfig(const std::string& content, const std::string& path, Config& config)
98 {
100  config::parseComponentConfig(content, path, config.compConfig),
101  "parse dataloader component content failed");
102 
103  YAML::Node node = YAML::Load(config.compConfig.configBody);
104  auto streams = node["streams"];
105  auto yWidth = node["width"];
106  auto yHeight = node["height"];
107  auto yTitle = node["title"];
108  auto yBlock = node["block"];
109 
110  if (streams) {
111  const static std::set<std::string> kValidStreams{
113  auto toString = [&]() {
114  std::string r("[");
115  for (auto& i : kValidStreams) {
116  r += i + ",";
117  }
118  return r + "]";
119  };
120  std::vector<std::string> strStreams = streams.as<std::vector<std::string>>();
121  for (auto& each : strStreams) {
123  kValidStreams.count(each), ErrCode::kConfig,
124  "stream must choose from " + toString());
125  config.streams.emplace(each);
126  }
127  }
128  if (yWidth) {
129  config.width = yWidth.as<uint32_t>();
130  }
131  if (yHeight) {
132  config.height = yHeight.as<uint32_t>();
133  }
134 
135  if (yTitle) {
136  config.title = yTitle.as<std::string>();
137  }
138  if (yBlock) {
139  config.block = yBlock.as<bool>();
140  }
141  return ErrCode::kGood;
142 }
143 
144 inline ErrCode
145 parseDepthColorConfig(const std::string& content, const std::string& path, DepthConfig& config)
146 {
148  parseBaseConfig(content, path, config), "paser datarender config base failed.");
149  YAML::Node node = YAML::Load(config.compConfig.configBody);
150  auto yminDepth = node["min_depth"];
151  auto ymaxDepth = node["max_depth"];
152  auto yMinDepthColor = node["min_depth_color"];
153  auto yMaxDepthColor = node["max_depth_color"];
154 
155  if (yminDepth) {
156  config.minDepth = yminDepth.as<float>();
157  }
158  if (ymaxDepth) {
159  config.maxDepth = ymaxDepth.as<float>();
160  }
161  if (yMinDepthColor) {
162  auto color = yMinDepthColor.as<std::vector<uint32_t>>();
164  color.size() >= 3, ErrCode::kConfig, "min_depth_color need RGB 3 values");
165  config.minDepthColor.x = color[0];
166  config.minDepthColor.y = color[1];
167  config.minDepthColor.z = color[2];
168  }
169  if (yMaxDepthColor) {
170  auto color = yMaxDepthColor.as<std::vector<uint32_t>>();
172  color.size() >= 3, ErrCode::kConfig, "max_depth_color need RGB 3 values");
173  config.maxDepthColor.x = color[0];
174  config.maxDepthColor.y = color[1];
175  config.maxDepthColor.z = color[2];
176  }
177  return ErrCode::kGood;
178 }
179 
180 inline ErrCode
181 parsePointsConfig(const std::string& content, const std::string& path, PointsConfig& config)
182 {
184  parseBaseConfig(content, path, config), "paser datarender config base failed.");
185  YAML::Node node = YAML::Load(config.compConfig.configBody);
186  auto yViewPos = node["view_position"];
187  auto yViewTarget = node["view_target"];
188  auto yViewUp = node["view_up"];
189  auto yNear = node["near"];
190  auto yFar = node["far"];
191  auto yFov = node["fov"];
192  auto yCoordYOpp = node["coord_y_opposite"];
193  auto yPositiveZonly = node["positive_z_only"];
194 
195  if (yViewPos) {
196  auto pos = yViewPos.as<std::vector<float>>();
197  DS3D_FAILED_RETURN(pos.size() >= 3, ErrCode::kConfig, "view_position need x,y,z 3 values");
198  config.viewPosition.x = pos[0];
199  config.viewPosition.y = pos[1];
200  config.viewPosition.z = pos[2];
201  }
202  if (yViewTarget) {
203  auto target = yViewTarget.as<std::vector<float>>();
204  DS3D_FAILED_RETURN(target.size() >= 3, ErrCode::kConfig, "view_target need x,y,z 3 values");
205  config.viewTarget.x = target[0];
206  config.viewTarget.y = target[1];
207  config.viewTarget.z = target[2];
208  }
209  if (yViewUp) {
210  auto up = yViewUp.as<std::vector<float>>();
211  DS3D_FAILED_RETURN(up.size() >= 3, ErrCode::kConfig, "view_up need x,y,z 3 values");
212  config.viewUp.x = up[0];
213  config.viewUp.y = up[1];
214  config.viewUp.z = up[2];
215  }
216  if (yNear) {
217  config.near = yNear.as<float>();
218  }
219  if (yFar) {
220  config.far = yFar.as<float>();
221  }
222  if (yFov) {
223  config.fov = yFov.as<float>();
224  }
225  if (yCoordYOpp) {
226  config.coordYOpposite = yCoordYOpp.as<bool>();
227  }
228  if (yPositiveZonly) {
229  config.positiveZOnly = yPositiveZonly.as<bool>();
230  }
231  return ErrCode::kGood;
232 }
233 
234 inline ErrCode
235 parseLidarConfig(const std::string& content, const std::string& path, LidarConfig& config)
236 {
238  parsePointsConfig(content, path, config), "paser datarender config base failed.");
239  YAML::Node node = YAML::Load(config.compConfig.configBody);
240  auto yEleSize = node["element_size"];
241  auto yLidarDataKey = node["lidar_data_key"];
242  auto yLidarBboxKey = node["lidar_bbox_key"];
243  auto yColor = node["lidar_color"];
244  auto ylabel = node["enable_label"];
245 
246  if (yEleSize) {
247  config.elementSize = yEleSize.as<uint32_t>();
248  }
249  if (yLidarDataKey) {
250  config.lidarDataKey = yLidarDataKey.as<std::string>();
251  }
252  if (yLidarBboxKey) {
253  config.lidarBboxKey = yLidarBboxKey.as<std::string>();
254  }
255  if (yColor) {
256  auto color = yColor.as<std::vector<uint32_t>>();
257  size_t size = (color.size() < 3 ? color.size() : 3);
258  for (size_t i = 0; i < size; ++i) {
259  config.lidarColor.data[i] = (uint8_t)color[i];
260  }
261  }
262  if (ylabel) {
263  config.enableLabel = ylabel.as<bool>();
264  }
265 
266  return ErrCode::kGood;
267 }
268 
269 }}} // namespace ds3d::impl::render
270 
271 #endif // _DS3D_DATARENDER_GL3D_RENDER_CONFIG__H
ds3d::impl::render::DepthConfig::minDepthColor
vec3b minDepthColor
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:73
ds3d::impl::render::PointsConfig::viewPosition
vec3f viewPosition
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:78
ds3d::impl::render::kDefaultMaxDepthColor
static vec3b kDefaultMaxDepthColor
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:39
ds3d::impl::render::DepthConfig::maxDepth
float maxDepth
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:72
ds3d::__xyz::data
T data[3]
Definition: includes/ds3d/common/idatatype.h:40
ds3d::impl::render::Config::title
std::string title
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:46
ds3d::impl::render::Config::streams
std::set< std::string > streams
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:43
ds3d::__xyz
Definition: includes/ds3d/common/idatatype.h:39
ds3d::impl::render::PointsConfig::near
float near
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:81
ds3d::impl::render::Config::width
uint32_t width
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:44
ds3d::impl::render::parseLidarConfig
ErrCode parseLidarConfig(const std::string &content, const std::string &path, LidarConfig &config)
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:235
ds3d::impl::render::PointsConfig::positiveZOnly
bool positiveZOnly
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:85
ds3d::kLidar3DBboxRawData
static constexpr const char * kLidar3DBboxRawData
get array of Lidar3DBbox from FrameGuard [N, sizeof(Lidar3DBbox)]
Definition: includes/ds3d/common/common.h:119
ds3d::impl::render::parseBaseConfig
ErrCode parseBaseConfig(const std::string &content, const std::string &path, Config &config)
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:97
ds3d::impl::render::PointsConfig::fov
float fov
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:83
ds3d::__xyz::z
T z
Definition: includes/ds3d/common/idatatype.h:42
ds3d::ErrCode::kGood
@ kGood
ds3d::FrameType::kLidarXYZI
@ kLidarXYZI
ds3d::impl::render::LidarConfig
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:88
ds3d::impl::render::Config::hasColorStream
bool hasColorStream() const
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:50
ds3d::impl::render::Config::block
bool block
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:47
ds3d::impl::render::LidarConfig::enableLabel
bool enableLabel
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:93
ds3d::impl::render::DepthConfig::minDepth
float minDepth
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:71
ds3d::impl::render::kMinDepth
constexpr float kMinDepth
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:30
ds3d::impl::render::parsePointsConfig
ErrCode parsePointsConfig(const std::string &content, const std::string &path, PointsConfig &config)
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:181
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_FAILED_RETURN
#define DS3D_FAILED_RETURN(condition, ret, fmt,...)
Definition: includes/ds3d/common/defines.h:69
ds3d::ErrCode
ErrCode
Definition: includes/ds3d/common/common.h:47
ds3d::impl::render::kDefaultMinDepthColor
static vec3b kDefaultMinDepthColor
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:38
ds3d::impl::render::kDefaultHeight
constexpr uint32_t kDefaultHeight
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:29
ds3d::impl::render::kPointStream
constexpr const char * kPointStream
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:35
ds3d::impl::render::PointsConfig::viewTarget
vec3f viewTarget
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:79
ds3d::impl::render::kDefaultWidth
constexpr uint32_t kDefaultWidth
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:28
ds3d::impl::render::LidarConfig::lidarDataKey
std::string lidarDataKey
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:90
ds3d::__xyz::y
T y
Definition: includes/ds3d/common/idatatype.h:42
ds3d::impl::render::Config::hasDepthStream
bool hasDepthStream() const
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:49
ds3d::impl::render::Config::height
uint32_t height
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:45
ds3d::impl::render::Config::check
bool check()
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:53
ds3d::impl::render::parseDepthColorConfig
ErrCode parseDepthColorConfig(const std::string &content, const std::string &path, DepthConfig &config)
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:145
ds3d::impl::render::kLidarStream
constexpr const char * kLidarStream
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:36
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
ds3d::impl::render::PointsConfig::coordYOpposite
bool coordYOpposite
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:84
ds3d::ErrCode::kConfig
@ kConfig
ds3d::impl::render::Config
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:41
ds3d::config::ComponentConfig::configBody
std::string configBody
Definition: includes/ds3d/common/config.h:48
ds3d::impl::render::kColorStream
constexpr const char * kColorStream
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:34
ds3d::impl::render::LidarConfig::elementSize
uint32_t elementSize
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:89
ds3d::impl::render::DepthConfig
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:70
DS3D_ERROR_RETURN
#define DS3D_ERROR_RETURN(code, fmt,...)
Definition: includes/ds3d/common/defines.h:77
ds3d::__xyz::x
T x
Definition: includes/ds3d/common/idatatype.h:42
ds3d::impl::render::DepthConfig::maxDepthColor
vec3b maxDepthColor
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:74
ds3d::impl::render::Config::hasPointsStream
bool hasPointsStream() const
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:51
ds3d::config::ComponentConfig
Definition: includes/ds3d/common/config.h:38
ds3d::impl::render::LidarConfig::lidarColor
vec3b lidarColor
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:92
ds3d::impl::render::PointsConfig
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:77
ds3d::impl::render::PointsConfig::viewUp
vec3f viewUp
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:80
ds3d::impl::render::PointsConfig::far
float far
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:82
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::render::LidarConfig::lidarBboxKey
std::string lidarBboxKey
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:91
ds3d::impl::render::kDepthStream
constexpr const char * kDepthStream
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:33
ds3d::impl::render::Config::compConfig
config::ComponentConfig compConfig
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:42
ds3d::impl::render::kMaxDepth
constexpr float kMaxDepth
Definition: sources/libs/ds3d/datarender/gl3d/render_config.h:31