src/kdtree.h
author Radek Brich <radek.brich@devl.cz>
Sun, 18 Nov 2007 11:20:56 +0100
branchpyrit
changeset 6 d8d596d26f25
parent 0 3547b885df7e
child 7 bf17f9f84c91
permissions -rw-r--r--
pthreads and other fixes for Windows

#ifndef KDTREE_H
#define KDTREE_H

#include <vector>

#include "scene.h"

class SpaceDivider
{
	ShapeList *shapes;
public:
	SpaceDivider(ShapeList &shapelist): shapes(shapelist) {};
};

class KdNode:
{
	float split;
	bool leaf; /* is this node a leaf? */
	char axis; /* 0,1,2 => x,y,z */
	KdNode *leftchild, *rightchild;
public:
	vector<Shape*> shapes;

	KdNode() : leaf(true), axis(0), shapes() {};

	setAxis(char aAxis) { axis = aAxis; };
	char getAxis() { return axis; };

	setSplit(float aSplit) { split = aSplit; };
	float getSplit() { return split; };

	setLeaf(bool aLeaf) { leaf = aLeaf; };
	bool isLeaf() { return leaf; };

	setLeftChild(KdNode *aLeft) { leftchild = aLeft; };
	KdNode *getLeftChild() { return leftchild; };
	setRightChild(KdNode *aRight) { rightchild = aRight; };
	KdNode *getRightChild() { return rightchild; };

	addShape(Shape* aShape) { shapes.push_back(aShape); };
};

class KdTree: public SpaceDivider
{
	KdNote *root;
public:
	KdTree(ShapeList &shapelist);
	rebuild();
};

#endif