include/octree.h
branchpyrit
changeset 92 9af5c039b678
parent 46 6493fb65f0b1
child 93 96d65f841791
equal deleted inserted replaced
91:9d66d323c354 92:9af5c039b678
    59 
    59 
    60 	void makeChildren() { children = new OctreeNode[8]; assert(!isLeaf()); }; // this also cleans leaf bit
    60 	void makeChildren() { children = new OctreeNode[8]; assert(!isLeaf()); }; // this also cleans leaf bit
    61 	OctreeNode *getChild(const int num) { assert(!isLeaf()); return children + num; };
    61 	OctreeNode *getChild(const int num) { assert(!isLeaf()); return children + num; };
    62 
    62 
    63 	void addShape(Shape* aShape) { getShapes()->push_back(aShape); };
    63 	void addShape(Shape* aShape) { getShapes()->push_back(aShape); };
    64 	ShapeList *getShapes() { return (ShapeList*)((off_t)shapes & ~(off_t)1); };
    64 	ShapeList *getShapes() { return (ShapeList*)((size_t)shapes & ~(size_t)1); };
    65 	void setShapes(ShapeList *const ashapes) { shapes = ashapes; assert(!isLeaf()); setLeaf(); };
    65 	void setShapes(ShapeList *const ashapes) { shapes = ashapes; assert(!isLeaf()); setLeaf(); };
    66 
    66 
    67 	void subdivide(BBox bbox, int maxdepth);
    67 	void subdivide(const BBox &bbox, int maxdepth);
    68 };
    68 };
    69 
    69 
    70 /**
    70 /**
    71  * optimized octree
    71  * optimized octree
    72  */
    72  */
    73 class Octree: public Container
    73 class Octree: public Container
    74 {
    74 {
    75 	OctreeNode *root;
    75 	OctreeNode *root;
    76 	bool built;
    76 	bool built;
    77 	int max_depth;
    77 	const int max_depth;
    78 public:
    78 public:
    79 	Octree() : Container(), root(NULL), built(false), max_depth(10) {};
    79 	Octree() : Container(), root(NULL), built(false), max_depth(10) {};
       
    80 	Octree(int maxdepth) : Container(), root(NULL), built(false), max_depth(maxdepth) {};
    80 	~Octree() { if (root) delete root; };
    81 	~Octree() { if (root) delete root; };
    81 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    82 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    82 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    83 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    83 		Float &nearest_distance);
    84 		Float &nearest_distance);
    84 	void optimize() { build(); };
    85 	void optimize() { build(); };
    85 	void build();
    86 	void build();
    86 	void save(ostream &str, OctreeNode *node = NULL) {};
    87 	void save(ostream &str, OctreeNode *node = NULL) {};
    87 	void load(istream &str, OctreeNode *node = NULL) {};
    88 	void load(istream &str, OctreeNode *node = NULL) {};
    88 	void setMaxDepth(int md) { max_depth = md; };
       
    89 };
    89 };
    90 
    90 
    91 #endif
    91 #endif