这几天研究多边形的选取,终于把代码意义搞清楚了。写在BLOG上留个纪念,以后自己可以查阅。。:)
for (int side=0; side<4; side++){ //画4条线,4个点的坐标分别是(Xmin,Ymin)等等
switch(side){
case 0:
xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.bottom+1;
break;
case 1:
xmin=localbox.right; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.top+1;
break;
case 2:
xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.top; ymax=localbox.top+1;
break;
case 3:
xmin=localbox.left; xmax=localbox.left+1; ymin=localbox.bottom; ymax=localbox.top+1;
break;
}
//fill from the border points //按行,按区域检测
for(y=ymin;y<ymax;y++){
for(x=xmin;x<xmax;x++){
if (plocal[x+y*head.biWidth]==0){
// Subject: FLOOD FILL ROUTINE Date: 12-23-97 (00:57)
// Author: Petter Holmberg Code: QB, QBasic, PDS
// Origin: petter.holmberg@usa.net Packet: GRAPHICS.ABC
first=0; //头指针表示检测的基点
last=1; //尾指针指向最后一个检测点
while(first!=last){
fx = pix[first].x;
fy = pix[first].y;
fxx = fx + x; //相对位移
fyy = fy + y;
for(;;)
{
if ((plocal[fxx + fyy*head.biWidth] == back) && //检测是否为空白
fxx>=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top )
//判断是否还在LOCALBOX中
{
plocal[fxx + fyy*head.biWidth] = mark; //如果为空白,那么设为标志1,表示已经检测过。
if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){
pix[last].x = fx; //pix数组用来存放带检测点的相对坐标,LAST和FIRST是队列的头和尾
pix[last].y = fy - 1;
last++;
if (last == npix) last = 0;
}
if ((fyy + 1)<head.biHeight && plocal[fxx + (fyy + 1)*head.biWidth] == back){
pix[last].x = fx;
pix[last].y = fy + 1;
last++;
if (last == npix) last = 0;
}
} else {
break;
}
fx++;
fxx++;
};
fx = pix[first].x - 1; //反方向检测
fy = pix[first].y;
fxx = fx + x;
fyy = fy + y;
for( ;; )
{
if ((plocal[fxx + fyy*head.biWidth] == back) &&
fxx>=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top )
{
plocal[fxx + (y + fy)*head.biWidth] = mark;
if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){
pix[last].x = fx;
pix[last].y = fy - 1;
last++;
if (last == npix) last = 0;
}
if ((fyy + 1)<head.biHeight && plocal[fxx + (fyy + 1)*head.biWidth] == back){
pix[last].x = fx;
pix[last].y = fy + 1;
last++;
if (last == npix) last = 0;
}
} else {
break;
}
fx--;
fxx--;
}
first++;
if (first == npix) first = 0;
}
}
}
}
}