chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
2 / 6
33.3%
Branches:
2 / 20
10.0%
Functions:
-
-%

overlay/overlay.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <memory>
6 #include <optional>
7 #include <string>
8 #include <string_view>
9 #include <vector>
10
11 #include "chrono_batch_render/device/operation.h"
12 #include "chrono_batch_render/device/ref.h"
13 #include "chrono_batch_render/device/tensor.h"
14 #include "chrono_batch_render/export.h"
15 #include "chrono_batch_render/overlay/kernels/style.h"
16 #include "chrono_batch_render/stage/schema/ids.h"
17 #include "chrono_batch_render/stage/schema/types.h"
18 #include "chrono_batch_render/util/span.h"
19
20 namespace chrono::batch_render {
21
22 struct CHRONO_BATCH_RENDER_API OverlayStyle {
23 Float4 color = {1, 1, 1, 1};
24 float width = 2;
25 float size = 8;
26 MarkerShape marker = MarkerShape::Circle;
27 OverlayDepth depth = OverlayDepth::Test;
28 uint32_t world = kGlobalWorld;
29 uint32_t anchor = kNoPrim;
30 Float4 background = {0, 0, 0, 0.55f};
31 Float4 halo = {0, 0, 0, 0};
32 Float2 align = {0, 0.5f};
33 float dash = 0;
34 float gap = 0;
35 OverlayUnits units = OverlayUnits::Pixels;
36 bool screenSized = false;
37 bool facing = false;
38 bool pickable = true;
39 uint32_t id = 0;
40 std::optional<Float2> screen;
41 };
42
43
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ struct CHRONO_BATCH_RENDER_API ScreenPlacement {
44 Float2 at;
45 Float2 offset;
46 std::optional<Float2> align;
47
48 Float2 Alignment() const;
49 };
50
51 ✗ struct CHRONO_BATCH_RENDER_API OverlayNumberFormat {
52 std::string prefix;
53 std::string suffix;
54 uint32_t decimals = 2;
55 };
56
57 struct CHRONO_BATCH_RENDER_API OverlayLines {
58 device::Tensor points;
59 device::Tensor ends;
60 device::Tensor colors;
61 device::Tensor widths;
62 device::Tensor worlds;
63 device::Tensor itemCount;
64 OverlayStyle style;
65 std::shared_ptr<const void> owner;
66 };
67
68 struct CHRONO_BATCH_RENDER_API OverlayMarkers {
69 device::Tensor points;
70 device::Tensor colors;
71 device::Tensor sizes;
72 device::Tensor worlds;
73 device::Tensor itemCount;
74 OverlayStyle style;
75 std::shared_ptr<const void> owner;
76 };
77
78 struct CHRONO_BATCH_RENDER_API OverlayBoxes {
79 device::Tensor points;
80 device::Tensor halfExtents;
81 device::Tensor orientations;
82 device::Tensor colors;
83 device::Tensor widths;
84 device::Tensor worlds;
85 device::Tensor itemCount;
86 OverlayStyle style;
87 std::shared_ptr<const void> owner;
88 };
89
90 struct CHRONO_BATCH_RENDER_API OverlaySpheres {
91 device::Tensor points;
92 device::Tensor radii;
93 device::Tensor colors;
94 device::Tensor widths;
95 device::Tensor worlds;
96 device::Tensor itemCount;
97 OverlayStyle style;
98 std::shared_ptr<const void> owner;
99 };
100
101 struct CHRONO_BATCH_RENDER_API OverlayCircles {
102 device::Tensor points;
103 device::Tensor normals;
104 device::Tensor radii;
105 device::Tensor colors;
106 device::Tensor widths;
107 device::Tensor worlds;
108 device::Tensor itemCount;
109 OverlayStyle style;
110 std::shared_ptr<const void> owner;
111 };
112
113 struct CHRONO_BATCH_RENDER_API OverlayFrames {
114 device::Tensor points;
115 device::Tensor orientations;
116 device::Tensor lengths;
117 device::Tensor widths;
118 device::Tensor worlds;
119 device::Tensor itemCount;
120 float length = 1;
121 OverlayStyle style;
122 std::shared_ptr<const void> owner;
123 };
124
125 struct CHRONO_BATCH_RENDER_API OverlayArrows {
126 device::Tensor points;
127 device::Tensor ends;
128 device::Tensor vectors;
129 float vectorScale = 1;
130 device::Tensor headLengths;
131 device::Tensor colors;
132 device::Tensor widths;
133 device::Tensor worlds;
134 device::Tensor itemCount;
135 float headLength = 0;
136 OverlayStyle style;
137 std::shared_ptr<const void> owner;
138 };
139
140 struct CHRONO_BATCH_RENDER_API OverlayCapsules {
141 device::Tensor points;
142 device::Tensor orientations;
143 device::Tensor radii;
144 device::Tensor halfHeights;
145 device::Tensor colors;
146 device::Tensor widths;
147 device::Tensor worlds;
148 device::Tensor itemCount;
149 OverlayStyle style;
150 std::shared_ptr<const void> owner;
151 };
152
153 struct CHRONO_BATCH_RENDER_API OverlayTrails {
154 device::Tensor points;
155 device::Tensor heads;
156 device::Tensor colors;
157 device::Tensor widths;
158 device::Tensor worlds;
159 device::Tensor itemCount;
160 float fade = 0;
161 OverlayStyle style;
162 std::shared_ptr<const void> owner;
163 };
164
165 struct CHRONO_BATCH_RENDER_API OverlayTexts {
166 device::Tensor points;
167 device::Tensor chars;
168 device::Tensor colors;
169 device::Tensor sizes;
170 device::Tensor worlds;
171 device::Tensor itemCount;
172 std::optional<ScreenPlacement> placement;
173 OverlayStyle style;
174 std::shared_ptr<const void> owner;
175 };
176
177 struct CHRONO_BATCH_RENDER_API OverlayNumbers {
178 device::Tensor points;
179 device::Tensor values;
180 OverlayNumberFormat format;
181 device::Tensor colors;
182 device::Tensor sizes;
183 device::Tensor worlds;
184 device::Tensor itemCount;
185 std::optional<ScreenPlacement> placement;
186 OverlayStyle style;
187 std::shared_ptr<const void> owner;
188 };
189
190 struct CHRONO_BATCH_RENDER_API OverlayTriangles {
191 device::Tensor points;
192 device::Tensor colors;
193 device::Tensor worlds;
194 device::Tensor itemCount;
195 OverlayStyle style;
196 std::shared_ptr<const void> owner;
197 };
198
199 struct CHRONO_BATCH_RENDER_API OverlayImages {
200 device::Tensor points;
201 device::Tensor rights;
202 device::Tensor downs;
203 device::Tensor pixels;
204 device::Tensor colors;
205 device::Tensor worlds;
206 device::Tensor itemCount;
207 OverlayStyle style;
208 std::shared_ptr<const void> owner;
209 };
210
211 struct CHRONO_BATCH_RENDER_API OverlayPrims {
212 device::Tensor prims;
213 device::Tensor groups;
214 uint32_t groupCount = 0;
215 OverlayPrimShape shape = OverlayPrimShape::Frames;
216 float length = 1;
217 device::Tensor pixels;
218 device::Tensor colors;
219 device::Tensor widths;
220 OverlayStyle style;
221 std::shared_ptr<const void> owner;
222 };
223
224 struct OverlayData;
225
226 6 struct CHRONO_BATCH_RENDER_API OverlayHit {
227 std::string overlay;
228 uint32_t id = 0;
229 uint32_t batch = 0;
230 uint32_t item = 0;
231 uint32_t piece = 0;
232 uint32_t world = kGlobalWorld;
233 uint32_t prim = kNoPrim;
234 float distance = 0;
235 float depth = 0;
236 Float3 position;
237 };
238
239 struct CHRONO_BATCH_RENDER_API OverlayRay {
240 Float3 origin;
241 Float3 direction;
242 };
243
244 struct OverlayPickState;
245
246
2/18
<unknown function 226>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
<unknown function 43>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 class CHRONO_BATCH_RENDER_API OverlayPick {
247 public:
248 OverlayPick() = default;
249 explicit OverlayPick(std::shared_ptr<OverlayPickState> state);
250
251 bool Ready() const;
252 void Wait() const;
253 std::optional<OverlayHit> Hit() const;
254 std::optional<OverlayRay> Ray() const;
255
256 private:
257 std::shared_ptr<OverlayPickState> m_state;
258 };
259
260 class CHRONO_BATCH_RENDER_API Overlay {
261 public:
262 Overlay();
263 ~Overlay();
264 Overlay(const Overlay& other);
265 Overlay(Overlay&& other) noexcept;
266 Overlay& operator=(const Overlay& other);
267 Overlay& operator=(Overlay&& other) noexcept;
268
269 Overlay& Line(Float3 a, Float3 b, const OverlayStyle& style = {});
270 Overlay& Lines(Span<const Float3> endpoints, const OverlayStyle& style = {},
271 Span<const Float4> colors = {});
272 Overlay& Polyline(Span<const Float3> points, bool closed = false,
273 const OverlayStyle& style = {});
274 Overlay& Marker(Float3 point, const OverlayStyle& style = {});
275 Overlay& Markers(Span<const Float3> points, const OverlayStyle& style = {},
276 Span<const Float4> colors = {});
277 Overlay& Box(Float3 center, Float3 halfExtents, const OverlayStyle& style = {},
278 Quatd orientation = {});
279 Overlay& Sphere(Float3 center, float radius, const OverlayStyle& style = {});
280 Overlay& Circle(Float3 center, Float3 normal, float radius, const OverlayStyle& style = {});
281 Overlay& Frame(Float3 origin, Quatd orientation, float length = 1,
282 const OverlayStyle& style = {});
283 Overlay& Arrow(Float3 from, Float3 to, const OverlayStyle& style = {}, float headLength = 0);
284 Overlay& Capsule(Float3 center, Quatd orientation, float radius, float halfHeight,
285 const OverlayStyle& style = {});
286 Overlay& Label(Float3 point, std::string_view text, const OverlayStyle& style = {});
287 Overlay& Text(const ScreenPlacement& placement, std::string_view text,
288 const OverlayStyle& style = {});
289 Overlay& Triangle(Float3 a, Float3 b, Float3 c, const OverlayStyle& style = {});
290 Overlay& Polygon(Span<const Float3> points, const OverlayStyle& style = {});
291 Overlay& Curve(Span<const Float3> controls, const OverlayStyle& style = {},
292 uint32_t tessellation = 16);
293 Overlay& Arc(Float3 center, Float3 normal, float radius, float begin, float end,
294 const OverlayStyle& style = {}, bool filled = false);
295 Overlay& Rectangle(Float3 center, Float3 halfRight, Float3 halfUp,
296 const OverlayStyle& style = {}, bool filled = false);
297 Overlay& Mesh(Span<const Float3> points, Span<const uint32_t> faceCounts,
298 Span<const uint32_t> indices, const OverlayStyle& style = {},
299 bool wireframe = false);
300 Overlay& Image(Float3 topLeft, Float3 right, Float3 down, device::Tensor pixels,
301 const OverlayStyle& style = {});
302 Overlay& Prims(Span<const uint32_t> prims, OverlayPrimShape shape,
303 const OverlayStyle& style = {}, float length = 1,
304 Span<const uint32_t> groups = {}, Span<const Float4> colors = {});
305 Overlay& Outline(Span<const uint32_t> prims, const OverlayStyle& style = {});
306 Overlay& Add(OverlayLines lines);
307 Overlay& Add(OverlayMarkers markers);
308 Overlay& Add(OverlayBoxes boxes);
309 Overlay& Add(OverlaySpheres spheres);
310 Overlay& Add(OverlayCircles circles);
311 Overlay& Add(OverlayFrames frames);
312 Overlay& Add(OverlayArrows arrows);
313 Overlay& Add(OverlayCapsules capsules);
314 Overlay& Add(OverlayTrails trails);
315 Overlay& Add(OverlayTexts texts);
316 Overlay& Add(OverlayNumbers numbers);
317 Overlay& Add(OverlayTriangles triangles);
318 Overlay& Add(OverlayImages images);
319 Overlay& Add(OverlayPrims prims);
320
321 bool Empty() const;
322
323 private:
324 friend class OverlayPass;
325
326 OverlayData& Edit();
327
328 std::shared_ptr<OverlayData> m_data;
329 };
330
331 struct OverlaysImpl;
332
333 class CHRONO_BATCH_RENDER_API Overlays : public RefCounted {
334 public:
335 static Ref<Overlays> Create(device::Device& device);
336 ~Overlays() override;
337
338 void Set(std::string_view name, Overlay overlay);
339 void Remove(std::string_view name);
340 std::vector<std::string> Names() const;
341 OverlayPick Pick(std::string_view product, Float2 pixel, float radius = 6, uint32_t layer = 0);
342
343 private:
344 friend struct OverlaysImpl;
345
346 explicit Overlays(device::Device& device);
347
348 std::unique_ptr<OverlaysImpl> m_impl;
349 };
350
351 CHRONO_BATCH_RENDER_API device::Tensor RenderOverlayText(device::Device& target,
352 std::string_view text, float lineHeight,
353 Float4 color = {1, 1, 1, 1});
354
355 CHRONO_BATCH_RENDER_API device::Tensor CompositeOverlay(const device::Tensor& color,
356 const device::Tensor& overlay,
357 const device::Operation& after = {},
358 device::Operation* done = nullptr);
359
360 }
361