chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
3 / 3
100.0%
Branches:
26 / 28
92.9%
Functions:
-
-%

render/ray_cast/ray_cast.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <limits>
6 #include <memory>
7 #include <optional>
8 #include <string>
9 #include <vector>
10
11 #include "chrono_batch_render/device/operation.h"
12 #include "chrono_batch_render/device/ref.h"
13 #include "chrono_batch_render/device/stream.h"
14 #include "chrono_batch_render/device/tensor.h"
15 #include "chrono_batch_render/export.h"
16 #include "chrono_batch_render/scene/prim.h"
17 #include "chrono_batch_render/stage/schema/ids.h"
18
19 namespace chrono::batch_render {
20
21 class Scene;
22
23 enum class RayOutput : uint32_t {
24 None = 0,
25 Distance = 1u << 0,
26 Prim = 1u << 1,
27 Normal = 1u << 2,
28 Position = 1u << 3,
29 InstanceId = 1u << 4,
30 };
31
32 constexpr RayOutput operator|(RayOutput a, RayOutput b) {
33 return RayOutput(uint32_t(a) | uint32_t(b));
34 }
35
36 1445 constexpr bool operator&(RayOutput a, RayOutput b) {
37
10/10
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 265 times.
✓ Branch 4 taken 288 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 275 times.
✓ Branch 7 taken 14 times.
✓ Branch 8 taken 280 times.
✓ Branch 9 taken 9 times.
1445 return (uint32_t(a) & uint32_t(b)) != 0;
38 }
39
40 enum class RayCastMode : uint8_t { Closest, Any };
41
42 struct CHRONO_BATCH_RENDER_API Rays {
43 device::Tensor origins;
44 device::Tensor directions;
45 device::Tensor tMins;
46 device::Tensor tMaxes;
47 device::Tensor worlds;
48 float minDistance = 0;
49 float maxDistance = std::numeric_limits<float>::infinity();
50 uint32_t world = kGlobalWorld;
51 std::optional<Prim> space;
52 };
53
54 struct CHRONO_BATCH_RENDER_API RayHits {
55 device::Tensor hit;
56 device::Tensor distance;
57 device::Tensor prim;
58 device::Tensor normal;
59 device::Tensor position;
60 device::Tensor instance;
61 device::Operation done;
62 };
63
64
16/18
✗ Branch 2 not taken.
✓ Branch 3 taken 123 times.
✓ Branch 10 taken 1 time.
✓ Branch 17 taken 41 times.
✓ Branch 19 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 45 taken 4 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 1 time.
✓ Branch 69 taken 1 time.
✓ Branch 91 taken 4 times.
✓ Branch 99 taken 2 times.
✓ Branch 121 taken 2 times.
✓ Branch 128 taken 1 time.
✓ Branch 144 taken 1 time.
✓ Branch 157 taken 1 time.
✓ Branch 168 taken 1 time.
✓ Branch 175 taken 1 time.
298 struct CHRONO_BATCH_RENDER_API RayCastDesc {
65 RayCastMode mode = RayCastMode::Closest;
66 RayOutput outputs = RayOutput::Distance | RayOutput::Prim;
67 std::string label = "RayCast";
68 std::vector<Prim> ignore;
69 };
70
71 class CHRONO_BATCH_RENDER_API RayCaster {
72 public:
73 explicit RayCaster(Ref<Scene> scene);
74 ~RayCaster();
75 RayCaster(RayCaster&&) noexcept;
76 RayCaster& operator=(RayCaster&&) noexcept;
77
78 device::Operation Cast(const Rays& rays, RayHits& hits, const RayCastDesc& desc = {},
79 Stream stream = Stream::None());
80 RayHits Cast(const Rays& rays, const RayCastDesc& desc = {});
81 Scene& GetScene() const;
82
83 private:
84 struct State;
85 std::unique_ptr<State> m_state;
86 };
87
88 }
89