nextXY ( x, y, d ); // get x,y of pixel in direction d
if ( getpixel ( x, y ) == borderColor ) {
addBPList ( d ); // add pixel x,y to the table currentPixel.x = x; // pixel at x,y becomes currentPixel.y = y; // current pixel
return TRUE;
}
return FALSE;
}
int findNextPixel () {
for ( int i = -1; i <= 5; i++ ) { // find next border pixel
int flag = findBP ( ( D + i ) & 7 );
if ( flag ) // flag is TRUE if found
{
D = ( D + i ) & 6; // (D+i) MOD 2 return flag;
}
}
}
int scanRight ( int x, int y ) {
while ( getpixel ( x, y ) != borderColor )
if ( ++x == 639 ) break;
return x;
}
void scanRegion (int& x, int& y ) {
for (int i = bpStart; i < bpEnd;) { // skip pixel if blocked
if ( bp [i].flag == BLOCKED )
else // skip last pixel in line
if (bp [i].y!= bp p+1].y) i++;
else
{ // if at least one pixel
// to fill then scan the line if (bp [i].x<bp [i+1].x-1 ) {
int xr = scanRight ( bp [i].x + 1, bp [i].y );
if (xr<bp[i+1].x) {
x = xr;
y = bp [i].y;
break;
}
}
i += 2;
}
}
bpStart = i;
}
int compareBP ( BPStruct * arg1, BPStruct * arg2 ) {
int i = arg1 -> y - arg2 -> y;
if (i != 0 ) return i;
if ((i = arg1 -> x - arg2 -> x ) != 0 ) return i;
return arg1 -> flag - arg2 -> flag;
}
void sortBP () {
qsort ( bp + bpStart, bpEnd - bpStart, sizeof ( BPStruct), (int (*)(const void *, const void *)) compareBP );
}
void fillRegion () {

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

for (int i = 0; i < bpEnd; ) {
if ( bp [i].flag == BLOCKED ) // skip pixel i++; // if blocked
else
if ( bp [i].y != bp [i+1].y ) // skip pixel
i++; // if last in line
else // if at least one pixel to fill
{ // draw a line
if (bp [i].x<bp [i+1].x- 1 )
line ( bp [i].x + 1, bp [ij.y, bp [i+1].x -1, bp [i+1].y );
i += 2;
}
}
}
void traceBorder (int startX, int startY ) {
int nextFound; int done;
currentPixel.x = startX; currentPixel.y = startY;
D = 6; // current search direction
prevD = 8; // previous search direction
prevV = 2; // most recent vertical direction

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