src/kdtree.cc
branchpyrit
changeset 0 3547b885df7e
child 7 bf17f9f84c91
equal deleted inserted replaced
-1:000000000000 0:3547b885df7e
       
     1 #include "kdtree.cc"
       
     2 
       
     3 void KdTree::KdTree(ShapeList &shapelist):
       
     4 {
       
     5 	root = new KdNode();
       
     6 	shapes = new vector<Shape*>();
       
     7 	ShapeList::iterator shape;
       
     8 	for (shape = shapelist.begin(); shape != shapes.end(); shape++)
       
     9 		addShape(*shape);
       
    10 
       
    11 	rebuild();
       
    12 }
       
    13 
       
    14 void KdTree::Subdivide(KdNode* node, AABB& bbox, int depth, int count)
       
    15 {
       
    16 	
       
    17 	/*if (stopcriterionmet()) return
       
    18 	splitpos = findoptimalsplitposition()
       
    19 	leftnode = new Node()
       
    20 	rightnode = new Node()
       
    21 	for (all primitives in node)
       
    22 	{
       
    23 		if (node->intersectleftnode()) leftnode->addprimitive( primitive )
       
    24 		if (node->intersectrightnode()) rightnode->addprimitive( primitive )
       
    25 	}
       
    26 	buildkdtree( leftnode )
       
    27 		buildkdtree( rightnode )*/
       
    28 }
       
    29 
       
    30 void KdTree::rebuild()
       
    31 {
       
    32 	int count = shapes->size();
       
    33 	AABB bbox = shapes->extends();
       
    34 
       
    35 	Subdivide(root, bbox, 0, count);
       
    36 }