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 | 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 | 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 | 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 | 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 |