Presentation is loading. Please wait.

Presentation is loading. Please wait.

Similar presentations


Presentation on theme: ""— Presentation transcript:

292 COMPUTER GRAPHICS CHAPTER 37 CS 482 – Fall 2017 DATA STRUCTURES
QUAD TREES OCTREES K-D TREES BINARY SPACE PARTITIONING

293 CHAPTER 37: DATA STRUCTURES
QUAD TREES 2D PARTITIONING Quad trees are used to partition two-dimensional space by recursively subdividing it into quadrants until each quadrant contains all or part of a single shape or reaches some minimum size (usually a pixel). Quad trees are effectively utilized in applications such as image representation, efficient 2D collision detection, and fractal image analysis. CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 293

294 QUAD TREES RECURSIVE SUBDIVISION OF TOPOGRAPHICAL SURFACES
In the application, a topographical map is recursively subdivided until each region is reasonably flat (i.e., the center and four corners are within ten meters of each other in elevation). Pink regions aren’t flat enough Yellow-green regions became flat enough on this iteration Tan regions don’t require further subdivision Final subdivision squares Circle drawn in center of each square Circles colored with a gradient CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 294

295 CHAPTER 37: DATA STRUCTURES
OCTREES 3D PARTITIONING Octrees extend the notion of Quad trees into three dimensions by recursively subdividing 3D space into octants until each contains all or part of a single shape or reaches some minimum size (usually a voxel). Commonly used for view 3D image representation, frustum culling, and 3D collision detection, octrees have also proven effective in reducing a scene’s color palette. CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 295

296 CHAPTER 37: DATA STRUCTURES
OCTREES COLOR QUANTIZATION To restrict an image’s color palette to a particular size, the following octree algorithm starts by creating an octree whose leaf nodes constitute a count of how many pixels in the image possess a particular color. For each color in the scene, separate the color into 8-bit RGB components. RGB=(100, 117, 214) R: G: B: Starting with the most significant bit for each primary color, use the eight 3-bit sequences to generate indices between 0 and 7 by adding R+2G+4B. 001 7 110     2 Traverse the octree structure, using the computed indices to determine which offspring to visit, adding one to the count of the color in question in the leaf node. After finishing all pixels, if the number of leaf nodes exceeds the desired palette size, start merging leaf nodes with low counts into their parent. CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 296

297 OCTREES COLOR QUANTIZATION Full Color Image
16-Color Octree Quantization CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 297

298 K-D TREES BALANCED PARTITIONING
K-D TREES PARTITION SPACE IN A BALANCED MANNER BY ALTERNATING BETWEEN VERTICAL AND HORIZONTAL SPLITTING OF REGIONS INTO TWO PARTS, EACH CONTAINING HALF OF THE REGION’S OBJECTS. CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 298

299 K-D TREES NEAREST NEIGHBOR ALGORITHM
K-D TREES MAY BE USED TO DETERMINE WHICH OF THE ORIGINAL OBJECTS IN THE SCENE ARE CLOSEST TO A PARTICULAR LOCATION. Recursively traverse the tree until you determine which sector the new location belongs in. The object in this sector is the initial candidate for being closest. Backtrack up the tree from the leaf node to the root, determining whether the subtree on the other side of each partition contains an object that’s closer to the location in question, which would make it the new candidate for closest. This algorithm may be used to speed up ray tracing (by determining that a ray doesn’t intersect particular portioned sectors). Once the backtracking reaches the root of the tree, the current candidate object is the actual closest object to the specified location. CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 299

300 K-D TREES a b g c f h i d e DETAILED EXAMPLE: K-D TREE CONSTRUCTION
x=s1 y=s2 y=s6 x=s3 y=s4 y=s7 y=s8 a b x=s5 g c f h i d e CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 300

301 K-D TREES a b g c f h i d e g g f f h h e e
DETAILED EXAMPLE: K-D TREE CONSTRUCTION x=s1 y=s2 x=s3 y=s4 y=s6 y=s7 y=s8 a b x=s5 g c f h i d e g g f f h h e e CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 301

302 BINARY SPACE PARTITIONING
BSP TREES Using a binary tree structure, object space can be partitioned into numerous half-spaces, and the viewpoint’s position in these half-spaces can be used to determine the order in which they should be rendered in the Painter’s Algorithm. A B C D2 E F D1 Pick a polygon and split the space into the part in front of the polygon and the part in back of it (splitting all intersected polygons) B A,D2,E,F C,D1 front back A B C D2 E F D1 A B C D2 E F D1 A B C D2 E F D1 B F C front back A D2 D1 E Continue this process B F C,D1 front back A D2,E B F C front back A D2,E D1 The process ends when each tree node contains one object (or sub-object) CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 302

303 BINARY SPACE PARTITIONING
PAINTER’S ALGORITHM IMPLEMENTATION B F C front back A D2 D1 E When determining the order in which the objects should be displayed (e.g., in a painter’s algorithm) for a particular viewpoint, merely traverse the BSP tree recursively: If the viewpoint is in front of the root, traverse Back-Root-Front; otherwise, traverse Front-Root-Back. Example 1 Example 2 A B C D2 E F D1 A B C D2 E F D1 Viewpoint Viewpoint B-subtree: in front  C-subtree, B, F-subtree C-subtree: in front  C, D1 F-subtree: in front  A, F, D2-subtree D2-subtree: in back  D2, E Complete Traversal: C, D1, B, A, F, D2, E B-subtree: in back  F-subtree, B, C-subtree F-subtree: in front  A, F, D2-subtree D2-subtree: in front  E, D2 C-subtree: in front  C, D1 Complete Traversal: A, F, E, D2, B, C, D1 CS 482 – Fall 2017 CHAPTER 37: DATA STRUCTURES PAGE 303


Download ppt ""

Similar presentations


Ads by Google