chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
29 / 29
100.0%
Branches:
25 / 27
92.6%
Functions:
3 / 3
100.0%

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
2/2
✓ Branch 0 taken 3535 times.
✓ Branch 1 taken 3532 times.
7067 for (const std::shared_ptr<const ResolvedProduct>& product : products) {
22 3535 Entry& entry = m_entries[product->prim];
23
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3497 times.
3535 const float rate = product->frameRate;
24
4/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3497 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 31 times.
3535 if (rate <= 0 || dt <= 0) {
25 3504 entry.due = true;
26 3504 continue;
27 }
28
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7 times.
31 const float first = product->startTime;
29
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
31 if (entry.frameRate != rate || entry.startTime != first) {
30 7 const double next = std::ceil((start - first) * rate - kCaptureTolerance);
31
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 6 times.
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
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 16 times.
31 if (!entry.due) {
36 15 continue;
37 }
38 16 const auto last = int64_t(std::floor(reached));
39
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 15 times.
16 if (last > entry.next) {
40
1/1
✓ Branch 2 taken 1 time.
2 Log(LogLevel::Debug, "{} skipped {} in a step of {} s",
41
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
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
3/4
✓ Branch 0 taken 3535 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3520 times.
✓ Branch 3 taken 15 times.
3535 return found == m_entries.end() || found->second.due;
55 }
56
57 }
58