chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
40 / 40
100.0%
Branches:
42 / 63
66.7%
Functions:
6 / 6, 1 excl
100.0%

scene/tables/products.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <map>
6 #include <memory>
7 #include <mutex>
8 #include <span>
9 #include <string>
10 #include <string_view>
11 #include <vector>
12
13 #include "chrono_batch_render/device/tensor.h"
14 #include "chrono_batch_render/scene/records/products.h"
15 #include "chrono_batch_render/scene/tables/sensor_pipelines.h"
16 #include "chrono_batch_render/scene/tables/storage.h"
17 #include "chrono_batch_render/scene/tables/table.h"
18 #include "chrono_batch_render/stage/structure/structure.h"
19
20 namespace chrono::batch_render {
21
22 class Scene;
23
24 enum class RenderEntry : uint32_t {
25 MinimalData,
26 MinimalDisplayColor,
27 MinimalTextureDiffuse,
28 MinimalFull,
29 RealTime,
30 RealTimeBands,
31 Lidar,
32 Radar,
33 };
34
35 inline constexpr uint32_t kRenderEntryCount = 8;
36
37 inline constexpr const char* kRenderEntryNames[kRenderEntryCount] = {"RenderMinimalData",
38 "RenderMinimalDisplayColor",
39 "RenderMinimalTextureDiffuse",
40 "RenderMinimalFull",
41 "RenderRealTime",
42 "RenderRealTimeBands",
43 "RenderLidar",
44 "RenderRadar"};
45
46 enum class PointChannel : uint32_t {
47 Coordinates,
48 Distance,
49 Intensity,
50 StableId,
51 Emitter,
52 Firing,
53 Echo,
54 RadialVelocity,
55 InstanceId,
56 RadialVelocityVector,
57 };
58
59 struct PointChannelInfo {
60 std::string_view name;
61 device::DType type;
62 int64_t lanes;
63 };
64
65 inline constexpr PointChannelInfo kPointChannels[] = {
66 {"Coordinates", device::DType::Float32, 3},
67 {"Distance", device::DType::Float32, 1},
68 {"Intensity", device::DType::Float32, 1},
69 {"StableId", device::DType::UInt32, 4},
70 {"Emitter", device::DType::UInt32, 1},
71 {"Firing", device::DType::UInt32, 1},
72 {"Echo", device::DType::UInt32, 1},
73 {"RadialVelocity", device::DType::Float32, 1},
74 {"InstanceId", device::DType::Int64, 1},
75 {"RadialVelocityVector", device::DType::Float32, 3}};
76
77 struct ResolvedVar {
78 210 uint32_t prim = kNoPrim;
79 210 std::string path;
80 210 RenderVarSource source = RenderVarSource::LdrColor;
81 210 FrameOfReference frame = FrameOfReference::Sensor;
82 210 device::DType type = device::DType::UInt8;
83 210 std::vector<int64_t> shape;
84 210 std::vector<PointChannel> channels;
85 210 std::string output;
86 210 bool tap = false;
87 210 bool semantic = false;
88
89
10/20
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 210 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 210 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 210 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 210 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 210 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 210 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 210 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 210 times.
210 bool operator==(const ResolvedVar&) const = default;
90 };
91
92 struct ProductShape {
93 219 SchemaId sensor = SchemaId::None;
94 217 std::vector<uint32_t> sensors;
95 215 uint32_t width = 0;
96 211 uint32_t height = 0;
97 210 uint32_t returns = 0;
98 210 uint32_t channels = 0;
99 208 float frameRate = 0;
100 206 float startTime = 0;
101 206 float missDistance = 0;
102 206 std::vector<ResolvedVar> vars;
103 199 std::vector<std::string> overlays;
104 196 Token taxonomy;
105 196 RenderEntry entry = RenderEntry::MinimalData;
106 190 uint32_t pipeline = kNoPrim;
107 190 std::vector<sensor_pipeline::SignalLayout> layouts;
108 187 bool semantic = false;
109 187 std::string error;
110
111
27/34
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 215 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 211 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 210 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 210 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 208 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 206 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 206 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 206 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 199 times.
✓ Branch 20 taken 7 times.
✓ Branch 22 taken 196 times.
✓ Branch 23 taken 3 times.
✓ Branch 24 taken 196 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 190 times.
✓ Branch 27 taken 6 times.
✓ Branch 28 taken 190 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 187 times.
✓ Branch 32 taken 3 times.
✓ Branch 33 taken 187 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 187 times.
219 bool operator==(const ProductShape&) const = default;
112 };
113
114 808 struct ResolvedProduct : ProductShape {
115 uint32_t prim = kNoPrim;
116 ProductRecord record{};
117 uint64_t version = 0;
118 };
119
120 class ProductTable : public RenderTable {
121 public:
122 353 ProductTable(Scene& scene, Structure& structure, const SensorPipelineTable& pipelines)
123
1/1
✓ Branch 1 taken 353 times.
353 : m_scene(scene), m_structure(structure), m_pipelines(pipelines) {}
124
125 928 std::string_view Name() const override {
126 928 return "products";
127 }
128
129 std::span<const ColumnRef> Inputs() const override;
130
131 353 std::span<const TableId> TableOutputs() const override {
132 353 static constexpr TableId kTables[] = {TableId::Products};
133 353 return kTables;
134 }
135
136 void Run(const ChangeSet& changes, TableVersions& versions) override;
137 void Describe(RenderTables& tables) const override;
138
139 928 void Hold(std::vector<Ref<const RefCounted>>& held) const override {
140
4/8
✓ Branch 0 taken 928 times.
✓ Branch 1 taken 928 times.
✓ Branch 2 taken 927 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1856 HoldBuffers(held, {m_records.Buffer()});
141 1856 }
142
143 std::shared_ptr<const ResolvedProduct> Find(uint32_t prim) const;
144 std::vector<std::shared_ptr<const ResolvedProduct>> Products() const;
145
146 private:
147 ResolvedProduct Resolve(uint32_t prim) const;
148 void Resolve();
149
150 Scene& m_scene;
151 Structure& m_structure;
152 const SensorPipelineTable& m_pipelines;
153 uint64_t m_pipelineVersion = 0;
154 mutable std::mutex m_mutex;
155 std::map<uint32_t, std::shared_ptr<const ResolvedProduct>> m_products;
156 RecordTable<ProductRecord> m_records{"product records"};
157 uint64_t m_versions = 0;
158 uint64_t m_seen = 0;
159 };
160
161 }
162