NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-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_GLPROCESS_GL_LIDAR_RENDER_CTX_H
19 #define DS3D_GLPROCESS_GL_LIDAR_RENDER_CTX_H
20 
21 #include "ds3d/common/common.h"
22 #include "ds3d/common/hpp/datamap.hpp"
23 #include "ds3d/common/hpp/frame.hpp"
24 
25 #include "glprocess/gl_program.h"
26 #include "glprocess/gl_buf.h"
27 #include "glprocess/window.h"
28 #include "glprocess/gl_render_ctx.h"
29 #include "glprocess/gl_text.h"
30 #include "glprocess/gl_point_cloud_render_ctx.h"
31 #include "ds3d/glprocess/gl_cuda_utils.h"
32 
33 namespace ds3d { namespace gl {
34 
35 
36 static constexpr const uint32_t kDefaultMaxPoints = 2048000;
37 static constexpr const uint32_t kDefaultMax3DBboxes = 2048;
38 
40  uint32_t elementSize = 4;
41  std::string lidarDataKey = kLidarXYZI;
43  vec3b lidarColor = {{0, 255, 0}}; // RGB
44  bool enableLabel = false;
45  // projecting lidar to image need image width/height settings
47  uint32_t imageWidth = 0;
48  uint32_t imageHeight = 0;
49  std::string intrinsicsMatKey;
50  std::string extrinsicsMatKey;
51  // render range in xyz axes, default range [-2^20, - 2^20]
52  vec2f xyzRange[3] = {
53  {{-1048576.0f, 1048576.0f}}, {{-1048576.0f, 1048576.0f}}, {{-1048576.0f, 1048576.0f}}};
54  bool xRangeEnabled = false;
55  bool yRangeEnabled = false;
56  bool zRangeEnabled = false;
57  float lineWidth = 1.0f;
59 };
60 
62 public:
64  ~LidarRenderCtxImpl() = default;
65 
66  ErrCode initResource() override;
67  ErrCode uploadData(GuardDataMap datamap) override;
68  ErrCode draw(GuardDataMap datamap) override;
69  ErrCode deinitResource() override;
70  void setElementSize(uint32_t elements) override
71  {
72  DS_ASSERT(elements == 3 || elements == 4);
73  _elementSize = elements;
74  }
75  void setPointsDataKey(const std::string& key) override { _lidarDataName = key; }
76  void set3DBboxKey(const std::string& key) override { _lidarBboxName = key; }
77 
78  void setLidarDataColor(const vec3b& color) override
79  {
80  _pointColor = {{color.x / 255.0f, color.y / 255.0f, color.z / 255.0f, 1.0f}};
81  }
82 
83  void setMaxPoints(uint32_t num) override { _maxPoints = num; }
84  void setMaxBboxes(uint32_t num) override { _maxBboxes = num; }
85  void enableLabels(bool flag) override { _enableLabels = flag; }
86 
87 private:
88  ErrCode configure(const char* yamlConfig, uint32_t size) override;
89  ErrCode initVertexBuffer();
90  ErrCode initVAO();
91  ErrCode initTextResource();
92  uint32_t elementSize() const { return _elementSize; }
93 
94  ErrCode uploadLidarData(FrameGuard& lidarData);
95  ErrCode uploadLidarBboxData(FrameGuard& lidarRawBbox);
96  ErrCode uploadTransformMat(GuardDataMap datamap);
97  ErrCode generateBboxBufs(
98  const Lidar3DBbox* bbox, uint32_t num, std::vector<vec3f>& boxBuf,
99  std::vector<vec4f>& colorBuf);
100  ErrCode uploadLabelImageBufs(const Lidar3DBbox* bbox, uint32_t num);
101  ErrCode drawLabels();
102  mat4f getMvp();
103 
104  LidarRenderConfig _conf;
105  NormalViewPort _normalizedView;
106  bool _confParsed = false;
107 
108  std::unique_ptr<Program> _pointProgram;
109  std::unique_ptr<Program> _bboxProgram;
110  std::unique_ptr<Program> _textProgram;
111  Ptr<VertexBuf> _pointsBuf;
112  std::unique_ptr<VertexArray> _pointsVao;
113  Ptr<CudaVertexBuf> _cuPointsGlBuf;
114 
115  std::unique_ptr<VertexBuf> _bboxVertBuf;
116  std::unique_ptr<VertexBuf> _bboxColorBuf;
117  std::unique_ptr<VertexArray> _bboxVao;
118 
119  std::unique_ptr<VertexBuf> _textVertexBuf;
120  std::unique_ptr<VertexBuf> _textUvBuf;
121  std::unique_ptr<VertexArray> _textVao;
122  std::vector<std::unique_ptr<Texture>> _textImages;
123  uint32_t _labelCount = 0;
124 
125  bool _enableLabels = false;
126  int _pointAttrib = -1;
127  uint32_t _maxPoints = kDefaultMaxPoints;
128  uint32_t _maxBboxes = kDefaultMax3DBboxes;
129  vec4f _pointColor{{0, 1.0, 0, 1.0f}};
130  uint32_t _elementSize = 4; // XYZI by default
131  std::string _lidarDataName = kLidarXYZI;
132  std::string _lidarBboxName = kLidar3DBboxRawData;
133 
134  mat4f _frameExtrinsicMat = eye4x4();
135  mat4f _frameIntrisicMat = eye4x4();
136 };
137 
138 }} // namespace ds3d::gl
139 
140 
141 #endif // DS3D_GLPROCESS_GL_LIDAR_RENDER_CTX_H
ds3d::gl::LidarRenderConfig::intrinsicsMatKey
std::string intrinsicsMatKey
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:49
ds3d::gl::LidarRenderConfig::enableLabel
bool enableLabel
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:44
ds3d::gl::LidarRenderConfig::lidarBboxKey
std::string lidarBboxKey
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:42
ds3d::gl::LidarRenderCtxImpl::setMaxPoints
void setMaxPoints(uint32_t num) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:83
ds3d::gl::LidarRenderConfig::elementSize
uint32_t elementSize
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:40
ds3d::gl::LidarRenderConfig::imageWidth
uint32_t imageWidth
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:47
ds3d::gl::LidarRenderCtxImpl::initResource
ErrCode initResource() override
ds3d::__xyz
Definition: includes/ds3d/common/idatatype.h:39
ds3d::gl::LidarRenderConfig::lidarColor
vec3b lidarColor
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:43
ds3d::gl::LidarRenderConfig::lineWidth
float lineWidth
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:57
ds3d::gl::mat4f
std::vector< vec4f > mat4f
Definition: sources/libs/ds3d/glprocess/gl_common.h:60
ds3d::kLidar3DBboxRawData
static constexpr const char * kLidar3DBboxRawData
get array of Lidar3DBbox from FrameGuard [N, sizeof(Lidar3DBbox)]
Definition: includes/ds3d/common/common.h:119
ds3d::gl::kTextDefaultFontSize
static const int kTextDefaultFontSize
Definition: sources/libs/ds3d/glprocess/gl_text.h:31
ds3d::gl::LidarRenderConfig::fontSize
uint32_t fontSize
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:58
ds3d::gl::LidarRenderConfig::lidarDataKey
std::string lidarDataKey
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:41
ds3d::gl::LidarRenderConfig::yRangeEnabled
bool yRangeEnabled
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:55
ds3d::__xyz::z
T z
Definition: includes/ds3d/common/idatatype.h:42
ds3d::gl::LidarRenderCtxImpl::draw
ErrCode draw(GuardDataMap datamap) override
ds3d::FrameType::kLidarXYZI
@ kLidarXYZI
ds3d::gl::kDefaultMax3DBboxes
static constexpr const uint32_t kDefaultMax3DBboxes
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:37
ds3d::gl::LidarRenderConfig::enableLidarTo2DImageProject
bool enableLidarTo2DImageProject
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:46
ds3d::gl::LidarRenderCtxImpl::setMaxBboxes
void setMaxBboxes(uint32_t num) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:84
ds3d::ErrCode
ErrCode
Definition: includes/ds3d/common/common.h:47
ds3d::gl::LidarRenderConfig
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:39
ds3d::GuardDataT
Definition: includes/ds3d/common/hpp/obj.hpp:335
ds3d::gl::LidarRenderConfig::zRangeEnabled
bool zRangeEnabled
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:56
ds3d::gl::BaseRenderConfig
base config for all renders layout: [0, 0, 1280, 720] color_clear: True
Definition: sources/libs/ds3d/glprocess/gl_render_base_priv.h:65
ds3d::gl::LidarRenderConfig::extrinsicsMatKey
std::string extrinsicsMatKey
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:50
ds3d::__xyz::y
T y
Definition: includes/ds3d/common/idatatype.h:42
ds3d::gl::LidarRenderCtxImpl::setPointsDataKey
void setPointsDataKey(const std::string &key) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:75
ds3d::gl::LidarRenderConfig::xyzRange
vec2f xyzRange[3]
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:52
ds3d::gl::LidarRenderCtxImpl::setLidarDataColor
void setLidarDataColor(const vec3b &color) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:78
ds3d::gl::LidarRenderCtxImpl
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:61
ds3d::gl::kDefaultMaxPoints
static constexpr const uint32_t kDefaultMaxPoints
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:36
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
ds3d::gl::PointCloudRenderCtxImpl
Definition: sources/libs/ds3d/glprocess/gl_point_cloud_render_ctx.h:41
ds3d::gl::LidarRenderConfig::xRangeEnabled
bool xRangeEnabled
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:54
ds3d::gl::LidarRenderCtxImpl::deinitResource
ErrCode deinitResource() override
ds3d::gl::LidarRenderCtxImpl::setElementSize
void setElementSize(uint32_t elements) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:70
ds3d::gl::LidarRenderCtxImpl::set3DBboxKey
void set3DBboxKey(const std::string &key) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:76
ds3d::gl::LidarRenderCtxImpl::enableLabels
void enableLabels(bool flag) override
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:85
ds3d::__xy
Definition: includes/ds3d/common/idatatype.h:47
ds3d::gl::LidarRenderCtxImpl::LidarRenderCtxImpl
LidarRenderCtxImpl()
ds3d::gl::LidarRenderCtxImpl::~LidarRenderCtxImpl
~LidarRenderCtxImpl()=default
ds3d::Ptr
ShrdPtr< T > Ptr
Definition: includes/ds3d/common/hpp/obj.hpp:37
ds3d::__xyz::x
T x
Definition: includes/ds3d/common/idatatype.h:42
ds3d::GuardDataMap
Definition: includes/ds3d/common/hpp/datamap.hpp:27
ds3d::__xyzw
Definition: includes/ds3d/common/idatatype.h:31
ds3d::gl::LidarRenderConfig::imageHeight
uint32_t imageHeight
Definition: sources/libs/ds3d/glprocess/gl_lidar_render_ctx.h:48
ds3d::gl::eye4x4
mat4f eye4x4()
Definition: sources/libs/ds3d/glprocess/gl_helper.h:32
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
ds3d::Lidar3DBbox
Object 3D bounding box description.
Definition: includes/ds3d/common/ds3d_analysis_datatype.h:47
DS_ASSERT
#define DS_ASSERT(...)
Definition: includes/ds3d/common/defines.h:36
ds3d::gl::LidarRenderCtxImpl::uploadData
ErrCode uploadData(GuardDataMap datamap) override