bsp binary space partitioning yves kronenburg. binary space partitioning - bsp motivation painters...

45
BSP Binary Space Partitioning Yves Kronenburg

Upload: conradine-westphall

Post on 05-Apr-2015

127 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

BSP Binary Space Partitioning

Yves Kronenburg

Page 2: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees• BSP Trees 2D• BSP Trees 3D

Gliederung

Page 3: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees• BSP Trees 2D• BSP Trees 3D

Page 4: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPMotivation

Page 5: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPMotivation

Objekte müssen schnell undkorrekt aufgebaut werden!

Page 6: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPMotivation

z-Buffer Algorithmus

1. Die Szene wird so transformiert, dass die Blickrichtung die positive z-Achse ist.

2. Das erste Objekt wird in den Frame Buffer geladen. Zusätzlich werden dessen z-Koordinaten in den z-Buffer geschrieben.

3. Das nächste Objekt wird analysiert. Wenn die z-Koordinate des Objekts in einem Pixel kleiner ist, als die z-Koordinate des z-Buffers in diesem Pixel, so wird an dieser Stelle der Frame Buffer und z-Buffer mit den neuen Werten überschrieben.

4. Wiederhole 3. bis alle Objekte durchlaufen.

Page 7: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPMotivation

z-Buffer AlgorithmusNachteile:

• Zusätzlicher Speicher für den z-Buffer benötigt

• Für jedes Pixel eines Objektes muss ein Test der z-Koordinate stattfinden.

Page 8: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees• BSP Trees 2D• BSP Trees 3D

Page 9: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Page 10: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

1.

2.

3.

4.

5.

6.

Page 11: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

1. Objekte werden nach Ihrer Entfernung sortiert, weit entferntestes Objekt steht dabei an erster Stelle

2. Objekte werden komplett gezeichnet, bereits gesetzte Pixel werden einfach überschrieben

Page 12: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Page 13: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Page 14: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Page 15: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Page 16: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Objekte, die sich kreisförmig überlappen, lassen sich mitdem PA nicht zeichnen.

Page 17: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Dafür müssen Texturen zerschnitten werden

Page 18: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPPainters Algorithmus

Welches Objekt zerschneiden?Wo zerschneiden wir das Objekt?Neusortierung für jeden Blickwinkel!

Datenstruktur benötigt, die diese Informationenspeichert und uns für jeden beliebigen Blickpunktschnell ermöglicht, die Szene korrekt aufzubauen.

Page 19: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees • BSP Trees 2D• BSP Trees 3D

Page 20: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

Page 21: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

l1

l1

l5

l2l3

l4l5

BSP Baum

l3

l2

l4

Page 22: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

Sei h eine Hyperebene. Dann beschreibt h+ den oberen Halbraum zu h und h- den unteren Halbraum.

h+

h-

Page 23: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

Sei h eine Hyperebene. Dann beschreibt h+ den oberen Halbraum zu h und h- den unteren Halbraum.

Sei T der BSP Tree und sei S die Menge der Objekte die gezeichnet werden sollen.

Wenn |S| ≤ 1, dann ist T ein Blatt mit der Information über das Objekt in S.

Wenn |S| > 1, dann wird in die Wurzel v von T die Information über h gespeichert, sowie die Objekte aus S, die komplett in dieser Ebene liegen.Das linke Kind ist dann die Wurzel des BSP Trees T- mit den Objekten aus S, diein h- liegen, das rechte Kind die Wurzel des BSP Trees T+ mit den Objekten in h+.

Page 24: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

Wie können wir aus einem BSP Tree mittels PA unsere Szene erstellen?

Page 25: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

l1

l1

l5

l2l3

l4l5

BSP Baum

l3

l2

l4

Page 26: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

l1

l1

l5

l2l3

l4l5

BSP Baum

l3

l2

l4

Page 27: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees

Algorithmus PaintersAlogrithm(T, pview)

1. Sei v die Wurzel von T2. If v ein Blatt3. then Zeichne die Objekte aus v4. else if pview ε hv

+

5. then PaintersAlogrithm(T -, pview)6. Zeichne die Objekte aus v 7. PaintersAlogrithm(T +, pview) 8. else if pview ε hv

- 9. then PaintersAlogrithm(T +, pview) 10. Zeichne die Objekte aus v 11. PaintersAlogrithm(T -, pview) 12. else (* pview ε hv *)13. PaintersAlogrithm(T +, pview) 14. PaintersAlogrithm(T -, pview)

Page 28: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees • BSP Trees 2D• BSP Trees 3D

Page 29: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Sei S nun eine Menge sich nicht kreuzender Liniensegmente.

Unsere Objekte sind alle trianguliert

Page 30: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Algorithmus 2dBsp(S)

Input. Eine Menge S mit Segmenten {s1,…,sn}Output. Ein BSP Tree für die Menge S1. If |S| ≤ 12. then erzeuge einen Baum T aus lediglich einem Blatt, in dem

die Segmente aus S explizit gespeichert sind.

7. Erzeuge einen BSP Baum T mit Wurzel v, linkem Unterbaum

