chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
17 / 25
68.0%
Branches:
33 / 34
97.1%
Functions:
2 / 3, 2 excl
66.7%

render/render_output.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <array>
5 #include <cstddef>
6 #include <cstdint>
7 #include <filesystem>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <string_view>
12 #include <vector>
13
14 #include "chrono_batch_render/device/operation.h"
15 #include "chrono_batch_render/device/tensor.h"
16 #include "chrono_batch_render/export.h"
17 #include "chrono_batch_render/io/image.h"
18 #include "chrono_batch_render/stage/types.h"
19
20 namespace chrono::batch_render {
21
22 struct CHRONO_BATCH_RENDER_API RenderVarOutput {
23 std::string renderVarPath;
24 std::string sourceName;
25 device::Tensor tensor;
26 std::shared_ptr<const IdMap> idMap;
27 std::map<std::string, device::Tensor, std::less<>> channels;
28 };
29
30 struct CHRONO_BATCH_RENDER_API FrameOutput {
31 double startTime = 0;
32 double endTime = 0;
33 std::map<std::string, RenderVarOutput, std::less<>> renderVars;
34 device::Tensor overlay;
35
36 const RenderVarOutput& RenderVar(std::string_view path) const;
37 const RenderVarOutput& Source(std::string_view sourceName) const;
38 };
39
40 3711 struct CHRONO_BATCH_RENDER_API ProductOutput {
41 std::string name;
42 std::vector<FrameOutput> frames;
43 };
44
45 CHRONO_BATCH_RENDER_API IdTexts DecodeIdMap(const device::Tensor& map);
46
47 CHRONO_BATCH_RENDER_API std::filesystem::path
48 WriteRenderVar(std::filesystem::path path, const RenderVarOutput& renderVar, int64_t camera = 0);
49 CHRONO_BATCH_RENDER_API std::vector<std::filesystem::path>
50 WriteFrame(const std::filesystem::path& directory, const FrameOutput& frame, bool raw = false);
51
52 class CHRONO_BATCH_RENDER_API ImageWriter {
53 public:
54 explicit ImageWriter(uint32_t threads = 4, uint32_t maxPending = 64);
55 ~ImageWriter();
56 ImageWriter(const ImageWriter&) = delete;
57 ImageWriter& operator=(const ImageWriter&) = delete;
58
59 void WriteImage(std::filesystem::path path, Pixels image);
60 void WriteImage(std::filesystem::path path, const device::Tensor& image);
61 void WriteRenderVar(std::filesystem::path path, const RenderVarOutput& renderVar,
62 int64_t camera = 0);
63 std::vector<std::filesystem::path> WriteFrame(const std::filesystem::path& directory,
64 const FrameOutput& frame, bool raw = false);
65 void Wait();
66 size_t Pending() const;
67
68 private:
69 struct State;
70 std::unique_ptr<State> m_state;
71 };
72
73
4/5
✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 17 taken 1 time.
7356 class CHRONO_BATCH_RENDER_API RenderOutput {
74 public:
75 double simulationStartTime = 0;
76 double simulationEndTime = 0;
77
78 1 bool Ready() const {
79
1/1
✓ Branch 1 taken 1 time.
1 return m_done.Ready();
80 }
81
82 3489 void Wait() const {
83
27/27
✓ Branch 1 taken 2920 times.
✓ Branch 1 taken 52 times.
✓ Branch 1 taken 12 times.
✓ Branch 1 taken 17 times.
✓ Branch 1 taken 2 times.
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 14 times.
✓ Branch 4 taken 32 times.
✓ Branch 4 taken 7 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 145 times.
✓ Branch 7 taken 3 times.
✓ Branch 7 taken 28 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 24 times.
✓ Branch 10 taken 44 times.
✓ Branch 10 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 10 taken 8 times.
✓ Branch 13 taken 8 times.
✓ Branch 13 taken 5 times.
✓ Branch 13 taken 10 times.
✓ Branch 16 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 8 times.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 4 times.
3520 m_done.Wait();
84 3508 }
85
86 ✗ const device::Operation& Done() const {
87 ✗ return m_done;
88 }
89
90 const ProductOutput& operator[](std::string_view product) const;
91
92 4 bool Contains(std::string_view product) const {
93 4 return m_products.find(product) != m_products.end();
94 }
95
96 2 size_t Size() const {
97
1/1
✓ Branch 1 taken 1 time.
2 return m_products.size();
98 }
99
100 ✗ auto begin() const {
101 ✗ return m_products.begin();
102 }
103
104 ✗ auto end() const {
105 ✗ return m_products.end();
106 }
107
108 private:
109 friend class RendererImpl;
110
111 device::Operation m_done;
112 std::map<std::string, ProductOutput, std::less<>> m_products;
113 };
114
115 }
116