43
Advanced Computer Graphics Spring 2009 K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology

Advanced Computer Graphics Spring 2009

Embed Size (px)

DESCRIPTION

Advanced Computer Graphics Spring 2009. K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology. BSP Trees. BSP trees were developed for addressing the hidden-surface problem. They allow a scene to be view-independently decomposed in a preprocessing phase. - PowerPoint PPT Presentation

Citation preview

Page 1: Advanced Computer Graphics  Spring 2009

Advanced Computer Graphics Spring 2009

K. H. Ko

Department of MechatronicsGwangju Institute of Science and Technology

Page 2: Advanced Computer Graphics  Spring 2009

2

BSP Trees

BSP trees were developed for addressing the hidden-surface problem. They allow a scene to be view-independently

decomposed in a preprocessing phase. The resulting tree can then be traversed at

runtime to give the correct sorting order of objects or individual polygons from an arbitrary viewpoint.

Page 3: Advanced Computer Graphics  Spring 2009

3

BSP Trees BSP trees are also very versatile when it comes t

o collision detection as they can serve both as a spatial partitioning (a nonboundary representation) and as a volume representation (a boundary representation). As a spatial partitioning scheme, BSP trees are very s

imilar to quadtrees, octrees and k-d trees, but BSP trees are more general as they can emulate these other spatial data structures.

Page 4: Advanced Computer Graphics  Spring 2009

4

BSP TreesAs a volume representation, BSP trees can be

used to represent and distinguish the interiors of polygons and polyhedra from their exteriors.

Page 5: Advanced Computer Graphics  Spring 2009

5

BSP Trees Constructing a BSP tree from scratch or r

ecomputing parts of a tree is sufficiently expensive that they are rarely built or modified at runtime.For this reason, BSP trees are primarily used t

o hold static background geometry.

Page 6: Advanced Computer Graphics  Spring 2009

6

BSP Trees

Two noticeably different variants in computer graphics

Axis-Aligned Polygon-Aligned

The trees are created by using a plane to divide the space in two, and then sorting the geometry into these two spaces.

This division is done recursively. One interesting property

If the trees are traversed in a certain way, then the geometrical contents of the tree can be sorted from any point of view.

Page 7: Advanced Computer Graphics  Spring 2009

7

An extremely efficient method for calculating the visibility relationships among a static group of 3D polygons as seen from an arbitrary viewpoint. Suitable for applications in which the

viewpoint changes but the objects do not.

BSP Trees

Page 8: Advanced Computer Graphics  Spring 2009

8

Basic idea of BSP tree algorithm Environments can be viewed as being

composed of clusters (collections of faces).

If a plane can be found that wholly separates one set of clusters from another, then clusters that are on the same side of the plane as the eye point can obscure but cannot be obscured by, clusters on the other side.

Each of these sets of clusters can be recursively subdivided if suitable separating planes can be found.

BSP Trees

Page 9: Advanced Computer Graphics  Spring 2009

9

BSP Trees

Axis-Aligned BSP Trees The whole scene is enclosed in an Axis aligned

Bounding Box. Then recursively subdivide that box into smaller boxes.

Some schemes fix this partitioning plane so that it divides the box exactly in half.

Others allow the plane to vary in position. Each subset is now in a smaller box and this plane-

splitting procedure is repeated, subdividing each AABB recursively until some criterion is fulfilled to halt the process.

Page 10: Advanced Computer Graphics  Spring 2009

10

BSP Trees

Axis-Aligned BSP Trees One strategy for splitting a box is to cycle through the

axes. At the root, the box is always split along the x axis, its childr

en are split along the y, the grandchildren along z, then the cycle repeats. BSP trees using this strategy are sometimes called k-d trees.

Another strategy is to find the largest side of the box and split the box along this direction. This approach is time consuming.

Page 11: Advanced Computer Graphics  Spring 2009

11

BSP Trees

Axis-Aligned BSP Trees

Page 12: Advanced Computer Graphics  Spring 2009

12

BSP Trees

Polygon-Aligned BSP Trees A polygon is chosen as the divider, splitting space into

two halves. At the root, a polygon is selected. The plane in which the polygon lies is used to divide the rest

of the polygons in the scene into two sets. Any polygon that is intersected by the dividing plane is

broken into two separate pieces along the intersection line. Now in each half-space of the dividing plane another polygon

