Skip to content

Commit

Permalink
New release (20190707)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Jul 18, 2019
1 parent 8fb0a35 commit 6c63599
Show file tree
Hide file tree
Showing 31 changed files with 2,717 additions and 328 deletions.
50 changes: 47 additions & 3 deletions colorTable.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ interface

const //maximum number of control points for color schemes...
maxNodes = 32;
kPaintHideDefaultBehavior = -1;
kPaintHideDarkHideBright = 0;
kPaintHideDarkShowBright = 1;
kPaintShowDarkHideBright = 2;
kPaintShowDarkShowBright = 3;

type

Expand All @@ -22,7 +27,9 @@ function UpdateTransferFunction (var lIndex: integer; isInvert: boolean): TLUT;/
function CLUTDir: string;
function blendRGBA(c1, c2: TRGBA ): TRGBA;
function maxRGBA(c1, c2: TRGBA ): TRGBA;
function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA;
//function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA;
function inten2rgb(intensity, mn, mx: single; lut: TLUT; mode: integer): TRGBA; overload;
//function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA; overload;
function inten2rgb1(intensity, mn, mx: single; lut: TLUT): TRGBA; //use 1st not 0th LUT color (0 is transparent)
function desaturateRGBA ( rgba: TRGBA; frac: single; alpha: byte): TRGBA;
function isFreeSurferLUT(lIndex: integer): boolean;
Expand Down Expand Up @@ -69,7 +76,44 @@ function maxRGBA(c1, c2: TRGBA ): TRGBA;
result.A := c2.A;
end;

function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA;


function inten2rgb(intensity, mn, mx: single; lut: TLUT; mode: integer): TRGBA; overload;
var
i: byte;
isInvert : boolean;
begin
if (mn < 0) and (mx < 0) and (mode = kPaintHideDefaultBehavior) then begin
if intensity >= mx then
exit( lut[0])
else if intensity <= mn then
exit( lut[255])
else
exit( lut[round(255* (1.0- (intensity-mn)/(mx-mn)))]);
end;
if intensity > mx then begin
i := 255;
if (mode = kPaintHideDarkHideBright) or (mode = kPaintShowDarkHideBright) then //hide bright
i := 0;
end else if intensity < mn then begin
i := 0;
if (mode = kPaintShowDarkHideBright) or (mode = kPaintShowDarkShowBright) then //hide dark
i := 1;
end else begin
i := round(255*(intensity-mn)/(mx-mn));
if (i = 0) and ((mode = kPaintHideDefaultBehavior) or (mode = kPaintShowDarkHideBright) or (mode = kPaintShowDarkShowBright)) then //hide dark
i := 1;
end;
result := lut[i];
end;

function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA; overload;
begin
//result := inten2rgb(intensity, mn, mx, lut, kPaintHideDefaultBehavior);
result := inten2rgb(intensity, mn, mx, lut,kPaintHideDarkHideBright);
end;

(*function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA;
begin
if (mn < 0) and (mx < 0) then begin
if intensity >= mx then begin
Expand All @@ -91,7 +135,7 @@ function inten2rgb(intensity, mn, mx: single; lut: TLUT): TRGBA;
else
result := lut[round(255*(intensity-mn)/(mx-mn))];
end;
end;
end; *)

function inten2rgb1(intensity, mn, mx: single; lut: TLUT): TRGBA; //use 1st not 0th LUT color (0 is transparent)
var i :integer;
Expand Down
2 changes: 1 addition & 1 deletion define_types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
{$endif}

const
kVers = 'v1.0.20190518';
kVers = 'v1.0.20190707';
NaN : double = 1/0;
kTab = chr(9);
kCR = chr (13);
Expand Down
25 changes: 24 additions & 1 deletion glclrbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
interface

uses
{$IFNDEF OLD}graphTicks, {$ENDIF}
{$IFDEF COREGL}shaderu,glcorearb, gl_core_matrix, {$ELSE}gl, glext, {$ENDIF}
glmtext,Classes, SysUtils, Graphics, OpenGLContext, math, dialogs, define_types,colorTable;

Expand Down Expand Up @@ -322,6 +323,7 @@ function fRemainder(const a,b:double):double;

end;

{$IFDEF OLD}
type
TTicks = record
stepSize, remainder: single;
Expand Down Expand Up @@ -374,12 +376,18 @@ function setStepSizeForce(lRange: double; lDesiredSteps: integer): TTicks;
if result.remainder < (0.001* result.stepSize) then
result.remainder := 0;
end;
{$ENDIF}

