51 public: |
51 public: |
52 KdNode() { shapes = new ShapeList(); assert((flags & 3) == 0); setLeaf(); }; |
52 KdNode() { shapes = new ShapeList(); assert((flags & 3) == 0); setLeaf(); }; |
53 ~KdNode(); |
53 ~KdNode(); |
54 |
54 |
55 void setLeaf() { flags |= 3; }; |
55 void setLeaf() { flags |= 3; }; |
56 const bool isLeaf() const { return (flags & 3) == 3; }; |
56 bool isLeaf() const { return (flags & 3) == 3; }; |
57 |
57 |
58 void setAxis(int aAxis) { flags &= ~3; flags |= aAxis; }; |
58 void setAxis(int aAxis) { flags &= ~3; flags |= aAxis; }; |
59 const int getAxis() const { return flags & 3; }; |
59 int getAxis() const { return flags & 3; }; |
60 |
60 |
61 void setSplit(Float aSplit) { split = aSplit; }; |
61 void setSplit(Float aSplit) { split = aSplit; }; |
62 const Float& getSplit() const { return split; }; |
62 const Float& getSplit() const { return split; }; |
63 |
63 |
64 void setChildren(KdNode *node) { children = node; assert((flags & 3) == 0); }; |
64 void setChildren(KdNode *node) { children = node; assert((flags & 3) == 0); }; |
84 KdTree() : Container(), root(NULL), built(false), max_depth(32) {}; |
84 KdTree() : Container(), root(NULL), built(false), max_depth(32) {}; |
85 ~KdTree() { if (root) delete root; }; |
85 ~KdTree() { if (root) delete root; }; |
86 void addShape(Shape* aShape) { Container::addShape(aShape); built = false; }; |
86 void addShape(Shape* aShape) { Container::addShape(aShape); built = false; }; |
87 Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, |
87 Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, |
88 Float &nearest_distance); |
88 Float &nearest_distance); |
|
89 void packet_intersection(const Shape **origin_shapes, const RayPacket &rays, |
|
90 Float *nearest_distances, Shape **nearest_shapes); |
89 void optimize() { build(); }; |
91 void optimize() { build(); }; |
90 void build(); |
92 void build(); |
91 const bool isBuilt() const { return built; }; |
93 bool isBuilt() const { return built; }; |
92 KdNode *getRootNode() const { return root; }; |
94 KdNode *getRootNode() const { return root; }; |
93 void setMaxDepth(int md) { max_depth = md; }; |
95 void setMaxDepth(int md) { max_depth = md; }; |
94 |
96 |
95 ostream & dump(ostream &st); |
97 ostream & dump(ostream &st); |
96 istream & load(istream &st, Material *mat); |
98 istream & load(istream &st, Material *mat); |