Download presentation

Presentation is loading. Please wait.

Published byWayne Startup Modified over 2 years ago

1
Data Structures for 3D Searching partly based on: chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides by Marc van Kreveld 1

2
Data structures Data structures for representation – geometry (coordinates) – topology (connectivity) – attributes (anything else like material, …) Data structures for searching – use the geometry to reduce the number objects that need be tested from all of them to some small subset – windowing queries, ray tracing, nearest neighbors 2

3
Data structures for searching Several steps in the algorithms we have seen until now can be sped up using data structures for efficient searching – Find the k nearest neighbors to each point (straightforward in O(n 2 ) time) – Find the support of a plane tried in RANSAC (straightforward in O(n) time) – Test whether a mesh-changing operator causes self- intersections of the manifold (straightforward in O(n) time) – Also: for ray tracing 3

4
Data structures for searching Grid structure Quadtree and Octree Bounding Volume Hierarchy, R-tree Kd-tree BSP tree (Binary Space Partition) 4

5
Simple grid structure Also: cubical grid, cubic partitioning Tile the space with equal-size cubes and store each object with every cube it intersects The 3D grid is a 3D array of lists; list elements are pointers to the objects Small grid cells: much storage overhead, but good for query time Big grid cells: little storage overhead, worse query time 5

6
Simple grid structure 6

7
7 ray tracing query

8
Simple grid structure 8 k nearest neighbors query

9
Simple grid structure 9 RANSAC line support computation

10
Simple grid structure 10 windowing query

11
Simple grid structure A hierarchical version of a grid may give more efficient querying: one emptiness test at a higher level square may make several tests at lower level squares unnecessary 11

12
Quadtrees and Octrees Tree version of the (hierarchical) square/cube grid Storage requirements better than grid when large parts of the grid contain no objects In a quadtree – the root corresponds to a bounding square – children correspond to four subsquares : NW, NE, SW, SE – nodes with 0 or 1 objects in their square are leaves In an octree – the root corresponds to a bounding cube – children correspond to eight subcubes – nodes with 0 or 1 objects in their cube are leaves 12

13
Quadtrees and Octrees NWNESWSE NWNE SWSE leaf root leaf storing one object 13

14
Quadtrees and Octrees NWNESWSE NWNE SWSE leaf root leaf storing one object 14

15
Quadtrees and Octrees NWNE SWSE This ray tracing query visits 10 nodes in the quadtree (12 squares in the original grid) 15

16
Quadtrees and Octrees Other queries are performed in the straightforward way – windowing query: easy – RANSAC support of line: determine all cells intersected by the strip, and test points in those cells only for inclusion – k nearest neighbors: explore cells further and further away from the query point until we know for sure that we have the k nearest neighbors explore all cells that intersect the circle centered at the query point and through the k-th closest point 16

17
17

18
Octree 18

19
Quadtrees and Octrees Often a quadtree or octree is not made deeper than a desired level of precision E.g., given an object of 1 x 1 x 1 meters stored in a triangle mesh, store the triangles in an octree up to a cell size of 4 x 4 x 4 millimeters Leaves that contain more than one object store them in a list (it is assumed that there would only be O(1) of them at this detail level) Also possible: split a square/cube until at most some constant c objects or points intersect a cell 19

20
Bounding Volume Hierarchies Tree structure where internal nodes store bounding shapes of all objects in the subtree If a query object intersects the bounding shape, it may intersect some object in that subtree, otherwise certainly not Bounding shapes can be spheres, axis-parallel bounding boxes, or arbitrarily oriented bounding boxes; axis-parallel BB is most common 20

21
Bounding Volume Hierarchies In graphics usually binary trees For huge data sets where the data must be on disk, usually higher-degree trees: R-tree 21

22
R-trees 2-dimensional version of the B-tree: B-tree of maximum degree 8; degree between 3 and 8 Internal nodes with k children have k – 1 split values 22

23
R-trees Can store: – a set of polygons (regions of a subdivision) – a set of polygonal lines (or boundaries) – a set of points – a mix of the above Stored objects may overlap 23

