CS-184: Computer Graphics
Lecture #7: BSP and AABB Trees
Prof. James O’BrienUniversity of California, Berkeley
V2009-F-07-1.0
2
BSP-Trees
• Binary Space Partition Trees• Split space along planes• Allows fast queries of some spatial relations
• Simple construction algorithm• Select a plane as sub-tree root• Everything on one side to one child• Everything on the other side to other child• Use random polygon for splitting plane
5
a
b c2,e,f,g
c1 d
a
b
c1
d
e
g
f
c2
BSP-Trees
6
a
b c2
c1 d e1 ,f e2 ,g
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
7
a
b c2
c1 d e1 e2 ,g
f
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
8
a
b c2
c1 d e1 e2
f g
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
8
a
b c2
c1 d e1 e2
f g
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
+ -
+ - + -
+ +
+
++
+
9
BSP-Trees
• Visibility Traversal• Variation of in-order-traversal
• Child one• Sub-tree root• Child two
• Select “child one” based on location of viewpoint• Child one on same side of sub-tree root as viewpoint
10
a
b c2
c1 d e1 e2
f g
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
c1:b:d:a:f:e1:c2:g:e2
11
g:e2:c2:f:e1:a:c1:b:d
a
b c2
c1 d e1 e2
f g
a
b
c1
d
g
f
c2
e1 e2
BSP-Trees
Bounding Shapes
• Bounding shape completely encloses associated object
• Rays cannot hit object w/o intersecting bounding shape
• Two objects cannot collide if shapes don’t overlap
• Simplicity -vs- tightness12
Axis-Aligned Bounding Boxes
• Axis-aligned bounding box defined by min and max x,y,z
13
Min x,y,z
Max x,y,z
Axis-Aligned Bounding Boxes
14
Transform boxNot axis-aligned
Min/max of new pointsLinear cost to compute
15
Axis-Aligned Bounding Boxes
Min/max of transformed BB points
Constant timeAdds slopCumulative slop if multiple transforms occur sequentially
Why would we do this?
16
AABB Trees
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShapeGroup node
Geometry nodeTransformation stored at all nodes
One of many variations
HeadShape
B.BoxGeometry
Scale 2x
Transformation XF B.Box
17
AABB TreesRobot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
One of many variations
Geometry node
XF B.BoxChildren
Rot -25
Transformation
Head
Union B.Box XF B.Box
18
AABB TreesRobot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
One of many variations
Group node
19
AABB Trees One of many variations
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
Local Bounding Boxes
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
20
AABB Trees One of many variations
Transformed Bounding Boxes
21
AABB Trees One of many variations
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
22
AABB Trees One of many variations
23
AABB Trees One of many variations
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
Robot
L.Foot RFoot
Head L.Arm R.Arm L.Leg R.LegTorso
Mouth L.Eye R.EyeHeadShape
LegShape
LegShape
24
AABB Trees One of many variations
25
Ray Test Against Bound Tree
•RayHitSubTree(&ray,node)• If RayHitsBB(ray,node.xfBB)
• ixfRay = Inverse(node.xf)*ray• If RayHitsBB(ixfRay,node.BB)
• If node is group• Foreach child in node.children
• RayHitSubTree(ixfRay,child)• else // node not group
• RayHitGeometry(ixfRay,node.geom)• ray.collisionInfo.update(ixfRay)