is chosen as a divider, which divides only the polygons in its half-space.

This is done recursively until all polygons are in the BSP tree.

Page 13: Advanced Computer Graphics  Spring 2009

13

BSP Trees Binary Space-Partitioning (BSP) Trees

The partitioning of the environment can be represented by a binary tree rooted at the first partitioning plane chosen.

The tree’s internal nodes are the partitioning planes. Its leaves are regions in space. Each region is associated with a unique order in which cluste

rs can obscure one another if the viewpoint is located in that region.

Determining the region in which the eyepoint lies involves descending the tree from the root and choosing the left or right child of an internal node by comparing he viewpoint with the plane at that node.

A correct order for scan conversion can be easily determined by the BSP tree.

Page 14: Advanced Computer Graphics  Spring 2009

14

BSP Trees Construction of the BSP Tree

Page 15: Advanced Computer Graphics  Spring 2009

15

BSP Trees Binary Space-Partitioning (BSP) Trees

Traversal in a tree to yield a correct priority-ordered polygon list for an arbitrary viewpoint.

The algorithm needs to only guarantee that the sets are displayed in the correct relative order to ensure both that one set’s polygons do not interfere with the other’s and that the root polygon is displayed properly and in the correct order relative to the others.

Case 1: If the viewer is in the root polygon’s front half-space

Rear half-space, root, front half-space order Case 2: If the viewer is in the root polygon’s rear

half-space Front half-space, root, rear half-space

Case 3: If the polygon is seen on edge Either way works.

Page 16: Advanced Computer Graphics  Spring 2009

16

BSP Trees Traversal in a tree to yield a correct

priority-ordered polygon list for an arbitrary viewpoint.

Example

Page 17: Advanced Computer Graphics  Spring 2009

17

BSP Trees The algorithm performs intersection

and sorting entirely at object precision and relies on the image precision overwrite capabilities of a raster device. It performs all polygon splitting during a

preprocessing step that must be repeated only when the environment changes.

If a list priority algorithm is used for hidden line removal, special attention must be paid to the new edges introduced by the subdivision process.

Page 18: Advanced Computer Graphics  Spring 2009

18

BSP Trees Selecting Dividing Planes

The order in which dividing planes are selected during tree construction greatly affects the size and shape of the resulting tree, and therefore the effectiveness of the tree for querying.

It also affects the tree’s memory requirements.

However, computing an optimal BSP tree is an intractable problem.

But there are good or even near-optimal solutions used in practice.

Page 19: Advanced Computer Graphics  Spring 2009

19

BSP Trees Selecting Dividing Planes

There are infinitely many arbitrary dividing planes. One approach of constraining the problem is limiting t

he set of possible dividing planes to a finite number by relying on autopartitioning.

The strategy is to restrict the search to the supporting planes of the faces in the input geometry.

But autopartitioning (alone) is not always ideal. Relying on autopartitioning alone may lead to more splitting t

han is desired.

Page 20: Advanced Computer Graphics  Spring 2009

20

BSP Trees Selecting Dividing Planes

Page 21: Advanced Computer Graphics  Spring 2009

21

BSP Trees Selecting Dividing Planes

Another drawback of using just autopartitioning, consider the problem of building a BSP tree from a polygon sphere.

The sphere is a convex shape, all sphere faces will lie on just one side of a plane through any one of its faces.

The resulting tree will in some sense be maximally unbalanced, with a depth equal to the number of faces in the sphere.

Determining point containment is now an O(n) operation. If selected planes are instead allowed to cut across the sphe

re, roughly half the faces can be discarded for each plane tested, making the same worst-case query an O(log n) operation.

Page 22: Advanced Computer Graphics  Spring 2009

22

BSP Trees Selecting Dividing Planes

Another drawback of using just autopartitioning, consider the problem of building a BSP tree from a polygon sphere.

A better option is to use a hybrid approach of alternating autopartitioning and general cuts to get both an O(log n) tree height and potential early outs.

Page 23: Advanced Computer Graphics  Spring 2009

23

BSP Trees Selecting Dividing Planes

A set of autopartitioning planes is first selected to separate the sphere from the surrounding empty space, forming a tetrahedron surrounding the sphere.

The resulting volume is then separated into five disjoint parts through four planes interior to the sphere.

On region corresponds to a solid tetrahedron interior to the sphere.

The remaining four regions are recursively subjected to the same separating procedure until all faces have been processed.

