};
static AETEntry aet [20]; // active edge table static int aetCount; // # of items in AET static int cr [20]; // list of critical points
static int crCount; // # of critical points
static int findEdge (int& j, int dir, int n, Point p Q ) {
for(;;) {
int j1 = j + dir;
if(jKO)
j1 = n -1; else
if(j1>=n) j1 =0;

ЧрОЯу<рО]У) //edgejjl is return -1; // going upwards

else

if (p Di]-y == p Ш-у ) j = ji;

else
return j1;
>
}
void addEdge (int j, int j 1. int dir, Point p [])

Компьютерная графика. Полигональные модели

AETEntry tmp;
tmp.from = j; tmp.to =j1;
tmp.x = int2Fixed (p [j].x);
tmp.dx = int2Fixed (p |]1].x-p 0]x)/(p \}1].y-p fl].y);
tmp.dir = dir;
for ( int i = 0; i < aetCount; i++ ) // use x + dr for edges going
// from the same point if ( tmp.x + tmp.dx .< aet [i].x + aet [i].dx ) break;
// insert tmp at position i memmove ( &aet [i+1], &aet [i], (aetCount - i) * sizeof (AETEntry ) );
aet [i] = tmp; aetCount++;
}
void buildCR ( int n, Point p [] ) {
int candidate = 0; crCount = 0;
// find all critical points for ( int i = 0, j = 1 ; i < n; i++, j++ )
{
if ( j >= n ) // check for overflow j = 0; 
if ( P [i]-y > P D]-y ) -candidate = 1 ;
else
if ( p [i].y < p [j].y && candidate ) {
candidate = 0; cr [crCount++] = i;
}
}
if ( candidate && p [0].y < p [1].y ) cr [crCount++] = 0;
// now sort critical points for ( i = 0; i < crCount; i++ )
for ( int j = i + 1 ; j < crCount; j++ ) if (p[cr [i]].y>p[cr 0]].y) { // swap cr [i] and cr [j] int tmp = cr [i];
cr [i] = cr 0]; cr [j] = tmp;
}
}
void fillPoly ( int n, Point p [] ) {
int yMin = p [0].y;

6. Растровые алгоритмы

int yMax = p [0].y; int k =0;
for (int i = 1; i < n; i++ ) if ( p [i].y < vMin ) yMin = p [i].y;
else
if (p [i].y > yMax ) yMax = p p].y;
buildCR ( n, p );
aetCount = 0;
for (int s = yMin; s <=* yMax; s++) {
for (; k < crCount s == p [cr [k]].y; k++ ) {
int j = cr [k];
int j1 = findEdge (j, -1, n, p );
addEdge(j,j1,-1,p);
j =cr[k];

⇐ Предыдущая| |Следующая ⇒