-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmainunit.pas
executable file
·7281 lines (6903 loc) · 250 KB
/
mainunit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit mainunit;
{$Include opts.inc} //optiosn: DGL, CoreGL or legacy GL
{$IFDEF LCLgtk3}{$IFNDEF COREGL}
warning: GTK3 only supports OpenGL core - enable COREGL in opts.inc
{$ENDIF}{$ENDIF}
{$mode delphi}{$H+}
{$IFDEF Darwin}
{$modeswitch objectivec1}
{$ENDIF}
{$IFDEF MYPY}{$IFNDEF PY4LAZ}
{$ifdef darwin}
{$ifdef CPUAARCH64}
{$linklib ./PythonBridge/aarch64-darwin/libpython3.7m.a}
{$else}
{$linklib ./PythonBridge/x86_64-darwin/libpython3.7m.a}
{$endif}
{$endif}
{$ifdef linux}
{$linklib c}
{$linklib m}
{$linklib pthread}
{$linklib util}
{$linklib dl}
{$linklib ./PythonBridge/x86_64-linux/libpython3.7m.a}
{$endif}
{$ENDIF}{$ENDIF}
//{$DEFINE DARKMODE}
//{$DEFINE PY4LAZ}
interface
uses
{$IFDEF DGL} dglOpenGL, {$ELSE DGL} {$IFDEF COREGL}glcorearb, {$ELSE} gl, {$ENDIF} {$ENDIF DGL}
fphttpclient, strutils,
{$IFDEF MYPY}
{$IFDEF PY4LAZ}
PythonEngine, PyLib, //use PythonForLazarus
{$ELSE}
Python3Core, PythonBridge, //use PythonPascalBridge
{$ENDIF}
{$ENDIF}
//{$IFDEF SCRIPTING}
//{$ENDIF}
{$IFNDEF UNIX} shellapi, {$ELSE} Process, {$ENDIF}
{$IFDEF Linux} LazFileUtils, {$ENDIF}
{$IFDEF COREGL} gl_core_3d, {$ELSE} gl_legacy_3d, {$ENDIF}
{$IFDEF LHRH} meshlhrh, {$ENDIF}
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
math, ExtCtrls, OpenGLContext, mesh, LCLintf, ComCtrls, Menus, graphtype,
curv, ClipBrd, shaderui, shaderu, prefs, userdir, LCLtype, Spin,
Buttons, matmath, colorTable, Track, types, glcube, glclrbar, define_types,
meshify, zstream, gl_core_matrix, meshify_simplify, CheckLst; //Grids, proc_py,
type
{ TGLForm1 }
TGLForm1 = class(TForm)
LayerList: TCheckListBox;
LayerDarkLabel: TLabel;
LayerDarkEdit: TEdit;
LayerBrightEdit: TEdit;
LayerBrightLabel: TLabel;
LayerColorDrop: TComboBox;
LayerAlphaLabel: TLabel;
LayerAlphaTrack: TTrackBar;
LayerOptionsBtn: TButton;
LeftSplitter: TSplitter;
CenterPanel: TPanel;
LayerAOMapMenu: TMenuItem;
LayerPainHideMenu: TMenuItem;
ExitFullScreenMenu: TMenuItem;
EdgeLayerDrop: TComboBox;
BilateralMenu: TMenuItem;
BilateralEitherMenu: TMenuItem;
BilateralLeftOnlyMenu: TMenuItem;
BilateralRightOnlyMenu: TMenuItem;
MenuItem3: TMenuItem;
OpenBilateralMenu: TMenuItem;
PasteMenu: TMenuItem;
overlayoverlapoverwrite1: TMenuItem;
overlayopacity1: TMenuItem;
PaintModeAutomatic: TMenuItem;
PaintModeHideBrightHideDarkMenu: TMenuItem;
PaintModeHideDarkShowBrightMenu: TMenuItem;
PaintModeShowDarkHideBrightMenu: TMenuItem;
PaintModeShowBirghtShowDark: TMenuItem;
shadermatcap1: TMenuItem;
NextOverlayMenu: TMenuItem;
PrevOverlayMenu: TMenuItem;
OverlaySep: TMenuItem;
overlayload1: TMenuItem;
overlayvisible1: TMenuItem;
S3Label: TLabel;
BGShader: TLabel;
SaveScriptDialog: TSaveDialog;
ScriptingInsertMenu: TMenuItem;
mesh1: TMenuItem;
meshload1: TMenuItem;
meshcolor1: TMenuItem;
meshcurv1: TMenuItem;
meshcreate1: TMenuItem;
meshreversefaces1: TMenuItem;
meshsave1: TMenuItem;
overlays1: TMenuItem;
overlayadditive1: TMenuItem;
overlaycloseall1: TMenuItem;
overlaycolorname1: TMenuItem;
overlayminmax1: TMenuItem;
overlaytransparencyonbackground1: TMenuItem;
overlaycolorfromzero1: TMenuItem;
overlaytranslucent1: TMenuItem;
overlayinvert1: TMenuItem;
overlaysmoothvoxelwisedata1: TMenuItem;
meshoverlayorder1: TMenuItem;
Nodes1: TMenuItem;
edgeload1: TMenuItem;
edgecolor1: TMenuItem;
edgecreate1: TMenuItem;
edgesize1: TMenuItem;
edgethresh1: TMenuItem;
nodeload1: TMenuItem;
nodecolor1: TMenuItem;
nodecreate1: TMenuItem;
nodehemisphere1: TMenuItem;
ndepolarity1: TMenuItem;
nodesize1: TMenuItem;
nodethresh1: TMenuItem;
nodethreshbysizenotcolor1: TMenuItem;
MatCapDrop: TComboBox;
Tracks1: TMenuItem;
trackload1: TMenuItem;
trackprefs1: TMenuItem;
Atlas1: TMenuItem;
atlasgray1: TMenuItem;
atlashide1: TMenuItem;
atlasmaxindex1: TMenuItem;
atlassaturationalpha1: TMenuItem;
atlasstatmap1: TMenuItem;
Dialogs1: TMenuItem;
modalmessage1: TMenuItem;
modelessmessage1: TMenuItem;
Shaders1: TMenuItem;
shaderadjust1: TMenuItem;
shaderambientocclusion1: TMenuItem;
shadername1: TMenuItem;
shaderlightazimuthelevation1: TMenuItem;
shaderxray1: TMenuItem;
MenuItem1: TMenuItem;
Render1: TMenuItem;
azimuth1: TMenuItem;
azimuthelevation1: TMenuItem;
backcolor1: TMenuItem;
cameradistance1: TMenuItem;
camerapan1: TMenuItem;
MenuItem2: TMenuItem;
colorbarvisible1: TMenuItem;
clip1: TMenuItem;
clipazimuthelevation1: TMenuItem;
elevation1: TMenuItem;
orientcubevisible1: TMenuItem;
viewaxial1: TMenuItem;
viewcoronal1: TMenuItem;
viewsagittal1: TMenuItem;
Advanced1: TMenuItem;
bmpzoom1: TMenuItem;
exists1: TMenuItem;
fontname1: TMenuItem;
savebmp1: TMenuItem;
savebmpxy1: TMenuItem;
scriptformvisible1: TMenuItem;
version1: TMenuItem;
quit1: TMenuItem;
Close1: TMenuItem;
resetdefaults1: TMenuItem;
wait1: TMenuItem;
ScriptPanel: TPanel;
ScriptBox: TGroupBox;
ScriptMemo: TMemo;
ScriptOutputMemo: TMemo;
ScriptSplitter: TSplitter;
RightSplitter: TSplitter;
AOLabel: TLabel;
CurvMenu: TMenuItem;
CurvMenuTemp: TMenuItem;
ShaderForBackgroundOnlyCheck: TCheckBox;
GoldColorMenu: TMenuItem;
ConvertAtlas: TMenuItem;
ColorBarMenu: TMenuItem;
BlackClrbarMenu: TMenuItem;
ColorbarSep: TMenuItem;
meshAlphaTrack: TTrackBar;
MeshBlendTrack: TTrackBar;
ROImeshMenu: TMenuItem;
XRayLabel: TLabel;
TransBlackClrbarMenu: TMenuItem;
ColorBarVisibleMenu: TMenuItem;
WhiteClrbarMenu: TMenuItem;
TransWhiteClrBarMenu: TMenuItem;
NewWindowMenu: TMenuItem;
S1Check: TCheckBox;
S6Label: TLabel;
S6Track: TTrackBar;
S1Label: TLabel;
S7Label: TLabel;
S7Track: TTrackBar;
S2Label: TLabel;
S1Track: TTrackBar;
RestrictSep2Menu: TMenuItem;
RestrictHideNodesWithoutEdges: TMenuItem;
S8Label: TLabel;
S8Track: TTrackBar;
S2Track: TTrackBar;
S9Label: TLabel;
S9Track: TTrackBar;
S4Label: TLabel;
S3Track: TTrackBar;
S5Label: TLabel;
S4Track: TTrackBar;
S10Label: TLabel;
S5Track: TTrackBar;
S10Track: TTrackBar;
TrackScalarRangeBtn: TButton;
HelpMenu: TMenuItem;
DisplaySepMenu: TMenuItem;
AdvancedMenu: TMenuItem;
AdditiveOverlayMenu: TMenuItem;
CenterMeshMenu: TMenuItem;
TrackScalarLUTdrop: TComboBox;
TrackScalarNameDrop: TComboBox;
SimplifyMeshMenu: TMenuItem;
SimplifyTracksMenu: TMenuItem;
TransparencySepMenu: TMenuItem;
ReverseFacesMenu: TMenuItem;
SwapYZMenu: TMenuItem;
SaveMeshMenu: TMenuItem;
VolumeToMeshMenu: TMenuItem;
ResetMenu: TMenuItem;
OrientCubeMenu: TMenuItem;
Pref2Menu: TMenuItem;
About2Menu: TMenuItem;
EdgeSizeVariesCheck: TCheckBox;
FileSepMenu: TMenuItem;
occlusionTrack: TTrackBar;
SaveTracksMenu: TMenuItem;
NodeSizeVariesCheck: TCheckBox;
PrefMenu: TMenuItem;
NodeMaxEdit: TFloatSpinEdit;
NodeMinEdit: TFloatSpinEdit;
NodeThreshLabel: TLabel;
NodeThreshDrop: TComboBox;
EdgeSizeLabel: TLabel;
NodeScaleTrack: TTrackBar;
EdgeMinEdit: TFloatSpinEdit;
EdgeMaxEdit: TFloatSpinEdit;
LUTdropEdge: TComboBox;
EdgeBox: TGroupBox;
EdgeColorVariesCheck: TCheckBox;
NodeScaleLabel: TLabel;
EdgeThreshLabel: TLabel;
edgeScaleTrack: TTrackBar;
RestrictSepMenu: TMenuItem;
RestrictAnyEdgeMenu: TMenuItem;
RestrictPosEdgeMenu: TMenuItem;
RestrictNegEdgeMenu: TMenuItem;
RestrictRightMenu: TMenuItem;
RestrictLeftMenu: TMenuItem;
RestrictNoMenu: TMenuItem;
RestrictMenu: TMenuItem;
NodeColorVariesCheck: TCheckBox;
GrayColorMenu: TMenuItem;
BlueColorMenu: TMenuItem;
GreenColorMenu: TMenuItem;
ExitMenu: TMenuItem;
DisplayMenu: TMenuItem;
AnteriorMenu: TMenuItem;
LeftMenu: TMenuItem;
CloseMenu: TMenuItem;
AddNodesMenu: TMenuItem;
CloseNodesMenu: TMenuItem;
LUTdropNode: TComboBox;
SaveMeshDialog: TSaveDialog;
NodeMenu: TMenuItem;
RightMenu: TMenuItem;
InferiorMenu: TMenuItem;
SuperiorMenu: TMenuItem;
PosteriorMenu: TMenuItem;
RedColorItem: TMenuItem;
QuickColorMenu: TMenuItem;
NodeBox: TGroupBox;
MeshColorBox: TGroupBox;
SatLabel: TLabel;
MeshSaturationTrack: TTrackBar;
TrackWidthLabel: TLabel;
TrackLengthTrack: TTrackBar;
TrackLengthLabel: TLabel;
LightAziTrack: TTrackBar;
ClipAziTrack: TTrackBar;
ClipBox: TGroupBox;
ClipTrack: TTrackBar;
ColorDialog1: TColorDialog;
LightElevTrack: TTrackBar;
ClipElevTrack: TTrackBar;
TrackBox: TGroupBox;
LightLabel: TLabel;
DepthLabel: TLabel;
AzimuthLabel: TLabel;
ElevationLabel: TLabel;
MainMenu1: TMainMenu;
AppleMenu: TMenuItem;
FileMenu: TMenuItem;
ColorMenu: TMenuItem;
BackColorMenu: TMenuItem;
AboutMenu: TMenuItem;
EditMenu: TMenuItem;
CopyMenu: TMenuItem;
Memo1: TMemo;
AddOverlayMenu: TMenuItem;
CloseOverlaysMenu: TMenuItem;
AddTracksMenu: TMenuItem;
CloseTracksMenu: TMenuItem;
NodeColorLabel: TLabel;
EdgeColorLabel: TLabel;
TransLabel: TLabel;
TrackDitherLabel: TLabel;
TrackWidthTrack: TTrackBar;
TracksMenu: TMenuItem;
MeshTransparencyTrack: TTrackBar;
TrackDitherTrack: TTrackBar;
Transparency75: TMenuItem;
Transparency25: TMenuItem;
Transparency50: TMenuItem;
Transparency0: TMenuItem;
TransparencyMenu: TMenuItem;
OverlaysMenu: TMenuItem;
OpenDialog: TOpenDialog;
OverlayBox: TGroupBox;
ShaderBox: TGroupBox;
ShaderDrop: TComboBox;
ErrorTimer: TTimer;
OverlayTimer: TTimer;
UpdateTimer: TTimer;
ToolPanel: TScrollBox;
SaveBitmapDialog: TSaveDialog;
SaveMenu: TMenuItem;
ObjectColorMenu: TMenuItem;
OpenMenu: TMenuItem;
BackgroundBox: TGroupBox;
ScriptingMenu: TMenuItem;
ScriptingNewMenu: TMenuItem;
ScriptingOpenMenu: TMenuItem;
ScriptingPythonMenu: TMenuItem;
ScriptingRunMenu: TMenuItem;
ScriptingSaveMenu: TMenuItem;
ScriptOpenDialog: TOpenDialog;
LayerPopup: TPopupMenu;
LayerInvertColorsMenu: TMenuItem;
LayerShowHeaderMenu: TMenuItem;
procedure BilateralMenuClick(Sender: TObject);
procedure CenterPanelClick(Sender: TObject);
procedure EdgeLayerDropChange(Sender: TObject);
procedure ExitFullScreenMenuClick(Sender: TObject);
procedure LayerListClickCheck(Sender: TObject);
procedure LayerPopupPopup(Sender: TObject);
procedure LayerInvertColorsMenuClick(Sender: TObject);
procedure LayerShowHeaderMenuClick(Sender: TObject);
procedure LayerWidgetChange(Sender: TObject);
procedure LayerOptionsBtnClick(Sender: TObject);
procedure LayerContrastKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure LayerListSelectionChange(Sender: TObject; User: boolean);
procedure LayerAlphaTrackMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure LayerListShowHint(Sender: TObject; HintInfo: PHintInfo);
procedure LeftSplitterCanOffset(Sender: TObject; var NewOffset: Integer;
var Accept: Boolean);
procedure LeftSplitterCanResize(Sender: TObject; var NewSize: Integer;
var Accept: Boolean);
procedure LeftSplitterChangeBounds(Sender: TObject);
procedure LeftSplitterMoved(Sender: TObject);
procedure LayerAOMapMenuClick(Sender: TObject);
procedure MatCapDropChange(Sender: TObject);
procedure NodeMinEditKeyPress(Sender: TObject; var Key: char);
procedure OpenBilateralMenuClick(Sender: TObject);
procedure overlays1Click(Sender: TObject);
procedure PaintModeAutomaticMenu(Sender: TObject);
procedure PaintModeMenuClick(Sender: TObject);
procedure PasteMenuClick(Sender: TObject);
procedure PrevOverlayMenuClick(Sender: TObject);
procedure ScriptMemoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
);
procedure Shaders1Click(Sender: TObject);
procedure UpdateLayerBox(NewLayers: boolean);
procedure ScriptingNewMenuClick(Sender: TObject);
procedure ScriptingOpenMenuClick(Sender: TObject);
procedure ScriptingTemplatesMenuClick(Sender: TObject);
procedure ScriptingPascalMenuClick(Sender: TObject);
procedure ScriptingRunMenuClick(Sender: TObject);
procedure ScriptingSaveMenuClick(Sender: TObject);
procedure ScriptingGenerateTemplateMenu(isPython: boolean);
procedure ScriptFormVisible(vis: boolean);
procedure OpenScript(scriptname: string; isShowScriptPanel: boolean = true);
procedure FormDestroy(Sender: TObject);
procedure NodeThreshDropChange(Sender: TObject);
procedure ROImeshMenuClick(Sender: TObject);
function UpdateClrbar: integer;
procedure ClrbarClr(i: integer); overload;
procedure ClrbarClr(r,g,b,a: byte); overload;
procedure UpdateFont(initialSetup: boolean);
procedure ClrbarMenuClick(Sender: TObject);
procedure ColorBarVisibleMenuClick(Sender: TObject);
procedure SetColorBarPosition;
procedure FormChangeBounds(Sender: TObject);
procedure FormShow(Sender: TObject);
function GLBoxBackingWidth: integer;
function GLBoxBackingHeight: integer;
procedure GLboxDblClick(Sender: TObject);
procedure CurvMenuClick(Sender: TObject);
procedure DepthLabelDblClick(Sender: TObject);
procedure NewWindowMenuClick(Sender: TObject);
procedure Quit2TextEditor;
procedure CenterMeshMenuClick(Sender: TObject);
procedure AdditiveOverlayMenuClick(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure GLBoxClick(Sender: TObject);
procedure MeshColorBoxChange(Sender: TObject);
function OpenNode(FilenameIn: string): boolean;
function OpenTrack(FilenameIn: string): boolean;
function OpenOverlay(FilenameIn: string): boolean;
function OpenEdge(FilenameIn: string): boolean;
function OpenMesh(FilenameIn: string): boolean;
function Atlas2Node(FilenameOut: string): boolean;
procedure CheckForUpdates(Sender: TObject);
procedure AboutMenuClick(Sender: TObject);
procedure AddNodesMenuClick(Sender: TObject);
procedure AddOverlayMenuClick(Sender: TObject);
procedure AddTracksMenuClick(Sender: TObject);
procedure AzimuthLabelClick(Sender: TObject);
procedure BackColorMenuClick(Sender: TObject);
procedure ClipTrackChange(Sender: TObject);
procedure CloseMenuClick(Sender: TObject);
procedure CloseNodesMenuClick(Sender: TObject);
procedure CloseOverlaysMenuClick(Sender: TObject);
procedure CloseTracksMenuClick(Sender: TObject);
procedure CopyMenuClick(Sender: TObject);
procedure DepthLabelClick(Sender: TObject);
procedure DisplayMenuClick(Sender: TObject);
procedure ElevationLabelClick(Sender: TObject);
procedure ErrorTimerTimer(Sender: TObject);
procedure GLBoxMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure UpdateLUT(lOverlay,lLUTIndex: integer);
procedure NodePrefChange(Sender: TObject);
procedure OrientCubeMenuClick(Sender: TObject);
procedure OverlayTimerStart;
procedure AdjustFormPos (var lForm: TForm);
procedure OverlayBoxCreate;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure AppDropFiles(Sender: TObject; const FileNames: array of String);
procedure CreateRender(w,h: integer; isToScreen: boolean);
procedure GLboxPaint(Sender: TObject);
procedure GLboxMouseMove(Sender: TObject; Shift: TShiftState; lX, lY: Integer);
procedure GLboxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; lX, lY: Integer);
procedure GLboxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; lX, lY: Integer);
procedure ObjectColorMenuClick(Sender: TObject);
procedure OpenMenuClick(Sender: TObject);
procedure OverlayTimerTimer(Sender: TObject);
procedure OverlayVisible(lOverlay: integer; lVisible: integer);
procedure OverlayInvert(lOverlay: integer; lInvert: boolean);
procedure PrefMenuClick(Sender: TObject);
{$IFDEF LCLCocoa}
procedure SetRetina;
{$IFDEF DARKMODE}procedure SetDarkMode;{$ENDIF}
{$ENDIF}
procedure QuickColorClick(Sender: TObject);
procedure ExitMenuClick(Sender: TObject);
procedure ResetMenuClick(Sender: TObject);
procedure RestrictEdgeMenuClick(Sender: TObject);
procedure RestrictHideNodesWithoutEdgesClick(Sender: TObject);
procedure RestrictMenuClick(Sender: TObject);
procedure ReverseFacesMenuClick(Sender: TObject);
procedure SaveBitmap(FilenameIn: string); overload;
procedure SaveBitmap(FilenameIn: string; lX, lY: integer); overload;
procedure SaveMenuClick(Sender: TObject);
//procedure SaveMz3(var mesh: TMesh; isSaveOverlays: boolean);
procedure SaveTrack (var lTrack: TTrack);
function SaveMeshCore(lFilename: string): boolean;
{$IFDEF LHRH}
procedure SaveMeshLHRH(var mesh: TMeshLHRH; isSaveOverlays: boolean);
{$ENDIF}
procedure SaveMesh(var mesh: TMesh; isSaveOverlays: boolean);
procedure SaveMeshMenuClick(Sender: TObject);
procedure SaveTracksMenuClick(Sender: TObject);
procedure ScalarDropChange(Sender: TObject);
function ScreenShot(lForceRedraw: boolean = false): TBitmap;
function ScreenShotX1: TBitmap;
procedure ScriptPanelDblClick(Sender: TObject);
procedure SetOverlayTransparency(Sender: TObject);
procedure ShaderBoxResize(Sender: TObject);
procedure ShaderDropChange(Sender: TObject);
procedure ShowmessageError(s: string);
procedure GLboxRequestUpdate(Sender: TObject);
procedure SimplifyMeshMenuClick(Sender: TObject);
procedure SimplifyTracksMenuClick(Sender: TObject);
procedure SurfaceAppearanceChange(Sender: TObject);
procedure SwapYZMenuClick(Sender: TObject);
procedure TrackBoxChange(Sender: TObject);
procedure SetTrackAzimuthElevation(ANGLE,AZI,ELEV: single);
procedure TrackScalarRangeBtnClick(Sender: TObject);
procedure UniformChange(Sender: TObject);
procedure UpdateTimerTimer(Sender: TObject);
procedure UpdateImageIntensity;
function ComboBoxName2Index(var lCombo: TComboBox; lName: string; out OK: boolean): integer;
procedure SetDistance(Distance: single);
procedure OVERLAYEXTREME (lOverlay, lMode: integer);
procedure OVERLAYMINMAX (lOverlay: integer; lMin,lMax: single);
procedure OVERLAYCOLORNAME(lOverlay: integer; lFilename: string);
procedure OVERLAYCOLOR(lOverlay: integer; rLo, gLo, bLo, rHi, gHi, bHi: byte);
//procedure SetOrtho (w,h: integer; isMultiSample: boolean);
procedure AddMRU(lFilename: string);
procedure UpdateMRU;
procedure CreateMRU;
procedure OpenMRU(Sender: TObject);//open template or MRU
procedure UpdateToolbar;
procedure MultiPassRenderingToolsUpdate;
procedure VolumeToMeshMenuClick(Sender: TObject);
procedure ShaderForBackgroundOnlyClick(Sender: TObject);
procedure GLInvalidate;
procedure InsertCommand(Sender: TObject);
procedure CompileMainClick(Sender: TObject);
procedure PyIOSendData(Sender: TObject; const Data: AnsiString);
procedure PyIOSendUniData(Sender: TObject; const Data: UnicodeString);
//procedure PythonEngineAfterInit(Sender: TObject);
function PyIsPythonScriptMain(): boolean;
function PyExecMain(): boolean;
function PyCreate: boolean;
procedure GotPythonData(str: UnicodeString);
procedure PyModInitialization(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
GLForm1: TGLForm1;
gCube : TGLCube;
gClrbar: TGLClrbar;
gPrefs : TPrefs;
gElevation : integer =20;
gAzimuth : integer = 250;
{$IFDEF LHRH}
gMesh: TMeshLHRH;
{$ELSE}
gMesh: TMesh;
{$ENDIF}
implementation
//{$IFDEF COREGL}
{$IFDEF LCLcarbon}
This program does not support Carbon
Please choose Project/ProjectOptions, go to the CompilerOptions/Additions&Overrides and set the BuildMode pull-down to "MacOS"
{$ENDIF}
//{$ENDIF}
{$R *.lfm}
uses
{$IFDEF LCLCocoa}
CocoaAll, UserNotification, {$IFDEF DARKMODE}nsappkitext,{$ENDIF} glcocoanscontext,
{$ENDIF}
commandsu;
var
{$IFDEF MYPY}
{$IFDEF PY4LAZ}
PythonIO : TPythonInputOutput;
PyMod: TPythonModule;
PyEngine: TPythonEngine = nil;
{$ELSE}
PyEngine: TPythonModule = nil;
{$ENDIF}
gPyRunning: boolean = false;
{$ENDIF}
gNode: TMesh;
gTrack: TTrack;
gnLUT: integer = 0;
isBusy: boolean = true;
{$IFDEF Darwin}gRetinaScale : single = 1;{$ENDIF}
gDistance : single = 1;
gMouseX : integer = -1;
gMouseY : integer = -1;
GLerror : string = '';
clipPlane : TPoint4f; //clipping bottom
GLbox: TOpenGLControl;
const
//kFname=0;
//kLUT=1;
//kMin=2;
//kMax=3;
kTrackFilter = 'Camino, VTK, MRTrix, Quench, TrakVis, DTIstudio|*.Bfloat;*.Bfloat.gz;*.trk.gz;*.trk;*.tck;*.trx;*.pdb;*.fib;*.vtk;*.dat|Any file|*.*';
procedure CleanStr (var lStr: string);
//remove symbols, set lower case...
var
lLen,lPos: integer;
lS: string;
begin
lLen := length(lStr);
if lLen < 1 then
exit;
lS := '';
for lPos := 1 to lLen do
if lStr[lPos] in ['0'..'9','a'..'z','A'..'Z'] then
lS := lS + AnsiLowerCase(lStr[lPos]);
lStr := lS;
end;
function IsPythonCompatible(lType: integer): boolean;
//current Python can not handle passing array types
var
lTstr: string;
i, len, n, t: integer;
begin
result := true;
lTStr := inttostr(lType);
len := length(lTStr);
i := 1;
while i <= len do begin
if i = len then
n := 1
else begin
n := strtoint(lTStr[i]);
inc(i);
end;
t := strtoint(lTStr[i]);
if (t = 8) or (t = 9) then
result := false;
inc(i);
end;
end;
function TypeStr (lType: integer; isPy: boolean = false): string;
var
lTStr,lStr : string;
i,n,len,lLoop,lT: integer;//1=boolean,2=integer,3=float,4=string[filename]
begin
result := '';
if (lType = 0) and (isPy) then
result := '()';
if lType = 0 then
exit;
lTStr := inttostr(lType);
lStr := '(';
len := length(lTStr);
i := 1;
while i <= len do begin
if i = len then
n := 1
else begin
n := strtoint(lTStr[i]);
inc(i);
end;
lT := strtoint(lTStr[i]);
inc(i);
for lLoop := 1 to n do begin
case lT of
1: begin
if isPy then
lStr := lStr +'1'
else
lStr := lStr +'true';
end;
2: lStr := lStr +'1';
3: begin
if lLoop <= 3 then //for Cutout view, we need six values - make them different so this is a sensible cutout
lStr := lStr +'0.5'
else
lStr := lStr +'1.0';
end;
4: lStr := lStr +'''filename''';
5: lStr := lStr + '''0.2 0.4 0.6; 0.8 S 0.5''';
6: begin //byte
if lLoop <= 3 then //for Cutout view, we need six values - make them different so this is a sensible cutout
lStr := lStr +'1'
else
lStr := lStr +'255';
end;
7: lStr := lStr +'5';//kludge - make integer where 1 is not a good default, e.g. shaderquality
8: lStr := lStr +'[1, 2, 4]';
9: lStr := lStr +'[1.1, 2.5, 4.2]';
else lStr := lStr + '''?''';
end;//case
if lLoop < n then
lStr := lStr+', ';
end;//for each loop
if i < len then
lStr := lStr+', ';
end;
lStr := lStr + ')';
result := lStr;
end;
procedure MyWriteln(const s: string);
begin
GLForm1.ScriptOutputMemo.lines.add(S);
{$IFDEF Unix}writeln(s);{$ENDIF}
end;
procedure printf(const s: string);
begin
MyWriteln(s);
end;
procedure TGLForm1.InsertCommand(Sender: TObject);
var
lStr: string;
isPy: boolean;
begin
{$IFDEF MYPY}
isPy := PyIsPythonScriptMain();
{$ELSE}
isPy := false;
{$ENDIF}
lStr := (Sender as TMenuItem).Hint;
if lStr <> '' then begin
ScriptOutputMemo.Lines.Clear;
ScriptOutputMemo.Lines.Add(lStr);
end;
lStr := (Sender as TMenuItem).Caption;
CleanStr(lStr);
if isPy then begin
if IsPythonCompatible((Sender as TMenuItem).Tag) then
lStr := 'gl.'+lStr+TypeStr((Sender as TMenuItem).Tag, isPy)
else
lStr := '#not yet Python Compatible: gl.'+lStr+TypeStr((Sender as TMenuItem).Tag, isPy)
end else
lStr := lStr+TypeStr((Sender as TMenuItem).Tag)+ ';';
Clipboard.AsText := lStr;
{$IFDEF UNIX}
ScriptMemo.SelText := (lStr)+ kUNIXeoln;
{$ELSE}
ScriptMemo.SelText := (lStr)+ #13#10;
{$ENDIF}
end;
function ScriptDir: string;
begin
result := AppDir+'script';
{$IFDEF UNIX}
if fileexists(result) then exit;
result := '/usr/share/surfice/script';
if fileexists(result) then exit;
result := AppDir+'script'
{$ENDIF}
end;
{$IFDEF MYPY}
function PyVERSION(Self, Args : PPyObject): PPyObject; cdecl;
var
s: string;
begin
s := kVers+{$IFDEF PY4LAZ}'Python-for-Lazarus'{$ELSE}{$ifdef PYTHON_DYNAMIC} 'DynamicPythonBridge'{$ELSE}{$ENDIF}'StaticPythonBridge' {$ENDIF} +' PyLib: '+gPrefs.PyLib;
{$IFDEF PY4LAZ}with GetPythonEngine do {$ENDIF}
Result:= PyString_FromString(PChar(s));
end;
function PyOVERLAYCOUNT(Self, Args : PPyObject): PPyObject; cdecl;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do {$ENDIF}
Result:= PyLong_FromLong(gMesh.OpenOverlays);
end;
function PyRESETDEFAULTS(Self, Args : PPyObject): PPyObject; cdecl;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do {$ENDIF}
Result := PyBool_FromLong(Ord(True));
RESETDEFAULTS;
end;
function PyMESHCURV(Self, Args : PPyObject): PPyObject; cdecl;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do {$ENDIF}
Result:= PyBool_FromLong(Ord(True));
MESHCURV;
//GLForm1.Caption := inttostr(random(888));
end;
function PyMESHREVERSEFACES(Self, Args : PPyObject): PPyObject; cdecl;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do {$ENDIF}
Result:= PyBool_FromLong(Ord(True));
MESHREVERSEFACES;
end;
function BOOL(i: integer): boolean;
begin
result := i <> 0;
end;
function PySAVEBMP(Self, Args : PPyObject): PPyObject; cdecl;
var
PtrName: PChar;
StrName: string;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
//with GetPythonEngine do
if Bool(PyArg_ParseTuple(Args, 's:savebmp', @PtrName)) then
begin
StrName:= string(PtrName);
SAVEBMP(StrName);
end;
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PySAVEBMPXY(Self, Args : PPyObject): PPyObject; cdecl;
var
PtrName: PChar;
StrName: string;
x,y: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'sii:savebmpxy', @PtrName, @x, @y)) then
begin
StrName:= string(PtrName);
SAVEBMPXY(StrName, x, y);
end;
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyCOLORBARCOLOR(Self, Args : PPyObject): PPyObject; cdecl;
var
R,G,B,A: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:=PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'iiii:colorbarcolor', @R,@G,@B,@A)) then
COLORBARCOLOR(R,G,B, A);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
(*
function PyCOLORBARCOLOR(Self, Args : PPyObject): PPyObject; cdecl;
var
A: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'i:colorbarcolor', @A)) then
COLORBARCOLOR(A);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
*)
function PyBACKCOLOR(Self, Args : PPyObject): PPyObject; cdecl;
var
R,G,B: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:=PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'iii:backcolor', @R,@G,@B)) then
BACKCOLOR(R,G,B);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyMESHCOLOR(Self, Args : PPyObject): PPyObject; cdecl;
var
R,G,B: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'iii:meshcolor', @R,@G,@B)) then
MESHCOLOR(R,G,B);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyATLASMAXINDEX(Self, Args : PPyObject): PPyObject; cdecl;
var
i: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyLong_FromLong(-1);
if Bool(PyArg_ParseTuple(Args, 'i:atlasmaxindex', @I)) then
Result:= PyLong_FromLong(ATLASMAXINDEX(I));
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyEXISTS(Self, Args : PPyObject): PPyObject; cdecl;
var
PtrName: PChar;
StrName: string;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
if Bool(PyArg_ParseTuple(Args, 's:exists', @PtrName)) then
begin
StrName := string(PtrName);
Result := PyBool_FromLong(Ord(EXISTS(StrName)));
end;
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyAZIMUTH(Self, Args : PPyObject): PPyObject; cdecl;
var
A: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result := PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'i:azimuth', @A)) then
AZIMUTH(A);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyAZIMUTHELEVATION(Self, Args : PPyObject): PPyObject; cdecl;
var
A,E: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'ii:azimuthelevation', @A, @E)) then
AZIMUTHELEVATION(A,E);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyBMPZOOM(Self, Args : PPyObject): PPyObject; cdecl;
var
Z: integer;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'i:bmpzoom', @Z)) then
bmpzoom(Z);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyCAMERADISTANCE(Self, Args : PPyObject): PPyObject; cdecl;
var
Z: single;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'f:cameradistance', @Z)) then
CAMERADISTANCE(Z);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PySHADERAMBIENTOCCLUSION(Self, Args : PPyObject): PPyObject; cdecl;
var
Z: single;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'f:shaderambientocclusion', @Z)) then
SHADERAMBIENTOCCLUSION(Z);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyCLIP(Self, Args : PPyObject): PPyObject; cdecl;
var
D: single;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'f:clip', @D)) then
CLIP(D);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyCLIPAZIMUTHELEVATION(Self, Args : PPyObject): PPyObject; cdecl;
var
D,A,E: single;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'fff:clipazimuthelevation', @D,@A,@E)) then
CLIPAZIMUTHELEVATION(D,A,E);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyTRACKPREFS(Self, Args : PPyObject): PPyObject; cdecl;
var
D,A,E: single;
begin
{$IFDEF PY4LAZ}with GetPythonEngine do begin{$ENDIF}
Result:= PyBool_FromLong(Ord(True));
if Bool(PyArg_ParseTuple(Args, 'fff:trackprefs', @D,@A,@E)) then
TRACKPREFS(D,A,E);
{$IFDEF PY4LAZ}end;{$ENDIF}
end;
function PyTRACKAZIMUTHELEVATION(Self, Args : PPyObject): PPyObject; cdecl;