The resulting three can be seen as providing a sequence of approximations of the sphere through successive refinement, becoming more and more accurate with each additional level of the tree.

Page 24: Advanced Computer Graphics  Spring 2009

24

Convexity-based Methods The bounding volume representations have

one feature in common: They are convex objects. The existence of a separating plane for

nonintersecting convex objects. The distance between two points (one from

each object) is at a local minimum. The distance is also a global minimum

By exploiting the special properties of convex objects, it is possible to design efficient collision detection algorithms for them.

Page 25: Advanced Computer Graphics  Spring 2009

25

Boundary-based Collision Detection A simple solution to the collision detection

problem for two polyhedra is to base the test on the boundary description of the objects.

Let two polyhedra P and Q be given in a form allowing easy access to their vertices and faces.

Page 26: Advanced Computer Graphics  Spring 2009

26

Boundary-based Collision Detection The intersection can be determined as follows:

Intersect each edge of P against polyhedron Q. If an edge lies partly or fully inside Q, stop and report the polyhedra as intersecting.

Conversely, intersect each edge of Q against polyhedron P. If an edge lies partly or fully inside P, stop and report P and Q as intersecting.

Finally to deal with the degenerate case of identical objects passing through each other with their faces aligned, test the centroid of each face of Q against all faces of P. If a centroid is found contained in P, stop and return intersection.

Return nonintersection.

Page 27: Advanced Computer Graphics  Spring 2009

27

Boundary-based Collision Detection The algorithm formulations are O(n2)

in the number of vertices or edges tested.

In most cases, near linear behavior can be expected.

But by better exploiting the convexity of the objects, faster collision algorithms can be obtained.

Page 28: Advanced Computer Graphics  Spring 2009

28

Closest-features Algorithms In real-time simulations objects tend to move or rotate b

y small amounts from one frame to the next. For convex objects, this frame-to-frame coherence sugge

sts that in general the closest points between two nonintersecting objects are located in the near vicinity of the closest points between the objects of the previous frame.

For polyhedra, rather than tracking the closest points and using the closest points of the previous frame as a starting point a better approach is to track the closest features (vertices, edges, or faces) from frame to frame. A pair of features, one from each of two disjoint polyhedra, are s

aid to be the closest features if they contain a pair of closest points for the polyhedra.

Page 29: Advanced Computer Graphics  Spring 2009

29

Closest-features Algorithms

The V-Clip Algorithm It operates on a pair of polyhedra and is base

d on the following theorem, defining the closest points between the pair in terms of the closest features of the polyhedra.

Page 30: Advanced Computer Graphics  Spring 2009

30

Closest-features Algorithms

The V-Clip Algorithm

Page 31: Advanced Computer Graphics  Spring 2009

31

Closest-features Algorithms

V-Clip starts with two features, one from each input polyhedron.

At each iteration of the algorithm, the features are tested to see if they meet the conditions of the theorem for being a closest pair of features. If so, the algorithm terminates, returning a result of nonintersect

ion along with the pair of closest features. If the conditions are not met, V-Clip updates one of the features

to a neighboring feature, where the neighbors of a feature are defined as follows:

The neighbors of a vertex are the edges incident to the vertex. The neighbors of a face are the edges bounding the face. The neighbors of an edge are the two vertices and the two faces inc

ident to the edge.

Page 32: Advanced Computer Graphics  Spring 2009

32

Closest-features Algorithms

Feature pair transition chart in which solid arrows indicate strict decrease of inter-feature distance and dashed arrows indicate no change.

Page 33: Advanced Computer Graphics  Spring 2009

33

Closest-features Algorithms

Solid arrows in the chart indicate that the interfeature distance is strictly decreased by a transition.

Dashed arrows indicate no change in distance taking place.

Because the chart does not contain a transition cycle of only dashed arrows, only a finite number of feature transitions can be performed before the feature distance is strictly decreased.

In addition there are no transitions that increase the interfeature distance.

Therefore, convergence is assured and the algorithm eventually terminates with the closest pair of features.

Page 34: Advanced Computer Graphics  Spring 2009

34

Closest-features Algorithms

One of the transitions in the chart does not follow from the neighbor definitions The solid arrow from the

vertex-face state back to itself.

This transition is present because it is possible for the V-Clip algorithm to become trapped in a local minimum in the vertex-face state.

