29 }; |
29 }; |
30 |
30 |
31 class KdNode |
31 class KdNode |
32 { |
32 { |
33 float split; |
33 float split; |
34 bool leaf; /* is this node a leaf? */ |
34 short axis; /* 0,1,2 => x,y,z; 3 => leaf */ |
35 short axis; /* 0,1,2 => x,y,z */ |
|
36 KdNode *children; |
|
37 public: |
35 public: |
38 ShapeList shapes; |
36 union { |
|
37 KdNode *children; |
|
38 ShapeList *shapes; |
|
39 }; |
39 |
40 |
40 KdNode() : leaf(true), axis(0), shapes() {}; |
41 KdNode() : axis(3) { shapes = new ShapeList(); }; |
41 |
42 |
42 void setAxis(short aAxis) { axis = aAxis; }; |
43 void setAxis(short aAxis) { axis = aAxis; }; |
43 short getAxis() { return axis; }; |
44 short getAxis() { return axis; }; |
44 |
45 |
45 void setSplit(float aSplit) { split = aSplit; }; |
46 void setSplit(float aSplit) { split = aSplit; }; |
46 float getSplit() { return split; }; |
47 float getSplit() { return split; }; |
47 |
48 |
48 void setLeaf(bool aLeaf) { leaf = aLeaf; }; |
49 void setLeaf() { axis = 3; }; |
49 bool isLeaf() { return leaf; }; |
50 bool isLeaf() { return axis == 3; }; |
50 |
51 |
51 KdNode *getLeftChild() { return children; }; |
52 KdNode *getLeftChild() { return children; }; |
52 KdNode *getRightChild() { return children+1; }; |
53 KdNode *getRightChild() { return children+1; }; |
53 |
54 |
54 void addShape(Shape* aShape) { shapes.push_back(aShape); }; |
55 void addShape(Shape* aShape) { shapes->push_back(aShape); }; |
55 |
56 |
56 void subdivide(BBox bbox, int depth); |
57 void subdivide(BBox bbox, int depth); |
57 }; |
58 }; |
58 |
59 |
59 class KdTree: public Container |
60 class KdTree: public Container |