基于洪水法的任意多边形的选取

 这几天研究多边形的选取,终于把代码意义搞清楚了。写在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;
     }
    }
   }
  }
 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值