670 likes | 856 Views
Matrix Trees. Nate Andrysco Xavier Tricoche Purdue University Department of Computer Science. Overview of Matrix Trees. Spatial subdivision trees are basic building blocks of graphics and visualization Octree KD-Tree BSP Tree Same underlying data structures for 30+ years
E N D
Matrix Trees Nate Andrysco Xavier Tricoche Purdue University Department of Computer Science EuroVis 2010
Overview of Matrix Trees • Spatial subdivision trees are basic building blocks of graphics and visualization • Octree • KD-Tree • BSP Tree • Same underlying data structures for 30+ years • A solved problem?
Overview of Matrix Trees • An octree and kd-tree data structure that is…
Overview of Matrix Trees • An octree and kd-tree data structure that is… Smaller!
Overview of Matrix Trees • An octree and kd-tree data structure that is… Smaller! Faster!
Overview of Matrix Trees • An octree and kd-tree data structure that is… Smaller! Faster! Versatile!
Overview of Matrix Trees • An octree and kd-tree data structure that is… Smaller! Faster! Versatile! GPU Friendly!
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Applications • Ray Casting • Unstructured Mesh
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Ray Casting Application • Unstructured Mesh Application
Previous Tree Representations • Pointer-based Trees • Each node contains some data
Previous Tree Representations • Pointer-based Trees • Each node contains some data • Now add in pointers
Previous Tree Representations • Pointer-based Trees • Each node contains some data • Now add in pointers • … add position information
Previous Tree Representations • Pointer-based Trees • Each node contains some data • Now add in pointers • … add position information
Previous Tree Representations • Pointer-based Trees • Each node contains some data • Now add in pointers • Extra programming difficulty
Previous Tree Representations • Pointer-based Trees • Each node contains some data • Now add in pointers • Extra programming difficulty • Memory required by tree is linear to nodes in tree
Previous Tree Representations • Pointerless Trees • Each node contains some data
Previous Tree Representations • Pointerless Trees • Each node contains some data • Derive position in memory of parents, children, neighbors, etc • Derive position information
Previous Tree Representations • Pointerless Trees • Each node contains some data • Derive position in memory of parents, children, neighbors, etc • Derive position information • GPU ready data structure
Previous Tree Representations • Pointerless Trees • Each node contains some data • Derive position in memory of parents, children, neighbors, etc • Derive position information • GPU ready data structure • Total memory is exponential to height of tree
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Applications • Ray Casting • Unstructured Mesh
Our Representation • Use matrices as underlying representation • Provides “best of both worlds” • A separate matrix per level of tree • Sparse matrix data structure • Allows for improvements to tree operations
Quadtree Example 1x1 Matrix 2x2 Matrix 4x4 Matrix 8x8 Matrix
Quadtree Example 1x1 Matrix 2x2 Matrix 4x4 Matrix 8x8 Matrix 1x1 Matrix 2x2 Matrix 4x4 Matrix ? 8x8 Matrix ?
Quadtree Example 1x1 Matrix 2x2 Matrix 4x4 Matrix 8x8 Matrix 1x1 Matrix 2x2 Matrix 4x4 Sparse Rep. 8x8 Sparse Rep.
Underlying Representation • Array of matrices • Each node is represented by a 4-tuple • Level in tree • (x,y,z) index position in matrix Level = 0 Level = 1 Level = 2 (1,1) (0,1) (x=0, y=0) (2,3) (3,3) (0,0) (1,0) (2,2) (3,2)
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Ray Casting Application • Unstructured Mesh Application
Deriving Node Indices • Given the node tuple, [ level, x, y ]: • Parent = [ level-1, x/2, y/2 ] Level = 0 Level = 1 Level = 2 (x=0, y=0) (1,0) (3,2)
Deriving Node Indices • Given the node tuple, [ level, x, y ]: • Child = [ level+1, x*2 + i, y*2 + j ] • Where (i,j)represent the relational index Level = 0 Level = 1 Level = 2 (x=0, y=0) (1,0) (3,2)
Deriving Node Indices • Given the node tuple, [ level, x, y ]: • Neighbor = [ level, x + i, y + j ] • Where (i,j)represent the relational index Level = 0 Level = 1 Level = 2 (1,1) (0,1) (0,0) (1,0)
Deriving Node Indices • KD-Trees need to keep track of split directions • i.e. for y-splits, parent = [ level-1, x, y/2 ] Level = 0 Level = 1 Level = 2 (0,3) (0,1) (0,2) (x=0, y=0)
Deriving Spatial Information • Cells have the same size • Easily derive matrix dimensions • Can spatially hash into any node at any level
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Ray Casting Application • Unstructured Mesh Application
Sparse Matrix Data Structure • Naïve approach – nested vectors • Easy to implement • Low cost insertions (dynamic) • Poor lookup performance • Compressed Sparse Row (CSR) • Quicker random access • Costly random insertions (static) • Easily and quickly transform naïve to CSR
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Lookup data at ( 2 , 1 ) 5.4 0 2.0 0 0 0 0 1.5 4.8 3.4 8.2 0 0 7.7 9.1 0
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Row index vector • O(1) lookup
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Lookup data at ( 2 , 1 ) 5.4 0 2.0 0 0 0 0 1.5 4.8 3.4 8.2 0 0 7.7 9.1 0
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Row index vector • O(1) lookup • Column index vector • O(lg m) lookup
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Lookup data at ( 2 , 1 ) 5.4 0 2.0 0 0 0 0 1.5 4.8 3.4 8.2 0 0 7.7 9.1 0
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Row index vector • O(1) lookup • Column index vector • O(lg m) lookup • Data vector • O(1) lookup
Sparse Matrix Data Structure • Compressed Sparse Row (2D) • Lookup data at ( 2 , 1 ) 5.4 0 2.0 0 0 0 0 1.5 4.8 3.4 8.2 0 0 7.7 9.1 0
Complementary CSR • Compressed Sparse Row (2D) • If our matrix is dense… 5.4 0 2.0 0 0 2.2 0 1.5 4.8 3.4 8.2 0 4.2 7.7 9.1 1.3
Complementary CSR • Compressed Sparse Row (2D) • If our matrix is dense… • Keep track of non-zeros 5.4 0 2.0 0 0 2.2 0 1.5 4.8 3.4 8.2 0 4.2 7.7 9.1 1.3
Complementary CSR • Compressed Sparse Row (2D) • If our matrix is dense… • Keep track of non-zeros • If we only care if a node exists 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 1
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Ray Casting Application • Unstructured Mesh Application
GPU Implementation • Data and indices are stored as vectors on CPU • Concatenate CPU vectors and store in GPU textures • Use helper vectors • Matrix types • Data offsets • CSR index vector offsets
Outline • Previous Tree Representations • Our Representation • Deriving Information • Sparse Matrix Data Structure • GPU Implementation • Tree Operations (Leaf and Neighbor Finding) • Theoretical Analysis • Applications • Ray Casting • Unstructured Mesh
Previous Leaf Finding • Given a point, find the leaf that contains it • Majority of previous methods are top-down • O(log N) average • … or O(h) 1 2 3 4 5
Our Improved Leaf Finding • Initial hash, O(1), eliminates N-h nodes
Our Improved Leaf Finding • Binary search along path, O (log2 h) 2 3 1
Improved Neighbor Finding • Previous method for pointer-based trees: • Can result in full leaf finding operation • Our method: • Neighbors at same level • Simply derive information • Neighbors at other levels • Do limited binary search