Added new variants

fixed filter buf
This commit is contained in:
ronaldhordijk 2005-03-20 18:30:21 +00:00
parent afa92f6412
commit 665af685f9
8 changed files with 155 additions and 55 deletions

View File

@ -25,11 +25,11 @@ uses
const
EPS = 1E-10;
NVARS = 22;
NVARS = Xform.NVARS;
NXFORMS = 12;
SUB_BATCH_SIZE = 10000;
PREFILTER_WHITE = (1 shl 26);
FILTER_CUTOFF = 2.5;
FILTER_CUTOFF = 1.8;
BRIGHT_ADJUST = 2.3;
type
@ -37,7 +37,8 @@ type
TLongintArray = array[0..8192] of Longint;
TVariation = (vLinear, vSinusoidal, vSpherical, vSwirl, vHorseshoe, vPolar,
vHandkerchief, vHeart, vDisc, vSpiral, vHyperbolic, vSquare, vEx, vJulia,
vBent, vWaves, vFisheye, vPopcorn, vExponential, vPower, vCosine, vSawTooth, vRandom);
vBent, vWaves, vFisheye, vPopcorn, vExponential, vPower, vCosine,
vRings, vFan, vRandom);
type
TPointsArray = array of TCPpoint;
@ -800,14 +801,14 @@ end;
procedure TControlPoint.SetVariation(vari: TVariation);
const
xform_distrib: array[0..12] of integer = (2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8);
var_distrib: array[0..40] of integer = (-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
mixed_var_distrib: array[0..30] of integer = (0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
var_distrib: array[0..41] of integer = (-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
mixed_var_distrib: array[0..31] of integer = (0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
var
i, j, v: integer;
rv: integer;
begin
repeat
rv := var_distrib[random(41)];
rv := var_distrib[random(Length(var_distrib))];
until Variations[rv];
for i := 0 to NXFORMS - 1 do begin
@ -820,7 +821,7 @@ begin
if rv < 0 then
begin
repeat
v := Mixed_var_distrib[random(31)];
v := Mixed_var_distrib[random(Length(mixed_var_distrib))];
until Variations[v]; // Use only Variations set in options
xform[i].vars[v] := 1
end
@ -835,8 +836,8 @@ end;
procedure TControlPoint.RandomCP(min: integer = 2; max: integer = NXFORMS; calc: boolean = true);
const
xform_distrib: array[0..12] of integer = (2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8);
var_distrib: array[0..40] of integer = (-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
mixed_var_distrib: array[0..30] of integer = (0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
var_distrib: array[0..41] of integer = (-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
mixed_var_distrib: array[0..31] of integer = (0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
var
nrXforms: integer;
i, j: integer;
@ -851,7 +852,7 @@ begin
//nrXforms := xform_distrib[random(13)];
nrXforms := random(Max - (Min - 1)) + Min;
repeat
rv := var_distrib[random(41)];
rv := var_distrib[random(Length(var_distrib))];
until Variations[rv];
for i := 0 to NXFORMS - 1 do begin
@ -880,7 +881,7 @@ begin
if rv < 0 then
begin
repeat
v := Mixed_var_distrib[random(31)];
v := Mixed_var_distrib[random(Length(mixed_var_distrib))];
until Variations[v]; // use only variations set in options
xform[i].vars[v] := 1
end

View File

@ -2,7 +2,7 @@ object MainForm: TMainForm
Left = 316
Top = 424
Width = 574
Height = 455
Height = 515
Caption = 'Apophysis'
Color = clBtnFace
Font.Charset = ANSI_CHARSET
@ -27,7 +27,7 @@ object MainForm: TMainForm
Left = 160
Top = 28
Width = 4
Height = 354
Height = 414
end
object ToolBar: TToolBar
Left = 0
@ -251,7 +251,7 @@ object MainForm: TMainForm
Left = 0
Top = 28
Width = 160
Height = 354
Height = 414
Align = alLeft
Columns = <
item
@ -270,7 +270,7 @@ object MainForm: TMainForm
Left = 164
Top = 28
Width = 402
Height = 354
Height = 414
Align = alClient
BevelInner = bvLowered
BevelOuter = bvNone
@ -281,7 +281,7 @@ object MainForm: TMainForm
Left = 1
Top = 1
Width = 400
Height = 352
Height = 412
Align = alClient
AutoSize = True
PopupMenu = DisplayPopup
@ -293,7 +293,7 @@ object MainForm: TMainForm
end
object StatusBar: TStatusBar
Left = 0
Top = 382
Top = 442
Width = 566
Height = 19
Panels = <
@ -2618,6 +2618,7 @@ object MainForm: TMainForm
end
object mnuimage: TMenuItem
Caption = 'Image '
Visible = False
OnClick = mnuimageClick
end
object N4: TMenuItem
@ -2836,11 +2837,16 @@ object MainForm: TMainForm
RadioItem = True
OnClick = mnuCosineClick
end
object mnuSawtooth: TMenuItem
Caption = 'Sawtooth'
object mnuRings: TMenuItem
Caption = 'Rings'
GroupIndex = 1
RadioItem = True
OnClick = mnuSawtoothClick
OnClick = mnuRingsClick
end
object mnuFan: TMenuItem
Caption = 'Fan'
GroupIndex = 1
OnClick = mnuFanClick
end
end
object mnuScript: TMenuItem

View File

@ -37,7 +37,7 @@ const
RS_DR = 1;
RS_XO = 2;
RS_VO = 3;
varnames: array[0..21] of PChar = (
varnames: array[0..NVARS -1] of PChar = (
'linear',
'sinusoidal',
'spherical',
@ -59,7 +59,8 @@ const
'exponential',
'power',
'cosine',
'sawtooth'
'rings',
'fan'
);
type
@ -216,12 +217,14 @@ type
MnuExponential: TMenuItem;
mnuPower: TMenuItem;
mnuCosine: TMenuItem;
mnuSawtooth: TMenuItem;
mnuRings: TMenuItem;
ToolButton4: TToolButton;
tbzoomwindow: TToolButton;
tbDrag: TToolButton;
tbRotate: TToolButton;
mnuimage: TMenuItem;
mnuFan: TMenuItem;
procedure mnuFanClick(Sender: TObject);
procedure mnuimageClick(Sender: TObject);
procedure mnuExitClick(Sender: TObject);
procedure mnuSaveUPRClick(Sender: TObject);
@ -329,7 +332,7 @@ type
procedure MnuExponentialClick(Sender: TObject);
procedure mnuPowerClick(Sender: TObject);
procedure mnuCosineClick(Sender: TObject);
procedure mnuSawtoothClick(Sender: TObject);
procedure mnuRingsClick(Sender: TObject);
procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
@ -425,7 +428,7 @@ implementation
uses Editor, Options, Regstry, Gradient, Render,
FullScreen, FormRender, Mutate, Adjust, Browser, Save, About, CmapData,
HtmlHlp, ScriptForm, FormFavorites, Size, FormExport, msMultiPartFormData,
Sheep;
Sheep, ImageColoring;
{$R *.DFM}
@ -3107,7 +3110,7 @@ end;
///////////////////////////////////////////////////////////////////////////////
procedure TMainForm.mnuimageClick(Sender: TObject);
begin
// frmImageColoring.Show;
frmImageColoring.Show;
end;
procedure swapcolor(var clist: array of cardinal; i, j: integer);
@ -4265,11 +4268,24 @@ begin
UpdateWindows;
end;
procedure TMainForm.mnuSawtoothClick(Sender: TObject);
procedure TMainForm.mnuRingsClick(Sender: TObject);
begin
mnuSawtooth.Checked := True;
mnuRings.Checked := True;
UpdateUndo;
Variation := vSawtooth;
Variation := vRings;
SetVariation(maincp);
ResetLocation;
RedrawTimer.Enabled := True;
UpdateWindows;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TMainForm.mnuFanClick(Sender: TObject);
begin
mnuFan.Checked := True;
UpdateUndo;
Variation := vFan;
SetVariation(maincp);
ResetLocation;
RedrawTimer.Enabled := True;

View File

@ -178,20 +178,33 @@ end;
procedure TRenderer32.CreateFilter;
var
i, j: integer;
fw: integer;
adjust: double;
ii, jj: double;
begin
oversample := fcp.spatial_oversample;
filter_width := Round(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
fw := Trunc(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
filter_width := fw + 1;
// make sure it has same parity as oversample
if odd(filter_width + oversample) then
inc(filter_width);
if (fw > 0.0) then
adjust := (1.0 * FILTER_CUTOFF * filter_width) / fw
else
adjust := 1.0;
setLength(filter, filter_width, filter_width);
for i := 0 to filter_width - 1 do begin
for j := 0 to filter_width - 1 do begin
filter[i, j] := exp(-2.0 * power(((2.0 * i + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2) *
power(((2.0 * j + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2));
ii := ((2.0 * i + 1.0)/ filter_width - 1.0) * adjust;
jj := ((2.0 * j + 1.0)/ filter_width - 1.0) * adjust;
filter[i, j] := exp(-2.0 * (ii * ii + jj * jj));
end;
end;
Normalizefilter;
end;

View File

@ -178,20 +178,33 @@ end;
procedure TRenderer64.CreateFilter;
var
i, j: integer;
fw: integer;
adjust: double;
ii, jj: double;
begin
oversample := fcp.spatial_oversample;
filter_width := Round(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
fw := Trunc(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
filter_width := fw + 1;
// make sure it has same parity as oversample
if odd(filter_width + oversample) then
inc(filter_width);
if (fw > 0.0) then
adjust := (1.0 * FILTER_CUTOFF * filter_width) / fw
else
adjust := 1.0;
setLength(filter, filter_width, filter_width);
for i := 0 to filter_width - 1 do begin
for j := 0 to filter_width - 1 do begin
filter[i, j] := exp(-2.0 * power(((2.0 * i + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2) *
power(((2.0 * j + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2));
ii := ((2.0 * i + 1.0)/ filter_width - 1.0) * adjust;
jj := ((2.0 * j + 1.0)/ filter_width - 1.0) * adjust;
filter[i, j] := exp(-2.0 * (ii * ii + jj * jj));
end;
end;
Normalizefilter;
end;
@ -357,11 +370,18 @@ end;
///////////////////////////////////////////////////////////////////////////////
procedure TRenderer64.SetPixels;
var
i: integer;
i{,j}: integer;
nsamples: Int64;
nrbatches: Integer;
points: TPointsArray;
// f: text;
begin
// if FileExists('c:\temp\flame.txt') then
// Deletefile('c:\temp\flame.txt');
// AssignFile(F, 'c:\temp\flame.txt');
// Rewrite(F);
SetLength(Points, SUB_BATCH_SIZE);
nsamples := Round(sample_density * bucketSize / (oversample * oversample));
@ -381,12 +401,17 @@ begin
1: fcp.iterateXYC(SUB_BATCH_SIZE, points);
end;
// for j := SUB_BATCH_SIZE - 1 downto 0 do
// Writeln(f, FloatTostr(points[j].x) + #9 + FloatTostr(points[j].y) + #9 + FloatTostr(points[j].c));
if FCP.FAngle = 0 then
AddPointsToBuckets(points)
else
AddPointsToBucketsAngle(points);
end;
// closefile(f);
Progress(1);
end;
@ -537,7 +562,7 @@ begin
else if (bi > 255) then
bi := 255;
Row[j] := RGB(bi, gi, ri) + (ai shl 24);
Row[j] := RGB(bi, gi, ri);// + (ai shl 24);
end;
Inc(bucketpos, 2 * gutter_width);

View File

@ -184,20 +184,33 @@ end;
procedure TRendererMM64.CreateFilter;
var
i, j: integer;
fw: integer;
adjust: double;
ii, jj: double;
begin
oversample := fcp.spatial_oversample;
filter_width := Round(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
fw := Trunc(2.0 * FILTER_CUTOFF * oversample * fcp.spatial_filter_radius);
filter_width := fw + 1;
// make sure it has same parity as oversample
if odd(filter_width + oversample) then
inc(filter_width);
if (fw > 0.0) then
adjust := (1.0 * FILTER_CUTOFF * filter_width) / fw
else
adjust := 1.0;
setLength(filter, filter_width, filter_width);
for i := 0 to filter_width - 1 do begin
for j := 0 to filter_width - 1 do begin
filter[i, j] := exp(-2.0 * power(((2.0 * i + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2) *
power(((2.0 * j + 1.0) / filter_width - 1.0) * FILTER_CUTOFF, 2));
ii := ((2.0 * i + 1.0)/ filter_width - 1.0) * adjust;
jj := ((2.0 * j + 1.0)/ filter_width - 1.0) * adjust;
filter[i, j] := exp(-2.0 * (ii * ii + jj * jj));
end;
end;
Normalizefilter;
end;
@ -549,6 +562,7 @@ begin
Inc(bucketpos, 2 * gutter_width);
Inc(bucketpos, (oversample - 1) * BucketWidth);
end;
bm.PixelFormat := pf24bit;
Progress(1);
end;

View File

@ -2693,7 +2693,8 @@ begin
Scripter.AddConstant('V_EXPONENTIAL', 18);
Scripter.AddConstant('V_POWER', 19);
Scripter.AddConstant('V_COSINE', 20);
Scripter.AddConstant('V_SAWTOOTH', 21);
Scripter.AddConstant('V_RINGS', 21);
Scripter.AddConstant('V_FAN', 22);
Scripter.AddConstant('V_RANDOM', -1);
{ Variables }
Scripter.AddVariable('SelectedTransform', SelectedTriangle);

View File

@ -3,7 +3,7 @@ unit XForm;
interface
const
NVARS = 22;
NVARS = 23;
EPS = 1E-10;
type
@ -57,7 +57,8 @@ type
procedure Exponential; // var[18]
procedure Power; // var[19]
procedure Cosine; // var[20]
procedure SawTooth; // var[21]
procedure Rings; // var[21]
procedure Fan; // var[22]
public
@ -230,12 +231,17 @@ begin
end;
if (vars[21] <> 0.0) then begin
FFunctionList[FNrFunctions] := SawTooth;
FFunctionList[FNrFunctions] := Rings;
Inc(FNrFunctions);
end;
if (vars[22] <> 0.0) then begin
FFunctionList[FNrFunctions] := Fan;
Inc(FNrFunctions);
end;
CalculateAngle := (vars[5] <> 0.0) or (vars[6] <> 0.0) or (vars[7] <> 0.0) or (vars[8] <> 0.0) or
(vars[12] <> 0.0) or (vars[13] <> 0.0);
(vars[12] <> 0.0) or (vars[13] <> 0.0) or (vars[21] <> 0.0) or (vars[22] <> 0.0);
CalculateLength := False;
CalculateSinCos := (vars[4] <> 0.0) or (vars[9] <> 0.0) or (vars[10] <> 0.0) or
(vars[11] <> 0.0) or (vars[16] <> 0.0) or (vars[19] <> 0.0) or
@ -495,21 +501,39 @@ begin
end;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.SawTooth;
procedure TXForm.Rings;
var
r: double;
// nx, ny: double;
dx: double;
begin
// r := sqrt(FTx * FTx + FTy * FTy);
// r := fmod(r + 1.0, 2.0) - 1.0;
r := FLength + 1;
r := r - System.Int(r/2) * 2.0 - 1;
dx := sqr(c20) + EPS;
r := FLength;
r := r + dx - System.Int((r + dx)/(2 * dx)) * 2 * dx - dx + r * (1-dx);
// nx := cos(FAngle) * r;
// ny := sin(FAngle) * r;
FPx := FPx + vars[21] * r * cos(FAngle);
FPy := FPy + vars[21] * r * sin(FAngle);
end;
FPx := FPx + vars[21] * r * FCosA;
FPy := FPy + vars[21] * r * FSinA;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Fan;
var
r,t,a : double;
dx, dy, dx2: double;
begin
dy := c21;
dx := PI * (sqr(c20) + EPS);
dx2 := dx/2;
r := sqrt(FTx * FTx + FTy * FTy);
t := FAngle+dy - System.Int((FAngle + dy)/dx) * dx;
if (t > dx2) then
a := FAngle - dx2
else
a := FAngle + dx2;
FPx := FPx + vars[22] * r * cos(a);
FPy := FPy + vars[22] * r * sin(a);
end;
///////////////////////////////////////////////////////////////////////////////