//××下面要进行的是扫描线种子填充的函数
void S1GraphDbx::seedline(CPoint p,CDC *pDC)
{
//求多边形的最大最小值
int index=m_dbx.size();
int i;
COLORREF fill=RGB(255,0,0);
COLORREF boundary=RGB(0,0,0);
for (i=0;i
{
if (m_dbx.at(i).isSelect==1)
{
CPoint seed, newSeed;
int xLeft, xRight, x, y; //[xLeft, xRight]表示扫描线的区段,x,y表示当前的像素点左边
int needFill = FALSE;
my_Stackst;//自定义的栈
seed.x = p.x; //种子坐标
seed.y = p.y;
// 种子入栈
st.Add(seed);
while ( !st.IsEmpty() ) //栈非空
{
//* 种子出栈并给点上色
seed=st.Top();
st.Delete();
pDC->SetPixel(seed.x,seed.y,fill);
//* 填充当前扫描线位于种子左边的部分
x = seed.x - 1;
y = seed.y;
while ( pDC->GetPixel(x,y) != fill &&
pDC->GetPixel(x,y) != boundary )
{
pDC->SetPixel(x,y,fill);
x -= 1;
}
//* 记录最左侧的内点
xLeft = x + 1;
//* 填充当前扫描线位于种子右边的部分
x = seed.x + 1;
y = seed.y;
while ( pDC->GetPixel(x,y) != fill &&
pDC->GetPixel(x,y) != boundary )
{
pDC->SetPixel(x,y,fill);
x += 1;
}
///* 记录最右侧的内点
xRight = x - 1;
///* 上移一条扫描线
y = seed.y - 1;
x = xLeft;
//* 从左向右检测非边界、未填充的象素
while ( x
{
while ( pDC->GetPixel(x,y) != fill &&
pDC->GetPixel(x,y) != boundary )
{
///* 存在未填充的像素,则需要填充
needFill = TRUE;
x += 1;
}
//* 最右侧像素入栈
if ( needFill == TRUE )
{
newSeed.x = x - 1;
newSeed.y = y;
st.Add(newSeed);
needFill = FALSE;
break;
}
x++;
}
needFill = FALSE;
///* 下移一条扫描线
y = seed.y + 1;
x = xLeft;
/* 从左向右检测非边界、未填充的象素
while ( x
{
while ( pDC->GetPixel(x,y) != fill &&
pDC->GetPixel(x,y) != boundary )
{
* 存在未填充的像素,则需要填充
needFill = TRUE;
x += 1;
}
/* 最右侧像素入栈
if ( needFill == TRUE )
{
newSeed.x = x - 1;
newSeed.y = y;
st.Add(newSeed);
needFill = FALSE;
break;
}
x++;
}
}
}
}
}