equal
deleted
inserted
replaced
|
1 #ifndef KDTREE_H |
|
2 #define KDTREE_H |
|
3 |
|
4 #include <vector> |
|
5 |
|
6 #include "scene.h" |
|
7 |
|
8 class SpaceDivider |
|
9 { |
|
10 ShapeList *shapes; |
|
11 public: |
|
12 SpaceDivider(ShapeList &shapelist): shapes(shapelist) {}; |
|
13 }; |
|
14 |
|
15 class KdNode: |
|
16 { |
|
17 float split; |
|
18 bool leaf; /* is this node a leaf? */ |
|
19 char axis; /* 0,1,2 => x,y,z */ |
|
20 KdNode *leftchild, *rightchild; |
|
21 public: |
|
22 vector<Shape*> shapes; |
|
23 |
|
24 KdNode() : leaf(true), axis(0), shapes() {}; |
|
25 |
|
26 setAxis(char aAxis) { axis = aAxis; }; |
|
27 char getAxis() { return axis; }; |
|
28 |
|
29 setSplit(float aSplit) { split = aSplit; }; |
|
30 float getSplit() { return split; }; |
|
31 |
|
32 setLeaf(bool aLeaf) { leaf = aLeaf; }; |
|
33 bool isLeaf() { return leaf; }; |
|
34 |
|
35 setLeftChild(KdNode *aLeft) { leftchild = aLeft; }; |
|
36 KdNode *getLeftChild() { return leftchild; }; |
|
37 setRightChild(KdNode *aRight) { rightchild = aRight; }; |
|
38 KdNode *getRightChild() { return rightchild; }; |
|
39 |
|
40 addShape(Shape* aShape) { shapes.push_back(aShape); }; |
|
41 }; |
|
42 |
|
43 class KdTree: public SpaceDivider |
|
44 { |
|
45 KdNote *root; |
|
46 public: |
|
47 KdTree(ShapeList &shapelist); |
|
48 rebuild(); |
|
49 }; |
|
50 |
|
51 #endif |