3. return T 4. else (* Benutze l(s1) als Trennlinie *) 5. S+ { s l(s1) + : s ε S} ; T+ 2dBsp(S+)6. S- { s l(s1) - : s ε S} ; T- 2dBsp(S-)

T-, rechtem Unterbaum T+ und mit S(v) = { s ε S : s l(s1)}. 8. return T

Page 31: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

s3s2

s1

5 Fragmente

3 Fragmente

s1

s2

s3

Page 32: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Algorithmus 2dRandomBsp(S)

1. Erzeuge aus der Menge S eine zufällige Permutation S‘ = s1,…, sn 2. T 2dBsp(S‘) 3. return T

Page 33: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Abschätzung der Fragmente

Sei si das nächste Segment welches vom Algorithmus als neueTrennlinie benutzt wird.

Page 34: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

s3s2

s1

5 Fragmente

3 Fragmente

s1

s2

s3

Page 35: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Wir definieren eine Distanzfunktion wie folgt:

Anzahl der schützendenSegmente zwischen si undsj

js sdist

i

Binary Space Partitioning - BSPBSP Trees 2D

Abschätzung der Fragmente

Sei si das nächste Segment welches vom Algorithmus als neueTrennlinie benutzt wird.

Es gibt Segmente, die andere Segmente vor dem Zerschneiden „schützen“ können.

Falls l(si) sj schneiden kann

sonst

Page 36: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

dist = 0

dist = 1

dist = 0

dist = 1

dist = 2

si

dist =

Page 37: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Abschätzung der Fragmente

Die Wahrscheinlichkeit, dass ein Segment si ein Segment sj schneidet, hängt also von seinem Distanzwert ab.

2

1

js sdisti

p ( l(si) schneidet sj )

Hieraus ergibt sich ein Erwartungswert von:

ij js sdist

i2

1E ( Anzahl der Schnitte durch si )

2

0 2

12n

k k

nln2

Page 38: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Abschätzung der Fragmente

Für alle Segmente n folgt (bei linearer Betrachtung), dass

2 n ln n

Schnitte erzeugt wurden.

Daraus ergibt sich, dass die erwartete Anzahl an Fragmenten

n + 2 n ln n

ist.

Page 39: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Laufzeitanalyse

Die Laufzeit hängt direkt von der Anzahl der Fragmente ab.

Page 40: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Laufzeitanalyse

Algorithmus 2dBsp(S)

Input. Eine Menge S mit Segmenten {s1,…,sn}Output. Ein BSP Tree für die Menge S1. If |S| ≤ 12. then erzeuge einen Baum T aus lediglich einem Blatt, in dem

die Segmente aus S explizit gespeichert sind.

7. Erzeuge einen BSP Baum T mit Wurzel v, linkem Unterbaum

3. return T 4. else (* Benutze l(s1) als Trennlinie *) 5. S+ { s l(s1) + : s ε S} ; T+ 2dBsp(S+)6. S- { s l(s1) - : s ε S} ; T- 2dBsp(S-)

T-, rechtem Unterbaum T+ und mit S(v) = { s ε S : s l(s1)}. 8. return T

Zeile 1-4 maximal n mal, da durch S begrenzt.

Zeile 5 oder 6 wird für jedes Fragment einmal Aufgerufen

Page 41: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 2D

Laufzeitanalyse

2dBsp(S) läuft in O(n² log n)

Page 42: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSP

• Motivation• Painters Algorithmus• BSP Trees • BSP Trees 2D• BSP Trees 3D

Page 43: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 3D

Page 44: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Binary Space Partitioning - BSPBSP Trees 3D

Algorithmus 3dBsp(S)

Input. Eine Menge S ={t1,…,tn} mit Dreicken aus Output. Ein BSP Tree für die Menge S1. If |S| ≤ 12. then erzeuge einen Baum T aus lediglich einem Blatt, in dem

S explizit gespeichert ist.

7. Erzeuge einen BSP Baum T mit Wurzel v, linkem Unterbaum

3. return T 4. else (* Benutze h(t1) als Trennebene *) 5. S+ { t h(t1) + : t ε S} ; T+ 3dBsp(S+)6. S- { t h(t1) - : t ε S} ; T- 3dBsp(S-)

T-, rechtem Unterbaum T+ und mit S(v) = { t ε S : t h(t1)}. 8. return T

3

Page 45: BSP Binary Space Partitioning Yves Kronenburg. Binary Space Partitioning - BSP Motivation Painters Algorithmus BSP Trees BSP Trees 2D BSP Trees 3D Gliederung

Quellenverzeichnis

• „Computational Geometry – Algorithms and Applications“ von Mark de Berg, Otfried Cheong, Marc van Kreveld, Mark OvermarsSpringer Verlag, Berlin, 3. Auflage (Mai 2008), Kapitel 12 (S.251-260)

• Bild: Microsoft Flight Simulators Xhttp://www.gursch.eu/resources/msfsx_textbild_1136468426.jpg

• Bild: Sims 3http://z.about.com/d/compsimgames/1/7/9/7/2/sims3pcscrnvday01.jpg

• Bild: Quake 2http://www.bluesnews.com/screenshots/q2/quake2-15.jpg