Spatial data structures 1998-2015 Josef Pelikán CGG MFF UK Praha pepca@cgg.mff.cuni.cz http://cgg.mff.cuni.cz/~pepca/ SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 1 / 48
Application areas geographic information systems (GIS) area, line and point entities huge databases (10 4 to 10 9 objects) image analysis, recognition computer graphics, games 2D & 3D algorithm speedup (ray casting, collisions) industry, CAD VLSI design, component positioning, collisions SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 2 / 48
Elementary tasks I point localization in 2-3D net looking for an area object which contains the point nearest N points from the given center global variation: looking for the closest point pair curve intersections (polylines) collisions in a set of curves (polylines) point objects closest to the given curve (route) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 3 / 48
Elementary tasks II interval queries in 2-3D space (databases) set operations on map entities areas, line objects, points collision tests (interferences), minimal distances among planar objects (VLSI) first ray-scene intersection (3D scene) object processing in some geometric order increasing distance from a given center SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 4 / 48
Region quadtree representation of areal regions in 2D splitting exactly in the middle E D C B information is stored in leaf nodes only A SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 5 / 48
Region quadtree A B C D E SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 6 / 48
Pyramid representation of areal regions in 2D additional summary info in inner nodes pyramid nodes up to level: E SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 7 / 48
Pyramid pyramid nodes up to level: D SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 8 / 48
Pyramid pyramid nodes up to level: C SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 9 / 48
Pyramid pyramid nodes up to level: B SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 10 / 48
MX quadtree (MatriX) representation of point objects Kralupy Kostelec Brandýs Roztoky splitting exactly in the middle Kladno Praha Úvaly object information stored in the leafs (of equal depths) Řevnice Černošice Mníšek Jílové Říčany SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 11 / 48
PR quadtree (Point-Region) representation of point objects Kralupy Kostelec Brandýs Roztoky splitting exactly in the middle Kladno Praha Úvaly object information stored in leaf nodes (all levels, max. one object per node) Řevnice Černošice Mníšek Jílové Říčany SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 12 / 48
PR quadtree (Orenstein) Kralupy Kladno Roztoky Praha Kostelec Brandýs Úvaly Černošice Řevnice Mníšek Říčany Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 13 / 48
Bucket methods node can store information about more than one object 0 object# Max Max is constant value tuned for storage efficiency (record size..) memory & time efficiency less overhead in pointer management AB-tree analogy SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 14 / 48
Bucket PR quadtree representation of point objects Kralupy Kostelec Brandýs Roztoky splitting exactly in the middle Kladno Praha Úvaly object information stored in leaf nodes (all levels, Max object per node) Řevnice Černošice Mníšek Jílové Říčany Max = 2 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 15 / 48
Bucket PR quadtree Kralupy Kladno Roztoky Praha Kostelec Brandýs Úvaly Černošice Řevnice Mníšek Říčany Jílové Max = 2 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 16 / 48
Point quadtree (Finkel/Bentley) representation of point objects Kralupy Roztoky Kostelec Brandýs adaptive splitting (exactly at object position) object information stored in all nodes (even inner ones) Kladno Černošice Řevnice Praha Říčany Jílové Úvaly Mníšek SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 17 / 48
Point quadtree Praha Kralupy Říčany Brandýs Černošice Kladno Roztoky Kostelec Řevnice Mníšek Úvaly Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 18 / 48
Pseudo quadtree (Overmars) representation of point objects Kralupy B Kostelec Brandýs adaptive splitting (loosely by object position) Kladno Roztoky A Černošice C Praha Říčany Úvaly object information stored in leafs only D Řevnice Jílové E Mníšek SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 19 / 48
Pseudo quadtree A B C D E Kralupy Kladno Roztoky Kostelec Brandýs Praha Černošice Řevnice Mníšek Říčany Úvaly Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 20 / 48
K-D tree (Bentley) representation of point objects Kralupy Kostelec Brandýs adaptive splitting - one coordinate at a time (binary tree). regular alternation of the coordinates Kladno Černošice Roztoky Praha Říčany Úvaly object information stored in all nodes Řevnice Mníšek Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 21 / 48
K-D tree Praha Roztoky y Jílové Kladno x Brandýs Řevnice x Říčany y y y y x Kralupy x Kostelec x Černošice x Mníšek x Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 22 / 48
Adaptive K-D tree (Friedman) representation of point objects adaptive splitting - one coordinate at a time (binary tree). Exact object coordinates not used object information stored in leafs only Kralupy Kostelec x 3 x x 1 2 Brandýs Kladno y y 2 Roztoky 3 Praha Úvaly y 4 Černošice Řevnice x 5 Mníšek y 1 x 4 Říčany Jílové x 6 y 5 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 23 / 48
Adaptive K-D tree y 1 x 1 x 4 x 2 y 3 y 4 x 6 y 2 x 3 x 5 y 5 Kladno Kralupy Roztoky Kostelec Brandýs Praha Černošice Řevnice Mníšek Jílové Říčany Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 24 / 48
BSP tree (Fuchs, Kedem, Naylor) decomposition of a plane into convex regions adaptive splitting by arbitrary hyperplane Kralupy Kladno Roztoky p 8 p 4 p 3 p 5 Černošice Praha p 7 Kostelec p 2 p 6 p 1 p 11 Brandýs Úvaly Říčany object information stored in leafs only p 9 Řevnice Mníšek p 10 Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 25 / 48
Point BSP tree p 1 p2 p 7 p 3 p 6 p 8 p 10 p 4 p 5 p 9 p 11 Kladno Kralupy Roztoky Praha Kostelec Brandýs Řevnice Mníšek Černošice Jílové Říčany Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 26 / 48
Region BSP tree polygonal decomposition of 2/3D space individual regions (polygons/polyhedra) need not be convex polygonal 2/3D scene representation inner nodes store information about boundary edges/faces set operations on polygons/polyhedra CSG B-rep conversion, shadow casting (shadow volumes) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 27 / 48
Region BSP tree polygonal decomposition A p 8 B arbitrary splitting hyperplanes (nodes could store information about edges/faces) p 3 p 6 p 2 p 1 C p 7 p 9 p 10 E polygon identif. in the leafs D p 5 p 4 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 28 / 48
Region BSP tree p 1 p2 p 7 p 3 p 4 p 8 p 9 p 5 p 10 A D E A B C p 6 D B E A C SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 29 / 48
Range trees efficient implementation of range queries x min, x max y min, y max ve 2D complexity: O(log 2 N + F) in 1D, O(log 22 N + F) in 2D 1D range tree balanced binary search tree, leaves are connected by a double-linked list 2D range tree balanced binary search tree for the x coordinate every inner node contains 1D range tree (y coord.) for all points in the relevant region SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 30 / 48
2D range tree balanced binary tree for x-coordinate object information in leaves only inner nodes: 1D range trees for y-coordinate 5 Kralupy 1 Kladno 6 Roztoky 4 Černošice 2 Řevnice 3 Mníšek 9 Kostelec B Brandýs C Úvaly 7 Praha A Říčany 8 Jílové SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 31 / 48
2D range tree Query: (3.5,A.5) 6,4 7 2 4 561423 A 95B617CA4283 5 8 B 9B7CA8 123 3 564 6 978 9 C BCA 1 Kladno 2 Řevnice 23 3 Mníšek 4 Černošice 5 Kralupy 56 6 Roztoky 7 Praha 8 Jílové 98 9 Kostelec A Říčany B Brandýs BC C Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 32 / 48
R-tree (Guttman) objects can be areal bounding boxes in inner nodes (the whole subtree must fit into the bounding box) Kladno Kralupy R 7 R R 8 3 Černošice Kostelec Roztoky Praha Říčany Brandýs R 6 R 5 Úvaly object references in leaf nodes Řevnice Mníšek R 4 R 2 Jílové R 9 R 1 R 0 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 33 / 48
R-tree R 0 R 1 R 2 R 3 R 4 R 5 R 6 R 7 R 8 R 9 R 10 Kladno Kralupy Roztoky Praha Černošice Řevnice Mníšek Jílové Kostelec Brandýs Říčany Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 34 / 48
Strip tree (Ballard) planar curve (polyline) adaptive splitting induced by the curvature P 1 W L oriented bounding rectangle defined by: starting point (P 1 ), endpoint (P 2 ), widths (W L, W R ) W R P 2 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 35 / 48
Intersection of two curves strip trees were built for both curves trivial cases subdivision is necessary SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 36 / 48
Bounding system hierarchies Sphere tree (Palmer, Grimsdale, 1995) simple tests & transform, approximation not so good AABB tree (Held, Klosowski, Mitchell, 1995) simple test, more complicated transform OBB tree (Gottschalk, Lin, Manocha, 1996) simple transform, more complicated test, good approximation K-dop tree (Klosowski, Held, Mitchell, 1998) complicated transform & test, excellent aproximation SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 37 / 48
PM 1 quadtree (Samet, Webber) polygonal maps max. one vertex per leaf node more edges in one leaf only if they share common vertex (stored in that leaf node) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 38 / 48
PM 2 quadtree polygonal maps max. one vertex per leaf node more edges in one leaf only if they share common vertex (anywhere) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 39 / 48
PM 3 quadtree polygonal maps max. one vertex per leaf node leaf node can store arbitrary number of edges ( PR quadtree with additional edges) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 40 / 48
PMR quadtree polygonal maps 3 1 4 max. N edges per leaf node 1 3 leaf can store up to 2N references to vertices 4 2 4 2 1 2 N = 4 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 41 / 48
Directional pass data pass using specific directional order visibility (front-to-back or vice versa) in orthographic projection plane sweep pass ( sweeping ) pass from the center point visibility (form-factors,..) in perspective projection knn search ( k-nearest Neighbors ) ray-scene intersections in 3D, etc. SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 42 / 48
Presumption hierarchical space decomposition inclusion conditions on objects only, not needed for bounding boxes (e.g. strip tree ) effective computation of minimal distance of each cell / box... d(b) distance from sweep plane or center point of the pass distance need not be an infimum (but has to be an lower bound) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 43 / 48
Algorithm auxiliary data structure H (heap) efficient operations: Min, DeleteMin, Insert put the root node into H d(b) is used for heap sorting if Min(H) is an object, process it and remove it if Min(H) is a hierarchy cell, remove it and put all its children back into the heap repeat steps and until the heap H is empty or until all required output objects are processed (knn) SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 44 / 48
Example I {R 0 } {R 1,R 2 } {R 1,R 2 } {R 3,R 4,R 2 } {R 3,R 4,R 2 } {R 7,R 4,R 8,R 2 } {R 7,R 4,R 8,R 2 } {Kladno,R 4, Kralupy,R 8,R 2 } Kladno {R 4,Kralupy,R 8,R 2 } {R 9,Kralupy,R 8, Jílové,R 2 } Kladno Kralupy Kostelec R 7 R R 8 3 Černošice Řevnice Mníšek Roztoky Praha Říčany R 4 R 2 Jílové R 5 Brandýs R 6 Úvaly R 9 R 1 R 0 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 45 / 48
Example II {R 9,Kralupy,R 8,Jílové,R 2 } {Řevnice,Mníšek, Kralupy,Černošice, R 8,Jílové,R 2 } - Řevnice,Mníšek, Kralupy,Černošice {R 8,Jílové,R 2 } {Roztoky,Praha, Jílové,R 2 } - Roztoky,Praha, Jílové Kralupy R 8 Černošice Řevnice R 9 Mníšek Kostelec Roztoky Praha Říčany Jílové Brandýs R 2 R 6 R 5 Úvaly SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 46 / 48
Example III {R 2 } {R 5,R 6 } Kostelec R 5 {R 5,R 6 } {Kostelec,R 6,Brandýs} Brandýs Kostelec {R 6,Brandýs} {Brandýs,Říčany,Úvaly} - Brandýs,Říčany,Úvaly Říčany R 6 Úvaly R 2 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 47 / 48
The End More information: H. Samet: The Design and Analysis of Spatial Data Structures, Addison-Wesley, 1990 H. Samet: Foundations of Multidimensional and Metric Data Structures, Morgan Kaufmann, 2006 F. Preparata, M. Shamos: Computational Geometry, An Introduction, Springer-Verlag, 1985 SpatialData 2015 Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 48 / 48