src/kdtree.cc
branchpyrit
changeset 11 4d192e13ee84
parent 10 f9fad94cd0cc
child 12 f4fcabf05785
--- a/src/kdtree.cc	Fri Nov 23 01:24:33 2007 +0100
+++ b/src/kdtree.cc	Fri Nov 23 16:14:38 2007 +0100
@@ -20,6 +20,17 @@
 	}
 };
 
+Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
+	float &nearest_distance)
+{
+	Shape *nearest_shape = NULL;
+	ShapeList::iterator shape;
+	for (shape = shapes.begin(); shape != shapes.end(); shape++)
+		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
+			nearest_shape = *shape;
+	return nearest_shape;
+}
+
 void KdNode::subdivide(BBox bbox, int depth)
 {
 	if (depth >= 10 || shapes.size() <= 2)
@@ -219,7 +230,7 @@
 	children[1].subdivide(rbb, depth+1);
 }
 
-void KdTree::optimize()
+void KdTree::build()
 {
 	root = new KdNode();
 	root->shapes = shapes;
@@ -227,6 +238,7 @@
 	built = true;
 }
 
+// this should save whole kd-tree with triangles distributed into leaves
 void KdTree::save(ostream &str, KdNode *node)
 {
 	if (!built)
@@ -244,3 +256,9 @@
 		str << ";)";
 	}
 }
+
+// load kd-tree from file/stream
+void KdTree::load(istream &str, KdNode *node)
+{
+	
+}