13.07.2015 Views

Improvements on the kd-tree

Improvements on the kd-tree

Improvements on the kd-tree

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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><strong>the</strong> array is 18n, where 6n nodes are reserved for <strong>the</strong> cuts, <strong>the</strong>leaves and <strong>the</strong> pointers. Although this may still be a roughover-estimati<strong>on</strong> for some simple scenes, going even lowermay involve disadvantageous effects. First of all, if <strong>the</strong> arrayis filled, <strong>the</strong> above menti<strong>on</strong>ed terminati<strong>on</strong> could occur.Sec<strong>on</strong>dly, even if <strong>the</strong> array is not filled, a deeper <strong>tree</strong> willallow l<strong>on</strong>ger branches without using pointers. Therefore,over-allocati<strong>on</strong> slightly increases compactness and traversalspeed. Setting <strong>the</strong> array to <strong>the</strong> size of 18n will allow for <strong>the</strong>storage of worst-case <strong>kd</strong>-<strong>tree</strong>s, and speed-effective representati<strong>on</strong>of simple <strong>on</strong>es.In <strong>the</strong> following table <strong>the</strong> numbers of leaves and pointersfor various scenes are listed. Obviously, <strong>the</strong> number ofpointers remains below <strong>the</strong> worst-case bound. This representati<strong>on</strong>definitely uses fewer pointers than <strong>the</strong> previous soluti<strong>on</strong>s,which should result in better cache coherence andfaster traversal.Scene Patches Nodes Leaves PointersCornell box 3968 9037 4296 444Beethoven 2636 23140 9883 3373Random 3515 39389 16981 5426Tea 10025 54392 23874 6643Chickens 16467 115455 49094 17266House 24737 156469 65540 253885. <strong>kd</strong>-<strong>tree</strong>s for animati<strong>on</strong>5.1. Separati<strong>on</strong> of dynamic and static objectsRebuilding <strong>the</strong> whole <strong>kd</strong>-<strong>tree</strong> for every frame is obviouslyvery expensive and also superfluous. If <strong>the</strong> objects are classifiedas static objects staying at a fixed positi<strong>on</strong> during <strong>the</strong>animati<strong>on</strong>, and dynamic objects that may move, we can buildtwo different <strong>kd</strong>-<strong>tree</strong>s. This may have various advantages.First of all, <strong>the</strong> time of <strong>the</strong> <strong>kd</strong>-<strong>tree</strong> c<strong>on</strong>structi<strong>on</strong> is dramaticallyreduced. It also becomes possible to shoot rays <strong>on</strong>lyinto <strong>the</strong> dynamic <strong>kd</strong>-<strong>tree</strong>, <strong>the</strong>reby identifying changes of <strong>the</strong>scene al<strong>on</strong>g previous shooting or ga<strong>the</strong>ring paths. It is interestingto examine how <strong>the</strong> data structure could be helpfulat making use of frame-to-frame coherence. However, in <strong>the</strong>dual <strong>kd</strong>-<strong>tree</strong> structure traversal will be slower. Theoretically,if <strong>the</strong> both <strong>tree</strong>s c<strong>on</strong>tain a large number of objects, <strong>the</strong> traversaltime would be independent of <strong>the</strong> size of <strong>the</strong> <strong>tree</strong>, <strong>the</strong>reforeseparating <strong>the</strong>m could double <strong>the</strong> time cost. This wouldof course be unacceptable, and should be addressed.Obviously, <strong>the</strong> less objects are in <strong>the</strong> dynamic <strong>kd</strong>-<strong>tree</strong>,<strong>the</strong> faster it can be built. The moving objects in an animati<strong>on</strong>sequence can usually be separated into sets of primitivesthat move toge<strong>the</strong>r. This is even more characteristic toscenes with rigid bodies, where <strong>the</strong> primitives of a higherlevelobject are static relative to each o<strong>the</strong>r. Rec<strong>on</strong>structing<strong>the</strong> <strong>kd</strong>-<strong>tree</strong> using <strong>the</strong> primitives would not take any advantageof this property. The <strong>kd</strong>-<strong>tree</strong> for <strong>the</strong> rigid objects can bebuilt in advance, but if <strong>the</strong> objects are rotated, <strong>the</strong> splittingplanes would not be axis-aligned any more, and such a structurecould not be used as a sub-<strong>tree</strong> of <strong>the</strong> dynamic <strong>kd</strong>-<strong>tree</strong>.The soluti<strong>on</strong> is pre-compute <strong>the</strong> <strong>kd</strong>-<strong>tree</strong>s for <strong>the</strong> rigid objects,attach <strong>the</strong>m <strong>the</strong>se objects, and define <strong>the</strong> intersecti<strong>on</strong>test for an object as <strong>the</strong> ray shot in its <strong>kd</strong>-<strong>tree</strong>. If <strong>the</strong> objectsare translated, rotated or transformed in any o<strong>the</strong>r way,<strong>the</strong>n <strong>the</strong> ray must be transformed into <strong>the</strong> model space 5 ,inwhich <strong>the</strong> sub-<strong>kd</strong>-<strong>tree</strong> is axis-aligned. This way <strong>the</strong> dynamic<strong>tree</strong> will be built of a few rigid objects, and not many moreprimitives. The rec<strong>on</strong>structi<strong>on</strong> of <strong>the</strong> data structure betweenframes will be d<strong>on</strong>e in very little time, and traversal overheadbecause of <strong>the</strong> dual <strong>tree</strong> structure will be minimal.However, several questi<strong>on</strong>s arise. In order to build a <strong>kd</strong><strong>tree</strong>of transformed objects, <strong>the</strong> extremes al<strong>on</strong>g every axishave to be found. Computing a bounding box for a set ofpoints is straightforward but may be unacceptably expensivefor a large number of vertices. Fur<strong>the</strong>rmore, as an intersecti<strong>on</strong>test for such a high-level object is costly, a cheaper prefilteringwould be useful. Both problems are addressed by apre-computing a bounding object easy to transform. An ellipsoid,being a quadratic surface, is <strong>the</strong> most appropriate. If<strong>the</strong> smallest enclosing ellipsoid for <strong>the</strong> vertices of <strong>the</strong> objectis calculated, it can be transformed appropriately for everyframe. Its extremes may be used to determine <strong>the</strong> boundingbox, and an intersecti<strong>on</strong> test with a quadratic object can beused to filter a huge amount of n<strong>on</strong>-intersecting rays out. Thealgorithm used to determine <strong>the</strong> smallest enclosing ellipsoidis based <strong>on</strong> linear programming 7 and runs in Ç´nµ time 1 .5.2. Synchr<strong>on</strong>ous traversal of <strong>the</strong> dual <strong>tree</strong>We have menti<strong>on</strong>ed above that <strong>the</strong> traversal cost for two <strong>tree</strong>smay be <strong>the</strong> double of <strong>the</strong> cost for <strong>on</strong>e <strong>tree</strong> of twice as manyobjects. This is, however, a worst case assumpti<strong>on</strong>, and canbe avoided in several ways. First of all, <strong>the</strong> formerly describeduse of compound rigid objects will decrease <strong>the</strong> sizeand traversal cost of <strong>the</strong> dynamic <strong>tree</strong>. Sec<strong>on</strong>dly, it is obviousthat if we have found an intersecti<strong>on</strong> in <strong>the</strong> dynamic <strong>tree</strong>,<strong>the</strong> search in <strong>the</strong> static <strong>tree</strong> may be limited to <strong>the</strong> segment of<strong>the</strong> ray between <strong>the</strong> origin and <strong>the</strong> intersecti<strong>on</strong> point. Thatis, we do not test in areas occluded by dynamic objects. Thissimple modificati<strong>on</strong> will result traversal times very close to<strong>the</strong> <strong>on</strong>e <strong>tree</strong> case, especially if <strong>the</strong> dynamic objects are rarelyoccluded by static <strong>on</strong>es. However, it is not always possibleto identify rigid objects, and <strong>the</strong> visibility relati<strong>on</strong> between<strong>the</strong> dynamic and static objects may not be so determined forsome animati<strong>on</strong> sequences. Therefore, we introduce a costeffectivetraversal algorithm for multiple overlapping <strong>kd</strong><strong>tree</strong>s,especially useful if a large number of independentlymoving primitives are stored in <strong>the</strong> <strong>kd</strong>-<strong>tree</strong>.Basically, a <strong>the</strong> cell boundaries of a <strong>kd</strong>-<strong>tree</strong> separate atraversing ray into segments. A traversal algorithm will identifythose segments, and will compute intersecti<strong>on</strong> tests <strong>on</strong>every segment in order. If <strong>the</strong> objects are stored in multiple<strong>kd</strong>-<strong>tree</strong>, multiple segmentati<strong>on</strong>s exist. The task is to find an

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

Saved successfully!

Ooh no, something went wrong!