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 | 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 | return m_done.Ready(); | |
| 80 | } | ||
| 81 | |||
| 82 | 3489 | void Wait() const { | |
| 83 | 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 | 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 |