rasterizing polygons
DESCRIPTION
Rasterizing Polygons. Lecture 29 Wed, Dec 7, 2005. Rasterizing Polygons. Given a the vertices of a polygon, in viewport coordinates, which pixels should be shaded? How do we determine them efficiently?. Rasterizing Polygons. Rasterizing Polygons. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/1.jpg)
Rasterizing Polygons
Lecture 29Wed, Dec 7, 2005
![Page 2: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/2.jpg)
Rasterizing Polygons
Given a the vertices of a polygon, in viewport coordinates, which pixels should be shaded?How do we determine them efficiently?
![Page 3: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/3.jpg)
Rasterizing Polygons
![Page 4: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/4.jpg)
Rasterizing Polygons
Obviously, any pixel lying entirely within the polygon should be shaded.What about the pixels that are partially within the polygon? Rule: Shade them if their center is
within the polygon.
What about the pixels whose center is exactly on the edge?
![Page 5: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/5.jpg)
Edge Pixels
![Page 6: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/6.jpg)
Neighboring Polygons
When two polygons share an edge, which one “owns” the pixels on the edge?Rule A polygon owns all pixels whose
centers are within its interior. A polygon owns all pixels whose
centers lie on one of its left edges.
![Page 7: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/7.jpg)
Neighboring Polygons
Fill in all pixels whose centers are within the polygon.
![Page 8: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/8.jpg)
Neighboring Polygons
Fill in all pixels whose centers are on a left edge of the polygon.
![Page 9: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/9.jpg)
A Rasterization Algorithm
To rasterize a polygon, first determine its bounding box.
![Page 10: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/10.jpg)
A Rasterization Algorithm
To rasterize a polygon, first determine its bounding rectangle.
![Page 11: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/11.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
![Page 12: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/12.jpg)
A Rasterization Algorithm
When an edge is encountered, If we were on the outside, we move
to the inside. If we were on the inside, we move to
the outside.
Thus, we stop or resume shading accordingly.
![Page 13: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/13.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 0
![Page 14: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/14.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 1
![Page 15: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/15.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 2
![Page 16: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/16.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 3
![Page 17: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/17.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 4
![Page 18: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/18.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 5
![Page 19: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/19.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 6
![Page 20: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/20.jpg)
A Rasterization Algorithm
Then scan each row of pixels in the bounding rectangle, left to right, bottom to top.
row 7
![Page 21: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/21.jpg)
A Rasterization Algorithm
The following algorithm is designed to allow rapid shading of the pixels. As the vertices are given, create a list of
the vertices. (The order matters!) {(1, 0), (4, 3), (6, 1), (12, 1), (11, 8), (7, 8), (6,
5), (4, 8), (0, 7), (1, 0)}. From the list of vertices, form an edge
table. {{(1, 0), (4, 3)}, {(4, 3), (6, 1)}, …, {(0, 7), (1,
0)}}.
![Page 22: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/22.jpg)
A Rasterization Algorithm
Organization of the edge table. Eliminate any horizontal edges. Sort the edges in the edge table by
the y-coordinate of the lower endpoint.
Begin scanning with the bottom scan line.
![Page 23: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/23.jpg)
The Active Edge Table
Create the active edge table (AET). For each edge in the edge table
whose lower endpoint is on the scan line, Create an active-edge-table entry. Add it to the active edge table. Delete the edge from the edge table.
![Page 24: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/24.jpg)
The Active Edge Table
Organization of an active-edge-table entry: y-coordinate of upper endpoint. Reciprocal of the slope. x-intercept with the horizontal line ½
unit above the current scan line.
![Page 25: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/25.jpg)
The Active Edge Table
Activeedges
Scanline
![Page 26: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/26.jpg)
The Active Edge Table
Scanline
(7, -1/7, 13/14)
(3, 1, 1-1/2)
![Page 27: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/27.jpg)
The Active Edge Table
Sort the AET entries by their x-intercepts.The AET must contain an even number of entries. Why?
Shade pixels from the 1st to the 2nd x-intercepts, 3rd to 4th x-intercepts, etc., in the AET.
![Page 28: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/28.jpg)
The Active Edge Table
Scanline
(no shading onthis scan line)
(7, -1/7, 13/14)
(3, 1, 1-1/2)
![Page 29: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/29.jpg)
The Active Edge Table
Update the AET. Increment the scan line number. Delete from the AET any entries for which
the upper endpoint is on the scan line. Update the x-intercepts of all AET entries.
Add the reciprocal slope to the x-intercept. Create and add entries from the edge
table for edges whose lower endpoint is on the scan line.
![Page 30: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/30.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 13/14)
(3, 1, 1-1/2)
![Page 31: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/31.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 11/14)
(3, 1, 2-1/2)(3, -1, 5-1/2)
(8, -1/7, 11-13/14)
![Page 32: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/32.jpg)
A Rasterization Algorithm
Scanline
(3, 1, 2-1/2)(3, -1, 5-1/2)
(7, -1/7, 11/14)
(8, -1/7, 11-13/14)
![Page 33: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/33.jpg)
A Rasterization Algorithm
Scanline
(3, 1, 3-1/2)(3, -1, 4-1/2)
(8, -1/7, 11-11/14)
(7, -1/7, 9/14)
![Page 34: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/34.jpg)
A Rasterization Algorithm
Scanline
(3, 1, 3-1/2)(3, -1, 4-1/2)
(7, -1/7, 9/14)
(8, -1/7, 11-11/14)
![Page 35: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/35.jpg)
A Rasterization Algorithm
Scanline (8, -1/7, 11-9/14)
(7, -1/7, 1/2)
![Page 36: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/36.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 1/2)
(8, -1/7, 11-9/14)
![Page 37: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/37.jpg)
A Rasterization Algorithm
Scanline (8, -1/7, 11-1/2)
(7, -1/7, 5/14)
![Page 38: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/38.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 5/14)
(8, -1/7, 11-1/2)
![Page 39: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/39.jpg)
A Rasterization Algorithm
Scanline (8, -1/7, 11-5/14)
(7, -1/7, 3/14)
(8, -2/3, 5-5/6) (8, 1/3, 6-1/6)
![Page 40: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/40.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 3/14)
(8, -2/3, 5-2/3) (8, 1/3, 6-1/6)
(8, -1/7, 11-5/14)
![Page 41: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/41.jpg)
A Rasterization Algorithm
Scanline (8, -1/7, 11-3/14)
(7, -1/7, 1/14)
(8, -2/3, 5) (8, 1/3, 6-1/2)
![Page 42: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/42.jpg)
A Rasterization Algorithm
Scanline
(7, -1/7, 1/14)
(8, -2/3, 5) (8, 1/3, 6-1/2)
(8, -1/7, 11-3/14)
![Page 43: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/43.jpg)
A Rasterization Algorithm
Scanline (8, -1/7, 11-3/14)
(8, -2/3, 5) (8, 1/3, 6-1/2)(8, 4, 2)
![Page 44: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/44.jpg)
A Rasterization Algorithm
Scanline
(8, -2/3, 5) (8, 1/3, 6-1/2)(8, 4, 2)
(8, -1/7, 11-3/14)
![Page 45: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/45.jpg)
A Rasterization Algorithm
![Page 46: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/46.jpg)
Rasterizing Polygons
Read
Run
![Page 47: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/47.jpg)
Rasterizing Polygons in OpenGL
Read
Run
![Page 48: Rasterizing Polygons](https://reader035.vdocuments.us/reader035/viewer/2022081421/56815937550346895dc67128/html5/thumbnails/48.jpg)
Freehand Polygons
Read
Run