Page 35: Advanced Computer Graphics  Spring 2009

35

Closest-features Algorithms

The vertex V lies below the supporting plane of face F and at the same time lies inside all Voronoi planes of the Voronoi region, VR(F) of F. In this situation there are no legal sta

te transitions per the chart Any attempted transition would eit

her increase the interfeature distance or increase the dimension of a feature while the interfeature distance stayed the same.

Page 36: Advanced Computer Graphics  Spring 2009

36

Closest-features Algorithms When such problem distance is detected, an O

(n) brute-force test is performed of the vertex V against all face of planes of object A. If V lies inside all face planes, the objects are interse

cting and the algorithm stops and reports the objects as penetrating.

Otherwise, F is updated to the face G of A that V has the largest positive signed distance from.

This choice of a new face guarantees there is no possibility of descending into the same local minimum again, in that V is strictly closer to G than to F and is at least as close to G as to all other faces of A.

Page 37: Advanced Computer Graphics  Spring 2009

37

Hierarchical Polyhedron Representations Hierarchical representations are also useful to a

ccelerate many queries on polyhedra. BSP trees is one possible representation. An alternative form of hierarchical representation is th

e forming of a sequence of polyhedra, nested inside each other like Russian dolls.

Starting from the original polyhedron, each inscribed polyhedron of the sequence is a simplified version of its immediate outer parent.

Page 38: Advanced Computer Graphics  Spring 2009

38

Hierarchical Polyhedron Representations Given such a hierarchy, the idea is to perform queries st

arting at the simplest innermost polyhedron and moving up through the hierarchy to the original polyhedron. With just a small topological difference from one polyhedron to t

he next, only a small amount of work must be performed at each step, typically resulting in O(log n) queries.

The most well known representation is the Dobkin-Kirkpatrick hierarchy. It can be used for queries such as finding an extreme vertex in a

given direction, locating the point on a polyhedron closest to a given point, or determining the intersection of two polyhedra.

Page 39: Advanced Computer Graphics  Spring 2009

39

Hierarchical Polyhedron Representations The Dobkin-Kirkpatrick (DK) Hierarchy

The DK hierarchy of a d-dimensional polyhedron P is a sequence P0, P1, …, Pk of nested increasingly smaller polytopal approximations of P,

where P = P0 and Pi+1 is obtained from Pi by deletion of a subset of the vertices

of Pi. The subset of vertices is selected to form a maximal set of ind

ependent vertices (such that no two vertices in the set are adjacent to each other.)

The construction of the hierarchy stops with the innermost polyhedron Pk being a d-simplex.

Page 40: Advanced Computer Graphics  Spring 2009

40

Hierarchical Polyhedron Representations The Dobkin-Kirkpatrick (DK) Hierarchy

P0 is set to be equivalent to P. P1 is obtained from P0 by deleting the vertices V1, V3, V5, V7, V9 a

nd V11. P2 is similarly obtained from P1 by deleting V2, V6, V10. P2 is a 2-simplex, the hierarchy construction stops.

Page 41: Advanced Computer Graphics  Spring 2009

41

Hierarchical Polyhedron Representations Given a DK hierarchy many different queries

can be answered in an efficient manner. The point on P closest to a query point S can be

located through a simple recursive procedure.

Page 42: Advanced Computer Graphics  Spring 2009

42

Hierarchical Polyhedron Representations Starting at the innermost polyhedra Pi, i=2,

the closest point Ri on Pi to S is found through straightforward calculation.

If Ri=S, then S is contained in P and the algorithm stops.

Otherwise, knowing Ri, the closest point for Pi-1 is found as follows:

Page 43: Advanced Computer Graphics  Spring 2009

43

Hierarchical Polyhedron Representations Let H be the supporting plane for Pi through Ri. Pi-1 can be d

escribed as consisting of the part in front of H and the part behind H: Pi-1 = (Pi-1 ∩ H+) ∪ (Pi-1 ∩ H-)

The closest point Ri-1 is therefore realized either between Pi

-1 ∩ H+ and S or between Pi-1 ∩ H- and S. The closest point between Pi-1 ∩ H- and S is directly given b

y Ri. Because Pi-1 ∩ H+ is defined by one vertex and two edges, t

he closest point between Pi-1 ∩ H+ and S is computed in constant time.

The point on P closest to the query point S is located in O(log n) steps and in O(log n) time.