Area-Filling Algorithms What's The Point of Filling Algorithms?
Area-Filling Algorithms What's The Point of Filling Algorithms?
Lecture 8 Slide 1 6.837 Fall ’98 Lecture 8 Slide 2 6.837 Fall ’98
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1
Your winding number is the number of full revolutions that you complete.
Very fragile algorithm If you winding number is 0 then you are outside of the polygon, otherwise you are inside.
Ray crosses a vertex
Ray is coincident with an edge
Commonly used in ECAD
Suitable for H/W
A second important class of area-filling algorithms start at a point know to be inside a figure and start filling in the figure outward from the point. Using
these algorithms a graphics artist may sketch the outline of a figure and then select a color or patten from a menu with which to fill it. The actual filling
process begins when a point inside of the figure is slected. These routines are like the paint-can function seen in common interactive paint packages.
The first such method that we will discuss is called the boundary-fill algorithm. The boundary-fill method requires the coordinate of a starting point, a fill
color, and a background color as arguments.
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1
/*
find the triangle’s centroid
*/
int x = (int) ((v[0].x + v[1].x + v[2].x)/3 + 0.5);
int y = (int) ((v[0].y + v[1].y + v[2].y)/3 + 0.5);
param[2] -= edge[2].A;
Modified Boundary Fill param[3] -= alpha.A;
param[4] -= red.A;
private void fillTri(int x, int y, int param[]) {
param[5] -= green.A;
/*
param[6] -= blue.A;
pixel inside bounding box?
fillTri(x-1, y+1, param);
*/
if ((x > xMax) || (x < xMin)) return;
param[0] -= edge[0].B;
if ((y > yMax) || (y < yMin)) return;
param[1] -= edge[1].B;
param[2] -= edge[2].B;
/*
param[3] -= alpha.B;
pixel inside triangle?
param[4] -= red.B;
*/
param[5] -= green.B;
if ((param[0]|param[1]|param[2]) < 0) return;
param[6] -= blue.B;
fillTri(x-1, y, param);
/*
compute fill color
param[0] -= edge[0].B;
*/
param[1] -= edge[1].B;
int pixa = (param[3] >> EdgeEqn.FRACBITS);
param[2] -= edge[2].B;
int pixr = (param[4] >> EdgeEqn.FRACBITS);
param[3] -= alpha.B;
int pixg = (param[5] >> EdgeEqn.FRACBITS);
param[4] -= red.B;
int pixb = (param[6] >> EdgeEqn.FRACBITS);
param[5] -= green.B;
pixa = ((pixa & ~255) == 0) ? pixa << 24 : ((pixa < 0) ? 0 : 255
param[6] -= blue.B;
param[0] -= edge[0].A;
fillTri(x-1, y-1, param);
param[1] -= edge[1].A;
param[2] -= edge[2].A;
param[0] += edge[0].A;
param[3] -= alpha.A;
param[1] += edge[1].A;
param[4] -= red.A;
param[2] += edge[2].A;
param[5] -= green.A;
param[3] += alpha.A;
param[6] -= blue.A;
param[4] += red.A;
fillTri(x, y+1, param);
param[5] += green.A;
param[6] += blue.A;
param[0] -= edge[0].A;
fillTri(x, y-1, param);
param[1] -= edge[1].A;
file://localhost/E:/6.837/GRAPHICS.LCS.MIT.EDU/CLASSES/6.837/F98/LECTURE8/SLIDE21.HTML 05:36:08 10/10/98 file://localhost/E:/6.837/GRAPHICS.LCS.MIT.EDU/CLASSES/6.837/F98/LECTURE8/SLIDE21.HTML 05:36:08 10/10/98
/*
fix it up back to the way we found it (Why?)
*/
param[0] += edge[0].B - edge[0].A;
param[1] += edge[1].B - edge[1].A;
param[2] += edge[2].B - edge[2].A;
param[3] += alpha.B - alpha.A;
param[4] += red.B - red.A;
param[5] += green.B - green.A;
param[6] += blue.B - blue.A;
}
}
Lecture 8 Slide 21 6.837 Fall ’98
The rounded coordinates of a triangle’s centroid are not necessarily inside of the triangle!
Solutions?
Redefine what it means to be inside of a triangle
Different routines for nasty little triangles
Lecture 8 Slide 24 6.837 Fall ’98
Lecture 8 --- 6.837 Fall ’98 Page 1 Lecture 8 --- 6.837 Fall ’98 Page 1