10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees.

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Nearest Neighbor Search

Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Computer graphics & visualization Collisions. computer graphics & visualization Simulation and Animation – SS07 Jens Krüger – Computer Graphics and Visualization.
Searching on Multi-Dimensional Data
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
CSE 381 – Advanced Game Programming Scene Management
Korea Univ. Graphics Lab. 3D Game Engine Design Chapter 12. Spatial Sorting Chung Ji Hye
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Advanced Data Structures for Games and Graphics Lecture 4
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why.
UNC Chapel Hill M. C. Lin Overview of Last Lecture About Final Course Project –presentation, demo, write-up More geometric data structures –Binary Space.
1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
1 Advanced Scene Management System. 2 A tree-based or graph-based representation is good for 3D data management A tree-based or graph-based representation.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
10/02/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Octrees.
Hidden Surface Removal
12/4/2001CS 638, Fall 2001 Today Using separating planes/axes for collision testing Collision detection packages.
BSP Trees, Quadtrees & Octrees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January 28, 2004.
Computer Graphics 2 Lecture x: Acceleration Techniques for Ray-Tracing Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Data Structures for Computer Graphics Point Based Representations and Data Structures Lectured by Vlastimil Havran.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Spatial Partitioning, Visibility and Culling Spring.
1 Speeding Up Ray Tracing Images from Virtual Light Field Project ©Slides Anthony Steed 1999 & Mel Slater 2004.
The Visibility Problem In many environments, most of the primitives (triangles) are not visible most of the time –Architectural walkthroughs, Urban environments.
Graphics Graphics Korea University cgvr.korea.ac.kr Solid Modeling 고려대학교 컴퓨터 그래픽스 연구실.
Visible-Surface Detection Jehee Lee Seoul National University.
CS-378: Game Technology Lecture #10: Spatial Data Structures Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran.
12/4/2001CS 638, Fall 2001 Today Managing large numbers of objects Some special cases.
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 03 / 21 / 2007 Instructor: Michael Eckmann.
Implementation II.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
Multi-dimensional Search Trees CS302 Data Structures Modified from Dr George Bebis.
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
Maths & Technologies for Games Spatial Partitioning 2
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
1 Advanced Scene Management. 2 This is a game-type-oriented issue Bounding Volume Hierarchies (BVHs) Binary space partition trees (BSP Trees) “Quake”
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Ray Tracing Acceleration (3)
Hierarchical Data Structure in Game Programming Yanci Zhang Game Programming Practice.
Spatial Data Management

Computer Graphics Implementation II
BSP Trees Binary space partitioning trees.
Collision Detection Spring 2004.
Modeliranje kompleksnih modelov
KD Tree A binary search tree where every node is a
Quadtrees 1.
© University of Wisconsin, CS559 Fall 2004
CS679 - Fall Copyright Univ. of Wisconsin
Modeliranje kompleksnih modelov
Presentation transcript:

10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees

10/09/2001CS 638, Fall 2001 Spatial Data Structures Spatial data structures store data indexed in some way by their spatial location –For instance, store points according to their location, or polygons, … –Before graphics, used for queries like “Where is the nearest McDonalds?” or “Which stars are strong enough to influence the sun?” Multitude of uses in computer games –Visibility - What can I see? –Ray intersections - What did the player just shoot? –Collision detection - Did the player just hit a wall? –Proximity queries - Where is the nearest power-up?

10/09/2001CS 638, Fall 2001 Spatial Decompositions Focus on spatial data structures that partition space into regions, or cells, of some type –Generally, cut up space with planes that separate regions –Always based on tree structures (surprise, huh?) Octrees (Quadtrees): Axis aligned, regularly spaced planes cut space into cubes (squares) Kd-trees: Axis aligned planes, in alternating directions, cut space into rectilinear regions BSP Trees: Arbitrarily aligned planes cut space into convex regions

10/09/2001CS 638, Fall 2001 Using Decompositions Many geometric queries are expensive to answer precisely –All of the questions two slides back fall into this category The best way to reduce the cost is with fast, approximate queries that eliminate most objects quickly –Trees with a containment property allow us to do this –The cell of a parent completely contains all the cells of its children –If a query fails for the cell, we know it will fail for all its children –If the query succeeds, we try it for the children –If we get to a leaf, we do the expensive query for things in the cell Spatial decompositions are most frequently used in this way –For example, if we cannot see any part of a cell, we cannot see its children, if we see a leaf, use the Z-buffer to draw the contents

10/09/2001CS 638, Fall 2001 Octree Gems Ch 4.10 Root node represents a cube containing the entire world Then, recursively, the eight children of each node represent the eight sub-cubes of the parent Quadtree is for 2D decompositions - root is square and four children are sub-squares –What sorts of games might use quadtrees instead of octrees? Objects can be assigned to nodes in one of two common ways: –All objects are in leaf nodes –Each object is in the smallest node that fully contains it –What are the benefits and problems with each approach?

