Skip to content

Commit

Permalink
Windows 10 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Aug 1, 2018
1 parent 4a5544e commit 8369138
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 99 deletions.
24 changes: 17 additions & 7 deletions mainunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,10 @@ function TGLForm1.OpenMesh(FilenameIN: string): boolean;
Filename, curvname, ext: string;
begin
result := false;
Filename := FindFile(FilenameIN);
if FilenameIN <> '-' then
Filename := FindFile(FilenameIN)
else
Filename := FilenameIN;
if Filename = '' then exit;
result := true;
ext := ExtractFileExtGzUpper(Filename);
Expand Down Expand Up @@ -1324,7 +1327,7 @@ function SimplifyPref(out Tol, minLength: single): boolean;
OkBtn.Parent:=PrefForm;
OkBtn.ModalResult:= mrOK;
{$IFNDEF Darwin}
ScaleDPIX(PrefForm, 96);
ScaleDPI(PrefForm, 96);
{$ENDIF}
{$IFDEF LCLCocoa}
if gPrefs.DarkMode then SetFormDarkMode(PrefForm);
Expand Down Expand Up @@ -1453,7 +1456,7 @@ function ScalarPref(var min, max: single; var ColorBarPrecedenceTracksNotOverla
OkBtn.Left := PrefForm.Width - OkBtn.Width - 8;
OkBtn.Parent:=PrefForm;
OkBtn.ModalResult:= mrOK;
{$IFNDEF Darwin} ScaleDPIX(PrefForm, 96);{$ENDIF}
{$IFNDEF Darwin} ScaleDPI(PrefForm, 96);{$ENDIF}
{$IFDEF LCLCocoa}
if gPrefs.DarkMode then SetFormDarkMode(PrefForm);
{$ENDIF}
Expand Down Expand Up @@ -1964,7 +1967,7 @@ procedure TGLForm1.PrefMenuClick(Sender: TObject);
AdvancedBtn.Top := 378;
AdvancedBtn.Parent:=PrefForm;
AdvancedBtn.ModalResult:= mrYesToAll;
{$IFNDEF Darwin} ScaleDPIX(PrefForm, 96); {$ENDIF}
{$IFNDEF Darwin} ScaleDPI(PrefForm, 96); {$ENDIF}
PrefForm.ShowModal;
if (PrefForm.ModalResult <> mrOK) and (PrefForm.ModalResult <> mrYesToAll) then begin
FreeAndNil(PrefForm);
Expand Down Expand Up @@ -2160,7 +2163,7 @@ function GetFloat(prompt: string; min,def,max: extended): extended;
OkBtn.Left := PrefForm.Width - OkBtn.Width - 8;
OkBtn.Parent:=PrefForm;
OkBtn.ModalResult:= mrOK;
{$IFNDEF Darwin} ScaleDPIX(PrefForm, 96);{$ENDIF}
{$IFNDEF Darwin} ScaleDPI(PrefForm, 96);{$ENDIF}
{$IFDEF LCLCocoa}
if gPrefs.DarkMode then SetFormDarkMode(PrefForm);
{$ENDIF}
Expand Down Expand Up @@ -3207,7 +3210,7 @@ procedure TGLForm1.AboutMenuClick(Sender: TObject);
const
kSamp = 36;
var
titleStr, isAtlasStr, TrackStr, MeshStr, str: string;
fpsStr, titleStr, isAtlasStr, TrackStr, MeshStr, str: string;
s: dword;
i: integer;
scale: single;
Expand All @@ -3228,6 +3231,9 @@ procedure TGLForm1.AboutMenuClick(Sender: TObject);
gAzimuth := (gAzimuth + 10) mod 360;
GLbox.Repaint;
end;
fpsStr := '';
if (gettickcount<> s) then
fpsStr := LineEnding+' FPS ' +inttostr(round( (kSamp*1000)/(gettickcount-s)));
origin := GetOrigin(scale);
isAtlasStr := '';
if (length(gMesh.vertexAtlas) > 0) then isAtlasStr := ' Indexed Atlas ';
Expand All @@ -3253,7 +3259,7 @@ procedure TGLForm1.AboutMenuClick(Sender: TObject);
{$ENDIF}
{$ENDIF}
+LineEnding+' www.mricro.com :: BSD 2-Clause License (opensource.org/licenses/BSD-2-Clause)'
+LineEnding+' FPS ' +inttostr(round( (kSamp*1000)/(gettickcount-s)))
+FPSstr
+LineEnding+format(' Scale %.4f',[scale])
+LineEnding+format(' Origin %.4fx%.4fx%.4f',[origin.X, origin.Y, origin.Z])
+LineEnding+' Mesh Vertices '+inttostr(length(gMesh.vertices))+' Faces '+ inttostr(length(gMesh.faces)) +' Colors '+ inttostr(length(gMesh.vertexRGBA))
Expand Down Expand Up @@ -3552,6 +3558,10 @@ procedure TGLForm1.OpenMenuClick(Sender: TObject);
const
kMeshFilter = 'Mesh (GIfTI, PLY, FreeSurfer, etc)|*.*';
begin
if (ssCtrl in KeyDataToShiftState(vk_Shift)) then begin
OpenMesh('-');
exit;
end;
OpenDialog.Filter := kMeshFilter;
OpenDialog.Title := 'Select mesh file';
if Fileexists(gPrefs.PrevFilename[1]) then begin
Expand Down
117 changes: 113 additions & 4 deletions mesh.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{$Include opts.inc}
{$mode objfpc}{$H+}
interface
{$DEFINE TREFOIL} //use Trefoil Knot as default object (instead of pyramid)
uses

{$IFDEF DGL} dglOpenGL, {$ELSE DGL} {$IFDEF COREGL}glcorearb, {$ELSE} gl, {$ENDIF} {$ENDIF DGL}
Expand Down Expand Up @@ -78,6 +79,7 @@ TMesh = class
procedure SetOverlayDescriptives(lOverlayIndex: integer);
procedure MinMaxPct(lOverlayIndex, num_v: integer; var mx, mn: single; isExcludeZero: boolean);
procedure SetDescriptives;
{$IFDEF TREFOIL} procedure MakeTrefoil; {$ENDIF}
procedure MakeSphere;
procedure BuildListCore(Clr: TRGBA; var f: TFaces; var v: TVertices; var vtxRGBA: TVertexRGBA);
procedure BuildListPartialAtlas(Clr: TRGBA; vtxRGBA: TVertexRGBA);
Expand Down Expand Up @@ -1119,8 +1121,107 @@ procedure TMesh.MakeSphere;
end;
{$ENDIF}

{$IFDEF TREFOIL}
procedure TMesh.MakeTrefoil;
//http://prideout.net/blog/?p=22
function EvaluateTrefoil(s, t: single): TPoint3f;
function Normalized(v: TPoint3f): TPoint3f;
var len: single;
begin
len := sqrt(sqr(v.x) + sqr(v.y) + sqr(v.z));
result := v;
if len = 0 then
exit;
result.X := result.X / len;
result.Y := result.Y / len;
result.Z := result.Z / len;
end;
function Cross(v1, v2: TPoint3f): TPoint3f;
begin
result.x:=(V1.y*V2.z)-(V1.z*V2.y);
result.y:=(V1.z*V2.x)-(V1.x*V2.z);
result.z:=(V1.x*V2.y)-(V1.y*V2.x);
end;
const
TwoPi = 2 * Pi;
a = 0.5;
b = 0.3;
c = 0.5;
d = 0.1;
var
u,v,r,x,y,z: single;
q, qvn, ww, dv : TPoint3f;
begin
u := (1 - s) * 2 * TwoPi;
v := t * TwoPi;
r := a + b * cos(1.5 * u);
x := r * cos(u);
y := r * sin(u);
z := c * sin(1.5 * u);
dv.x := -1.5 * b * sin(1.5 * u) * cos(u) - (a + b * cos(1.5 * u)) * sin(u);
dv.y := -1.5 * b * sin(1.5 * u) * sin(u) +
(a + b * cos(1.5 * u)) * cos(u);
dv.z := 1.5 * c * cos(1.5 * u);
q := Normalized(dv);
qvn.X := q.y;
qvn.Y := -q.X;
qvn.z := 0;
qvn := Normalized(qvn);
ww := Cross(q, qvn);
result.x := x + d * (qvn.x * cos(v) + ww.x * sin(v));
result.y := y + d * (qvn.y * cos(v) + ww.y * sin(v));
result.z := z + d * ww.z * sin(v);
end;
const
kSlices = 128;
kStacks = 32;
kVertexCount = kSlices * kStacks;
kIndexCount = kVertexCount * 6;
var
ds, dt, s, t: single;
i,j,k, n: integer;
begin
setlength(faces, kIndexCount);
n := 0;
k := 0;
for i := 0 to (kSlices-1) do begin
for j := 0 to (kStacks-1) do begin
faces[k].x := n + j;
faces[k].z := n + (j + 1) mod kStacks;
faces[k].y := (n + j + kStacks) mod kVertexCount;
k := k + 1;
faces[k].x := (n + j + kStacks) mod kVertexCount;
faces[k].z := (n + (j + 1) mod kStacks) mod kVertexCount;
faces[k].y := (n + (j + 1) mod kStacks + kStacks) mod kVertexCount;
k := k + 1;
end;
n := n + kStacks;
end;
setlength(vertices, kVertexCount);
setlength(faces, kIndexCount);
ds := 1.0 / kSlices;
dt := 1.0 / kStacks;
// The upper bounds in these loops are tweaked to reduce the
// chance of precision error causing an incorrect # of iterations.
s := 0.0;
i := 0;
while (s < 1 - ds / 2) do begin
s := s + ds;
t := 0;
while (t < 1 - dt / 2) do begin
t := t + dt;
vertices[i] := EvaluateTrefoil(s, t);
i := i+1;
end;
end;
end; // MakeTrefoil()
{$ENDIF}

procedure TMesh.MakePyramid;
begin
{$IFDEF TREFOIL}
MakeTrefoil;
{$ELSE}
{$IFDEF SPHERE}
MakeSphere;
{$ELSE}
Expand All @@ -1136,6 +1237,7 @@ procedure TMesh.MakePyramid;
faces[2] := pti(4,3,0);
faces[3] := pti(1,4,0);
{$ENDIF}
{$ENDIF}
SetDescriptives;
end; // MakePyramid()

Expand Down Expand Up @@ -5265,12 +5367,19 @@ function TMesh.LoadFromFile(const FileName: string): boolean;
begin
result := false;
isEmbeddedEdge := false;
if not FileExistsF(FileName) then exit;
isNode := false;
isFreeSurferMesh := false;
if (FileName = '-') then begin
isRebuildList := true;
CloseOverlays;
self.Close;
MakePyramid;
//result := true;
end;
if not FileExistsF(FileName) then exit;
FileMode := fmOpenRead;
if (FSize(FileName) < 9) then exit;
isBusy := true;
isNode := false;
isFreeSurferMesh := false;
ext := UpperCase(ExtractFileExt(Filename));
isRebuildList := true;
CloseOverlays;
Expand Down Expand Up @@ -5348,7 +5457,7 @@ function TMesh.LoadFromFile(const FileName: string): boolean;
CheckMesh;
SetDescriptives;
if not isZDimIsUp then
SwapYZ;
SwapYZ;
//showmessage(Filename+' '+ inttostr(length(faces))+' '+inttostr(length(vertices)) );
//NormalizeSize;
isBusy := false;
Expand Down
2 changes: 1 addition & 1 deletion meshify.pas
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function MeshPref(min, max: single; out Thresh, Decim: single; out SmoothStyle,
OkBtn.Left := PrefForm.Width - OkBtn.Width - 8;
OkBtn.Parent:=PrefForm;
OkBtn.ModalResult:= mrOK;
{$IFNDEF Darwin} ScaleDPIX(PrefForm, 96);{$ENDIF}
{$IFNDEF Darwin} ScaleDPI(PrefForm, 96);{$ENDIF}
PrefForm.ShowModal;
{$IFDEF USEFLOATSPIN}
Thresh := ThreshEdit.value;
Expand Down
2 changes: 1 addition & 1 deletion scriptengine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ procedure TScriptForm.FormCreate(Sender: TObject);
var
lPos: integer;
begin
{$IFDEF Windows} ScaleDPIX(ScriptForm, 96); {$ENDIF}
{$IFDEF Windows} ScaleDPI(ScriptForm, 96); {$ENDIF}
{$IFNDEF Darwin} AppleMenu.Visible := false; {$ENDIF}
fn := '';
gchanged := False;
Expand Down
Loading

0 comments on commit 8369138

Please sign in to comment.