Autor Beitrag
Squall_Titus
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Fr 22.06.07 17:05 
Hi

Ich habe ein Programm zum Füllen von geschlossenen Bereichen.
Leider kommt es beim Füllen von großen Bereichen zu einem Stack-Überlauf.

In den Projektoptionen steht schon

Min. $00004000
Max. $01000000 <-- Geht komischerweise nicht höher, er meckert muß zwischen 65536 und 16777216 sein bin ich doch aber?
Image $01400000

Wie kann ich den Stack nochweiter vergrößern?

Hier mal der Füllalgorithmus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.fill(x,y:integer;color1:tcolor;farbfeld:farbtyp;n:integer);
var act_color : TColor; l:boolean;   i:integer;
begin
  act_color := paintbox1.canvas.pixels[x,y];
  l:=false;
  for i:=1 to n do
       if farbfeld[i]=act_color  then  l:=true;     // l wird true, falls die akt. Farbe einer der Randfarben entspricht
  if (act_color<>color1) and not   l   then      //nur, falls das nicht der Fall ist, wir mit dem rek. Füllen fortgefahren
    begin
      paintbox1.canvas.pixels[x,y]:=color1;
      fill(x+1,y  ,color1,farbfeld,n);
      fill(x  ,y+1,color1,farbfeld,n);
      fill(x-1,y  ,color1,farbfeld,n);
      fill(x  ,y-1,color1,farbfeld,n);
     end
end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 22.06.07 17:43 
Die Lösung dieses Problems liegt nicht darin, den Stack zu vergrößern, sondern den Algorithmus so anzupassen, dass er iterativ anstatt rekursiv funktioniert. Wie das geht, habe ich in einem anderen Thread einmal ausführlich beschrieben.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Squall_Titus Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Fr 22.06.07 17:51 
Hast du auch einen Link?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 22.06.07 18:39 

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 22.06.07 18:48 
user profile iconSquall_Titus hat folgendes geschrieben:
Max. $01000000 <-- Geht komischerweise nicht höher, er meckert muß zwischen 65536 und 16777216 sein bin ich doch aber?

Und was sagt der Rechner, was $1000000 für eine Hexadezimalzahl ist? 16777216(dezimal)! ;)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Squall_Titus Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Fr 22.06.07 20:29 
Ich will ja nicht kleinlich sein, aber das hätte man ja auch in die Fehlermeldung mal mit einbauen können.
Da steht nähmlich nichts von dezimal und so.


Aber andere Frage.
Kann mir mal einer sagen, wie ich diesen rekursiven Algorithmus in einen Iterativen umwandeln soll?
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 22.06.07 21:13 
Du hast einen Floodfill Algorithmus implementiert. Analyiere ihn.

Im Prinzip geht das so:
Nimm eine Liste von Pixelkoordinaten und zwei 'Zeiger' (keine Pointer, sondern Indizes). Die Zeiger heißen 'Vorne' und 'Hinten'

1. Am Anfang ist ein Pixel in der Liste. Vorne = 0 und Hinten = 0
2. Nimm den nächsten Pixel von Vorne und erhöhe Vorne um 1.
3. Wenn der Pixel noch nicht befüllt ist, dann
3.1 Fülle den Pixel in der Zielfarbe.
3.2 Jeder der vier Nachbarn, die noch nicht der Zielfarbe entsprechen, wird Hinten in die Liste geschrieben
4. Wiederhole die Schritte 2 und 3, bis Vorne > Hinten.

_________________
Na denn, dann. Bis dann, denn.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 23.06.07 01:02 
user profile iconSquall_Titus hat folgendes geschrieben:
Da steht nähmlich nichts von dezimal und so.
Als Delphi-Entwickler sollte man wissen: Das $ vor einer Zahl steht für eine Hexadezimalzahl ;)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 23.06.07 11:06 
Ich liebe es, wenn man einen Link extra raussucht und dieser dann trotzdem nicht gelesen wird ...

Dort stand nämlich genau diese Erklärung wie man von Rekursiv nach Iterativ kommt auch bereits drin ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Squall_Titus Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Sa 23.06.07 12:11 
Entschuldigung BenBE hatte wirklich übersehen, dass du mir den Link schon geschickt hattest.

Ich danke allen beteiligten.