scene/tables/captures.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #include "chrono_batch_render/scene/tables/captures.h" | ||
| 3 | |||
| 4 | #include <algorithm> | ||
| 5 | #include <cmath> | ||
| 6 | |||
| 7 | #include "chrono_batch_render/scene/scene.h" | ||
| 8 | #include "chrono_batch_render/util/log.h" | ||
| 9 | |||
| 10 | namespace chrono::batch_render { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | constexpr double kCaptureTolerance = 1e-6; | ||
| 15 | |||
| 16 | } | ||
| 17 | |||
| 18 | 3532 | void CaptureSchedule::Schedule(std::span<const std::shared_ptr<const ResolvedProduct>> products, | |
| 19 | double start, double end) { | ||
| 20 | 3532 | const double dt = end - start; | |
| 21 | 7067 | for (const std::shared_ptr<const ResolvedProduct>& product : products) { | |
| 22 | 3535 | Entry& entry = m_entries[product->prim]; | |
| 23 | 3535 | const float rate = product->frameRate; | |
| 24 | 3535 | if (rate <= 0 || dt <= 0) { | |
| 25 | 3504 | entry.due = true; | |
| 26 | 3504 | continue; | |
| 27 | } | ||
| 28 | 31 | const float first = product->startTime; | |
| 29 | 31 | if (entry.frameRate != rate || entry.startTime != first) { | |
| 30 | 7 | const double next = std::ceil((start - first) * rate - kCaptureTolerance); | |
| 31 | 8 | entry = {rate, first, std::max<int64_t>(0, int64_t(next))}; | |
| 32 | } | ||
| 33 | 31 | const double reached = (end - first) * rate + kCaptureTolerance; | |
| 34 | 31 | entry.due = double(entry.next) <= reached; | |
| 35 | 31 | if (!entry.due) { | |
| 36 | 15 | continue; | |
| 37 | } | ||
| 38 | 16 | const auto last = int64_t(std::floor(reached)); | |
| 39 | 16 | if (last > entry.next) { | |
| 40 | 2 | Log(LogLevel::Debug, "{} skipped {} in a step of {} s", | |
| 41 | 2 | m_scene.ByIndex(product->prim).Path(), | |
| 42 | 2 | Counted(uint64_t(last - entry.next), "capture"), dt); | |
| 43 | } | ||
| 44 | 16 | entry.next = last + 1; | |
| 45 | } | ||
| 46 | 3532 | } | |
| 47 | |||
| 48 | 3 | void CaptureSchedule::Reset() { | |
| 49 | 3 | m_entries.clear(); | |
| 50 | 3 | } | |
| 51 | |||
| 52 | 3535 | bool CaptureSchedule::Due(uint32_t prim) const { | |
| 53 | 3535 | const auto found = m_entries.find(prim); | |
| 54 | 3535 | return found == m_entries.end() || found->second.due; | |
| 55 | } | ||
| 56 | |||
| 57 | } | ||
| 58 |