Four, boundary sign filling algorithm
In the raster display plane, the polygon is closed, it is a closed area surrounded by a certain boundary color, the filling is carried out by line, that is, the polygon is intersecting with the scan line, and is filled between the intersection pairs. The boundary flag filling algorithm is used to fill the boundary or boundary color as a symbol when the line-by-row processing. To be exact, the boundary sign filling algorithm does not refer to a specific filling algorithm, but a generic term for a class of filling algorithms that use the idea of scanning line coherence. This kind of algorithm has many kinds, this article introduces several.
In this paper, we introduce an edge filling algorithm with edge as the center, the basic idea of this algorithm is: For each scan line and the intersection of each polygon edge (xi,yi), the scan line to the right of the intersection of all pixels to fill, in turn, each side of the polygon to do this processing, until the final completion of the fill. Here to introduce the definition of the complement, assuming that the color of a point is M, then to the point of the color of the M ' = A–m,a is a very large number, at least more than all the legal color value. According to the definition of the complement, if the color value of the grating bitmap has been marked m as an even number of times, the color of the region is unchanged, and the color of the region is changed to M because of the odd number of times. The algorithm can be described briefly as two steps:
1. Set the background color of the drawing window to M ' color;
2, to the polygon of each non horizontal edge, from the edge of each pixel start to the right balance;
The algorithm is processed as shown in figure (12), and the left side is the shape of the polygon, the right is the processing of each edge of the fill area after the color situation, the original background color is M ', after processing, need to fill the area is odd several times to fill, the final color is to fill the correct value m, the unfilled area after even several times to fill, Still the background color m ':
Figure (12) The process of edge filling algorithm
The implementation of the algorithm is very simple, for the display of raster bitmap, we still use the method used in the previous text, using a digital matrix to represent a raster bitmap region, each position of the matrix represents a pixel point, with 0-9 for the color value. This algorithm example uses 9 to indicate that the maximum value a,0 represents an invalid region, and the legal color value is 1-8.
Edgecentermarkfill void (const polygon& py, int color) std::vector<edge3> et; initscanlineedgestable (ET, py);//Initialization side table fillbackground (a-color);//fill the background color of the entire filled area For_each (Et.begin (), Et.end (), Edgescanmarkcolor), and/or process each side of the margin
} a
void Edgescanmarkcolor (edge3& e) (int y = E.ymax y >= e.ymin y--) is { int x = Round_int (E.XI);
Bayi complementscanlinecolor (x, Max_x_cord, y);
e.xi- = E.DX;
85}