Lesson 11 Scan Line Polygon

download Lesson 11 Scan Line Polygon

of 16

description

scan line polygon

Transcript of Lesson 11 Scan Line Polygon

  • Scan-Line Polygon Fill Algorithm

  • Scan-Line Polygon Fill AlgorithmFor each scan line crossing a polygon, this algorithm locates the intersection points of the scan line with the polygon edges.These intersection points are then sorted from left to right and the corresponding positions between each intersection pair are set to the specified fill color.The four pixel intersection positions with the polygon boundaries define two stretches of interior pixels from x=10 to x=14 and from x=18 to x=24.The scan line algorithm first finds the largest and smallest y values of the polygon.It then starts with the largest y value & works its down, scanning from left to right.

  • Scan-Line Polygon Fill Algorithm

  • Scan-Line Polygon Fill AlgorithmThe important task is to find the intersection points of the scan line with the polygon boundary.When intersection points are even, they are sorted from left to right, paired and pixels between paired points are set to the fill color.When scan line intersect polygon vertex, a special handling is required to find the exact intersection points.To handle such cases, look at the other endpoint of the two line segments of the polygon which meet at this vertex.If these points lie on the same(up & down) side of the scan line, then this point in question counts as an even number of intersection.If they lie on opposite sides of the scan line, then the point is counted as single intersection.

  • Scan-Line Polygon Fill AlgorithmEach scan line intersects the vertex or vertices of the polygon.For scan line 1,the other end points of the line segment of the polygon are B & D which lie on the same side of the scan line.Hence there are two intersections resulting two pairs:1-2 & 3-4.Intersections points are 2 & 3 are actually same points.

  • Scan-Line Polygon Fill AlgorithmFor scan line 2,the other endpoints (D & F) of the two line segments of the polygon lie on the opposite sides of the scan line.Hence, there is a single intersection resulting two pairs: 1-2 & 3-4.For scan line 3,two vertices are the intersection points.For vertex F, the other end points E & G of the two line segments of the polygon lie on the same side of the scan line.For vertex H, the other end points G & I of the two line segments of the polygon lie on the opposite side of the scan line.

  • Scan-Line Polygon Fill AlgorithmAt vertex F there are two intersections & at vertex H there is only one intersection.This results two pairs:1-2 and 3-4 and points 2-3 are actually same points.It is necessary to calculate x intersection points for scan line with every polygon side.These calculations can be simplified by using Coherence Property.A coherence property of a scene is a property of a scene by which we can relate one part of a scene with the other parts of the scene.Slope of an edge is used as a coherence property.By using this property we can determine the x intersection value on the lower scan line if the x intersection value for current scan line is known.

  • Scan-Line Polygon Fill AlgorithmThis is given as

    xi+1 = xi 1/mWhere m is the slope of the edge.As we move from top to bottom value of y coordinates between the two scan line changes by 1.yi+1 = yi -1Many times it is not necessary to compute the x intersection for scan line with every polygon side.We need to consider only the polygon sides with endpoints stradding the current scan line.

  • Scan-Line Polygon Fill AlgorithmIt will be easier to identify which polygon sides should be tested for x intersection, if we first sort the sides in order of their maximum y value.

    Once the sides are sorted we can process the scan lines from top of the polygon to its bottom producing an active edge list for each scan line crossing the polygon boundaries.

    The active edge list for a scan line contain all edges crossed by that scan line.

  • Scan-Line Polygon Fill AlgorithmTOPBOTTOMSorted List of edges

    BCBADCDEAJGFGHEFHIJI

  • Text GenerationLetters, numbers and other characters are displayed to label and interpret drawing & to give instructions & information to the user.

    There are basic three methods of generating characters:

    Stroke Method

    Starbust Method

    Bitmap Method

  • Stroke MethodThis method uses small line segment to generate a character.

    The small series of line segments are drawn like a strokes of a pen to form a character.

    It is necessary to decide which line segments are needed for each character and then drawing these segments using line drawing algorithm.

  • Starbust MethodA fix pattern of line segments are used to generate characters.Out of these 24 line segments, segments required to display for particular character are highlighted.This method is known as starbust method because of its characteristic appearance.The patterns for particular characters are stored in the form of 24 bit code; each bit representing one line segment.The bit is set to 1 to highlight the line segment; otherwise it is set to zero.Disadvantages:

    More memory is required. Each character is represented by 24-bits.Code conversion s/w is required to display character from its 24-bits code

  • Starbust Method120213141516231719183412111098765242221

  • Bitmap MethodIt is also known as dot matrix because in this characters are represented by an array of dots in the matrix form.It is a two dimensional array having columns and rows.An 5 X 7 array is commonly used to represent character. However 7 X 9 and 9 X 13 arrays are also used.Each dot in the matrix is a pixel.The character is placed on the screen by copying pixel values from the character array into some portion of the screens frame buffer.The value of the pixel controls the intensity of the pixel.

  • Have a nice evening