src/kdtree.h
branchpyrit
changeset 16 20bceb605f48
parent 15 a0a3e334744f
child 21 79b516a3803d
equal deleted inserted replaced
15:a0a3e334744f 16:20bceb605f48
    37 		KdNode *children;
    37 		KdNode *children;
    38 		ShapeList *shapes;
    38 		ShapeList *shapes;
    39 	};
    39 	};
    40 
    40 
    41 	KdNode() : axis(3) { shapes = new ShapeList(); };
    41 	KdNode() : axis(3) { shapes = new ShapeList(); };
       
    42 	~KdNode();
    42 
    43 
    43 	void setAxis(short aAxis) { axis = aAxis; };
    44 	void setAxis(short aAxis) { axis = aAxis; };
    44 	short getAxis() { return axis; };
    45 	short getAxis() { return axis; };
    45 
    46 
    46 	void setSplit(float aSplit) { split = aSplit; };
    47 	void setSplit(float aSplit) { split = aSplit; };
    60 class KdTree: public Container
    61 class KdTree: public Container
    61 {
    62 {
    62 	KdNode *root;
    63 	KdNode *root;
    63 	bool built;
    64 	bool built;
    64 public:
    65 public:
    65 	KdTree() : Container(), built(false) {};
    66 	KdTree() : Container(), root(NULL), built(false) {};
       
    67 	~KdTree() { if (root) delete root; };
    66 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    68 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    67 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    69 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    68 		float &nearest_distance);
    70 		float &nearest_distance);
    69 	void optimize() { build(); };
    71 	void optimize() { build(); };
    70 	void build();
    72 	void build();