--- a/src/kdtree.h Thu Nov 22 21:46:09 2007 +0100
+++ b/src/kdtree.h Fri Nov 23 01:24:33 2007 +0100
@@ -2,6 +2,8 @@
#define KDTREE_H
#include <vector>
+#include <iostream>
+#include <fstream>
#include "scene.h"
@@ -44,9 +46,12 @@
public:
float pos;
int lnum, rnum;
- SplitPos(float &aPos): pos(aPos) {};
+ SplitPos(): pos(0.0), lnum(0), rnum(0) {};
+ SplitPos(float &aPos): pos(aPos), lnum(0), rnum(0) {};
friend bool operator<(const SplitPos& a, const SplitPos& b)
{ return a.pos < b.pos; };
+ friend bool operator==(const SplitPos& a, const SplitPos& b)
+ { return a.pos == b.pos; };
};
class SplitList: public vector<SplitPos>
@@ -56,12 +61,13 @@
class Container
{
protected:
- ShapeList shapes;
BBox bbox;
public:
- Container(): shapes(), bbox() {};
- void addShape(Shape* aShape);
+ ShapeList shapes;
+ Container(): bbox(), shapes() {};
+ virtual void addShape(Shape* aShape);
//void addShapeNoExtend(Shape* aShape) { shapes.push_back(aShape); };
+ virtual void optimize() {};
};
class KdNode
@@ -95,9 +101,12 @@
class KdTree: public Container
{
KdNode *root;
+ bool built;
public:
- KdTree() {};
- void build();
+ KdTree() : Container(), built(false) {};
+ void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
+ void optimize(); // build kd-tree
+ void save(ostream &str, KdNode *node = NULL);
};
#endif