diff -r 2a853d284a6a -r 64638385798a include/kdtree.h --- a/include/kdtree.h Thu May 15 19:15:57 2008 +0200 +++ b/include/kdtree.h Mon May 19 22:59:04 2008 +0200 @@ -55,20 +55,27 @@ KdNode() { shapes = new ShapeList(); assert((flags & 3) == 0); setLeaf(); }; ~KdNode(); + /** mark this node as leaf */ void setLeaf() { flags |= 3; }; bool isLeaf() const { return (flags & 3) == 3; }; + /** set split axis (this removes leaf flag) */ void setAxis(int aAxis) { flags &= ~3; flags |= aAxis; }; int getAxis() const { return flags & 3; }; + /** set split position (leaf) */ void setSplit(Float aSplit) { split = aSplit; }; const Float& getSplit() const { return split; }; + /** set children (non-leaf) */ void setChildren(KdNode *node) { children = node; assert((flags & 3) == 0); }; KdNode* getLeftChild() const { return (KdNode*)((size_t)children & ~3); }; KdNode* getRightChild() const { return (KdNode*)(((size_t)children & ~3) + 16); }; + /** get shape list of the leaf node*/ ShapeList* getShapes() const { return (ShapeList*)((size_t)shapes & ~3); }; + + /** add shape to shape list */ void addShape(const Shape* aShape) { getShapes()->push_back(aShape); }; }; @@ -85,9 +92,14 @@ void recursive_build(KdNode *node, const BBox &bbox, int maxdepth); void recursive_load(istream &st, KdNode *node); public: + /** default constructor, maximum depth is set to 32 */ KdTree(): Container(), mempool(64), root(NULL), max_depth(32), built(false) {}; + + /** constructor which allows to se maximum tree depth (cannot be changed later) */ KdTree(int maxdepth): Container(), mempool(64), root(NULL), max_depth(maxdepth), built(false) {}; ~KdTree() { if (root) delete root; }; + + /** add shape pointer to the container */ void addShape(const Shape* aShape) { Container::addShape(aShape); built = false; }; const Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, Float &nearest_distance); @@ -96,6 +108,8 @@ Float *nearest_distances, const Shape **nearest_shapes); #endif void optimize() { build(); }; + + /** build the tree (alias for 'optimize') */ void build(); bool isBuilt() const { return built; }; KdNode *getRootNode() const { return root; };