Polygon filling method

Abstract: Two faster polygon fill routines are presented for filling polygons on a graphics display in addition to a conventional fill routine. The first fast fill routine fills polygons that are strictly convex. The second fast fill routine fills a larger class of polygons than the first fast fill routine which includes polygons being concave in the x direction, and polygons having crossing lines. The first fast fill routine tests the polygon for strict convexity by testing for a consistent turning direction, and by testing for once around in the y direction. The first polygon fill routine then stores the maximum and minimum value of the pel selected by the Bresenham routine for each scan line of the polygon. The fill line is drawn from the pel having the minimum value to the pel having the maximum value for each scan line of the polygon. The second fast fill routine tests the polygon to ensure that it can be filled with one unique fill line for each scan line of the polygon. The second fast fill routine stores both a minimum value and maximum value for each scan line line of the polygon for each line of the polygon. A fill line is then drawn from the least minimum value to the greatest maximum value for each scan line of the polygon.

Description: This invention relates to polygon filling, that is to say, in data processing output devices such as graphical raster displays, to a method for filling in the area defined by the boundaries of a polygon that is being displayed. There is a general routine for filling polygons as described in J. D. Foley and A. Van Dam, Fundamentals of Interactive Computer Graphics (Addison-Wesley, 1982), pages 456-460. This general routine is referred to as an edge table driven routine. This type of routine is used in computer graphic applications as one of the standard routines that are called to perform certain graphic tasks. Some of these graphic tasks include drawing lines, circles, arcs, etc., including filling polygons. These tasks are typically supplied in a library containing graphical functions such as a Graphics Support Library (GSL). In general, a graphics support library is a package of graphic subroutines that are typically delivered with a processing system so that users can write to displays with a higher level interface without having to know the complexity of any particular display and how to write to that display. For some simpler shapes of polygons, this routine becomes too time consuming. A routine becomes unduly time consuming when users of graphical applications have to wait after they have selected the polygon fill routine from a graphics library before the display screen displays the resulting filled polygon. It is important for customer satisfaction that the fill rate be as fast as possible without trading off the accuracy of the filled polygon. In another known routine, the routine routine uses the Bresenham routine defined in J. E. Bresenham, "Algorithm for Computer Control of a Digital Plotter", IBM Systems Journal , Vol. 4, No. 1 (1965), pages 25-30. The Bresenham routine is also described in J. D. Foley and A. Van Dam, Fundamentals of Interactive Computer Graphics (Addison-Wesley), 1982), pages 433-436. The Bresenham routine is used to scan the lines of the polygon boundary, and to generate the points that make up the polygon boundary. However, this known polygon fill routine selects the first point after a change in the scan line. The problem with this routine is that it does not accurately fill within the boundaries of the polygon. The resulting displayed polygon will appear as if it is incompletely filled. That is, the fill does not reach the boundary of the polygon at all locations. There are a variety of different shapes of polygons. Depending on the shape of a particular polygon, there may exist a polygon fill routine that is more efficient for that particular polygon shape than for other polygons having a different shape. The article "Method To Determine The Convexity of Polygons", IBM Technical Disclosure Bulletin Vol. 28 No. 5 October 1985 pages 2203 to 2208 discloses that for convex polygons, there exist filling routines which are more efficient than those for general polygons. By referring to Fig. 1A, the above mentioned article states that a polygon 10 is convex if all of its interior angles at the vertices A, B, C, D, E, are less than 180 degrees. Fig. 1B illustrates a polygon 11 that is not convex by this definition since it has an interior angle at its vertex E which is greater than 180 degrees. A method is disclosed in the article that determines whether or not all interior angles are less than 180 degrees, and therefore whether or not the polygon is convex. The method takes the cross product for each two adjoining vectors given by the edges of the polygon. If all of the cross products have the same sign, then the polygon is convex. The cross product indicates whether each side of the polygon is turning in the same direction. As shown in Fig. 1A, proceeding around the polygon 10 in the direction shown by the arrow 12 and starting at vertex E, all turns are to the left. However, in Fig. 1B, proceeding around the polygon 11 in the directions shown by the arrow 13 and starting at vertex D, all turns are to the left, except the turn at vertex E which is to the right. The above test would thereby classify the polygons 20, 21 shown in Fig. 2A and 2B as being convex since all interior angles are less than 180 degrees. Also, as shown in either Fig. 2A or Fig. 2B, in proceeding around the polygon 20, 21 in the direction shown by the arrow 22, 23 and starting at vertex B, all turns are to the left. However, the polygons 20, 21 shown in Fig. 2A and 2B have crossing lines and turn more than once around. These types of polygon are more complex and are not accurately filled by the simpler and more efficient fill routines previously known in the art. Therefore, the method described in the above mentioned article does not correctly determine the convexity of polygons for all types of polygons. Another problem is that the previous methods of testing polygons classified polygons having shapes as shown in Fig. 3A and 3B together with all other general polygons. The polygons 30, 31 of Fig. 3A and Fig. 3B are known as having x-concavity. Also, the polygon 31 of Fig. 3B has both x-concavity and crossing lines. The present invention provides a method of polygon filling in a by-line, pel driven data processing output in which a polygon to be filled is defined by a multiple line boundary which can be defined by a plurality of selectable pels per scan line, in which a general polygon fill routine is used unless a once round test performed on the vertices of the polygon, defined by the sign of the difference between ordinates transverse to the scan line direction of successive vertices of the polygon changing sign exactly two or three times in one circuit of the polygon, is satisfied, in which case a faster fill routine is used, possibly with other tests having to be additionally satisfied. An embodiment of the invention disclosed hereinafter implements one of three polygon fill routines for optimising the processing time required to fill a polygon depending upon the particular shape of the polygon. Several tests are used on the polygon to determine if the polygon falls within the class of polygons to be filled by a particular polygon fill routine. For one class of polygons, strictly convex polygons, the processing time required for filling a polygon is optimised by a first polygon fill routine by storing one maximum value for each scan line of the polygon for one half of the polygon, and one minimum value for each scan line of the polygon for the other half of the polygon. This routine stores exactly one value since the routine knows whether at any particularly point along the polygon, the point is part of the maximum or minimum values. For another class of polygons, x-concavity polygons, the first polygon fill routine is inadequate to accurately fill a polygon within this class of polygons. In this class of polygons, the processing time required to accurately fill a polygon is optimised by storing two minimum and maximum values for each scan line of a polygon. The fill line is then drawn from the least minimum value to the greatest maximum value for each scan line. The first polygon fill routine fills polygons that are strictly convex. The second polygon fill routine fills a larger set of polygons than the first polygon fill routine. The second polygon fill routine fills all polygons which can be filled with exactly one continuous line per scan. Polygons in this set may have x-concavity and crossing lines. The first polygon fill routine checks the polygon to determine if the polygon is strictly convex by checking for the combination of two conditions. First, the polygon is checked for consistent "turning" direction. That is, determining whether each sequential line of the polygon bend in the same direction. As a result of this test, the direction is determined as being clockwise or counter clockwise. For any two adjacent lines with points (x0, y0), (x1,y1), (x2,y2), the calculation for the sign of the vector product is as follows: (y1-y0)*(x2-x1)-(y2-y1)*(x1-x0) If the above expression is greater than zero, then the polygon is turning right, or clockwise. If the above expression is less than zero, then the polygon is turning left, or counter clockwise. If all adjacent lines have the same vector product sign, the polygon meets this first condition as having a consistent "turning" direction. The second condition that must be met for the polygon to be strictly convex is the once around y direction test. This is equivalent to having the sum of the interior angles equal to 360 degrees. The "once around test states that if the starting location is the lowermost vertex, and the polygon is traversed sequentially along its edges, the y coordinates of the sequential edges must first all increase and then decrease. In other words, a first group of edges of the polygon must first all rise, and the second group of edges of the polygon must all then fall. The once around condition is met if by starting at the first line of the polygon the algebraic sign of y(i+1)-y(i) for all adjacent vertices changes exactly 2 or 3 times. Horizontal lines are considered to have the same sign as the previous line. Polygons passing this test have y-convexity. That is, for any value of y there is one and only one continuous fill line. While traversing around the points of the polygon for the "once around" test, the maximum and minimum y values and locations are stored in memory. If the consistent turning direction test and the once around test are met, the polygon is strictly convex. The lines of the polygon can be partitioned into two sets such that the lines of one set defines maximum values of scan lines, while the other set defines minimum values. For a strictly convex polygon, a single table of two values per y value is used. The y value ranges from zero to the largest number of scan lines on the display of interest. Starting at the point of the minimum y value and proceeding in a counter clockwise direction, for each line of the polygon the maximum value of that line for every scan line that it intersects is saved in a table. An exception is made for vertexes having two lines that intersect on the same scan line. Special processing is used to store one maximum value on that scan line of a pel that both lines may share. This is continued for each line of the polygon until the maximum vertex in the y direction (ymax) is reached. From this point on, the lines define only minimum scan lines. For each line of the polygon, the minimum value of that line for every scan line that it intersects is saved in the table. Again, an exception is made for vertexes having two lines that intersect on the same scan line. Special processing is used to store one minimum value on that scan line of a pel that both lines may share. After filling the table by traversing all of the lines of the polygon, the GSL multiline draw routine is called in one preferred embodiment to draw one horizontal line per y in the range ymin to ymax. Other preferred embodiments may use other methods to draw a line from the selected minimum pel to the selected maximum pel for each scan line. The second polygon fill routine fills a larger set of polygons than the first polygon fill routine. All polygons can be filled with this second polygon fill routine if the polygon can be filled with exactly one continuous line per scan line. Polygons in this set have x-concavity and/or crossing lines. The only check is for the once around in the y direction condition as described above. Also, the ymin and ymax values and their associated vertices are recorded. In this case, there is no knowledge about whether the direction is clockwise or counter clockwise. In fact, in polygons with crossing lines, the clockwise and counter clockwise distinction is irrelevant. The lines of the polygon are again divided into two sets, those between ymin and ymax in the order originally presented. Lines of the polygon in either set may define a minimum or maximum on a given scan line. Therefore, two tables are used to store either the minimum or the maximum value, one for each set of lines. Starting at the point of the minimum y value of the polygon and proceeding through the first set of lines, both the minimum and maximum of a given line at the intersection with a scan line are stored. As the polygon is traversed, the second table likewise stores the minimum and maximum values of a given line at each intersection with a scan line for the second set of lines in the polygon. The minimum value for a given scan line is the minimum of the two values for that scan line from the two tables. Likewise, the maximum value for a given scan line is the maximum of the two values for that scan line from the two tables. At this point, either the two tables are scanned and combined to one table and the GSL multiline function is called; or pointers to both tables are passed to a new GSL multiline routine that combines them as it calls for each horizontal line to be drawn. Other preferred embodiments may use other methods to draw a line from the selected minimum pel to the selected maximum pel for each scan line. In the above polygon fill routines, there are two stages of the routine. The first stage scans all the lines of the polygon. For each line of the polygon, the Bresenham routine is utilised on each point along a line of the polygon. The processing time required to fill a polygon is optimised since the determination of whether the value of a point is to be stored in a min/max table is made at the time the Bresenham routine operates on that particular point. In this way, the second stage, the post processing is done integrally with the preprocessing, the first stage. Once the first stage, the preprocessing is complete, only a minimal amount of additional processing is needed to fill the polygon. The second stage, the post process, is virtually nonexistent for the first polygon fill routine. As the Bresenham routine operates, a single store is performed in a table having a minimum and maximum value for each y value of each scan line. In the post processing, the polygon is filled by scanning the array from ymin to ymax, and drawing a line from the minimum to the maximum value stored for each y value. In the post processing of the second polygon fill routine, the polygon is filled by first determining the maximum of the maximum values stored, and the minimum of the minimum values stored for each y value. A line is then drawn from the least minimum value to the greatest maximum value for each y scan line. The present invention will be described further by way of example with reference to both examples of the prior art referred to and an embodiment of the invention as illustrated in the accompanying drawings, in which: Fig. 1A illustrates a polygon that is convex as defined by prior art methods; Fig. 1B illustrates a polygon that is not convex as defined by prior art methods; Fig. 2A illustrates a polygon that is convex as defined by prior art methods; Fig. 2B illustrates a polygon that is convex as defined by prior art methods; Fig. 3A illustrates a polygon classified as a general polygon for utilising a general polygon fill routine; Fig. 3B illustrates a polygon classified as a general polygon for utilising a general polygon fill routine; Fig. 4A illustrates the hardware including a display of a processing system for utilising this way of polygon filling; Fig. 4B illustrates the logical structure of the processing system; Fig. 4C illustrates the physical structure of the processing system; Fig. 5 illustrates an array used with the first polygon fill routine; Fig. 6 illustrates the two arrays that are used with the second polygon fill routine; Fig. 7 illustrates a polygon displayed by pels which is filled by the first and second polygon fill routines; Fig. 8A represents a class of polygons that can be filled by the first polygon fill routine and the second polygon fill routine; Figs. 8B and 8C represent a class of polygons that can be filled by the second polygon fill routine; Fig. 8D represents a class of polygons that cannot be filled by either the first or second polygon fill routine; Fig. 9 illustrates the arrangement of a polygon in octants; Fig. 10 illustrates the rounding error when the direction of traverse is reversed; Fig. 11A illustrates a class of polygons that meet the once around test, and can be filled by the second polygon fill routine; Fig. 11B illustrates a class of polygons that fail the once around test, and cannot be filled by the second polygon fill routine; and Fig. 11C illustrates a class of polygons that are not strictly convex, are concave in the x direction, and meet the once around test, and can be filled by the second polygon fill routine. The embodiment of the present invention disclosed herein comprises a suite of two routines for faster polygon filling, together with a slower known general routine and the necessary driver for the combination. These routines could be used with any by line, pel driven output, such as the displays 94 (Fig. 4A) provided with a processing system 90 such as the IBM RT PC. Fig. 4B shows the logical structure 91 of the processing system 90. Fig. 4C shows the physical structure 92 of the processing system 90. The RT PC is more fully described in IBM RT Personal Computer Technology , Form No. SA23-1057. Each routine has advantages and disadvantages. Depending on the relative processor, display adapter, memory, and I/O speeds, one or the other routines will be more efficient for a particular implementation for a given display. Both fast fill routines are used to fast fill certain polygons having a specific classification of shape. The first fast polygon fill routine utilises one table 100 (Fig. 5) for storing values 110 at each y location 101, and the second fast polygon fill routine utilises two tables 111, 112 (Fig. 6) for storing values 113 at each y location 101 that are needed to fill a polygon. The size of the table 100 (Fig. 5), 111, 112 (Fig. 6) that is required depends upon the size of the particular display screen 94 (Fig. 4A) that is being used. If the display 94 that is being used is a monochrome display having 375 picture elements (pels) in the y direction 102, the table 100, 111, 112 needs 375 entries 103. If the display 94 (Fig. 4A) is an APA8 display which has 512 pels in the y direction 102, then the table 100, 111, 112 needs 512 entries 103. If the display 94 (Fig. 4A) is a megapel display which has 1024 pels in the y direction 102, the table 100, 111, 112 needs 1024 entries 102. The y entries 101 in the table 100, 111, 112 would range from zero 105 to the size of the screen minus one 107. The table 100, 111, 112 is therefore sized according to the size of the display 94. The fast fill routines are arranged so that if the actual polygon 120 (Fig. 4A) (not shown to scale) in the y direction ranges from pels having the value of y=10 to y=47, the table 100 (Fig. 5), or the tables 111, 112 (Fig. 6) does/do not have to be initialised for each positioning of the polygon 120. Only the entries 103 in each table 100, 111, 112 having the y values 101 within the polygon range (y=10 to y=47) in the y direction 102 (Fig. 4) are used. If the lowermost vertex A of the polygon 120 begins at the 10th pel in the y direction 102 from the bottom of the screen display 94, no table 100, 111, 112 has to be initialised so that the zero entry 105 represents vertex A at the 10th pel position. If the polygon has a total height of 37 pels, only the 11th through 48th table entries 103 would be utilised. The second fast fill routine utilises two tables 111, 112 shown in Fig. 6. Each table, 111, 112 has a minimum column 116 and maximum column 118. The tables 111, 112 also have a size that range from zero 105 to the size of the screen minus one 107. Referring to Fig. 7, as shown on a display 94 (Fig. 4A), the lines 121 - 124 of polygon 120 are represented by picture elements (pels) such as pels 130 that are turned on throughout scan lines 132 y10 - y18 to represent the line 121 of polygon 120. The lines 121 - 124 of polygon 120 are not actually displayed on the screen 94 (Fig. 4A), but are shown here for purposes of description only. Determining which pels 130 are to be turned on for each scan line 132 to best represent each of the lines 121 - 124 when displayed is accomplished by utilising the Bresenham routine as described in J. E. Bresenham, "Algorithm for Computer Control of a Digital Plotter", IBM Systems Journal , Vol. 4, No. 1 (1965), and in J. D. Foley and A. Van Dam, Fundamentals of Interactive Computer Graphics (Addison-Wesley), 1982. In both fast fill routines, the points 130 of a polygon 120 (Fig. 7) are generated by using the Bresenham routine. The pels 130 selected by the Bresenham routine to represent the line 121 are shown in Fig. 7 as filled in zero's. The pels 131 not selected by the Bresenham routine to represent a line 121 of the polygon 120 are shown in Fig. 7 as x's. There is a set of scan lines 132 representing each sequential row of pels 130, 131 in the y direction 102. For each line 121, 122, 123, 124 of the polygon 120, points 130 are generated on one scan line 132 at a time to represent collectively a line 121, 122, 123, 124 of the polygon 120. The two fast fill routines each have a different range of a set of polygons 33 (Fig. 8A), 34 (Fig. 8B), 35 (Fig. 8C) that can be filled with the particular routine. The second routine can fill a larger set of polygons 33, 34, 35 than the first routine 60. This set includes the set of all polygons that can be filled such that for each y value 102 there is a unique single line 133 that can be used to fill the polygon 33, 34, 35. This set of polygons 33, 34, 35 can include polygons that are concave 28 in the x direction 104. Additionally, this set includes polygons 35 having crossing lines 37, 38. Polygon 36 (Fig. 8D) illustrates that for each y value 102, there is not a unique single line that can be used to fill the polygon 36. For the lower values of y, there are two lines 134, 135 for each value of y. Therefore, a polygon 36 that is concave 29 in the y direction can not be filled using the second fast fill routine. For the first fast fill routine, the set of polygons includes only strictly convex polygons 33. There can not be any concavity in either x or y direction, and no crossing lines. Therefore, there is a front end to each fast fill routine that determines whether the polygon fits within the range of polygons for that particular routine and exits from the routine as quickly as possible when no fit is discovered. This is why, although one of the tests is common to both routines, it appears in both front ends. The following describes the tests that are performed on the polygon to determine in which range of polygons a particular polygon belongs. The following discussion will centre around the polygon 120 in Fig. 7. To begin, a discussion as to the definition of the term direction sensitivity of a polygon is needed. The same polygon 120 can be described by a sequence of x and y coordinates in either a clockwise 25 or counter clockwise 26 order around the polygon 120. The application of any given polygon fill routine should have the same result whether the polygon fill routine was applied to the polygon in a clockwise 25 or counterclockwise 26 direction. That is, the polygon should result in the same fill regardless of the direction the polygon 120 was traversed in applying the fill routine. In both fast fill routines hereof, there is no direction sensitivity regardless of the order that the coordinates of the resulting Bresenham pels 130 are presented. In addition, the first test for the first fast fill routine for strictly convex polygons determines the direction, clockwise 25 or counterclockwise 26, that the polygon is traversed in presenting the coordinates of the corresponding pels 130 of the polygon 120. The first fast fill routine is not direction sensitive since the direction is specifically detected as part of the test of the routine. If the direction is found to be clockwise 25, the order that the points (pels) 130 are scanned is reversed. The points 130 are always scanned counterclockwise 26 around a polygon. In the second fast fill routine, there is no direction sensitivity because there are two tables 111, 112 (Fig. 6) for each side 115, 114 of the polygon 120. Each table 111, 112 has minimum 116 and maximum 118 values in the x direction 104 for each scan line 132 in the y direction 102. Therefore, it does not matter if the polygon 120 is traversed up one side 114 and down the other 115 or vice versa. The result is two tables 111, 112 with minimum 116 and maximum 118 values in each table 111, 112 for each scan line 132 in the y direction 102. For each scan line 132, the maximum value of the two maximum values 118 for the two tables 111, 112 is selected, and the minimum value of the two minimum values 116 for the two tables 111, 112 is selected. A fill line is then drawn from the selected minimum pel to the selected maximum pel. This is illustrated by referring to Fig. 6 and Fig. 7. For scan line 132 representing the y value 101 of y=13, the maximum value 118 for line 121 of the polygon 120 is pel 46 having a value 118 in this example of x=263. This value would be stored in Table B 112. The minimum value 116 for line 121 of polygon 120 at scan line y=13 is x=262 at pel 45. This value of x=262 would then be stored in Table B 112 of entry y=13. For line 124 of polygon 120, at scan line 132 of y=13 the value of the pel 54 is x=256. Since there is only one pel 130 that is turned on by the Bresenham routine for line 124 at this scan line, this value is both the maximum and minimum value of x at y=13. This value of x=256 is stored in Table A at entry y=13. From Table A 111 and Table B 112, the maximum of the maximum values 118 is 263 for y=13, and the minimum of the minimum values 116 is 256 for y=13. A fill line 142 is then drawn from pel 54 to pel 46 by turning on all the pels 130, 131 there between as indicated by the symbolic boxing of the pel mark at each pel location. For the first fast fill routine, there is a determination as to whether the polygon 120 fits into the range of polygons for this particular fill routine and, at the same time, on the assumption that the determination will succeed, certain initialisation values are registered. There are three parts to this effectively extended test which are included within the front end of the routine: - the clockwise/counterclockwise test, picking up the turning direction as an aside; the once around test in either the x or y direction and the determination of y minimum and y maximum for the particular polygon for table initialisation. If the polygon meets the first two of these tests, the operative part of this first fast fill routine called "genline" will be called from the gsff routine. If the polygon fails either one of these tests, there will be an escape out, to the general fill routine as described in J. D. Foley, A. Van Dam, Fundamentals of Interactive Computer Graphics , pages 456-460. The first test for the first fast fill routine is the clockwise/counterclockwise test, otherwise referred to as the turning test and is described in "Method To Determine the Convexity of Polygons", IBM Technical Disclosure Bulletin , Vol. 28, No. 5, October 1985. More specifically, the preferred embodiment of this invention incorporates this turning test to check for consistent turning direction. That is, going from line to line of a polygon, it is determined whether each new line bends in the same direction. As a fallout of this test, clockwise or counterclockwise is also determined. If two adjacent lines 121, 122 (Fig. 7) has points (x0,y0), (x1,y1), (x2,y2), the calculation for the sign of the vector product is as follows: (y1-y0)*(x2-x1)-(y2-y1)*(x1-x0) If the above expression is greater than zero, then the polygon 120 is turning right for those two lines of the polygon. In this example, the vector product of lines 121 and 122 of polygon 120 would be less than zero indicating that the polygon 120 is turning left or counterclockwise 26. This turning test is repeated for each two adjacent lines of the polygon. If the results of this test for the same polygon result in the same sign, the polygon meets the consistent turning direction test. The second condition that must be met for the polygon to be strictly convex is the once around y direction test. This is equivalent to having the sum of the interior angles equal to 360 degrees. The "once around" test states that if the starting location for traversing the polygon begins at the lowermost vertex 1 (Fig. 7), and the polygon is traversed sequentially along its edges 121, 122, 123, 124, the y coordinates 102 of the sequential edges 121, 122, 123, 124 must first all increase and then decrease. In other words, a first group of edges 121, 122 of the polygon 120 must first all rise, and the second group of edges 123, 124 of the polygon 120 must all then fall. The once around condition is met if by starting at the first line 121 of the polygon 120, not necessarily the lowest point thereof, the algebraic sign of y(i+1)-y(i) for all adjacent vertexes changes exactly 2 or 3 times. Horizontal lines are considered to have the same sign as the previous line. Polygons passing this test have y-convexity. That is, for any value of y 102 there is one and only one continuous fill line 142. While traversing around the points 130 of the polygon 120 for the "once around" test 58 (Fig. 5A), the maximum and minimum y values and locations are stored in memory. Before the Bresenham routine is used in this polygon fill routine, the y maximum 2 and y minimum 1 values are initialised in the table 100 with the x value at those locations. This same x value for y maximum 2 is stored in both the max 107 and min 106 entries in the table 100 for the y maximum entry 103. Likewise, the same x value for y minimum 1 is stored in both the max 107 and min 106 entries in the table 100 for the y minimum entry 103. The consistent turning direction test along with the once around in the y direction test, which is equivalent to stating that the sum of the angles inside the polygon is 360 degrees, state that the polygon 120 has strict convexity. As a result of passing these two tests, the sign of the vector product calculated in the consistent turning direction test is then used to determine the direction of the polygon 120. If the value of the above expression is greater than zero, then the polygon 120 was traversed in a clockwise direction 25. If the value of the above expression is less than zero, then the polygon 120 was traversed in a counterclockwise direction 26. Since the first fast fill routine is based on a unidirectional, say counterclockwise 26, operation, if the sign of the expression indicates a clockwise direction 25 of presentation, the order that the points 130 are traversed is reversed. Referring to Fig. 7, once the polygon 120 is determined to have strict convexity as stated above, the lines 121, 122, 123, 124 of the polygon 120 can be partitioned into two sets 114, 115 such that the lines 121, 122 of one set 114 defines maximum values 107 (Fig. 5) of scan lines 132, while the other set 123, 124 defines minimum values 106 (Fig. 56). Regardless of the presentation of the polygon 120 through the preprocessing of the polygon in the above tests, vertex 1 will be determined to be y minimum, and vertex 2 will be determined to be y maximum. Traversing the polygon 120 from y minimum 1 in a counterclockwise direction 26 to y maximum 2, the maximum value of a scan line 132 is stored in the max entry 107 (Fig. 5) of the table 100 for the appropriate index 103 of y. As the first fast fill routine proceeds from one scan line 132 to the next sequential scan line 132, the maximum value 107 of x at the previous scan line is stored. This is repeated for each scan line 132 of y until y maximum 2 is reached. Once y maximum 2 is reached, the polygon 120 is traversed down from y maximum 2 to y minimum 1 down the lines 123, 124 that were previously partitioned. For this set 115 of partitioned lines 123, 124, the last point 130 on the scan line 132 is stored as the minimum value 106 of x in the table 100 for each y entry 103. This is repeated for each y scan line 132. For the first fast fill routine, the routine begins at y minimum (pel 1, Fig. 7) and proceeds in a counterclockwise direction 26 to y maximum shown as pel 2. During this traverse from y minimum 1 to y maximum 2, table 100 having min and max entries 110 for each y 102 is used. The maximum x value (which is the last point (pel) 130 on a scan line 132) for each y 102 is stored in the table 100. Once y maximum 2 is reached in the traverse, the polygon is traversed from y maximum 2 to y minimum 1. During this part of the polygon traverse, the minimum value for a pel 130 on each scan line 132 is stored in the table. In other words, it is the last point 130 that is scanned on the previous scan line after proceeding to the next y scan line. Going from the lowermost vertex 1 to the higher most vertex 2 of the polygon 120 in counter clockwise direction 26, the maximum value is stored in the array. Going from the higher most vertex 2 to the lower most vertex 1 in counter clockwise direction 26, the minimum value is stored in the array. For example, traversing the polygon 120 counterclockwise 26 starting with line 121, the x value at pel 42 would be stored at the max entry 107 for the y entry 103 at y=11 representing scan line 132 for y=11. For the next scan line 132 of y=12, the value of pel 44 would be stored at the maximum entry 107 for the y entry 103 of y=12. This is repeated for each scan line 132. Likewise, traversing the polygon 120 down from vertex 2, the minimum value for a pel 130 at a scan line 132 would be stored in the minimum entry 106 for the corresponding y entry 103. For example, the value of pels 54, 53, 51 would be stored at the minimum entry 106 for scan lines 132 representing y=13, y=12, and y=11 respectively in table 100. For the first fast fill routine, called gsff, there are three input parameters of significance to the present discussion. a first argument, inlines, which is the number of lines 121 - 124 in the polygon 120; a second argument, inx, which is the array of x points in the polygon 120; and a third argument, iny, which identifies the array of y points in the polygon 120. The xs argument is a pointer to the beginning of the array 100 which contains both min 106 and max 107 values in an alternating fashion as shown in Fig. 5. The first entry is x min 106 at y=0, the second entry is x max 107 at y=0, the third entry is x min 106 at y=1, the fourth entry is x max 107 at y=1, and so forth. This continues for the size of the screen minus 1, such as 1023 for a screen having 1024 pels in the y direction 102. The ys argument 155 is simply an array of points 0,0,1,1,2,2,3,3, etc. to the size of the screen minus one, i.e., 1023, 1023. The ys array 101 is initialised once. When this array 101 is called, it is called with an x 110 and y 101 pair to get the right y value with the right x value. The routine continues by initialising the once around y test and the turning test including the y min and y max at the first point. Next, there is a for loop which performs an incidence of each of the tests previously discussed. The for loop keeps calculating the turning test, it progressively updates y min and y max and it updates the once around test. In the turning test, if the sign of the inner product changes a local flag is set. In the once around test, the new sign is equal to 0 if it is negative, and 1 if it is positive. One is added to the count if the new sign is not equal to the old sign. This counts the number of changes in the sign. If the local flag is set which indicates that the direction calculated in previous incidences of the loop is different from the direction that was just calculated, or if the count of the number of changes in the sign of y reaches four - or, in theory, greater than four - the test fails, a combined fail flag is set and the loop is exited. If the combined fail flag is not set, the loop continues. The next step is the y high test. If the new y is higher than the previous y max, the y max is updated to the new value. The index where the new y max was found is stored. The same is done with the minimum. If the maximum was not exceeded, the y min value is checked to see if the new y value is less than the previous y min value. If it is, the y min value is updated with the new y min value. The index is also updated to note the location of the y min value. This ends the loop which can be regarded as a pretest. The total number of points for the y array 101 (Fig. 5) is calculated as two times the sum of y max minus y min plus one. A provision can be made, at this point, for there to be conditional print out for debugging purposes together with a diagnostic output. If the fail flag equals one, the pretest failed. If the directions are different, the routine prints out that the convexity test failed. If the change in sign is more than or equal to four, the routine prints out that the around test failed. Also, this is the point a more general routine would be called to fill the polygon if the pretest failed since the first fast fill routine gsff cannot be used for the type of polygon that is selected by the user to be filled. If the fail flag was not set during the entire pretest, the gsff routine continues. If the direction determined to be constant in the pretest is zero, then it is already counterclockwise, and the points 130 are scanned from the low point in a counter clockwise direction for each line 121-124, in the polygon. If the low point is not the first line of the polygon, the parameters for genline, the actual call, to the heart of the first fast fill routine, are adjusted to accommodate this. The steps prior to genline call ensured that the right line was pointed to and that it was counter clockwise, etc. Genline has five arguments corresponding to the parameters, possibly adjusted, as described above. The first argument is an address to the min/max array 100 (Fig. 5) in which values of xmin 106 and xmax 107 for each y value 103 are stored. The next two arguments are the x and y of the jth point in the scan and the last two arguments are the x and y of the point immediately after the jth point. Therefore, genline is called with a pointer into the array 100, and a line described by an x and y for a first pel and the next adjacent x and y for the second pel. Genline computes the minimum 106 and maximum 107 values for each y value of a scan line 132. It is assumed that the polygon 120 is strictly convex and the polygon 120 is presented in a counterclockwise 26 order. Therefore, the polygon 120 can be filled with a single horizontal line 142 for each value of y 102. Only one table 100 is used, and only one minimum 106 and maximum 107 value is saved in this table 100 for each scan line 132. A line with multiple pels 130 at the same y 102 is handled by only updating x when y changes. For lines in octants I, II, VII, VIII the update will be maximum 107, while for octants III, IV, V, VI the update will be minimum 106. As shown in Fig. 9, the octant I begins at 0 degrees where y is zero and x is any positive value and terminates at 45 degrees. Octant II ranges from 45 degrees to 90 degrees. This continues in likewise fashion for octants I-VIII. A line of a polygon is in octant I if the line's angle is between zero and 45 degrees. A line of a polygon is in octant II if the angle of the line is between 45 degrees and 90 degrees. A line of a polygon is in one of the eight octants depending on the angle of the line. The polygon 120 is organised within these octants such that as the polygon is traversed up the front face 121, 122, the points can only lie in octants VII, VIII, I, II. The table 100 (Fig. 5) is specifically designed for the first fast fill routine, but could be used for other implementations. The key is that since there is only one x minimum 106 and one x maximum 107 for each y 103, all y's are constant and are computed only once at initialisation. The table is organised as illustrated in Fig. 5 as follows: y0 xmin y0 xmax y1 xmin y1 xmax y2 xmin y2 xmax . . . . ymax xmin ymax xmax The xmin is initialised for the ymax, and the xmax is initialised for the ymax. This eliminates having to save the x value, minimum or maximum, at the first point of a line. The first point 141, 161 (Fig. 7) is excluded when drawing a line, but every point 130 after that is included. Only the portion of the table 100 from ymin 1 to ymax 2 of the given polygon 120 is used for filling the polygon. Therefore, genline generates the points 130 for one line 121 - 124 of the polygon 120. The slope of the line is generated and the address of the present location in the array is calculated. This address points to the minimum of x 106 in the table 100 at the present location. For example, if y were 10, the pointer would point to the 20th location 108 in the array 100. This entry 108 would contain the minimum x value 106 for y10, and the next entry 109 would contain the maximum value 107 of x for y10. The special case where the line of the polygon 120 is horizontal is covered as follows: If the first y is equal to the second y, then there is a horizontal line. If on the horizontal line, x2 is greater than x1, all the points are on the same scan line, and the implementation of the Bresenham routine is not needed. In this case the greatest value of x, x2, is stored as x max. If x2 is less than x1, the line lies in either octant III, IV, V, VI and the smallest value of x, x1, is stored as x min 106. In other words, the octant of each one of the lines of the polygon is determined and the lines of the polygon are traversed sequentially while conceptually stepping repetitively from a previous scan line to a next scan line during said sequential traverse. If the current line is in octant I, a last selectable pel on the previous scan line is selected after stepping from the previous scan line to the next scan line, and the last selectable pel on the next scan line is selected if the next scan line is a last scan line. If the line is in octant V, the last selectable pel on the previous scan line is selected after stepping from the previous scan line to the next scan line while the last selectable pel on the next scan line is selected if the next scan line is a last scan line. If the line is in octant II or octant III or octant VI or octant VII, the selectable pel on said next scan line is selected. If the line is in octant IV or octant VIII, the first selectable pel on the next scan line is selected after stepping from the previous scan line to the next scan line. Which octant the line 121-124 lies in is calculated. The logic branches out depending on whether x1 or x2 is greater, whether y1 or y2 is greater, and the relative signs of the slopes. Depending on these three variables, there are eight different cases. The octant that the line will be drawn in is then set up, along with the Bresenham constants "a" and "b". The "a" and "b" constants are used to generate three more Bresenham constants called "bma", "b2" and "i". The bma constant 170 is equal to two times b minus a. The b2 constant 171 is equal to two times b. The i constant 172 is the error constant which is equal to 2 times b minus a minus x2 less than x1. The term x2 less than x1 forces the rounding to be correct so that the same points are selected regardless of the direction the polygon is traversed. An example of this is shown in Fig. 10. Typically, if a Bresenham line is drawn by traversing points in one direction, the same Bresenham line will not result if the points are traversed in the opposite direction. A simple way to show this is a line 8 that has a slope equal to one half as shown in Fig. 10. If the line starts at (0,0), pel 81 and ends at (2,1), pel 84, the ideal line 80 lies directly between pels 82 and 83. The Bresenham routine is defined such that there is a rounding up. Therefore, pel 83 would be turned on instead of pel 82 if the line were in the first octant. The Bresenham line would therefore consist of pels 81, 83, 84. If this same line were drawn as if it resided in octant five, the starting point would be at 2,1 and the line would be traversed to 0,0. Going in the opposite direction, the rounding up would cause pel 82 to be selected. In order to ensure that the same line drawn in either direction comprises the same points, the rounding is always forced the same regardless of direction. The rest of the genline execution branches to cover the appropriate one of the eight different cases depending upon which octant the current one of lines 121 - 124 lies in. For example, for octant one, the line is going up as was previously defined for octants I, II, VII, VIII. Therefore, the routine is looking to store the maximum value of x for each y. The first point 141, (Fig. 7) is excluded in the loop. The loop begins with x equal to x1 plus 1. This loop is performed for x less than or equal to x2. If the error coefficient is less than zero, this means that the value was not great enough to move to the next scan line. The constant b2 is added to i and the loop is done again. If i is equal or greater than zero, this means that the half way point is exceeded and the next scan line is accessed. In that case, the previous value (x minus 1) 42, 44, 46, etc. on the previous scan line is saved in the table as x max 107 for the previous value of y. In this way there is stored the last maximum value 42, 44, 46 of each scan line 132. In the other four octants, a minimum value is sought. In octants I, IV, V and VIII, x is indexed and y is indexed in the other quadrants. There are also some special cases when the end of a scan line 132 is reached and no values have been stored yet. In this case, the last x value (as represented by x minus one since the for loop has already incremented x) for that scan line is stored. All of the other cases also store the last pel from the previous scan line. For each line 121 - 124 of the polygon 120, the genline routine is called. The part of the routine that is implemented is dependent upon which octant the line resides. The routine only stores one pel location 130 for each scan line 132 for each line 121- 24 of the polygon 120. This minimises the number of store operations that have to be performed. Since the polygon is strictly convex, there will be exactly one minimum 106 and maximum 107 value stored for each scan line 132. The main driver program calls to the first fast fill routine, gsff which, in turn, if permitted, calls genline. If the gsff pretest fails, the break to the driver results in a call to the second fast fill routine, gsff2. If the pretest conditions of gsff2 are met, it calls its own genline, genline2. The second fast fill routine, gsff2, also checks to see if the particular polygon is within the range of polygons suitable for the second polygon fill routine. This test is simpler than the test for the first polygon fill routine since the test for the second polygon fill routine only contains the once around in the y direction test. As long as the y values 102 of a particular polygon only increase, and then decrease, assuming a start at the lowest point thereof, the polygon can be filled by this second fast fill routine. Starting anywhere on the closed polygon, the algebraic sign of y2-y1 is checked to see whether it changes either 2 or 3 times. This gives the condition of "y-convexity". That is, for any value of y 102, there is one and only one continuous fill line 133, Fig 8A, 8B, 8C. Horizontal lines are considered to have the same sign as the previous line. Also, the maximum and minimum y values are recorded at the same time. If the polygon fails the gsff2 pretest, the the break is to the driver which calls the standard GSL polygon fill routine instead of genline2. Referring to Fig. 11A for this once around test, and starting with vertex P and proceeding in the clockwise direction 25, the change in the delta y sign is recorded. Proceeding from vertex P to vertex Q, delta y is positive. Proceeding from vertex Q to vertex R, delta y is negative. Proceeding from vertex R to vertex S, delta y is negative. Proceeding from vertex S to vertex T, delta y is negative. Proceeding from vertex T to vertex U, delta y is positive. Proceeding from vertex U to vertex P, delta y is positive. Analysing the changes in the change, delta y changed signs three times. If a polygon meets the once around test, the number of different sign changes will be exactly either two or three times. Taking this same polygon 61 as in Fig. 11A, if the polygon 61 were traversed beginning at vertex T in a clockwise direction 25, the count of the sign changes would be two. From vertex T to vertex Q, all delta y's are positive, and from vertex Q to vertex T in the clockwise direction 25, all delta y's are negative. If the count of each group of delta y change in sign is greater than three, then the polygon fails the once around test as shown in Fig. 11B. The polygon 62 shown in Fig. 11B shows four different changes in signs of delta y as the polygon 62 is traversed clockwise starting with vertex V. The polygon 62 shown in Fig. 11B illustrates a polygon that could not be filled with this second polygon fill routine 80. This polygon 62 could not be filled with just one scan line 134, 135 as illustrated between point 5 and point 6. Although both point 5 and point 6 have the same y value 102, two different lines 134, 135 are needed to fill the polygon 62. The second fast fill routine could be modified to fill polygons having the characteristics of the polygon 62 in Fig. 11B, but the routine would become more complex. For example, the routine could be expanded by having two sets of minimum and maximums, and initialising these values. However, the routine becomes more complex and the generality of the routine is lost. The polygon 63 shown in Fig. 11C is not strictly convex, but this polygon 63 still fits in with the second polygon fill routine 80. This polygon 63 is concave in the x direction. However, this polygon 63 meets this once around test. By traversing the polygon 63 clockwise 25 starting with vertex J, the delta y is positive from vertex J to vertex K. The delta y sign is negative from vertex K to vertex L and vertex L to vertex M. The delta y sign is then positive from vertex M to vertex J. No matter what the starting position, there will either be two or three changes in the sign of delta y. This polygon can be filled by a unique y scan line 132 for each y value 102. If the once around condition is met, gsff2 calls genline2, as already stated. Genline2 is similar to genline1. However, instead of storing the last point on the scan line 132, it stores the first and last points on a scan line 132. The slope is computed as in genline1. The same octant logic is followed as in genline1 and the Bresenham routine is initialised in the same way. The same for loop from x equal x plus one to x less than or equal to x2, or the counterpart y loop depending on the quadrant, is performed. The only difference is that now both minimum and maximum values are selected. If i is less than zero, this means that nothing is changing. When i equals i plus b minus a, at table plus one, the previous maximum value of x is stored. Immediately, the table is moved up one and the present value of x which is on the new scan line is also stored. For any scan line, the fill line is drawn from the least minimum value to the greatest maximum value of the values which are stored in the two arrays. Execution of genline2, begins at the point where y has the minimum value 1. For each line 121 - 124, the minimum and maximum value on each scan line 132 is saved in two tables 111, 112, Fig. 6. Each table 111, 112 has two entries 116, 118 for each y value 103. For lines 121, 122 between ymin 1 and ymax 2, in a counter clockwise direction 26, entries are made in a second table 112. For lines 123, 124 between ymax 2 and ymin 1, in a counter clockwise direction 26, entries are made in a first table 111. Traversing up the polygon 120, table B 112 is used, and traversing down the polygon 120, table A 111 is used. There are more stores and processing in this routine than is required by the first fast fill routine. This makes the second fast fill routine slower than the first. However, the advantage is that it can fill a larger class of polygons Fig. 1A, 1B, 3A, 3B, 8A, 8B, 8C, 11A, 11B, 11C. However, it is still appreciably faster i.e, it takes less processing time, than the general polygon fill routine. After filling the tables 111, 112 and before a multiline draw routine is called to draw one horizontal line 142 per y 102 in the range ymin 1 to y max 2, the two tables 111, 112 are combined into one table. The combining consists of finding the minimum of two minimums and the maximum of two maximums for each scan line 132. Alternatively, the multiline routine could be written that takes a pointer to both tables 111, 112 and create the min and max for each scan line as it proceeds. Traversing up the polygon 120, both values of the first pel 41, 43, 45 and last pels 42, 44, 46 on each scan line 132 respectively are stored. When this is completed the B array 112 is filled with both minimum and maximum values of x for each scan line 132. Traversing down the polygon 120, the minimum and maximum values of x for each scan line 132 are stored in the A array 111. Because of the convexity requirement, there is exactly one line on the way up, and one line on the way down. As a final post process, either pointers to both arrays are sent off to the display, or a post processor determines the least minimum value and the greatest maximum value for each scan line which is then sent off to the display. It is pointed out that the x and y directions adopted for the foregoing description are purely conventional and the described approach can be adapted to accommodate any display that operates by having scan lines in the y direction instead of the x direction.

