where : ibrtses delphi

Delphi - grassfire fill without canvas

disclaimer

the source code of this page may not appear correctly in certain browsers
due to special characters. Have a look at the source of this HTML page
with notepad instead

When filling a region with the floodfill algorithm, it 
may be a disadvantage when the algorithm runs into a 
corner and fills from there. This algorithm grows the
area from the center. The datastructures are assumed as 
in the floodfill

The recursive process is controlled by pixel lists(stacks)
There is a list of pixels being processed and another list
containing the pixels to be checked in the next round.


procedure GrassfireFill(var image,FResult:MyField; startx,starty:integer);
var processlist,nextlist:pixellist;
  cp:pixel;
 

procedure gf(a,b:integer);
begin
 if (FResult[a,b]=0)and(test(image[a,b])) then begin   // valid pixel
   FResult[a,b]:=1;	// set the pixel as used
   if inside(a-1,b-1) then nextlist.push(a-1,b-1);
   if inside(a-1,b)   then nextlist.push(a-1,b);
   if inside(a-1,b+1) then nextlist.push(a-1,b+1);
   if inside(a,b-1)   then nextlist.push(a,b-1);
   if inside(a,b+1)   then nextlist.push(a,b+1);
   if inside(a+1,b-1) then nextlist.push(a+1,b-1);
   if inside(a+1,b)   then nextlist.push(a+1,b);
   if inside(a+1,b+1) then nextlist.push(a+1,b+1);
  end
 else FResult[a,b]:=-1;
end;  // local proc gf


begin
 Fresult.clear;                    // set the result field to zero
 processlist.push(startx,starty);  // start with give pixel
 repeat
  nextlist.clear;                  
  cp:=processlist.pop;             // loop over all pixels in the list
  while cp < > nil do
    gf(cp.x,cp.y);                 // pushes all next pixels onto list
    cp:=processlist.pop;
  end;
  processlist:=nextlist;           // initiate new round
 until processlist=empty;
end;

findings

Though more complicated than the floodfill, some applications may require the sequence of pixels being processed





Feedback is welcome



sponsored links



Delphi
home

last updated: 23.june.99

Copyright (99,2000) Ing.Büro R.Tschaggelar