| author | Radek Brich <radek.brich@devl.cz> | 
| Mon, 29 Oct 2007 15:50:17 +0100 | |
| branch | pyrit | 
| changeset 1 | e74bf781067e | 
| parent 0 | 3547b885df7e | 
| child 7 | bf17f9f84c91 | 
| permissions | -rw-r--r-- | 
| 0 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 1 | #include "kdtree.cc" | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 2 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 3 | void KdTree::KdTree(ShapeList &shapelist): | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 4 | {
 | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 5 | root = new KdNode(); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 6 | shapes = new vector<Shape*>(); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 7 | ShapeList::iterator shape; | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 8 | for (shape = shapelist.begin(); shape != shapes.end(); shape++) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 9 | addShape(*shape); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 10 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 11 | rebuild(); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 12 | } | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 13 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 14 | void KdTree::Subdivide(KdNode* node, AABB& bbox, int depth, int count) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 15 | {
 | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 16 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 17 | /*if (stopcriterionmet()) return | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 18 | splitpos = findoptimalsplitposition() | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 19 | leftnode = new Node() | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 20 | rightnode = new Node() | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 21 | for (all primitives in node) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 22 | 	{
 | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 23 | if (node->intersectleftnode()) leftnode->addprimitive( primitive ) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 24 | if (node->intersectrightnode()) rightnode->addprimitive( primitive ) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 25 | } | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 26 | buildkdtree( leftnode ) | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 27 | buildkdtree( rightnode )*/ | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 28 | } | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 29 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 30 | void KdTree::rebuild() | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 31 | {
 | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 32 | int count = shapes->size(); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 33 | AABB bbox = shapes->extends(); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 34 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 35 | Subdivide(root, bbox, 0, count); | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 36 | } |