Hi Roger and all,
Here's the the main part of the Inverse IFS algorithm
as I've implimented it in Ultrafractal (somewhat abbreviated
and not 100% documented but the general idea should be transparent):
PER PIXEL:
bool f
int xs=round(real(#screenpixel)*@os)
int ys=round(imag(#screenpixel)*@os)
complex zz[@igen] ; @igen is the maximum depth we want to go down
the tree
complex zo[@igen]
complex fz[@igen]
complex zt
complex z2
complex sz
complex tz
float x
float y
float x1
float y1
float m
float fc=-1.0
float fc1=-1.0
float c=0.0
float c1=0.0
float s[@igen]
float mm[@igen]
float ss
float s1
float fm=2.0*@bailout ; @bailout is the tolerance test value
int fn=-1
int i[@igen]
int j
int k
int l
tz=sz=z=#pixel
if @itest==0
tz=(0,0)
endif
k=i[0]=gnt-1 ; number of transforms
j=0
m=mm[0]=@bailout
ss=1.0
repeat
k=i[j]
zo[j]=z
(Here calculate new z using transform k)
zz[j]=z
x=|tz-z|
s[j]=ss=ss*gt[k,6] ; gt[k,6] is the scale of the original contractive
transform
if (j=j+1)==@igen || ss<gs2 ; gs2 is a precalculated figure based on
the required detail
j=j-1
if x<m
; The errfix is an attempt at correcting the algorithm on some fractals
; where points get found/coloured that should not be on the fractal.
; Only works with affine systems.
if @errfix>0.0
k=j
c=0
y=0
repeat
l=i[k]
ss=c
c=c*gt[l,0]+y*gt[l,2]+gt[l,4] ; Perform full contraction
using original
y=ss*gt[l,1]+y*gt[l,3]+gt[l,5] ; contractive functions
based on found genetics
k=k-1
until k<0
endif
if @errfix==0.0 || |sz-c-flip(y)|<gc2 ; if not error checking or
within limits of error check
if @orbits
if x<fm
fm=x
k=fn=j
repeat
fz[k]=zz[k]-tz
k=k-1
until k<0
endif
else
if @colour!=3
k=(gn+@older)%(j+1)
c=0.0
l=gn
repeat
c=i[k]*gs1+c*gc1 ; gs1 and gc1 are precalculated values
so that the genetic code is packed into an Ultrafractal float with the most
important genetic code as the most significant position
if (k=k-1)<0
k=j
endif
l=l-1
until l<0
if c>fc
fc=c
fm=x
endif
endif
if @lighting>0
k=(gn+@olderl)%(j+1)
c1=0.0
l=gn
repeat
c1=i[k]*gs1+c1*gc1
if (k=k-1)<0
k=j
endif
l=l-1
until l<0
if c1>fc1
fc1=c1
fm=x
endif
endif
if @colour==3 && @lighting==0
fm=x
endif
endif
if @errfix1==1 ; errfix1 dictates at what point we accept a
found point, if 1 we take the first found
j=-1
endif
m=x
endif
endif
if j>=0
f=false ; here we check for disallowed combinations
(limited RIFS) (gf[] flags)
repeat
if (i[j]=i[j]-1)<0
if (j=j-1)<0
f=true
endif
elseif j>0
f=gf[i[j],i[j-1]+9]
else
f=true
endif
until f
if j==0
z=sz
ss=1.0
if @errfix1==2
m=mm[0]
endif
elseif j>0
z=zz[j-1]
ss=s[j-1]
if @errfix1==2
m=mm[j]
endif
endif
endif
elseif x>m
j=j-1 ; again check for limited RIFS
f=false
repeat
if (i[j]=i[j]-1)<0
if (j=j-1)<0
f=true
endif
elseif j>0
f=gf[i[j],i[j-1]+9]
else
f=true
endif
until f
if j==0
z=sz
ss=1.0
if @errfix1==2
m=mm[0]
endif
elseif j>0
z=zz[j-1]
ss=s[j-1]
if @errfix1==2
m=mm[j]
endif
endif
else
k=k+9
l=gnt
f=false
repeat
if (l=l-1)>=0
f=gf[l,k]
endif
until f || l<0
if l<0
j=j-1
f=false ; again check for limited RIFS
repeat
if (i[j]=i[j]-1)<0
if (j=j-1)<0
f=true
endif
elseif j>0
f=gf[i[j],i[j-1]+9]
else
f=true
endif
until f
if j==0
z=sz
ss=1.0
if @errfix1==2
m=mm[0]
endif
elseif j>0
z=zz[j-1]
ss=s[j-1]
if @errfix1==2
m=mm[j]
endif
endif
else
i[j]=l
if @errfix1==2
mm[j]=m
endif
endif
endif
until j<0
Note that the RIFS checks check that a given transform may be preceded by
another since the original forwards RIFS algorithm checks for transforms
that may follow another.
Now we have all necessary values to colour the point if it was on the
fractal using either the genetics or the orbital path as dictated by
the genetic sequence.
The algorithm needs considerable improvement for doing some sets,
for example quadratic Julia's by inverse IFS but for higher powers
the rate of divergence is such that branches of the tree for points
off the fractal are culled quickly, in fact I also found that if you set
a 2 transform IFS such that the 2 transforms are standard quadratic
Julia transforms but for different Julia seeds the results are also
reasonably
fast.
bye
Dave
http://website.lineone.net/~dave_makin/
http://www.ultrafractal.org/tiki-browse_gallery.php?galleryId=58