1 / 115

IT 300: Computer Graphics

IT 300: Computer Graphics. Lecture 4: Areas, text and colors. Lecturer Details. Dr. Walid Khedr, Ph.D. Email: khedrw@yahoo.com Web: www.staff.zu.edu.eg/wkhedr Department of Information Technology. Course Info. Course Name: Computer Graphics Course Number: IT300

gaia
Download Presentation

IT 300: Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IT 300: Computer Graphics Lecture 4: Areas, text and colors

  2. Lecturer Details • Dr. Walid Khedr, Ph.D. • Email: khedrw@yahoo.com • Web: www.staff.zu.edu.eg/wkhedr • Department of Information Technology

  3. Course Info • Course Name: Computer Graphics • Course Number: IT300 • Course Group: http://groups.yahoo.com/group/IT300_Computer_Graphics • Programming: JAVA • Prerequisite: JAVA, Linear Algebra • Course Materials: • Text Book • Lectures

  4. Main Topics • Introduction • Basic principles of two-dimensional graphics • Scan Conversion: Drawing lines and curves • Areas, text and colors • Basic principles of three-dimensional graphics • Modeling three-dimensional objects • Visible surface determination • Illumination and shading • Special effects and virtual reality

  5. Areas, text and colors • Objectives • Filling Areas • Which pixels to fill? • Scan line technique • Seed-fill technique • Scan line seed fill technique • With what value to fill them? • Color Models • RGB Model • CMY Model • HSV Model • Color Interpolation

  6. Objectives • Filling areas and polygons is a general technique of computer graphics. • This chapter contains in addition to techniques for filling areas also basic models for colors and a short introduction to handling text in images.

  7. Filling Areas • Areas are usually bounded by polygons or closed sequences of curves. • Two fundamental questions: • Which pixels to fill? • With what value to fill them? • In order to fill a polygon, points inside the polygon must be distinguished from exterior ones. • For polygons whose edges do not intersect, it is obvious which points should be considered as inner and outer points. • For polygons with intersecting edges it is not immediately clear what its inner parts are.

  8. Which pixels to fill? • In order to fill a polygon, points inside the polygon must be distinguished from exterior ones. • For polygons whose edges do not intersect, it is obvious which points should be considered as inner and outer points. • For polygons with intersecting edges it is not immediately clear what its inner parts are.

  9. Filling Areas • Two basic approaches: • Scan line technique: • Take successive scan lines that cross the area and fill in the spans of adjacent pixels that lie inside the area from left to right. • Typically used to fill polygons, circles, and other simple curves. • Seed-fill technique: • Start from a given interior position and paint outward from this position until we encounter the boundary. • Typically used to fill more complex boundaries.

  10. Filling Areas

  11. The Odd Parity Rule The odd parity rule provides a definition of inner and outer points.

  12. The Odd Parity Rule • The odd parity rule is a useful mathematical definition of interior and exterior points of a polygon • but it is not suited for implementation, since the computational costs would be unacceptable if the rule is applied separately to each pixel.

  13. Scan-Line Polygon Fill Algorithm • This algorithm handles polygonal regions that are geometrically defined by the coordinates of their vertices (along with the edges that connect the vertices). • Although such regions can be filled by the previous technique, the following is a much more efficient approach.

  14. Scan-Line Polygon Fill Algorithm • The algorithm begins with the first scan line the polygon occupies and proceeds line by line towards the last scan line. • For each scan line it finds all intersection points between the current scan line and the edges. • The intersection points are sorted according to their x coordinates and grouped into pairs such as (a, b) and (c, d). • Calculate parity of intersections to determine in/out • A line is drawn from the first point to the second point in each pair.

  15. Scan-Line Polygon Fill Algorithm • Special cases to be handled: • Horizontal edges. • Horizontal edges are ignored since the pixels that belong to them are automatically filled during scan conversion. • For vertices lying on scanlines.

  16. Scan-Line Polygon Fill Algorithm

  17. Scan-Line Polygon Fill Algorithm • When a scan line intersects a vertex. • If the vertex is a local minimum or maximum such as V1 and V7, no special treatment is necessary. • The two edges that join at the vertex will each yield an intersection point with the scan line.

  18. Scan-Line Polygon Fill Algorithm • However, in this case we don’t want to count p1 twice (p0,p1,p1,p2,p3), otherwise we will fill pixels between p1 and p2, which is wrong. • To avoid cases where a vertex needs to be counted as one intersection, shorten one of the two intersecting edges by one scan line

  19. Scan-Line Polygon Fill Algorithm

  20. count twice, once for each edge delete horizontal edges Special cases to be handled chop lowest pixel to only count once

  21. Scan-Line Polygon Fill Algorithm • Calculating intersections must be done cleverly. • In particular , we must avoid the brute-force technique of testing each polygon edge for intersection with each new scan line. • Calculations performed in scan-conversion and other graphics algorithms take advantage of various coherence properties • What we mean by coherence is simply that the properties of one part of a scene are related in some way to other parts of the scene so that the relationship can be used to reduce processing.

  22. Coherence Method

  23. Coherence Method • This allows for integer calculations to be performed.

  24. Polygon Fill • Building the sorted edge table • Traverse Edges to construct an Edge Table. • Eliminate horizontal edges • Shorten certain edges (where y changes monotonically) to resolve which intersection points to choose • For each edge, we add it to the scan-line that it begins with (that is, the scan-line equal to its lowest y-value). • For each edge entry, store (1) the x-intercept with the scan-line, (2) the largest y-value of the edge, and (3) the inverse of the slope. • Each scan-line entry thus contains a sorted list of edges. The edges are sorted left to right. (To maintain sorted order, just use insertion based on their x value.)

  25. Polygon Data Structure edges xmin ymax 1/m  (9, 6) 1 6 8/4  (1, 2) xmin = x value at lowest y ymax = highest y

  26. Polygon Fill

  27. Polygon Fill

  28. Polygon Fill • Use an active-edge table(AET) to keep track of the edges that the current scanline intersects • The AET contains all edges crossed by the current scan-line. • The edges in the AET are sorted in an increasing order, using the x intersection values.

  29. Algorithm (using ET and AET) • Process the scan lines from the bottom of the polygon to its top • Create a list of active edges for the first scan-line • Find intersection points (i.e., xk+1 = xk + 1/m, x0 = xmin), sort them, and fill the spans defined by the pairs • Move to the next scan-line and update AET • Delete edges which are currently in the AET but not intersected by the next scan-line (use ymax to find if next scan-line intersects an edge) • Add new edges from ET which are intersected by the next scanline • If AET is not empty, goto step 2

  30. Example

  31. Polygon Data Structureafter preprocessing 13 12 11 10  e6 9 8 7  e4 e5 6  e3 e7 e8 5 4 3 2 1  e2 e1 e11 0  e10  e9 11  e6 10 Edge Table (ET) has a list of edges for each scan line. 13 7  e3  e4 e5 6  e7 e8 e6 10 e5 e3 e7 e4 e8 5 e9 e2 e11 e11 e10 0 e1

  32. Running the Algorithm ET 13 12 11  e6 10 9 8 7  e3 e4 e5 6  e7 e8 5 4 3 2 1  e2 e11 0  e10  e9 xmin ymax 1/m e2 2 6 -2/5 e3 1/3 12 1/3 e4 4 12 -2/5 e5 4 13 0 e6 6 2/3 13 -4/3 e7 10 10 -1/2 e8 10 8 2 e9 11 8 3/8 e10 11 4 -3/4 e11 6 4 2/3 13 e6 10 e5 e3 e7 e4 e8 5 e9 e2 e11 e10 0 5 0 10 15

  33. Running the Algorithm y=0 SLB e10 13 e6 10 1/4 11 4 -3/4  10 e5 e3 e7 e9 e4 e8 11 8 3/8  11 3/8 5 e9 e2 e11 e10 0 5 0 10 15

  34. Running the Algorithm y=1 SLB e2 13 e6 1 3/5 2 6 -2/5  10 e5 e3 e7 e11 e4 e8 6 6 2/3 4 2/3  5 e9 e10 e2 e11 9 1/2 10 1/4 4 -3/4  e10 0 e9 5 0 10 15 11 6/8 8 3/8  11 3/8

  35. Running the Algorithm y=2 SLB e2 13 e6 1 1/5 1 3/5 6 -2/5  10 e5 e3 e7 e11 e4 e8 6 2/3 7 1/3 4 2/3  5 e9 e10 e2 e11 8 3/4 9 1/2 4 -3/4  e10 0 e9 0 5 10 15 12 1/8 11 6/8 8 3/8 

  36. Running the Algorithm y=3 SLB e2 13 e6 1 1/5 4/5 6 -2/5  10 e5 e3 e7 e11 e4 e8 7 1/3 4 2/3  8 5 e9 e10 e2 e11 8 8 3/4 4 -3/4  e10 0 e9 0 5 10 15 12 1/8 8 3/8  12 4/8

  37. Running the Algorithm y=4 SLB e2 13 e6 4/5 6 -2/5  10 e5 e3 e7 e11 e4 e8 8 4 2/3  5 e9 e10 e2 e11 8 4 -3/4  e10 0 e9 0 5 10 15 12 4/8 8 3/8  Remove these edges.

  38. Running the Algorithm y=4 SLB e2 13 e6 4/5 6 -2/5  2/5 10 e5 e3 e7 e9 e4 e8 12 7/8 12 4/8 8 3/8  5 e9 e2 e11 e11 and e10 are removed. e10 0 0 5 10 15

  39. Running the Algorithm y=5 SLB e2 13 e6 2/5 6 -2/5  0 10 e5 e3 e7 e9 e4 e8 12 7/8 8 3/8  13 2/8 5 e9 e2 e11 e10 0 0 5 10 15

  40. Running the Algorithm Remove this edge. y=6 SLB e2 13 e6 0 6 -2/5  10 e5 e3 e7 e7 e4 e8 9 1/2 10 10 -1/2  5 e9 e8 e2 e11 12 10 8 2  e10 0 e9 0 5 10 15 13 2/8 8 3/8  13 5/8

  41. Running the Algorithm Add these edges. e3 1/3 12 1/3  e4 4 12 -2/5  13 e6 e5 10 e5 e3 e7 4 13 0  e4 e8 y=7 SLB e7 5 9 1/2 10 -1/2  e9 e2 e11 e10 e8 0 12 8 2  0 5 10 15 e9 13 5/8 8 3/8 

  42. Seed Fill Algorithm • Polygon filling process start from seed pixel. • As soon as the filling process is initialed, the neighborhood of seed point is checked for its color content. • For neighboring pixels with old or previous color, they are flooded with new color. • The algorithm terminates once encountering a boundary pixel or pixels of new color in all sides. • Disadvantage: considerable stacking is needed

  43. The order of pixels that should be added to stack using 4-connected is above, below, left, and right. For 8-connected is above, below, left, right, above-left, above-right, below-left, and below-right.

  44. Start Position Boundary Fill Algorithm 4-connected (Example)

  45. 1 2 3 Boundary Fill Algorithm 4-connected (Example)

  46. 1 4 2 Boundary Fill Algorithm 4-connected (Example)

  47. 1 2 Boundary Fill Algorithm 4-connected (Example)

  48. 5 1 Boundary Fill Algorithm 4-connected (Example)

  49. 1 Boundary Fill Algorithm 4-connected (Example)

  50. Boundary Fill Algorithm 4-connected (Example)

More Related