77 /** |
74 /** |
78 * kd-tree |
75 * kd-tree |
79 */ |
76 */ |
80 class KdTree: public Container |
77 class KdTree: public Container |
81 { |
78 { |
|
79 MemoryPool<KdNode> mempool; |
82 KdNode *root; |
80 KdNode *root; |
|
81 const int max_depth; |
83 bool built; |
82 bool built; |
84 const int max_depth; |
|
85 MemoryPool<KdNode> mempool; |
|
86 |
83 |
87 void recursive_build(KdNode *node, const BBox &bbox, int maxdepth); |
84 void recursive_build(KdNode *node, const BBox &bbox, int maxdepth); |
88 void recursive_load(istream &st, KdNode *node); |
85 void recursive_load(istream &st, KdNode *node); |
89 public: |
86 public: |
90 KdTree(): Container(), root(NULL), built(false), max_depth(32), mempool(64) {}; |
87 KdTree(): Container(), mempool(64), root(NULL), max_depth(32), built(false) {}; |
91 KdTree(int maxdepth): Container(), root(NULL), built(false), max_depth(maxdepth), mempool(64) {}; |
88 KdTree(int maxdepth): Container(), mempool(64), root(NULL), max_depth(maxdepth), built(false) {}; |
92 ~KdTree() { if (root) delete root; }; |
89 ~KdTree() { if (root) delete root; }; |
93 void addShape(Shape* aShape) { Container::addShape(aShape); built = false; }; |
90 void addShape(Shape* aShape) { Container::addShape(aShape); built = false; }; |
94 Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, |
91 Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, |
95 Float &nearest_distance); |
92 Float &nearest_distance); |
96 #ifndef NO_SIMD |
93 #ifndef NO_SIMD |