10/09/2001CS 638, Fall 2001 Octree Node Data Structure What needs to be stored in a node? –Children pointers (at most eight) –Parent pointer - useful for moving about the tree –Extents of cube - can be inferred from tree structure, but easier to just store it –List of pointers to the contents of the cube Contents might be whole objects or individual polygons, or even something else –Neighbors are useful in some algorithms (but not all)

10/09/2001CS 638, Fall 2001 Building an Octree Define a function, buildNode, that: –Takes a node with its cube set and a list of its contents –Creates the children nodes, divides the objects among the children, and recurses on the children, or –Sets the node to be a leaf node Find the root cube (how?), create the root node and call buildNode with all the objects When do we choose to stop creating children? –Is the tree necessarily balanced? What is the hard part in all this? Hint: It depends on how we store objects in the tree

10/09/2001CS 638, Fall 2001 Example Construction

10/09/2001CS 638, Fall 2001 Assignment of Objects to Cells Basic operation is to intersect an object with a cell –What can we exploit to make it faster for octrees? Fast(est?) algorithm for polygons (Graphics Gem V): –Test for trivial accept/reject with each cell face plane Look at which side of which planes the polygon vertices lie Note speedups: Vertices outside one plane must be inside the opposite plane –Test for trivial reject with edge and vertex planes Planes through edges/vertices with normals like (1,1,1) and (0,1,1) –Test polygon edges against cell faces –Test a particular cell diagonal for intersection with the polygon –Information from one test informs the later tests. Code available online

10/09/2001CS 638, Fall 2001 Polygon-Cell Intersection Tests: Poly-Planes Tests Planes are chosen because testing for inside outside requires summing coordinates and a comparison –Eg. Testing against a plane with normal (1,1,0) only requires checking x+y against a number (2 for a unit cube) –What tests for the other planes? Images from Möller and Haines

10/09/2001CS 638, Fall 2001 Polygon-Cell Intersection Tests: Edge-Cube Test Testing an edge against a cube is the same as testing a point (the center of the cube) against a swept volume (the cube swept along the edge) Images from Möller and Haines

10/09/2001CS 638, Fall 2001 Polygon-Cell Intersection Tests: Interior-Cube Test Test for this type of intersection by checking whether a diagonal of the cube intersects the polygon –Only one diagonal need to be checked –Which one? Images from Möller and Haines

10/09/2001CS 638, Fall 2001 Approximate Assignment Recall, we typically use spatial decompositions to answer approximate queries –Conservative approximation: We will sometimes answer yes for something that should be no, but we will never answer no for something that should be yes Observation 1: If one polygon of an object is inside a cell, most of its other polygons probably are also –Should we store lists of objects or polygons? Observation 2: If a bounding volume for an object intersects the cell, the object probably also does –Should we test objects or their bounding volumes? (There is more than one answer to this - the reasons are more interesting)

10/09/2001CS 638, Fall 2001 Objects in Multiple Cells Assume an object intersects more than one cell Typically store pointers to it in all the cells it intersects –Why can’t we store it in just one cell? Consider the ray intersection test But it might be considered twice for some tests, and this might be a problem –One solution is to flag an object when it has been tested, and not consider it again until the next round of testing Why is this inefficient? –Better solution is to tag it with the frame number it was last tested Subtle point: How long before the frame counter overflows? Also read Gems Ch 4.11 for another solution

10/09/2001CS 638, Fall 2001 Neighboring Cells Sometimes it helps if a cell knows it neighbors –How far away might they be in the tree? (How many links to reach them?) –How does neighbor information help with ray intersection? Neighbors of cell A are cells that: –Share a face plane with A –Have all of A’s vertices contained within the neighbor’s part of the common plane –Have no child with the same property

10/09/2001CS 638, Fall 2001 Finding Neighbors Your right neighbor in a binary tree is the leftmost node of the first sub-tree on your right –Go up to find first rightmost sub-tree –Go down and left to find leftmost node (but don’t go down further than you went up) –Symmetric case for left neighbor Find all neighbors for all nodes with an in-order traversal Natural extensions for quadtrees and octrees

10/09/2001CS 638, Fall 2001 Frustum Culling With Octrees We wish to eliminate objects that do not intersect the view frustum Which node/cell do we test first? What is the test? If the test succeeds, what do we know? If the test fails, what do we know? What do we do?

10/09/2001CS 638, Fall 2001 Frustum Culling With Octrees We wish to eliminate objects that do not intersect the view frustum Have a test that succeeds if a cell may be visible –Test the corners of the cell against each clip plane. If all the corners are outside one clip plane, the cell is not visible –Otherwise, is the cell itself definitely visible? Starting with the root node cell, perform the test –If it fails, nothing inside the cell is visible –If it succeeds, something inside the cell might be visible –Recurse for each of the children of a visible cell This algorithm with quadtrees is particularly effective for a certain style of game. What style?

10/09/2001CS 638, Fall 2001 Octree Problems Octrees become very unbalanced if the objects are far from a uniform distribution –Many nodes could contain no objects The problem is the requirement that cube always be equally split amongst children A bad octree case