Click to See Complete Forum and Search --> : Algorithm for FillRgn


arumugajothi
March 3rd, 2003, 05:30 AM
Hi All,

I need to implement an algorithm for filling complex polygons.I've used so many algorithms but all the algorithms are doing only if the polygon doesn't overlap.but my application need is to fill the polygons that may be completely inside other polygons. so i need a algorithm which fills the polygons with Xor mode. accuracy is much more important(ie double precision). user should not be able to see any cracks within the filled polygons. we can implement that using the following win32 APIS
CRgn Target;
Target.CreatePolyPolygonRgn( m_p2DPointBuffer, 1, iCount, ALTERNATE );

//fill the resultant region
HBRUSH hbr, holdbr;
int iOldROP = 0;
hbr=CreateSolidBrush(RGB(0,0,0));
holdbr=(HBRUSH)SelectObject(m_hDC, hbr);

iOldROP = SetROP2(m_hDC, R2_NOTXORPEN);
FillRgn(m_hDC, HRGN(Target),hbr);
SetROP2(m_pDwgFile->m_hDC, iOldROP);

hbr=(HBRUSH)SelectObject(m_hDC, holdbr);
DeleteObject(hbr);
Target.DeleteObject())

If any of u have the polygon algorithm to give the output same as the above code or if u have any other links for this algorithm please do tell me.
Best regards
Jothi

lord loh
March 12th, 2003, 11:10 PM
I dont know C /c++

But just a suggestion....

try drawing the overlaping polygons in different layers...

So when you fill one polygon completely...It also fills inside the other polygon....(appears to fill)

Then merge these layers (appear to merge on the screen)...

Any problems with this ?

arumugajothi
March 13th, 2003, 09:57 PM
Hi Lard Loh,

Thank you for your suggestion. The problem is accuracy. i've implented an algorithm for filling polygons in XOR Mode. but due to round off of minute floating values i am experiencing some cracks within filled polygons.I've tried so many algorithms but nothing helps. so i am searching for an algorithm which effectively fills complex polygons without cracks.

Thanks a lot
Waiting for responses
Jothi

lord loh
March 18th, 2003, 11:39 PM
Are you sure there are cracks ?

Could it not be a problem due to display resolution ?

If you try to draw a filled circle in LOGO, will find cracks but it is only due to low resolution problem....

Try the same algorithm on a different resolution...

And do tell me your results and comments....

Hope this helps....

arumugajothi
March 19th, 2003, 02:22 AM
Yes u are right the cracks are not there if the user zooms the view. but the cracks are there in the normal view. i've attached a crack.bmp contains filled font. here each letter is the complex polygons.

i will explain u in detail about the problem.
Input to my algorithm is the array of Points(line segments) with double precision. i am filling the polygons using these line segments. code is as follows. Please give any suggestions for not getting the crack in the normal view too.

//sort
SortScanedData(MinY,MaxY);
//fill
for(int y =MinY ; y<=MaxY ; y++)
{
for( int j = 0; j<m_pScanLineList[y].HitCount-1 ; j=j+2)
{
x1 = m_pScanLineList[y].HitXArr[j];
x2 = m_pScanLineList[y].HitXArr[j+1];

int iColor = m_nCurrentColor;
if(x1 < x2 )
{

int istart = m_pPreCalc[ y + m_nClipMinY ] + x1;
int iend = istart + (x2 - x1) + 1;
for(int i = istart; i < iend; i++)
{
//XOR Mode filling
if(m_pBits[i] == m_nCurrentColor)
iColor = m_nPrevColor; else
iColor = m_nCurrentColor;
m_pBits[i] = (BYTE)iColor;
}
memset(&m_pBits[iend - 1], m_nCurrentColor, 1);
}
}
}

Thanks in advance.