int prevV; // prev. vertical direction
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHII
void appendBPList ( int x, int y, int flag ) {
bp [bpEnd ].x - x; bp [bpEnd ].y = y; bp [bpEnd++].flag = flag;
}
void sarneDirection () {
if ( prevD == 0 ) // moving right
bp [bpEnd-1].flag = BLOCKED ;// block previous pixel
else
if ( prevD != 4 ) // if not moving horizontally
appendBPList ( currentPixel.x, currentPixel.y, UNBLOCKED);
}
void differentDirection ( int d )
Растровые алгоритм

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

{
if ( prevD == 4 ) // previously moving left {
if ( prevV == 5 )//if from above block rightmost in line bp [bpEnd-1].flag = BLOCKED;
appendBPList ( currentPixel.x, currentPixel.y, BLOCKED);
}
else
if ( prevD == 0 ) // previously moving right { // block rightmost in line
bp [bpEnd-1].flag = BLOCKED;
if ( d == 7 ) // if line started from above
appendBPList (currentPixel.x, currentPixel.y, BLOCKED);
else
appendBPList ( currentPixel.x, currentPixel.y, UNBLOCKED);
}
else // prev. moving in some
{ // vert. dir.
appendBPList ( currentPixel.x, currentPixel.y, UNBLOCKED);
// add pixel twice if local min or max if ((( d >= 1 ) && ( d <= 3 )) &&
(( prevD >= 5 ) && ( prevD <= 7 )) || (( d >= 5 ) && ( d <= 7 )) && (( prevD >= 1 ) && ( prevD <= 3 )))
AppendBPList ( currentPixel.x, currentPixel.y, UNBLOCKED);
}
}
addBPList (int d ) {
if ( d == prevD ) sameDirection ();
else {
differentDirection (d);
prevV = prevD; // new previous vertical direction
}
prevD = d; // new previous search direction
}
void nextXY (int& x, int& y, int direction ) {
switch ( direction ) //321 { //4 0
case 1: //567 case 2: case 3:
y~; // go up break;
case 5: case 6:

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

case 7:
y++; // go down break;
}
switch ( direction ) {
case 3: case 4: case 5:
x~; // go left
break;
case 1 : case 0: case 7:
x++; // go right
break;
}
}
int findBP ( int d ) {
int x = currentPixel.x; int y = currentPixel.y;

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