13.07.2015 Views

Improvements on the kd-tree

Improvements on the kd-tree

Improvements on the kd-tree

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

László Szécsi and Balázs Benedek / <str<strong>on</strong>g>Improvements</str<strong>on</strong>g> <strong>on</strong> <strong>the</strong> <strong>kd</strong>-<strong>tree</strong>is, we have to discard <strong>the</strong> c<strong>on</strong>cept of balancedness, and willhave to find <strong>the</strong> means to store a n<strong>on</strong>-balanced <strong>tree</strong> in a compactway.Although simple cut heuristics produce inferior traversaltimes, fast c<strong>on</strong>structi<strong>on</strong> and compact data structure are advantages.Therefore, <strong>the</strong>y may have some relevance if <strong>the</strong>structure is to be built real-time, despite <strong>the</strong> fact that in globallyilluminated animati<strong>on</strong> <strong>the</strong> traversal cost tends to be <strong>the</strong>bottleneck. As <strong>the</strong> <strong>tree</strong> c<strong>on</strong>structi<strong>on</strong> time rapidly increaseswith <strong>the</strong> number of objects, but <strong>the</strong> traversal time for sceneslarge enough is c<strong>on</strong>stant, it is not to exclude, that <strong>the</strong> situati<strong>on</strong>may change, especially in <strong>the</strong> case of very high polyg<strong>on</strong>number, vertex-based animati<strong>on</strong>s. The compact memoryrepresentati<strong>on</strong> used for <strong>the</strong> balanced <strong>tree</strong> is definitely to beused somehow in <strong>the</strong> more sophisticated methods.3. Improvement of <strong>the</strong> cost functi<strong>on</strong>3.1. Previous workA way to find <strong>the</strong> optimal cut is to c<strong>on</strong>sider all reas<strong>on</strong>ablecuts, including cutting off empty space and terminati<strong>on</strong> of<strong>the</strong> build, and choose <strong>the</strong> <strong>on</strong>e that produces <strong>the</strong> shortest expectedtraversal time. To achieve this we need estimate thattime. Havran proposed <strong>the</strong> following functi<strong>on</strong>, linear withrespect to <strong>the</strong> number of objects in <strong>the</strong> sub-volumes:C 1V SA´V SA´le ftChild´V µµ´N L · N SP µ·µSA´rightChild´V µµ´N SP · N R µ℄ (1)Where C V is <strong>the</strong> cost corresp<strong>on</strong>ding to volume V, SA´V µ is<strong>the</strong> surface area of volume V, and N L , N R , N SP are <strong>the</strong> numberof objects completely in <strong>the</strong> left and right sub-volumes,and <strong>the</strong> number of objects intersected by <strong>the</strong> splitting plane,respectively.This means that <strong>the</strong> expected time for <strong>the</strong> traversal of avolume is <strong>the</strong> time needed to carry out <strong>the</strong> naïve intersecti<strong>on</strong>test for all objects, multiplied by <strong>the</strong> probability of a rayhitting <strong>the</strong> volume. This probability, c<strong>on</strong>sidering that <strong>the</strong> volumesare c<strong>on</strong>vex, equals <strong>the</strong> ratio of <strong>the</strong> surface areas. Obviously,<strong>the</strong> estimate given by this functi<strong>on</strong> does not equal <strong>the</strong>actual time cost, as <strong>the</strong> created volumes will be subdividedfur<strong>the</strong>r, and not handled with <strong>the</strong> naïve algorithm. Havranalso identified this problem and proposed some ideas for <strong>the</strong>soluti<strong>on</strong>. He stated that <strong>the</strong> optimal cost functi<strong>on</strong> depends <strong>on</strong><strong>the</strong> distributi<strong>on</strong> of <strong>the</strong> objects in <strong>the</strong> actual scene to a greatextent, and thus for a better estimate <strong>the</strong> cost must be measuredin some way. Although it is possible to build <strong>the</strong> <strong>tree</strong>and compute <strong>the</strong> cost precisely, doing this every time <strong>the</strong>functi<strong>on</strong> should be evaluated would lead to computati<strong>on</strong>alexplosi<strong>on</strong> of <strong>the</strong> c<strong>on</strong>structi<strong>on</strong> algorithm. Therefore, in orderto obtain a more effective functi<strong>on</strong>, <strong>the</strong> scene should be characterisedby values that are easily determined, and influence<strong>the</strong> cost functi<strong>on</strong>.3.2. N<strong>on</strong>-linear cost estimateIn a recent article we have shown that for scenes with largenumber of random objects, <strong>kd</strong>-<strong>tree</strong> traversal is d<strong>on</strong>e in c<strong>on</strong>stanttime. How can this be brought into c<strong>on</strong>s<strong>on</strong>ance with <strong>the</strong>linear estimati<strong>on</strong>? How can Havran’s method provide outstandingresults despite this c<strong>on</strong>tradicti<strong>on</strong>? If we are low in<strong>the</strong> <strong>tree</strong>, near <strong>the</strong> leaves, and it is true that <strong>the</strong> sub-volumeswill go through little to no fur<strong>the</strong>r subdivisi<strong>on</strong>, than <strong>the</strong> linearestimati<strong>on</strong> is of course perfect. On <strong>the</strong> o<strong>the</strong>r hand, if weare near <strong>the</strong> root of <strong>the</strong> <strong>tree</strong>, meaning that <strong>the</strong> c<strong>on</strong>stant timetraversal statement hold for <strong>the</strong> sub-<strong>tree</strong>s, <strong>the</strong>n <strong>the</strong> expectedtraversal time is independent of <strong>the</strong> cut. Therefore, if <strong>the</strong> linearestimate would fail, <strong>the</strong>n where we cut is not so importantat all. However, it is possible to c<strong>on</strong>struct a more accuratecost estimate, if we are able to account for <strong>the</strong> gain fromseparating <strong>the</strong> elements and cutting off empty space. To calculatethat exactly would be hopelessly expensive, but bysimply changing <strong>the</strong> linear functi<strong>on</strong> to a bit more fitting <strong>on</strong>e,we may eliminate some of <strong>the</strong> inaccuracy <strong>on</strong> higher levels of<strong>the</strong> <strong>tree</strong>. It is of course imperative to keep <strong>the</strong> linearity in <strong>the</strong>lower regi<strong>on</strong>s where it works perfectly. Let us suppose thata cut improves <strong>the</strong> time by a factor of q 1 <strong>on</strong> average, andthat a cell c<strong>on</strong>taining n 0 elements is not worth dividing anymore. Actually, that means that a cell may c<strong>on</strong>tain n 0 objects<strong>on</strong> average. Using that <strong>the</strong> cost of traversal, without <strong>the</strong> adjustmentfor <strong>the</strong> probability of <strong>the</strong> volume being hit is givenin <strong>the</strong> following equati<strong>on</strong>. This functi<strong>on</strong> is to be applied to<strong>the</strong> number of objects in <strong>the</strong> sub-volumes in 1:f ´nµ n¡q log 2´n n 0µ(2)The value of n 0 is relatively easy to find, and will be determinedby <strong>the</strong> primitive geometry. The value q, however, isquite an abstracti<strong>on</strong>. It includes both cuts between objectsand cutting off empty space. Actually, it corresp<strong>on</strong>ds moreto <strong>the</strong> subdivisi<strong>on</strong> potential of <strong>the</strong> volume than to <strong>the</strong> obscurec<strong>on</strong>cept of cost reducti<strong>on</strong> achieved by a single cut. Still, it isnot harmful to overestimate both n 0 and q, as that will get usnearer to <strong>the</strong> original linear estimate. Therefore, <strong>the</strong> formulafor <strong>the</strong> expected number of intersecti<strong>on</strong> tests introduced inour previous article 3 can be applied to determine a probableupper bound for <strong>the</strong> traversal cost of <strong>the</strong> <strong>tree</strong> that is beingbuilt, providing a value for q. Naturally, significantly betterresults are <strong>on</strong>ly expected for large scenes with high primitivecount, as <strong>the</strong> linear functi<strong>on</strong> is less accurate, and <strong>the</strong> guessfor q is better in those cases. The previous equati<strong>on</strong> can fur<strong>the</strong>rbe written as:f ´nµ n¡´n n 0 µ log 2 q (3)f ´nµ ´n n 0 µ 1·log 2 q · n 0 ¡ ´n n 0 µ log2q (4)As ´n n 0 µ log2q 1, <strong>the</strong> cost may be over-estimated as:f ´nµ n¡´n n 0 µ log 2 q ´n n 0 µ 1·log 2 q · n 0 (5)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!