I have devised a new Flood Filling Algorithm but it seems to have a problem...
I have created a class Spawn ...
When a bounded Polygon is drawn on the screen, the user has to click on the interior of the Polygon. Then the following code is executed ...
This calls the constructor of the Spawn class...
What I want to do is that create an object for every point. When an object is created, based on the value of d (HORZ or VERT) it checks all the adjacent points horizontally or vertically and create objects of those points. the constructor for these points would spawn additional objects.
In order to prevent memory shortage I want to delete the object as soon as it has completed checking (left and right) or (top and bottom) neighbours.
I want each object to be independant of all the other objects in existence.
The problem with the above given code is that as soon as the parent object ejects out of the constructor code all the child objects get terminated w/o finishing their jobs. That why I added the childTerminated boolean variable. I also put an empty while loop which waits until the child objects have finished their jobs. But this loop hangs the system.
For those of u who are well familiar with Flash ActionScript programming, I want to do something similar to the duplicateMovieClip function,the movie clip having an onClipEvent(enterFrame) function. This would create movie objects which would be playing independantly.
HELP ME...
I have created a class Spawn ...
Code:
typedef enum DIR { HORZ, VERT } DIRECTION;
class Spawn
{
public:
Spawn(void);
virtual ~Spawn(void);
int x;
int y;
DIRECTION d;
Spawn(int x, int y, DIRECTION d, COLORREF oldColor, COLORREF newColor, Spawn* pParent);
Spawn* m_pParent;
bool childTerminated;
};
When a bounded Polygon is drawn on the screen, the user has to click on the interior of the Polygon. Then the following code is executed ...
Code:
Spawn* Initiator = new Spawn();
Spawn* Iterator = new Spawn(point.x, point.y, HORZ, oldColor, fillColor, Initiator);
This calls the constructor of the Spawn class...
Code:
Spawn::Spawn(int x, int y, DIRECTION d, COLORREF oldColor, COLORREF newColor, Spawn* pParent): x(x), y(y), d(d), m_pParent(pParent), childTerminated(false)
{
int mx, my;
DIRECTION next;
bool jump = false;
switch (d) {
case HORZ : mx = 1;
my = 0;
next = VERT;
break;
case VERT : mx = 0;
my = 1;
next = HORZ;
break;
}
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
CXFillView * pView = (CXFillView*)pFrame->GetActiveView();
CClientDC dc(pView); COLORREF pix = dc.GetPixel(x,y);
if ((pix != newColor) || (pix == oldColor)) {
int i,j;
dc.SetPixel(x, y, newColor);
Spawn* s;
for (i = x, j = y ; dc.GetPixel(i, j) != newColor ; i -= mx, j -= my)
s = new Spawn(i, j, next, oldColor, newColor, this);
for (i = x, j = y ; dc.GetPixel(i, j) != newColor ; i += mx, j += my)
s = new Spawn(i, j, next, oldColor, newColor,this);
while (!childTerminated);
}
m_pParent->childTerminated = true;
delete this;
}
What I want to do is that create an object for every point. When an object is created, based on the value of d (HORZ or VERT) it checks all the adjacent points horizontally or vertically and create objects of those points. the constructor for these points would spawn additional objects.
In order to prevent memory shortage I want to delete the object as soon as it has completed checking (left and right) or (top and bottom) neighbours.
I want each object to be independant of all the other objects in existence.
The problem with the above given code is that as soon as the parent object ejects out of the constructor code all the child objects get terminated w/o finishing their jobs. That why I added the childTerminated boolean variable. I also put an empty while loop which waits until the child objects have finished their jobs. But this loop hangs the system.
For those of u who are well familiar with Flash ActionScript programming, I want to do something similar to the duplicateMovieClip function,the movie clip having an onClipEvent(enterFrame) function. This would create movie objects which would be playing independantly.
HELP ME...