forked from brandonpelfrey/Fast-BVH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBVH.h
45 lines (34 loc) · 981 Bytes
/
BVH.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef BVH_h
#define BVH_h
#include "BBox.h"
#include <vector>
#include <functional>
#include <stdint.h>
#include "Object.h"
#include "IntersectionInfo.h"
#include "Ray.h"
//! Node descriptor for the flattened tree
namespace pelfrey {
struct BVHFlatNode {
pelfrey::BBox bbox;
uint32_t start, nPrims, rightOffset;
};
//! \author Brandon Pelfrey
//! A Bounding Volume Hierarchy system for fast Ray-Object intersection tests
class BVH {
uint32_t nNodes, nLeafs, leafSize;
std::vector<Object*> build_prims;
//! Build the BVH tree out of build_prims
void build();
// Fast Traversal System
BVHFlatNode *flatTree;
public:
BVH(const std::vector<Object*>& objects, uint32_t leafSize=4);
bool getIntersection(const Ray& ray,
IntersectionInfo *intersection,
bool occlusion,
std::function<bool(const Object&, const Ray&, IntersectionInfo*)> cb_intersection={}) const;
~BVH();
};
}
#endif