chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
67 / 69
97.1%
Branches:
76 / 93
81.7%
Functions:
3 / 3
100.0%

scene/tables/plans.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/scene/tables/plans.h"
3
4 #include <algorithm>
5 #include <optional>
6
7 #include "chrono_batch_render/scene/scene.h"
8 #include "chrono_batch_render/util/error.h"
9 #include "chrono_batch_render/util/profiler.h"
10
11 namespace chrono::batch_render {
12
13 3541 std::shared_ptr<const ProductPlan> ProductPlans::Plan(std::span<const std::string> paths) {
14 3541 std::vector<std::string> sorted(paths.begin(), paths.end());
15 3541 std::ranges::sort(sorted);
16 3541 sorted.erase(std::ranges::unique(sorted).begin(), sorted.end());
17
1/1
✓ Branch 1 taken 3541 times.
3541 const std::lock_guard lock(m_mutex);
18 3541 const auto cached =
19 6930 std::ranges::find_if(m_plans, [&](const auto& plan) { return plan->paths == sorted; });
20
2/2
✓ Branch 0 taken 3383 times.
✓ Branch 1 taken 158 times.
3541 if (cached != m_plans.end()) {
21
1/1
✓ Branch 1 taken 3383 times.
3383 const bool current = std::ranges::all_of((*cached)->products, [&](const auto& product) {
22 3386 const std::shared_ptr<const ResolvedProduct> now = m_products.Find(product->prim);
23
4/6
✓ Branch 0 taken 3386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 3368 times.
✓ Branch 4 taken 3386 times.
✗ Branch 5 not taken.
3404 return now && now->version == product->version;
24 3386 });
25
2/2
✓ Branch 0 taken 3365 times.
✓ Branch 1 taken 18 times.
3383 if (current) {
26 3365 m_plans.splice(m_plans.begin(), m_plans, cached);
27
1/2
✓ Branch 0 taken 3365 times.
✗ Branch 1 not taken.
6899 return m_plans.front();
28 }
29 18 m_plans.erase(cached);
30 }
31
32
5/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 171 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 10 taken 176 times.
176 CHRONO_BATCH_RENDER_ZONE("Products/Plan");
33
1/1
✓ Branch 1 taken 176 times.
176 auto plan = std::make_shared<ProductPlan>();
34 176 plan->id = ++m_ids;
35
2/2
✓ Branch 0 taken 185 times.
✓ Branch 1 taken 169 times.
354 for (const std::string& path : sorted) {
36
1/1
✓ Branch 1 taken 185 times.
185 const std::optional<Prim> prim = m_scene.Find(path);
37
4/5
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 183 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 183 times.
185 if (!prim || !prim->IsA<RenderProduct>()) {
38
1/1
✓ Branch 2 taken 2 times.
2 throw Error("\"{}\" isn't a RenderProduct", path);
39 }
40
1/1
✓ Branch 1 taken 183 times.
183 std::shared_ptr<const ResolvedProduct> product = m_products.Find(prim->Index());
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
183 if (!product) {
42
0/1
✗ Branch 2 not taken.
✗ throw Error("{} isn't published yet", path);
43 }
44
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 178 times.
183 if (!product->error.empty()) {
45
1/1
✓ Branch 2 taken 5 times.
5 throw Error("{}", product->error);
46 }
47
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 15 times.
178 PlannedCapture capture{.product = product->prim,
48 178 .width = product->width,
49 178 .height = product->height,
50 .taxonomy = 0,
51 178 .missDistance = product->missDistance,
52
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 15 times.
178 .returns = std::max(product->returns, 1u)};
53
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 175 times.
178 if (product->semantic) {
54 3 const auto found = std::ranges::find(plan->taxonomies, product->taxonomy);
55
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 capture.taxonomy = uint32_t(found - plan->taxonomies.begin());
56
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (found == plan->taxonomies.end()) {
57
1/1
✓ Branch 1 taken 3 times.
3 plan->taxonomies.push_back(product->taxonomy);
58 }
59 }
60 178 const auto entry = uint32_t(product->entry);
61 178 uint64_t& pixels = plan->pixelCounts[entry];
62
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 178 times.
383 for (capture.layer = 0; capture.layer < product->sensors.size(); ++capture.layer) {
63
1/1
✓ Branch 1 taken 205 times.
205 capture.sensor = product->sensors[capture.layer];
64 205 capture.firstPixel = pixels;
65
1/1
✓ Branch 1 taken 205 times.
205 plan->captures[entry].push_back(capture);
66 205 pixels += uint64_t(capture.width) * capture.height;
67 }
68
1/1
✓ Branch 1 taken 178 times.
178 const auto index = uint32_t(plan->products.size());
69
1/1
✓ Branch 1 taken 178 times.
178 plan->products.push_back(product);
70
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 145 times.
178 if (product->pipeline != kNoPrim) {
71
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 33 times.
67 for (const uint32_t sensor : product->sensors) {
72 34 const auto found =
73 34 std::ranges::find_if(plan->pipelines, [&](const PlannedSensorPipeline& run) {
74
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 const ResolvedProduct& first = *plan->products[run.products.front()];
75
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
5 return run.pipeline == product->pipeline && run.sensor == sensor &&
76
5/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
13 first.width == product->width && first.height == product->height;
77 });
78
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 3 times.
34 PlannedSensorPipeline& run =
79
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 3 times.
34 found != plan->pipelines.end()
80
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 3 times.
34 ? *found
81 31 : plan->pipelines.emplace_back(
82
2/3
✓ Branch 1 taken 31 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
36 PlannedSensorPipeline{product->pipeline, sensor, {}});
83
1/1
✓ Branch 1 taken 34 times.
34 run.products.push_back(index);
84 }
85 }
86
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 plan->captureCount += uint32_t(product->sensors.size());
87
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 plan->pixelCount += uint64_t(product->width) * product->height * product->sensors.size();
88 183 }
89 169 plan->paths = std::move(sorted);
90
3/5
✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 169 times.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
345 m_plans.push_front(plan);
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 169 times.
169 if (m_plans.size() > kCachedPlans) {
92 ✗ m_plans.pop_back();
93 }
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 169 times.
169 return plan;
95 3717 }
96
97 }
98