24
R-trees Originally by Guttman, 1984 Dozens of variations and optimizations since Suitable for windowing, point location, intersection queries, and ray tracing Heuristic structure, no order bounds ( O(..) ) Example of a bounding volume hierarchy 24

25
R-trees Every internal node contains entries (rectangle, pointer to child node) All leaves contain entries (rectangle, pointer to object) in database or file Rectangles are minimal axis- parallel bounding rectangles The root has 2 and M entries All other nodes have at least m and at most M entries All leaves have the same depth m > 1 and M > 2m (e.g. m = 200; M = 1000) 25

26
R-trees M is chosen so that a full node still (just) fits in a single block of disk memory m is chosen depending on a trade-off in search time and update time – larger m: faster queries, slower updates – smaller m: slower queries, faster updates 26

27
Object descriptions 27

28
Grouping of objects Windowing query: the fewer rectangles intersected, the fewer subtrees to descend into 28

29
Grouping of objects Objects close together in same leaves small rectangles queries descend in only few subtrees Group the child nodes under a parent node such that small rectangles arise 29

30
Heuristics for fast queries Small area of rectangles Small perimeter of rectangles Little overlap among rectangles Well-filled nodes (tree less deep fewer disk accesses on each search path) 30

31
Example R-tree 31

32
32

33
33

34
34

35
35

36
Object descriptions 36

37
point containment query 37

38
point containment query 38

39
Searching in an R-tree Q is query object (point, window, object); we search for intersections with stored objects For each rectangle R in the current node, if Q and R intersect, – search recursively in the subtree under the pointer at R (at an internal node) – get the object corresponding to R and test for intersection with R (at a leaf) 39

40
Nearest neighbor queries An R-tree can be used for nearest neighbor queries The idea is to perform a DFS, maintain the closest object so far and use the distance for pruning closest object so far queried pruned 40

41

42
Inserting in an R-tree Determine minimal bounding rectangle of new object When not yet at a leaf (choose subtree): – determine rectangle whose area increment after insertion of R is smallest – increase this rectangle if necessary and insert R At a leaf: – if there is space, insert, otherwise Split Node 42

43
43

44
44

45
45

46
46

47
47

48
Split Node Divide the M+1 rectangles into two groups, each with at least m and at most M rectangles Make a node for each group, with the rectangles and corresponding subtrees as entries Hang the two new nodes under the parent node in the place of the overfull node; determine the new bounding rectangles (if the root was overfull, make a new root with two child nodes) If the parent has M+1 children, repeat Split Node with this parent 48

49
Split Node, example new bounding rectangles 49

50
Strategies for Split Node Determine R 1 and R 2 with largest bounding rectangle: the seeds for sets S 1 and S 2 While |S 1 |, |S 2 | < M – m and not all rectangles distributed: – Take not yet distributed rectangle R j, add to the set whose bounding rectangle increases least Linear R-tree of Guttman,

51
Example Split Node 51

52
Strategies for Split Node If the total x-extent is larger than the total y-extent, then sort the rectangles by x-coordinate of center, otherwise by y-coordinate of center Split halfway in this sorted order Alternatively: choose a split close to halfway if this gives smaller resulting bounding box overlap 52

53
Example Split Node 53 x-extent is larger

54
Example Split Node 54 split in the middle

55
Example Split Node 55 split close to the middle

56
56

57
57

58
58

59
Deletion from an R-tree Find the leaf (node) and delete object; determine new (possibly smaller) bounding rectangle If the node is too empty (< m entries): – delete the node recursively at its parent – insert all entries of the deleted node into the R-tree Note: Insertion of entries/subtrees always occurs at the level where it came from 59

60
60

61
61

62
62

63
63

64
Insert as rectangle on middle level 64

65
Insert in a leaf object 65

66
66

67
67

68
68

69
69

70
70

71
71

72
72

73
73

74
74

75
75

76
76

77
Bounding Volume Hierarchy Other examples of bounding volume hierarchies are often binary trees Not all leaves will be on the same depth Different balancing schemes are needed if insertions and deletions occur All bounding volume hierarchies try to group objects suitably in their subtrees

78
Kd-trees Binary search tree that splits a point set through the middle, alternating on x- and y- (3D: on x-, y- and z-) coordinate split on x, vertical line split on y, horizontal line leaves, each with one point 78

