equal
deleted
inserted
replaced
|
1 /* |
|
2 * Pyrit Ray Tracer |
|
3 * file: octree.h |
|
4 * |
|
5 * Radek Brich, 2006-2007 |
|
6 */ |
|
7 |
|
8 #ifndef OCTREE_H |
|
9 #define OCTREE_H |
|
10 |
|
11 #include "container.h" |
|
12 #include "vector.h" |
|
13 #include "scene.h" |
|
14 |
|
15 using namespace std; |
|
16 |
|
17 class OctreeNode |
|
18 { |
|
19 OctreeNode *children; // pointer to first of eight children |
|
20 public: |
|
21 ShapeList *shapes; // pointer to shape array, if this is leaf |
|
22 |
|
23 OctreeNode() : children(NULL) { shapes = new ShapeList(); }; |
|
24 ~OctreeNode(); |
|
25 |
|
26 bool isLeaf() { return shapes != NULL; }; |
|
27 |
|
28 OctreeNode *getChild(const int num) { return children+num; }; |
|
29 |
|
30 void addShape(Shape* aShape) { shapes->push_back(aShape); }; |
|
31 |
|
32 void subdivide(BBox bbox, int maxdepth); |
|
33 }; |
|
34 |
|
35 class Octree: public Container |
|
36 { |
|
37 OctreeNode *root; |
|
38 bool built; |
|
39 int max_depth; |
|
40 public: |
|
41 Octree() : Container(), root(NULL), built(false), max_depth(4) {}; |
|
42 ~Octree() { if (root) delete root; }; |
|
43 void addShape(Shape* aShape) { Container::addShape(aShape); built = false; }; |
|
44 Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray, |
|
45 Float &nearest_distance); |
|
46 void optimize() { build(); }; |
|
47 void build(); |
|
48 void save(ostream &str, OctreeNode *node = NULL) {}; |
|
49 void load(istream &str, OctreeNode *node = NULL) {}; |
|
50 void setMaxDepth(int md) { max_depth = md; }; |
|
51 }; |
|
52 |
|
53 #endif |