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>optimal order of <strong>the</strong> segments, so that no segment fur<strong>the</strong>rthan <strong>the</strong> first valid intersecti<strong>on</strong> is examined. That means, ifany point of segment A is nearer to <strong>the</strong> origin of <strong>the</strong> ray thanany point of segment B, <strong>the</strong>n A must precede B in <strong>the</strong> traversalorder. A known recursive algorithm, described in detailby Havran 2 , is extended <strong>the</strong> following way:1. Set up a search interval for every <strong>tree</strong> as <strong>the</strong> entire ray.2. Choose that ’n<strong>on</strong>-terminated’ <strong>tree</strong>, for which <strong>the</strong> minimumpoint of <strong>the</strong> search interval is <strong>the</strong> nearest to <strong>the</strong> origin.3. Traverse <strong>the</strong> chosen <strong>tree</strong> using <strong>the</strong> recursive algorithm. Aseparate traversal stack and a current node identifier hasto be maintained for every <strong>tree</strong>. C<strong>on</strong>tinue until a leaf isreached.4. If a leaf is being processed, test for intersecti<strong>on</strong>s, and update<strong>the</strong> global closest intersecti<strong>on</strong> found if necessary. Set<strong>the</strong> search interval to <strong>the</strong> segment of <strong>the</strong> ray intersected by<strong>the</strong> volume of <strong>the</strong> next node to be processed according to<strong>the</strong> recursive traversal algorithm. If <strong>the</strong> traversal stack isempty, or a valid intersecti<strong>on</strong> was found, mark <strong>the</strong> <strong>tree</strong> as’terminated’.5. If a valid intersecti<strong>on</strong> was already found, and <strong>the</strong> searchinterval for every <strong>tree</strong> is entirely fur<strong>the</strong>r <strong>the</strong>n <strong>the</strong> closestintersecti<strong>on</strong>, terminate, and return <strong>the</strong> found intersecti<strong>on</strong>.6. If all <strong>the</strong> <strong>tree</strong>s are marked ’terminated’, <strong>the</strong>re was no intersecti<strong>on</strong>with <strong>the</strong> ray in ei<strong>the</strong>r of <strong>the</strong> <strong>tree</strong>s, return withouta result.7. C<strong>on</strong>tinue with step 2.opposite case <strong>the</strong> same amount of tests are carried out. However,we have to remark that <strong>the</strong>re is some overhead becauseof some additi<strong>on</strong>al administrati<strong>on</strong> and weaker cache coherence,a result of handling more <strong>kd</strong>-<strong>tree</strong>s simultaneously.5.3. ResultsScenes have been divided into a static and dynamic part totest <strong>the</strong> algorithm. Three cases were examined:One <strong>tree</strong>: All <strong>the</strong> patches, static or dynamic, are stored in acomm<strong>on</strong> <strong>kd</strong>-<strong>tree</strong>.Sequential: Static and dynamic patches are stored in separate<strong>tree</strong>s. When calculating a ray-scene intersecti<strong>on</strong>, firstwe traverse <strong>on</strong>ly <strong>the</strong> dynamic <strong>tree</strong>. Thereafter <strong>the</strong> static<strong>tree</strong> is tested, but <strong>on</strong>ly <strong>on</strong> <strong>the</strong> ray segment between <strong>the</strong>origin and <strong>the</strong> intersecti<strong>on</strong> point in <strong>the</strong> dynamic <strong>tree</strong>.Parallel: Static and dynamic patches are stored in separate<strong>tree</strong>s. The parallel traversal algorithm is used for raysceneintersecti<strong>on</strong>s.0 0001 23 045Figure 4: The parallel traversal of two <strong>kd</strong>-<strong>tree</strong>s partiti<strong>on</strong>ing<strong>the</strong> same space, c<strong>on</strong>taining different sets of objects. The cellsare numbered to indicate <strong>the</strong> order of <strong>the</strong>ir processing. N<strong>on</strong>processedcells al<strong>on</strong>g <strong>the</strong> ray are marked with 0.Figure 5: One of <strong>the</strong> test scenes. The two standing chickensare c<strong>on</strong>sidered static, <strong>the</strong> o<strong>the</strong>r two, those over <strong>the</strong> ground,are dynamic.Compared to <strong>the</strong> sequential soluti<strong>on</strong>, where <strong>the</strong> <strong>tree</strong>s aretraversed after <strong>on</strong>e ano<strong>the</strong>r, <strong>on</strong> <strong>the</strong> interval limited by previouslyfound intersecti<strong>on</strong>s, we spare <strong>the</strong> traversal of <strong>the</strong> raysegments between <strong>the</strong> nearest intersecti<strong>on</strong> and those fur<strong>the</strong>rintersecti<strong>on</strong>s, that were to be found in previously traversed<strong>tree</strong>s. Speaking about <strong>the</strong> dual <strong>tree</strong> structure, we have twoopti<strong>on</strong>s: traverse <strong>the</strong> dynamic <strong>tree</strong>, and <strong>the</strong>n <strong>the</strong> static <strong>tree</strong>, ordo it in parallel. If <strong>the</strong> nearest intersecti<strong>on</strong> is in <strong>the</strong> static <strong>tree</strong>,<strong>the</strong>n <strong>the</strong> parallel algorithm will not investigate <strong>the</strong> segmentbetween <strong>the</strong> dynamic and static intersecti<strong>on</strong> points. In <strong>the</strong>The tests were run with two different <strong>kd</strong>-<strong>tree</strong> c<strong>on</strong>structi<strong>on</strong>routines. We rendered an image using Bi-directi<strong>on</strong>al PathTracing 4 . We used a test scene of large static and dynamicobjects with a high primitive count, which simulates a frameof an animati<strong>on</strong> sequence well, we believe. In <strong>the</strong> o<strong>the</strong>r testscene, both <strong>the</strong> static and dynamic patches were generated<strong>on</strong> random. With <strong>the</strong> first versi<strong>on</strong>, we obtained satisfying resultsshowing that <strong>the</strong> parallel traversal is faster. Executi<strong>on</strong>times are specified in sec<strong>on</strong>ds:

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

Saved successfully!

Ooh no, something went wrong!