open gl 09 scan conversion
DESCRIPTION
TRANSCRIPT
![Page 1: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/1.jpg)
CS-184: Computer Graphics
Lecture #9: Scan Conversion Prof. James O’Brien
University of California, BerkeleyV2009-F-09-1.0
![Page 2: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/2.jpg)
2
Today
• 2D Scan Conversion• Drawing Lines• Drawing Curves• Filled Polygons• Filling Algorithms
![Page 3: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/3.jpg)
3
Drawing a Line• Basically, its easy... but for the details
• Lines are a basic primitive that needs to be done well...
![Page 4: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/4.jpg)
4
Drawing a Line• Basically, its easy... but for the details
• Lines are a basic primitive that needs to be done well...
From “A Procedural Approach to Style for NPR Line Drawing from 3D models,”by Grabli, Durand, Turquin, Sillion
![Page 5: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/5.jpg)
5
Drawing a Line
![Page 6: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/6.jpg)
6
Drawing a Line
![Page 7: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/7.jpg)
7
Drawing a Line• Some things to consider
• How thick are lines?• How should they join up?• Which pixels are the right ones?
For example:
![Page 8: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/8.jpg)
8
Drawing a Line
InclusiveEndpoints
![Page 9: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/9.jpg)
9
Drawing a Line
y= m · x+b,x ∈ [x1,x2]
m=y2− y1x2− x1
b= y1−m · x1
![Page 10: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/10.jpg)
10
Drawing a Line
Δx= 1Δy= m ·Δx
x=x1y=y1while(x<=x2) plot(x,y) x++ y+=Dy
![Page 11: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/11.jpg)
11
Drawing a Line
Δx= 1Δy= m ·ΔxAfter rounding
![Page 12: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/12.jpg)
12
Drawing a Line
Δx= 1Δy= m ·Δx
Accumulation ofroundoff errors
How slow is float-to-int conversion?
y+= Δy
![Page 13: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/13.jpg)
13
Drawing a Line
|m|≤ 1 |m| > 1
![Page 14: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/14.jpg)
14
Drawing a Linevoid drawLine-Error1(int x1,x2, int y1,y2) ! float m = float(y2-y1)/(x2-x1) int x = x1 float y = y1 while (x <= x2) setPixel(x,round(y),PIXEL_ON)
x += 1 y += m
Not exact math
Accumulates errors
![Page 15: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/15.jpg)
15
No more rounding
Drawing a Linevoid drawLine-Error2(int x1,x2, int y1,y2) ! float m = float(y2-y1)/(x2-x1) int x = x1 int y = y1 float e = 0.0 while (x <= x2) setPixel(x,y,PIXEL_ON)
x += 1 e += m if (e >= 0.5) y+=1 e-=1.0
![Page 16: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/16.jpg)
16
Drawing a Linevoid drawLine-Error3(int x1,x2, int y1,y2) ! int x = x1 int y = y1 float e = -0.5 while (x <= x2) setPixel(x,y,PIXEL_ON)
x += 1 e += float(y2-y1)/(x2-x1) if (e >= 0.0) y+=1 e-=1.0
![Page 17: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/17.jpg)
17
Drawing a Linevoid drawLine-Error4(int x1,x2, int y1,y2) ! int x = x1 int y = y1 float e = -0.5*(x2-x1) // was -0.5 while (x <= x2) setPixel(x,y,PIXEL_ON)
x += 1 e += y2-y1 // was /(x2-x1) if (e >= 0.0) // no change y+=1 e-=(x2-x1) // was 1.0
![Page 18: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/18.jpg)
18
Drawing a Linevoid drawLine-Error5(int x1,x2, int y1,y2) ! int x = x1 int y = y1 int e = -(x2-x1) // removed *0.5 while (x <= x2) setPixel(x,y,PIXEL_ON)
x += 1 e += 2*(y2-y1) // added 2* if (e >= 0.0) // no change y+=1 e-=2*(x2-x1) // added 2*
![Page 19: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/19.jpg)
19
Drawing a Linevoid drawLine-Bresenham(int x1,x2, int y1,y2) ! int x = x1 int y = y1 int e = -(x2-x1) while (x <= x2) setPixel(x,y,PIXEL_ON)
x += 1 e += 2*(y2-y1) if (e >= 0.0) y+=1 e-=2*(x2-x1)
FasterNot wrong
|m|≤ 1x1≤ x2
![Page 20: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/20.jpg)
20
Drawing Curves
y= f (x)
Only one value of y for each value of x...
![Page 21: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/21.jpg)
21
Drawing Curves• Parametric curves
• Both x and y are a function of some third parameter
y= f (u)x= f (u)
x= f(u)
u ∈ [u0 . . .u1]
![Page 22: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/22.jpg)
22
Drawing Curves
x= f(u) u ∈ [u0 . . .u1]
![Page 23: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/23.jpg)
23
• Draw curves by drawing line segments• Must take care in computing end points for lines• How long should each line segment be?
Drawing Curves
x= f(u) u ∈ [u0 . . .u1]
![Page 24: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/24.jpg)
24
• Draw curves by drawing line segments• Must take care in computing end points for lines• How long should each line segment be?• Variable spaced points
Drawing Curves
x= f(u) u ∈ [u0 . . .u1]
![Page 25: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/25.jpg)
25
Drawing Curves• Midpoint-test subdivision
|f(umid)− l(0.5)|
![Page 26: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/26.jpg)
26
Drawing Curves• Midpoint-test subdivision
|f(umid)− l(0.5)|
![Page 27: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/27.jpg)
27
Drawing Curves• Midpoint-test subdivision
|f(umid)− l(0.5)|
![Page 28: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/28.jpg)
28
Drawing Curves• Midpoint-test subdivision
• Not perfect• We need more information for a guarantee...
|f(umid)− l(0.5)|
![Page 29: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/29.jpg)
29
Filled Polygons
![Page 30: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/30.jpg)
30
Filled Polygons
![Page 31: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/31.jpg)
31
Filled Polygons
![Page 32: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/32.jpg)
32
Filled Polygons
![Page 33: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/33.jpg)
33
Filled Polygons
![Page 34: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/34.jpg)
34
Filled Polygons
![Page 35: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/35.jpg)
35
Filled Polygons
![Page 36: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/36.jpg)
36
Filled Polygons
Treat (scan y = vertex y) as (scan y > vertex y)
![Page 37: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/37.jpg)
37
Filled Polygons
Horizontal edges
![Page 38: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/38.jpg)
38
Filled Polygons
Horizontal edges
![Page 39: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/39.jpg)
39
• “Equality Removal” applies to all vertices
• Both x and y coordinates
Filled Polygons
![Page 40: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/40.jpg)
40
• Final result:
Filled Polygons
![Page 41: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/41.jpg)
41
• Who does this pixel belong to?
Filled Polygons
1
2
34
5
6
![Page 42: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/42.jpg)
42
Drawing a Line• How thick?
• Ends?
Butt
Round
Square
![Page 43: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/43.jpg)
43
Drawing a Line• Joining?
Ugly Bevel Round Miter
![Page 44: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/44.jpg)
44
Inside/Outside Testing
The Polygon Non-exterior
Non-zero winding Parity
![Page 45: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/45.jpg)
Optimize for Triangles
• Spilt triangle into two parts• Two edges per part• Y-span is monotonic
• For each row• Interpolate span
• Interpolate barycentric coordinates
45
![Page 46: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/46.jpg)
46
Flood Fill
![Page 47: Open GL 09 scan conversion](https://reader034.vdocument.in/reader034/viewer/2022052310/54b4da0b4a79592f4e8b46ab/html5/thumbnails/47.jpg)
47
Flood Fill