79
Kd-trees 79

80
Kd-trees 80

81
Kd-trees in 3D The point set is split on x-, y- and z-coordinate in the topmost three levels, and this is repeated Geometrically, this is splitting by axis-parallel planes x = c, y = c, or z = c 81

82
Kd-trees Every node corresponds to a region of the plane that is a rectangle (possibly unbounded) The points in the subtree below that node are exactly the points of the stored set in that region Denote the region of a node by Region( ) – Region(root) = R2 – Region(child of root) = half-plane left/right of vertical line – “most” nodes : Region( ) = some bounded rectangle 82

83
Kd-trees, windowing query Windowing query (report all points in the window) in a kd-tree with window W – [ at node , initially the root ] – if is a leaf, then report the stored point if it is in W – otherwise, if Region( ) intersects W then recursively query further in both subtrees Note: if Region( ) does not intersect W, then we return from recursion (we do nothing at this node, nor its subtree) 83

84
Kd-trees, window query For a set of n points in the plane, a kd-tree that stores them allows windowing queries with an axis-parallel rectangular window takes O( n + k) time in the worst case, where k is the number of answers reported In 3D this is O( n 2 + k) = O(n 2/3 + k) time For circular windowing queries similar bounds hold in practice, but these are not provable worst-case bounds For queries with small windows the observed bounds are better 3 84

85
Kd-trees, other objects, other queries kd-trees can store triangles, etc., where objects are split by the vertical and horizontal lines need different splitting rule storage may become large Ray tracing query can be performed easily k-nearest neighbor query can be done similar to such a query in a quadtree 85

86
3D kd-tree

87
BSP-trees BSP = Binary Space Partition Similar to a kd-tree that stores triangles, but with arbitrarily oriented splitting lines/planes Often lines/planes are chosen through edges/ triangles of the set to be stored For query answering and for producing depth orders for the painter’s algorithm 87

88
BSP-trees BSP-trees were used in Doom and in Quake 88

89
BSP-trees 89

90
BSP-trees 90

91
BSP-trees A B A B C D E G F C DEGF H H 91

92
BSP-trees A B A B C D E G F C DEGF H P PP Q QQ Q R R H 92

93
BSP-trees BSP-trees are not necessarily balanced – no problem for the painter’s algorithm – unbalanced is not good for querying BSP-trees split objects; such fragmentation is undesirable because it costs memory space and lowers efficiency 93

94
BSP-trees, painter’s algorithm 94

95
BSP-trees, painter’s algorithm A B A B C D E G F C DEGF H H Given a viewpoint, draw the objects back to front, “ overpainting ” what was drawn before 95

96
BSP-trees, painter’s algorithm A B C D E G F H Given a viewpoint, draw the objects back to front, “ overpainting ” what was drawn before For each split line, all object parts “ behind ” it are drawn first, and then all objects in front of it (w.r.t. viewpoint) 96

97
BSP-trees, painter’s algorithm A B C D E G F H Given a viewpoint, draw the objects back to front, “ overpainting ” what was drawn before For each split line, all object parts “ behind ” it are drawn first, and then all objects in front of it (w.r.t. viewpoint) first second third fourth fifth sixth seventh eighth ninth tenth eleventh 97

98
BSP-trees, painter’s algorithm In 3D it works similarly: choose splitting planes that contain triangles (and may cut other triangles) First draw stuff behind the plane, then the triangle in the plane, then the stuff in front of the plane Cutting may be necessary: cyclic overlap 98

99
BSP-trees, painter’s algorithm 99

100
BSP-trees, painter’s algorithm 100

101
Summary data structures There are two types of data structures: those for representation and those for efficient searching Data structures can partition the underlying space, or partition the objects it stores Choosing a data structure: – small data set: not worthwhile – medium size data set: choose a simple structure, it will help – large data set: orders of magnitude in efficiency are gained – huge data sets: use a structure suitable for disk storage 101

102
Questions 1.How would you implement ray tracing in an R-tree? 2.How many levels does the octree of slide 19 have, at most? 3.How many cyclic overlaps do you see? ;-) 102

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google