include/kdtree.h
branchpyrit
changeset 95 ca7d4c665531
parent 94 4c8abb8977dc
child 98 64638385798a
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
    67 	void setChildren(KdNode *node) { children = node; assert((flags & 3) == 0); };
    67 	void setChildren(KdNode *node) { children = node; assert((flags & 3) == 0); };
    68 	KdNode* getLeftChild() const { return (KdNode*)((size_t)children & ~3); };
    68 	KdNode* getLeftChild() const { return (KdNode*)((size_t)children & ~3); };
    69 	KdNode* getRightChild() const { return (KdNode*)(((size_t)children & ~3) + 16); };
    69 	KdNode* getRightChild() const { return (KdNode*)(((size_t)children & ~3) + 16); };
    70 
    70 
    71 	ShapeList* getShapes() const { return (ShapeList*)((size_t)shapes & ~3); };
    71 	ShapeList* getShapes() const { return (ShapeList*)((size_t)shapes & ~3); };
    72 	void addShape(Shape* aShape) { getShapes()->push_back(aShape); };
    72 	void addShape(const Shape* aShape) { getShapes()->push_back(aShape); };
    73 };
    73 };
    74 
    74 
    75 /**
    75 /**
    76  * kd-tree
    76  * kd-tree
    77  */
    77  */
    86 	void recursive_load(istream &st, KdNode *node);
    86 	void recursive_load(istream &st, KdNode *node);
    87 public:
    87 public:
    88 	KdTree(): Container(), mempool(64), root(NULL), max_depth(32), built(false) {};
    88 	KdTree(): Container(), mempool(64), root(NULL), max_depth(32), built(false) {};
    89 	KdTree(int maxdepth): Container(), mempool(64), root(NULL), max_depth(maxdepth), built(false) {};
    89 	KdTree(int maxdepth): Container(), mempool(64), root(NULL), max_depth(maxdepth), built(false) {};
    90 	~KdTree() { if (root) delete root; };
    90 	~KdTree() { if (root) delete root; };
    91 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    91 	void addShape(const Shape* aShape) { Container::addShape(aShape); built = false; };
    92 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    92 	const Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    93 		Float &nearest_distance);
    93 		Float &nearest_distance);
    94 #ifndef NO_SIMD
    94 #ifndef NO_SIMD
    95 	void packet_intersection(const Shape* const* origin_shapes, const RayPacket &rays,
    95 	void packet_intersection(const Shape* const* origin_shapes, const RayPacket &rays,
    96 		Float *nearest_distances, Shape **nearest_shapes);
    96 		Float *nearest_distances, const Shape **nearest_shapes);
    97 #endif
    97 #endif
    98 	void optimize() { build(); };
    98 	void optimize() { build(); };
    99 	void build();
    99 	void build();
   100 	bool isBuilt() const { return built; };
   100 	bool isBuilt() const { return built; };
   101 	KdNode *getRootNode() const { return root; };
   101 	KdNode *getRootNode() const { return root; };
   102 
   102 
   103 	ostream & dump(ostream &st);
   103 	ostream & dump(ostream &st) const;
   104 	istream & load(istream &st, Material *mat);
   104 	istream & load(istream &st, Material *mat);
   105 };
   105 };
   106 
   106 
   107 #endif
   107 #endif