Einzelnen Beitrag anzeigen

Furtbichler
(Gast)

n/a Beiträge
 
#3

AW: Iterativer FloodFill mit einem Stapelspeicher

  Alt 7. Jul 2012, 08:33
Floodfill geht doch so (peudocode):
Delphi-Quellcode:
Procedure FloodFill (Canvas : TCanvas; P : TPoint; NewColor : TColor);
Var
 q : TPoint;

begin
  Foreach Neighpor q of P do
    if not visited[q] then begin
      visited[q] := True;
      Canvas.Pixel[q.x, q.y] := NewColor;
      FloodFill(Canvas, q, NewColor);
    end
end
Eine iterative Umformung ginge so:
Delphi-Quellcode:
Procedure FloodFill (Canvas : TCanvas; P : TPoint; NewColor : TColor);
Var
  worktable: Stack of TPoint;
  Q : TPoint;

begin
  worktable.push(p):
  while not worktable.IsEmpty do begin
    q := worktable.pop;
    if not visited[q] then begin
      visited[q] := True;
      Canvas.Pixel[q.x, q.y] := NewColor;
      worktable.push(q);
    end
  end
end
  Mit Zitat antworten Zitat