Académique Documents
Professionnel Documents
Culture Documents
CSE 373
Data Structures
Lecture 22
Geometric Data Structures
• Organization of points, lines, planes, … to
support faster processing
• Applications
– Astrophysical simulation – evolution of galaxies
– Graphics – computing object intersections
– Data compression
• Points are representatives of 2x2 blocks in an
image
• Nearest neighbor search
i i
g g
h h
y d e y d e
f f
b b
a c a c
x x
i
g
h
y d e
f
query
b
a c
Nearest neighbor is e.
i
g
h
y d e
f
b
a c
x
divide perpendicular to the widest spread.
12/6/02 K-D Trees - Lecture 22 7
k-d Tree Construction (2)
x
i s1
g
h
y d e
f
b
a c
s1
g y
h s2
y d e
f
s2
b
a c
s1
g y
h s2
y d e
f x
s2
s3
b
a c
s3 s1
g y
h s2
y d e
f x
s2
s3
b
a c a
s3 s1
g y
h s2
y d e
f x
s2
s3
b
a c a b
s3 s1
g y
h s2
s4 e
y d f x y
s2
s3 s4
b
a c a b
s3 s1
g y
h s2
s4 e
y d f x y
s5
s2
s3 s4
b
a c a b x
s3 s1
s5
g y
h s2
s4 e
y d f x y
s5
s2
s3 s4
b
a c a b x
s3 s1
s5
x d
g y
h s2
s4 e
y d f x y
s5
s2
s3 s4
b
a c a b x
s3 s1
s5
x d e
g y
h s2
s4 e
y d f x y
s5
s2
s3 s4
b
a c a b x g
s3 s1
s5
x d e
g y y
h s2 s6
s4 e s6
y d f x y
s5
s2
s3 s4
b
a c a b x g
s3 s1
s5
x d e
g y y
h s2 s6
s4 e s6
y d f x y y
s5
s2
s3 s4 s7
b s7
a c a b x g
s3 s1
s5
x d e
g y y
h s2 s6
s4 e s6
y d f x y y
s5
s2
s3 s4 s7
b s7
a c a b x g c
s3 s1
s5
x d e
g y y
h s2 s6
s4 e s6
y d f x y y
s5
s2
s3 s4 s7
b s7
a c a b x g c f
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
3
12/6/02 K-D Trees - Lecture 22 25
k-d Tree Splitting
sorted points in each dimension
1 2 3 4 5 6 7 8 9
i x a d g be i c h f
y a c b d f e h g i
g
h
• max spread is the max of
e fx -ax and iy - ay.
y d f
• In the selected dimension the
middle point in the list splits the
b data.
a c
• To build the sorted lists for the
x other dimensions scan the sorted
list adding each point to one of two
sorted lists.
12/6/02 K-D Trees - Lecture 22 26
k-d Tree Splitting
sorted points in each dimension
1 2 3 4 5 6 7 8 9
i x a d g be i c h f
y a c b d f e h g i
g
h
indicator for each set
y d e
f a b c de f g h i
0 0 1 00 1 0 1 1
b
a c scan sorted points in y dimension
and add to correct set
x
y a b d eg c f h i
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
w h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
w h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
w h s2 s6
s4 e s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
g s8
y y
h s2 s6
s4 e w s6
y d f x y y y
s5
s2
s3 s4 s7 s8
b s7
a c a b x g c f h i
s3 s1
s5
x d e
n.axis = x
n.value q(n.axis) + w