-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoctree.hpp
54 lines (51 loc) · 1.15 KB
/
octree.hpp
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
46
47
48
49
50
51
52
53
54
#ifndef OCTREE_HPP
#define OCTREE_HPP
struct Box
{
Vector3f mn, mx;
Box(){}
Box(const Vector3f & a, const Vector3f & b):
mn(a),mx(b)
{}
Box(float mnx, float mny,float mnz,
float mxx,float mxy,float mxz):
mn(Vector3f(mnx,mny,mnz)),
mx(Vector3f(mxx,mxy,mxz))
{}
};
struct OctNode
{
OctNode * child[8];
OctNode(){
child[0] = 0;
}
///@brief is this terminal
bool isTerm(){return child[0]==0;}
std::vector<int> obj;
};
class Mesh;
struct Octree
{
//if a node contains more than 7 triangles and it
//hasn't reached the max level yet,
///split
static const int max_trig = 7;
int maxLevel;
OctNode root;
Octree(int level = 8):
maxLevel(level){
}
Box box;
void build(const Mesh & m);
void buildNode(OctNode & parent, const Box & pbox ,
const std::vector<int>&trigs,
const Mesh & m, int level);
///@brief indexing
unsigned char aa;
void proc_subtree (float tx0, float ty0, float tz0, float tx1, float ty1, float tz1, OctNode* node);
void intersect(const Ray & ray);
void ** arg;
void (*termFunc) (int idx, void ** arg);
};
Octree buildOctree(const Mesh & m, int maxLevel=7);
#endif