Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TIndexedKdtreeIntersector.ipp
Go to the documentation of this file.
1#pragma once
2
4#include "Core/Ray.h"
5#include "Core/HitProbe.h"
6
7#include <utility>
8
9namespace ph
10{
11
12template<typename Index>
15
17
18 m_tree(
19 0,
20 IndexedIntersectables(),
21 IntersectableAABBCalculator(),
22 params),
23 m_params(params)
24{}
25
26template<typename Index>
29{
30 IndexedIntersectables indexedIntersectables;
31 for(const Intersectable* intersectable : intersectables)
32 {
33 indexedIntersectables.vec.push_back(intersectable);
34 }
35
36 const std::size_t numIntersectables = indexedIntersectables.vec.size();
37 m_tree = Tree(
38 numIntersectables,
39 std::move(indexedIntersectables),
40 IntersectableAABBCalculator(),
41 m_params);
42}
43
44template<typename Index>
46isIntersecting(const Ray& ray, HitProbe& probe) const
47-> bool
48{
49 return m_tree.nearestTraversal(
50 ray.getSegment(),
51 [ray, &probe, originalProbe = probe](
52 const Intersectable* const intersectable,
53 const math::TLineSegment<real>& segment)
54 -> std::optional<real>
55 {
56 PH_ASSERT(intersectable);
57
58 const Ray raySegment(segment, ray.getTime());
59
60 HitProbe trialProbe = originalProbe;
61 if(intersectable->isIntersecting(raySegment, trialProbe))
62 {
63 probe = trialProbe;
64 return trialProbe.getHitRayT();
65 }
66 else
67 {
68 return std::nullopt;
69 }
70 });
71}
72
73template<typename Index>
75calcAABB() const
76-> math::AABB3D
77{
78 return m_tree.getAABB();
79}
80
81}// end namespace ph
Lightweight ray intersection testing and reporting object. If an intersection is found,...
Definition HitProbe.h:27
An object in the scene that a ray can intersect with.
Definition Intersectable.h:31
Definition Intersector.h:14
Represents a ray in space.
Definition Ray.h:21
Definition TIndexedKdtreeIntersector.h:16
TIndexedKdtreeIntersector(math::IndexedKdtreeParams params=math::IndexedKdtreeParams())
Definition TIndexedKdtreeIntersector.ipp:14
void update(TSpanView< const Intersectable * > intersectables) override
Definition TIndexedKdtreeIntersector.ipp:28
bool isIntersecting(const Ray &ray, HitProbe &probe) const override
Determine whether a given ray hits the object.
Definition TIndexedKdtreeIntersector.ipp:46
Definition IndexedKdtreeParams.h:9
Definition TIndexedKdtree.h:28
Represents a line segment in space.
Definition TLineSegment.h:25
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19