 # Filling Algorithms Linting Contents What is filling algorithms

• Slides: 20  Contents • What is filling algorithms • Different filling algorithms • The advantages and disadvantages of different filling algorithms 2 What is filling algorithms Filling algorithm is a kind of classification of computer algorithm, which is a process of filling pixel in irregular area into filling color. It is widely used in computer aided design, image processing and other fields. It includes filling region algorithm, seed filling algorithm, scan line filling algorithm, edge filling algorithm and so on. 3 Different filling algorithms • Scan line filling algorithm • Seed filling algorithm • Scanning line seed filling algorithm • Cyclic scan line seed filling algorithm 4 Scan line filling algorithm First, let's talk about the data structure used in this algorithm: edge table NET+ active edge table AET. In principle, the active edge table AET is filled according to the active edge table AET, but the update of the active edge table AET is based on the edge table NET. So what exactly is stored in NET? This NET stores the information of the intersection of polygon vertices and scanlines: 5 Scan line filling algorithm The number of each header represents the value of the scan line on the Y-axis Record all the edges of the polygon except the horizontal edge in the table without scan lines. The format of the record is: x: the coordinates of the intersection of the current scan line and the edge; dx: the increment of x between the current scan line and the next scan line ((x 2 -x 1)/(y 2 -y 1)); ymax: the highest scan line that this edge intersects 6 Scan line filling algorithm Example: 7 Seed filling algorithm Example: 8 Scanning line seed filling algorithm The scan line seed filling algorithm no longer processes the adjacent points of "4 -unicom" and "8 -unicom" in a recursive way, but processes the adjacent points of "4 -unicom" and "8 -unicom" by filling pixel segments along the horizontal scan line one by one. In this way, the algorithm only needs to push the starting point position of each horizontal pixel segment into a special stack, but does not need to push all the adjacent points around the current position into the stack like the recursive algorithm, thus saving stack space. 9 Scanning line seed filling algorithm The scanning line seed filling algorithm can be implemented by the following four steps: (1) Initialize an empty stack for storing seed points, and push the seed points (x, y) into the stack; (2) Judge whether the stack is empty, and end the algorithm if the stack is empty; otherwise, take the top element of the stack as the seed point of the current scanning line (x, y), and y is the current scanning line; (3) Start from the seed point (x, y) and fill it along the left and right directions of the current scanning line to the boundary. The left and right endpoint coordinates of the marked section are x. Left and x. Right respectively; (4)Respectively, check with the current scan line adjacent two scan lines and y y - 1 + 1 pixel in the interval [x. Left x. Right] since x. Left x. Right direction search, if there is not border and not fill pixels, then find out the adjacent pixel point the right one, and use it as a seed point pressure into the stack, and then return to step (2); 10 Scanning line seed filling algorithm 11 Cyclic scan line seed filling algorithm l Adopt Morton coding, there is only a unique code for each seed point, to avoid repeated entry of one point. l The improved algorithm adopts the method of circular scanning line to scan and fill clockwise or counterclockwise to avoid multiple entries and exits of the stack at the same point. 12 Conversion of row and column values to Morton code Because the rows and columns are unique, they are unique when combined. 13 Cyclic scan line seed filling algorithm l Start from the given seed filling embryo, spread and fill by clockwise or counterclockwise circular scanning, and push the filling embryo and boundary Morton code onto the stack. l The newly obtained filling embryos were successively removed from the stack, and the circular scanning diffusion and filling were carried out according to the method in the first step, so as to ensure that they are not repeated with the Morton code in the stack. l Put the row and column values of the new filled embryos generated by each annular scan cycle into the stack, keep only the filled embryos generated by the last two consecutive cycles, and delete all the previous filled embryos. l When the stack is non-empty, go to step 1, otherwise the algorithm ends. 14 Cyclic scan line seed filling algorithm 15 Cyclic scan line seed filling algorithm 16 The advantages and disadvantages of different filling algorithms Algorithm Advantages Disadvantages Scan line filling algorithm Rasterize contour can be avoided Low efficiency Seed Filling Easy Need a lot of stack space Low efficiency Scanning line seed filling algorithm Less stack space Low efficiency Cyclic scan line seed filling algorithm Less stack space but more than Scanning line seed filling algorithm Difficult to achieve 17  References 1、https: //blog. csdn. net/gongfuxiaozi 11/article/details/17248437 2、https: //blog. csdn. net/keneyr/article/details/83747501 3、https: //blog. csdn. net/weixin_34279184/article/details/85689045 4、https: //blog. csdn. net/keneyr/article/details/83753585 5、https: //blog. csdn. net/cd 1202/article/details/72887726 19 