Claims: A method of polygon filling in a by-line, pel driven data processing output in which a polygon to be filled is defined by a multiple line boundary which can be defined by a plurality of selectable pels per scan line, characterized in a general polygon fill routine being used unless a once around test performed on the vertices of the polygon, defined by the sign of the difference between ordinates transverse to the scan line direction of successive vertices of the polygon changing sign exactly two or three times in one circuit of the polygon, is satisfied, in which case a faster fill routine is used, possibly with other tests having to be additionally satisfied. A method as claimed in claim 1, wherein there are two possible alternative faster fill routines, the slower of which is dependent on the once round test only, the other being dependent on an additional test, the polygon being filled by the fastest fill routine permitted by the tests. A method as claimed in claim 2, wherein the tests are embedded in the routines and the fastest fill routine is attempted until either test fails, whereat it is exited to the next slower routine, and if the test thereof fails, it is exited to the general fill routine. A method as claimed in claim 2 or claim 3, wherein the additional test is a conventional turning test determining that the angles subtended by adjacent boundary lines of the polygon have the same sign, the fastest fill routine traversing each boundary line in turn and compiling a single table of maximum and minimum ordinate pairs for selectable pels for each of the scan lines traversing the polygon and, thereafter, using the table to switch the pels defined by such ordinate pairs together with all intervening pels. A method as claimed in any of claims 2 to 4, wherein the slower fast fill routine compiles two tables of maximum and minimum ordinate pairs for the selectable pels of the respective ends of the scan lines traversing the polygon and, thereafter, using the combination of the two tables to determine the absolute maximum and minimum ordinate pairs for each scan line and to switch the pels defined by such ordinate pairs together with all intervening pels. A method as claimed in either claim 5 or claim 6, wherein the table/tables is/are compiled whilst traversing the boundary lines of the polygon sequentially. A method as claimed in claim 6, wherein the maximum/minimum selection logic is dependent on the octant of the boundary line being traversed - the octants being referenced I through VIII, anticlockwise, with the scan line direction being parallel to the I/VIII - IV/V octant boundaries - and the lines of the polygon are traversed sequentially while conceptually stepping repetitively from a previous scan line to a next scan line during said sequential traverse: and. if the current line is in octant I, a last selectable pel on the previous scan line is selected after stepping from the previous scan line to the next scan line, and the last selectable pel on the next scan line is selected if the next scan line is a last scan line; if the line is in octant V, the last selectable pel on the previous scan line is selected after stepping from the previous scan line to the next scan line while the last selectable pel on the next scan line is selected if the next scan line is a last scan line; if the line is in octant II or octant III or octant VI or octant VII, the selectable pel on said next scan line is selected; and if the line is in octant IV or octant VIII, the first selectable pel on the next scan line is selected after stepping from the previous scan line to the next scan line.

Inventors: BEAUREGARD GARY MICHAEL, LOUCKS LARRY KEITH, NGUYEN KHOA DANG, URQUHART ROBERT JOHN, BEAUREGARD, GARY MICHAEL, LOUCKS, LARRY KEITH, NGUYEN, KHOA DANG, URQUHART, ROBERT JOHN
Applicants: IBM, INTERNATIONAL BUSINESS MACHINES CORPORATION
Application year: 1988
Main classification: G06F15
IPC codes: G06T11