1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "bvh.h"
7#include "../geometry/trianglev.h"
8#include "../geometry/object.h"
9
10namespace embree
11{
12 namespace isa
13 {
14 template<int N>
15 class BVHNCollider
16 {
17 typedef BVHN<N> BVH;
18 typedef typename BVH::NodeRef NodeRef;
19 typedef typename BVH::AABBNode AABBNode;
20
21 struct CollideJob
22 {
23 CollideJob () {}
24
25 CollideJob (NodeRef ref0, const BBox3fa& bounds0, size_t depth0,
26 NodeRef ref1, const BBox3fa& bounds1, size_t depth1)
27 : ref0(ref0), bounds0(bounds0), depth0(depth0), ref1(ref1), bounds1(bounds1), depth1(depth1) {}
28
29 NodeRef ref0;
30 BBox3fa bounds0;
31 size_t depth0;
32 NodeRef ref1;
33 BBox3fa bounds1;
34 size_t depth1;
35 };
36
37 typedef vector_t<CollideJob, aligned_allocator<CollideJob,16>> jobvector;
38
39 void split(const CollideJob& job, jobvector& jobs);
40
41 public:
42 __forceinline BVHNCollider (Scene* scene0, Scene* scene1, RTCCollideFunc callback, void* userPtr)
43 : scene0(scene0), scene1(scene1), callback(callback), userPtr(userPtr) {}
44
45 public:
46 virtual void processLeaf(NodeRef leaf0, NodeRef leaf1) = 0;
47 void collide_recurse(NodeRef node0, const BBox3fa& bounds0, NodeRef node1, const BBox3fa& bounds1, size_t depth0, size_t depth1);
48 void collide_recurse_entry(NodeRef node0, const BBox3fa& bounds0, NodeRef node1, const BBox3fa& bounds1);
49
50 protected:
51 Scene* scene0;
52 Scene* scene1;
53 RTCCollideFunc callback;
54 void* userPtr;
55 };
56
57 template<int N>
58 class BVHNColliderUserGeom : public BVHNCollider<N>
59 {
60 typedef BVHN<N> BVH;
61 typedef typename BVH::NodeRef NodeRef;
62 typedef typename BVH::AABBNode AABBNode;
63
64 __forceinline BVHNColliderUserGeom (Scene* scene0, Scene* scene1, RTCCollideFunc callback, void* userPtr)
65 : BVHNCollider<N>(scene0,scene1,callback,userPtr) {}
66
67 virtual void processLeaf(NodeRef leaf0, NodeRef leaf1);
68 public:
69 static void collide(BVH* __restrict__ bvh0, BVH* __restrict__ bvh1, RTCCollideFunc callback, void* userPtr);
70 };
71 }
72}
73