src/kdtree.h
branchpyrit
changeset 9 3239f749e394
parent 7 bf17f9f84c91
child 10 f9fad94cd0cc
equal deleted inserted replaced
8:e6567b740c5e 9:3239f749e394
    66 
    66 
    67 class KdNode
    67 class KdNode
    68 {
    68 {
    69 	float split;
    69 	float split;
    70 	bool leaf; /* is this node a leaf? */
    70 	bool leaf; /* is this node a leaf? */
    71 	char axis; /* 1,2,3 => x,y,z */
    71 	short axis; /* 0,1,2 => x,y,z */
    72 	KdNode *leftchild;
    72 	KdNode *children;
    73 public:
    73 public:
    74 	ShapeList shapes;
    74 	ShapeList shapes;
    75 
    75 
    76 	KdNode() : leaf(true), axis(0), shapes() {};
    76 	KdNode() : leaf(true), axis(0), shapes() {};
    77 
    77 
    78 	void setAxis(char aAxis) { axis = aAxis; };
    78 	void setAxis(short aAxis) { axis = aAxis; };
    79 	char getAxis() { return axis; };
    79 	short getAxis() { return axis; };
    80 
    80 
    81 	void setSplit(float aSplit) { split = aSplit; };
    81 	void setSplit(float aSplit) { split = aSplit; };
    82 	float getSplit() { return split; };
    82 	float getSplit() { return split; };
    83 
    83 
    84 	void setLeaf(bool aLeaf) { leaf = aLeaf; };
    84 	void setLeaf(bool aLeaf) { leaf = aLeaf; };
    85 	bool isLeaf() { return leaf; };
    85 	bool isLeaf() { return leaf; };
    86 
    86 
    87 	void setLeftChild(KdNode *aLeft) { leftchild = aLeft; };
    87 	KdNode *getLeftChild() { return children; };
    88 	KdNode *getLeftChild() { return leftchild; };
    88 	KdNode *getRightChild() { return children+1; };
    89 	KdNode *getRightChild() { return leftchild+1; };
       
    90 
    89 
    91 	void addShape(Shape* aShape) { shapes.push_back(aShape); };
    90 	void addShape(Shape* aShape) { shapes.push_back(aShape); };
    92 
    91 
    93 	void subdivide(BBox bbox, int depth, int count);
    92 	void subdivide(BBox bbox, int depth);
    94 };
    93 };
    95 
    94 
    96 class KdTree: public Container
    95 class KdTree: public Container
    97 {
    96 {
    98 	KdNode *root;
    97 	KdNode *root;