include/kdtree.h
branchpyrit
changeset 93 96d65f841791
parent 92 9af5c039b678
child 94 4c8abb8977dc
equal deleted inserted replaced
92:9af5c039b678 93:96d65f841791
    42 /**
    42 /**
    43  * a node of kd-tree
    43  * a node of kd-tree
    44  */
    44  */
    45 class KdNode
    45 class KdNode
    46 {
    46 {
    47 	union {
    47 	Float split;
    48 		Float split;
       
    49 		void *pad64;  /* pad to 64 bits on 64bit platforms */
       
    50 	};
       
    51 	union {
    48 	union {
    52 		KdNode *children;
    49 		KdNode *children;
    53 		ShapeList *shapes;
    50 		ShapeList *shapes;
    54 		int flags; /* 0,1,2 => x,y,z; 3 => leaf */
    51 		int flags; /* 0,1,2 => x,y,z; 3 => leaf */
    55 	};
    52 	};
    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