procedure TGLClrbar.CreateTicksText(mn,mx: single; BarLength, BarTop, BarThick, fntScale: single);
var
lStep,lRange, t, MarkerSzX,MarkerSzY, lPosX, lPosY, StWid: double;
isInvert: boolean;
{$IFDEF OLD}
tic, ticAlt: TTicks;
{$ELSE}
stepSize: double;
ticDecimals: integer;
{$ENDIF}
St: string;
begin
if (mx = mn) or (BarThick = 0) or (BarLength = 0) then exit;
Expand All @@ -404,6 +412,7 @@ procedure TGLClrbar.CreateTicksText(mn,mx: single; BarLength, BarTop, BarThick,
lRange := max(abs(mn),mx);// + (0.5 * min(abs(mn),mx));
if lRange < 0.000001 then exit;
//glform1.caption := inttostr(random(888))+' '+floattostr(min(abs(mn),mx) / lRange);
{$IFDEF OLD}
if ((mn < 0) and (mx > 0)) and ((min(abs(mn),mx)/lRange) > 0.65) then begin
tic := setStepSize(lRange, 2);
//now try forcing other values
Expand Down Expand Up @@ -435,6 +444,10 @@ procedure TGLClrbar.CreateTicksText(mn,mx: single; BarLength, BarTop, BarThick,
//if (rem < (lStepSize * 0.001)) then //e.g. 0.2..3.0 can be evenly spanned
// lStep := mn;
if (lStep < (mn)) and ((mn -lStep) > (lStep * 0.001) ) then lStep := lStep+tic.stepSize;
{$ELSE}
SelectTicks(mn, mx, lStep, stepSize, ticDecimals);
{$ENDIF}

lRange := abs(mx - mn); //full range, in case mn < 0 and mx > 0
nglColor4ub (FontClr.r,FontClr.g,FontClr.b,255);//outline
repeat
Expand All @@ -459,15 +472,25 @@ procedure TGLClrbar.CreateTicksText(mn,mx: single; BarLength, BarTop, BarThick,
nglVertex2fr(lPosX+MarkerSzX,lPosY+MarkerSzY);
nglEnd;
if fntScale > 0 then begin
{$IFDEF OLD}
St := FloatToStrF(lStep, ffFixed,7,tic.decimals);
{$ELSE}
St := FloatToStrF(lStep, ffFixed,7,ticDecimals);
{$ENDIF}
StWid := Txt.TextWidth(fntScale, St);
if not fisVertical then
Txt.TextOut(lPosX-(StWid*0.5),BarTop-(BarThick*0.88),fntScale, St)
else
Txt.TextOut(lPosX+(BarThick*0.88),lPosY-(StWid*0.5),fntScale,90, St)
end;
lStep := lStep + tic.stepSize;
{$IFDEF OLD}
lStep := lStep + tic.stepSize;
until lStep > (mx+(tic.stepSize*0.01));
{$ELSE}
lStep := lStep + stepSize;
until lStep > (mx+(stepSize*0.01));
{$ENDIF}

end; //CreateTicksText()

procedure TGLClrbar.CreateClrbar;
Expand Down
175 changes: 175 additions & 0 deletions graphticks.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
unit graphTicks;

{$mode objfpc}{$H+}

interface

procedure SelectTicks(mn, mx: double; out ticMin, ticStep: double; out ticDecimals: integer);

implementation

uses
//Dialogs, SysUtils,
Math;

function tickSpacing(tickCount: integer; mn, mx: double; out ticMin: double): double;
//https://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis
var
pow10x, x, range, unroundedTickSize: double;
begin
ticMin := mn;
range := abs(mx-mn);
if range = 0.0 then exit(0);
unroundedTickSize := range/(tickCount-1);
x := ceil(log10(unroundedTickSize)-1);
pow10x := power(10, x);
result := ceil(unroundedTickSize / pow10x) * pow10x;
//if mn < 0 then
// ticMin := ceil((mn+result) / result) * result
//else
if frac(mn / result) = 0.0 then exit;
ticMin := floor((mn+result) / result) * result;
end;

procedure SelectTicks(mn, mx: double; out ticMin, ticStep: double; out ticDecimals: integer);
var
imx, imn, range: double;
begin
imn := min(mx,mn);
imx := max(mx,mn);
range := mx - mn;
ticStep := tickSpacing(5, imn, imx, ticMin);
if frac(range / ticStep) <> 0.0 then begin
ticStep := tickSpacing(6, imn, imx, ticMin);
if frac(range / ticStep) <> 0.0 then begin
ticStep := tickSpacing(7, imn, imx, ticMin);
if frac(range / ticStep) <> 0.0 then begin
ticStep := tickSpacing(6, imn, imx, ticMin);
//if (range / ticStep) <> 0.0 then begin
// ticStep := tickSpacing(5, imn, imx, ticMin);
//end;
end;
end;
end;
ticDecimals := 0;
if ticStep > 1 then exit;
ticDecimals := abs(floor(log10(ticStep)));
end;

(*type
TTicks = record
stepSize, remainder: single;
decimals: integer;
end;
function decimals(v: double): integer;
var
f: double;
begin
result := 0;
f := frac(v);
while (f > 0.001) and (f < 0.999) do begin
v := v * 10;
result := result + 1;
f := frac(v);
end;
end;
function fRemainder(const a,b:double):double;
begin
result := a-b * Int(a/b);
if (result > (0.5 * b)) then result := b - result;
end;
function setStepSize(lRange: double; lDesiredSteps: integer): TTicks;
var
lPower: integer;
begin
result.stepSize := lRange / lDesiredSteps;
//{$DEFINE OLD}
{$IFDEF OLD}
lPower := 0;
while result.stepSize >= 10 do begin
result.stepSize := result.stepSize/10;
inc(lPower);
end;
while result.stepSize < 1 do begin
result.stepSize := result.stepSize * 10;
dec(lPower);
end;
{$ELSE}
lPower := floor(log10(result.stepSize));
result.stepSize := result.stepSize/power(10, lPower);
{$ENDIF}
if lPower < 0 then
result.decimals := abs(lPower)
else
result.decimals := 0;
result.stepSize := round(result.stepSize) * Power(10,lPower);
result.remainder := fRemainder(lRange, result.stepSize);
if result.remainder < (0.001* result.stepSize) then
result.remainder := 0;
end;
function setStepSizeForce(lRange: double; lDesiredSteps: integer): TTicks;
begin
result.stepSize := lRange / lDesiredSteps;
result.decimals := decimals(result.stepSize);
result.remainder := fRemainder(lRange, result.stepSize);
if result.remainder < (0.001* result.stepSize) then
result.remainder := 0;
end;
procedure SelectTicks(mn, mx: double; out ticMin, ticStep: double; out ticDecimals: integer);
var
lStep,lRange: double;
tic, ticAlt: TTicks;
begin
ticMin := 0;
ticStep := 1;
ticDecimals := 0;
lRange := abs(mx - mn);
if (mn < 0) and (mx > 0) then
lRange := max(abs(mn),mx);// + (0.5 * min(abs(mn),mx));
if lRange < 0.000001 then exit;
if ((mn < 0) and (mx > 0)) and ((min(abs(mn),mx)/lRange) > 0.65) then begin
tic := setStepSize(lRange, 2);
//now try forcing other values
ticAlt := setStepSizeForce(lRange, 3);
if (ticAlt.remainder < tic.remainder) and (ticAlt.decimals <= tic.decimals) then
tic := ticAlt;
ticAlt := setStepSizeForce(lRange, 4);
if (ticAlt.remainder < tic.remainder) and (ticAlt.decimals <= tic.decimals) then
tic := ticAlt;
end else begin
tic := setStepSize(lRange, 3);
//now try forcing other values
ticAlt := setStepSizeForce(lRange, 2);
if (ticAlt.remainder < tic.remainder) and (ticAlt.decimals <= tic.decimals) then
tic := ticAlt;
ticAlt := setStepSizeForce(lRange, 4);
if (ticAlt.remainder < tic.remainder) and (ticAlt.decimals <= tic.decimals) then
tic := ticAlt;
ticAlt := setStepSizeForce(lRange, 1);
if (ticAlt.remainder < tic.remainder) and (ticAlt.decimals < tic.decimals) then
tic := ticAlt;
end;
if (mn > 0) and (decimals(mn) <= tic.decimals) then
lStep := mn
else
lStep := trunc((mn) / tic.stepSize)*tic.stepSize;
if (lStep < (mn)) and ((mn -lStep) > (lStep * 0.001) ) then lStep := lStep+tic.stepSize;
lStep := 400;
//showmessage(format('%g %g', [lStep, mn]));
//lRange := abs(mx - mn); //full range, in case mn < 0 and mx > 0
ticMin := lStep;
ticStep := tic.stepSize;
ticDecimals := tic.decimals;
//result := format('stepSize %g 1stTick %g decimals %d', [tic.stepSize, lStep, tic.decimals]);
end; *)


end.

Loading

0 comments on commit 6c63599

Please sign in to comment.