/
figure_mri.m
3198 lines (3020 loc) · 144 KB
/
figure_mri.m
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
function varargout = figure_mri(varargin)
% FIGURE_MRI: Application M-file for figure_mri.fig
%
% USAGE: hFig = figure_mri('CreateFigure', FigureId)
% figure_mri('SetFigureStatus', hFig, isEditFiducials, isEditVolume, isOverlay, iEeg, isUpdateLandmarks)
% figure_mri('ColormapChangedCallback', iDS, iFig)
% figure_mri('DisplayFigurePopup', hFig)
%[sMri,handl] = figure_mri('SetupMri', hFig)
%[sMri,handl] = figure_mri('LoadLandmarks', sMri, Handles)
%[sMri,handl] = figure_mri('LoadFiducial', sMri, Handles, FidCategory, FidName, FidColor, hButton, hTitle, PtHandleName)
% figure_mri('SaveMri', hFig)
%[hI,hCH,hCV] = figure_mri('SetupView', hAxes, xySize, imgSize, orientLabels)
% XYZ = figure_mri('GetLocation', cs, sMri, Handles)
% figure_mri('SetLocation', cs, sMri, Handles, XYZ)
% figure_mri('JumpMaximum', hFig)
% figure_mri('MriTransform', hButton, Transf, iDim)
% figure_mri('UpdateMriDisplay', hFig, dims)
% figure_mri('UpdateSurfaceColor', hFig)
% figure_mri('UpdateCrosshairPosition', sMri, Handles)
% figure_mri('UpdateCoordinates', sMri, Handles)
% hPt = figure_mri('PlotPoint', sMri, Handles, ptLoc, ptColor, UserData)
% figure_mri('UpdateVisibleLandmarks', sMri, Handles, slicesToUpdate)
% figure_mri('SetFiducial', hFig, FidCategory, FidName)
% figure_mri('ViewFiducial', hFig, FidCategory, FiducialName)
% figure_mri('FiducialsValidation', MriFile)
% figure_mri('callback_name', ...) : Invoke the named callback.
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Sylvain Baillet, 2004
% Francois Tadel, 2008-2022
eval(macro_method);
end
%% ===== CREATE FIGURE =====
function [hFig, Handles] = CreateFigure(FigureId) %#ok<DEFNU>
import org.brainstorm.icon.*;
import java.awt.*;
import javax.swing.*;
% Get renderer name
if (bst_get('MatlabVersion') <= 803) % zbuffer was removed in Matlab 2014b
rendererName = 'zbuffer';
elseif (bst_get('DisableOpenGL') == 1)
rendererName = 'painters';
else
rendererName = 'opengl';
end
% Disable the Java-related warnings after 2019b
if (bst_get('MatlabVersion') >= 907)
warning('off', 'MATLAB:ui:javacomponent:FunctionToBeRemoved');
end
% ===== FIGURE =====
hFig = figure(...
'Visible', 'off', ...
'NumberTitle', 'off', ...
'IntegerHandle', 'off', ...
'MenuBar', 'none', ...
'Toolbar', 'none', ...
'DockControls', 'off', ...
'Units', 'pixels', ...
'Color', [0 0 0], ...
'Pointer', 'arrow', ...
'Tag', FigureId.Type, ...
'Renderer', rendererName, ...
'BusyAction', 'cancel', ...
'Interruptible', 'off', ...
'CloseRequestFcn', @(h,ev)bst_figures('DeleteFigure',h,ev), ...
'KeyPressFcn', @FigureKeyPress_Callback, ...
'WindowButtonDownFcn', [], ...
'WindowButtonMotionFcn', [], ...
'WindowButtonUpFcn', [], ...
bst_get('ResizeFunction'), @ResizeCallback);
% Set appdata
setappdata(hFig, 'Surface', repmat(db_template('TessInfo'), 0));
setappdata(hFig, 'iSurface', []);
setappdata(hFig, 'StudyFile', []);
setappdata(hFig, 'SubjectFile', []);
setappdata(hFig, 'DataFile', []);
setappdata(hFig, 'ResultsFile', []);
setappdata(hFig, 'isStatic', 1);
setappdata(hFig, 'isStaticFreq',1);
setappdata(hFig, 'Colormap', db_template('ColormapInfo'));
setappdata(hFig, 'ElectrodeDisplay', struct('DisplayMode', 'depth'));
setappdata(hFig, 'AnatAtlas', []);
% ===== AXES =====
% Sagittal
Handles.axs = axes(...
'Parent', hFig, ...
'Units', 'pixels', ...
'DataAspectRatio', [1 1 1], ...
'Tag', 'axs', ...
'BusyAction', 'cancel', ...
'Interruptible', 'off');
% Axial
Handles.axa = axes(...
'Parent', hFig, ...
'Units', 'pixels', ...
'DataAspectRatio', [1 1 1], ...
'Tag', 'axa', ...
'BusyAction', 'cancel', ...
'Interruptible', 'off');
% Coronal
Handles.axc = axes(...
'Parent', hFig, ...
'Units', 'pixels', ...
'DataAspectRatio', [1 1 1], ...
'Tag', 'axc', ...
'BusyAction', 'cancel', ...
'Interruptible', 'off');
% Configure axes
axis([Handles.axs, Handles.axa, Handles.axc], 'off');
% ===== SLIDERS =====
[Handles.jSliderSagittal, Handles.sliderSagittal] = javacomponent(javax.swing.JSlider(0,10,0), [0 0 1 1], hFig);
[Handles.jSliderAxial, Handles.sliderAxial] = javacomponent(javax.swing.JSlider(0,10,0), [0 0 1 1], hFig);
[Handles.jSliderCoronal, Handles.sliderCoronal] = javacomponent(javax.swing.JSlider(0,10,0), [0 0 1 1], hFig);
Handles.jSliderSagittal.setBackground(java.awt.Color(0,0,0));
Handles.jSliderAxial.setBackground(java.awt.Color(0,0,0));
Handles.jSliderCoronal.setBackground(java.awt.Color(0,0,0));
% When clicking on a slider: select the corresponding axis
java_setcb(Handles.jSliderSagittal, 'MouseClickedCallback', @(h,ev)set(hFig, 'CurrentAxes', Handles.axs));
java_setcb(Handles.jSliderAxial, 'MouseClickedCallback', @(h,ev)set(hFig, 'CurrentAxes', Handles.axa));
java_setcb(Handles.jSliderCoronal, 'MouseClickedCallback', @(h,ev)set(hFig, 'CurrentAxes', Handles.axc));
% Set tooltips
Handles.jSliderSagittal.setToolTipText('<HTML>Keyboard shortcuts: <BR><B> [X] / [SHIFT]+[X]<BR> [1] / [2]</B>');
Handles.jSliderCoronal.setToolTipText('<HTML>Keyboard shortcuts: <BR><B> [Y] / [SHIFT]+[Y]<BR> [3] / [4]</B>');
Handles.jSliderAxial.setToolTipText('<HTML>Keyboard shortcuts: <BR><B> [Z] / [SHIFT]+[Z]<BR> [5] / [6]</B>');
% ===== TITLE BARS =====
% Title: Panels
jPanelTitleSagittal = gui_river([0 0], [5 10 0 0]);
jPanelTitleAxial = gui_river([0 0], [5 10 0 0]);
jPanelTitleCoronal = gui_river([0 0], [5 10 0 0]);
jPanelTitleSagittal.setBackground(Color(0,0,0));
jPanelTitleAxial.setBackground(Color(0,0,0));
jPanelTitleCoronal.setBackground(Color(0,0,0));
% Title: Buttons
Handles.jButtonRotateS = gui_component('button', jPanelTitleSagittal, [], '', IconLoader.ICON_MRI_ROTATE, 'Rotate MRI: 90° clockwise around axis X', @(h,ev)MriTransform(hFig, 'Rotate', 1));
Handles.jButtonRotateA = gui_component('button', jPanelTitleAxial, [], '', IconLoader.ICON_MRI_ROTATE, 'Rotate MRI: 90° clockwise around axis Z', @(h,ev)MriTransform(hFig, 'Rotate', 3));
Handles.jButtonRotateC = gui_component('button', jPanelTitleCoronal, [], '', IconLoader.ICON_MRI_ROTATE, 'Rotate MRI: 90° clockwise around axis Y', @(h,ev)MriTransform(hFig, 'Rotate', 2));
Handles.jButtonFlipS = gui_component('button', jPanelTitleSagittal, [], '', IconLoader.ICON_MRI_FLIP, 'Flip MRI anterior-posterior', @(h,ev)MriTransform(hFig, 'Flip', 2));
Handles.jButtonFlipA = gui_component('button', jPanelTitleAxial, [], '', IconLoader.ICON_MRI_FLIP, 'Flip MRI left-right', @(h,ev)MriTransform(hFig, 'Flip', 1));
Handles.jButtonFlipC = gui_component('button', jPanelTitleCoronal, [], '', IconLoader.ICON_MRI_FLIP, 'Flip MRI left-right', @(h,ev)MriTransform(hFig, 'Flip', 1));
Handles.jButtonPermuteS = gui_component('button', jPanelTitleSagittal, [], '', IconLoader.ICON_MRI_PERMUTE, 'Permute MRI dimensions', @(h,ev)MriTransform(hFig, 'Permute', 1));
Handles.jButtonPermuteA = gui_component('button', jPanelTitleAxial, [], '', IconLoader.ICON_MRI_PERMUTE, 'Permute MRI dimensions', @(h,ev)MriTransform(hFig, 'Permute', 3));
Handles.jButtonPermuteC = gui_component('button', jPanelTitleCoronal, [], '', IconLoader.ICON_MRI_PERMUTE, 'Permute MRI dimensions', @(h,ev)MriTransform(hFig, 'Permute', 2));
% Set buttons size
jButtons = [Handles.jButtonRotateS, Handles.jButtonRotateA, Handles.jButtonRotateC, Handles.jButtonFlipS, Handles.jButtonFlipA, Handles.jButtonFlipC, Handles.jButtonPermuteS, Handles.jButtonPermuteA, Handles.jButtonPermuteC];
for i = 1:length(jButtons)
jButtons(i).setPreferredSize(Dimension(20,20));
end
% Title: Labels
Handles.jLabelTitleS = gui_component('label', jPanelTitleSagittal, [], '<HTML> <B>Sagittal</B>', [], [], @(h,ev)set(hFig,'CurrentAxes',Handles.axs));
Handles.jLabelTitleA = gui_component('label', jPanelTitleAxial, [], '<HTML> <B>Axial</B>', [], [], @(h,ev)set(hFig,'CurrentAxes',Handles.axa));
Handles.jLabelTitleC = gui_component('label', jPanelTitleCoronal, [], '<HTML> <B>Coronal</B>', [], [], @(h,ev)set(hFig,'CurrentAxes',Handles.axc));
% Title: Value
Handles.jLabelValue = gui_component('label', jPanelTitleSagittal, 'hfill', 'Value', [], [], @(h,ev)set(hFig,'CurrentAxes',Handles.axs));
Handles.jLabelValue.setHorizontalAlignment(Handles.jLabelValue.RIGHT);
% Add panels to the figure
[Handles.jPanelSagittal, Handles.panelTitleSagittal] = javacomponent(jPanelTitleSagittal, [0 0 1 1], hFig);
[Handles.jPanelAxial, Handles.panelTitleAxial] = javacomponent(jPanelTitleAxial, [0 0 1 1], hFig);
[Handles.jPanelCoronal, Handles.panelTitleCoronal] = javacomponent(jPanelTitleCoronal, [0 0 1 1], hFig);
% ===== OPTION PANELS =====
jPanelOptions = java_create('javax.swing.JPanel');
jPanelOptions.setLayout(java_create('java.awt.GridBagLayout'));
jPanelOptions.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
jPanelOptions.setBackground(Color(0,0,0));
[Handles.jPanelOptions, Handles.panelOptions] = javacomponent(jPanelOptions, [0 0 1 1], hFig);
% GridBag default constraints
c = GridBagConstraints();
c.gridx = 1;
c.weightx = 1;
c.fill = GridBagConstraints.BOTH;
c.insets = Insets(0,0,0,0);
% Panel: Fiducials
c.gridy = 1; c.weighty = 0.8;
Handles.jPanelCS = gui_component('Panel', jPanelOptions, c);
Handles.jPanelCS.setLayout(java_create('java.awt.GridBagLayout'));
jBorder = BorderFactory.createTitledBorder('Fiducials');
jBorder.setTitleFont(bst_get('Font', 11));
jBorder.setTitleColor(Color(.9,.9,.9));
Handles.jPanelCS.setBorder(jBorder);
Handles.jPanelCS.setOpaque(0);
% Additional place holder when the panel is hidden
Handles.jPanelCSHidden = gui_component('Panel', jPanelOptions, c);
Handles.jPanelCSHidden.setOpaque(0);
Handles.jPanelCSHidden.setVisible(0);
% Panel: Display options
c.gridy = 2; c.weighty = 0.5;
Handles.jPanelDisplayOptions = gui_component('Panel', jPanelOptions, c);
Handles.jPanelDisplayOptions.setLayout(java_create('java.awt.GridBagLayout'));
jBorder = BorderFactory.createTitledBorder('Display options');
jBorder.setTitleFont(bst_get('Font', 11));
jBorder.setTitleColor(Color(.9,.9,.9));
Handles.jPanelDisplayOptions.setBorder(jBorder);
Handles.jPanelDisplayOptions.setOpaque(0);
% Panel: Coordinates
c.gridy = 3; c.weighty = 0.7;
Handles.jPanelCoordinates = gui_component('Panel', jPanelOptions, c);
Handles.jPanelCoordinates.setLayout(java_create('java.awt.GridBagLayout'));
jBorder = BorderFactory.createTitledBorder('Coordinates (millimeters)');
jBorder.setTitleFont(bst_get('Font', 11));
jBorder.setTitleColor(Color(.9,.9,.9));
Handles.jPanelCoordinates.setBorder(jBorder);
Handles.jPanelCoordinates.setOpaque(0);
% Panel: Validation
c.gridy = 4; c.weighty = 0.2;
Handles.jPanelValidate = gui_component('Panel', jPanelOptions, c);
Handles.jPanelValidate.setLayout(java_create('java.awt.GridBagLayout'));
Handles.jPanelValidate.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
Handles.jPanelValidate.setOpaque(0);
% ===== FIDUCIALS =====
% Default constrains
c = GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
% Titles and buttons
c.insets = Insets(0,0,0,0);
c.gridx = 1; c.gridy = 1; Handles.jTitleNAS = gui_component('label', Handles.jPanelCS, c, 'NAS: ');
c.gridx = 1; c.gridy = 2; Handles.jTitleLPA = gui_component('label', Handles.jPanelCS, c, 'LPA: ');
c.gridx = 1; c.gridy = 3; Handles.jTitleRPA = gui_component('label', Handles.jPanelCS, c, 'RPA: ');
c.gridx = 4; c.gridy = 1; Handles.jTitleAC = gui_component('label', Handles.jPanelCS, c, 'AC: ');
c.gridx = 4; c.gridy = 2; Handles.jTitlePC = gui_component('label', Handles.jPanelCS, c, 'PC: ');
c.gridx = 4; c.gridy = 3; Handles.jTitleIH = gui_component('label', Handles.jPanelCS, c, 'IH: ');
c.insets = Insets(2,2,2,2);
c.gridx = 2; c.gridy = 1; Handles.jButtonNasSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'SCS', 'NAS'));
c.gridx = 2; c.gridy = 2; Handles.jButtonLpaSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'SCS', 'LPA'));
c.gridx = 2; c.gridy = 3; Handles.jButtonRpaSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'SCS', 'RPA'));
c.gridx = 3; c.gridy = 1; Handles.jButtonNasView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'SCS', 'NAS'));
c.gridx = 3; c.gridy = 2; Handles.jButtonLpaView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'SCS', 'LPA'));
c.gridx = 3; c.gridy = 3; Handles.jButtonRpaView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'SCS', 'RPA'));
c.gridx = 5; c.gridy = 1; Handles.jButtonAcSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'NCS', 'AC'));
c.gridx = 5; c.gridy = 2; Handles.jButtonPcSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'NCS', 'PC'));
c.gridx = 5; c.gridy = 3; Handles.jButtonIhSet = gui_component('button', Handles.jPanelCS, c, 'Set', [], '', @(h,ev)SetFiducial(hFig, 'NCS', 'IH'));
c.gridx = 6; c.gridy = 1; Handles.jButtonAcView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'NCS', 'AC'));
c.gridx = 6; c.gridy = 2; Handles.jButtonPcView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'NCS', 'PC'));
c.gridx = 6; c.gridy = 3; Handles.jButtonIhView = gui_component('button', Handles.jPanelCS, c, 'View', [], '', @(h,ev)ViewFiducial(hFig, 'NCS', 'IH'));
% ===== DISPLAY OPTIONS =====
% Default constrains
c = GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
c.insets = Insets(0,0,0,0);
% Group for radio buttons
groupOrient = ButtonGroup();
% Titles and checkboxes
c.gridx = 1; c.gridy = 1; Handles.jTitleView = gui_component('label', Handles.jPanelDisplayOptions, c);
c.gridx = 2; c.gridy = 1; Handles.jCheckMipAnatomy = gui_component('checkbox', Handles.jPanelDisplayOptions, c, 'MIP: Anatomy', [], '', @(h,ev)checkMip_Callback(hFig,ev));
c.gridx = 2; c.gridy = 2; Handles.jCheckMipFunctional = gui_component('checkbox', Handles.jPanelDisplayOptions, c, 'MIP: Functional', [], '', @(h,ev)checkMip_Callback(hFig,ev));
c.gridx = 3; c.gridy = 1; Handles.jCheckViewCrosshair = gui_component('checkbox', Handles.jPanelDisplayOptions, c, 'Crosshairs', [], '', @(h,ev)checkCrosshair_Callback(hFig,ev));
c.gridx = 3; c.gridy = 2; Handles.jCheckViewSliders = gui_component('checkbox', Handles.jPanelDisplayOptions, c, 'Controls', [], '', @(h,ev)checkViewControls_Callback(hFig,ev));
c.gridx = 4; c.gridy = 1; Handles.jRadioNeurological = gui_component('radio', Handles.jPanelDisplayOptions, c, 'Neurological', groupOrient, '', @(h,ev)orientation_Callback(hFig,ev));
c.gridx = 4; c.gridy = 2; Handles.jRadioRadiological = gui_component('radio', Handles.jPanelDisplayOptions, c, 'Radiological', groupOrient, '', @(h,ev)orientation_Callback(hFig,ev));
% Options selected by default
Handles.jCheckViewCrosshair.setSelected(1);
Handles.jCheckViewSliders.setSelected(1);
% ===== COORDINATES =====
% Default constrains
c = GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weighty = 0.1;
c.insets = Insets(0,0,0,0);
% Titles and labels
c.weightx = 0.1;
c.gridx = 1; c.gridy = 1; Handles.jTitleMRI = gui_component('label', Handles.jPanelCoordinates, c, 'MRI:');
c.gridx = 1; c.gridy = 2; Handles.jTitleSCS = gui_component('label', Handles.jPanelCoordinates, c, 'SCS:');
c.gridx = 1; c.gridy = 3; Handles.jTitleWRL = gui_component('label', Handles.jPanelCoordinates, c, 'World:');
c.gridx = 1; c.gridy = 4; Handles.jTitleMNI = gui_component('label', Handles.jPanelCoordinates, c, 'MNI:');
c.weightx = 0.2;
c.gridx = 2; c.gridy = 1; Handles.jTextCoordMriX = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 3; c.gridy = 1; Handles.jTextCoordMriY = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 4; c.gridy = 1; Handles.jTextCoordMriZ = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 2; c.gridy = 2; Handles.jTextCoordScsX = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 3; c.gridy = 2; Handles.jTextCoordScsY = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 4; c.gridy = 2; Handles.jTextCoordScsZ = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 2; c.gridy = 3; Handles.jTextCoordWrlX = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 3; c.gridy = 3; Handles.jTextCoordWrlY = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 4; c.gridy = 3; Handles.jTextCoordWrlZ = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 2; c.gridy = 4; Handles.jTextCoordMniX = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 3; c.gridy = 4; Handles.jTextCoordMniY = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 4; c.gridy = 4; Handles.jTextCoordMniZ = gui_component('label', Handles.jPanelCoordinates, c, '...');
c.gridx = 2; c.gridy = 4; c.gridwidth = 3;
Handles.jTextNoMni = gui_component('label', Handles.jPanelCoordinates, c, '<HTML> <FONT color="#E00000"><U>Click here to compute MNI normalization</U></FONT>', [], '', @(h,ev)ComputeMniCoordinates(hFig));
% ===== VALIDATION BAR =====
% Default constrains
c = GridBagConstraints();
c.gridy = 1;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.insets = Insets(2,3,2,3);
% Buttons: Zoom-, Zoom+, SetCoord, View3DHead, Cancel, Save
c.gridx = 1; c.weightx = 0.1; Handles.jButtonZoomMinus = gui_component('button', Handles.jPanelValidate, c, '', IconLoader.ICON_ZOOM_MINUS, '<HTML><B>Zoom out<BR>[-] or [CTRL + Mouse scroll]</B><BR>Double-click to reset view', @(h,ev)ButtonZoom_Callback(hFig, '-'));
c.gridx = 2; c.weightx = 0.1; Handles.jButtonZoomPlus = gui_component('button', Handles.jPanelValidate, c, '', IconLoader.ICON_ZOOM_PLUS, '<HTML><B>Zoom in<BR>[+] or [CTRL + Mouse scroll]</B><BR>Double-click to reset view', @(h,ev)ButtonZoom_Callback(hFig, '+'));
c.gridx = 3; c.weightx = 0.1; Handles.jButtonSetCoord = gui_component('button', Handles.jPanelValidate, c, '', IconLoader.ICON_VIEW_SCOUT_IN_MRI, 'Set the current coordinates', @(h,ev)ButtonSetCoordinates_Callback(hFig));
c.gridx = 4; c.weightx = 0.1; Handles.jButtonView3DHead = gui_component('button', Handles.jPanelValidate, c, '', IconLoader.ICON_SURFACE_SCALP, 'View 3D head surface', @(h,ev)ButtonView3DHead_Callback(hFig));
c.gridx = 5; c.weightx = 0.7; gui_component('label', Handles.jPanelValidate, c, '');
c.gridx = 6; c.weightx = 0.3; Handles.jButtonCancel = gui_component('button', Handles.jPanelValidate, c, 'Cancel', [], '', @(h,ev)ButtonCancel_Callback(hFig));
c.gridx = 7; c.weightx = 0.3; Handles.jButtonSave = gui_component('button', Handles.jPanelValidate, c, 'Save', [], '', @(h,ev)ButtonSave_Callback(hFig));
% ===== CONFIGURE OBJECTS =====
% Set labels in white
jLabels = [Handles.jLabelTitleS, Handles.jLabelTitleA, Handles.jLabelTitleC, Handles.jLabelValue, Handles.jTitleNAS, Handles.jTitleLPA, Handles.jTitleRPA, ...
Handles.jTitleAC, Handles.jTitlePC, Handles.jTitleIH, Handles.jCheckViewCrosshair, ...
Handles.jCheckViewSliders, Handles.jCheckMipAnatomy, Handles.jCheckMipFunctional, Handles.jRadioNeurological, Handles.jRadioRadiological, ...
Handles.jTitleMRI, Handles.jTitleSCS, Handles.jTitleMNI, Handles.jTitleWRL, Handles.jTextCoordMriX, Handles.jTextCoordMriY, Handles.jTextCoordMriZ, ...
Handles.jTextCoordScsX, Handles.jTextCoordScsY, Handles.jTextCoordScsZ, Handles.jTextCoordMniX, Handles.jTextCoordMniY, Handles.jTextCoordMniZ, ...
Handles.jTextCoordWrlX, Handles.jTextCoordWrlY, Handles.jTextCoordWrlZ];
for i = 1:length(jLabels)
jLabels(i).setFont(bst_get('Font', 11));
jLabels(i).setForeground(Color(.9,.9,.9));
jLabels(i).setOpaque(0);
end
Handles.jLabelValue.setForeground(Color(.4,.4,.4));
% Set text alignment to right
jLabels = [Handles.jTitleNAS, Handles.jTitleLPA, Handles.jTitleRPA, Handles.jTitleAC, Handles.jTitlePC, Handles.jTitleIH, ...
Handles.jTitleMRI, Handles.jTitleSCS, Handles.jTitleMNI, Handles.jTitleWRL];
for i = 1:length(jLabels)
jLabels(i).setHorizontalAlignment(JTextField.RIGHT);
end
% Set text alignment to center
jLabels = [Handles.jTextCoordMriX, Handles.jTextCoordMriY, Handles.jTextCoordMriZ, Handles.jTextCoordScsX, Handles.jTextCoordScsY, Handles.jTextCoordScsZ, ...
Handles.jTextCoordMniX, Handles.jTextCoordMniY, Handles.jTextCoordMniZ, Handles.jTextCoordWrlX, Handles.jTextCoordWrlY, Handles.jTextCoordWrlZ];
for i = 1:length(jLabels)
jLabels(i).setHorizontalAlignment(JTextField.CENTER);
end
% Set size for fiducial buttons (too big on MacOS)
jButtonsFid = [Handles.jButtonNasView, Handles.jButtonLpaView, Handles.jButtonRpaView, Handles.jButtonNasSet, Handles.jButtonLpaSet, Handles.jButtonRpaSet, ...
Handles.jButtonAcView, Handles.jButtonPcView, Handles.jButtonIhView, Handles.jButtonAcSet, Handles.jButtonPcSet, Handles.jButtonIhSet];
for i = 1:length(jButtonsFid)
jButtonsFid(i).setPreferredSize(Dimension(30,20));
jButtonsFid(i).setMinimumSize(Dimension(15,10));
jButtonsFid(i).setMaximumSize(Dimension(500,25));
end
% Remove margins for buttons
jButtonsAll = [Handles.jButtonZoomMinus, Handles.jButtonZoomPlus, Handles.jButtonSetCoord, Handles.jButtonView3DHead, jButtonsFid, Handles.jButtonSave, Handles.jButtonCancel];
for i = 1:length(jButtonsAll)
jButtonsAll(i).setMargin(java.awt.Insets(0,0,0,0));
end
% ===== PREVIOUS CONFIGURATION =====
% Get saved configuration
MriOptions = bst_get('MriOptions');
% Set MIP anat/functional status
Handles.jCheckMipAnatomy.setSelected(MriOptions.isMipAnatomy);
Handles.jCheckMipFunctional.setSelected(MriOptions.isMipFunctional);
% Load orientation
if MriOptions.isRadioOrient
Handles.jRadioRadiological.setSelected(1);
set([Handles.axs,Handles.axc,Handles.axa], 'XDir', 'reverse');
else
Handles.jRadioNeurological.setSelected(1);
set([Handles.axs,Handles.axc,Handles.axa], 'XDir', 'normal');
end
% ===== OTHER FIGURE HANDLES =====
% Initialize other handles
Handles.hFig = hFig;
Handles.hPointNAS = [];
Handles.hPointLPA = [];
Handles.hPointRPA = [];
Handles.hPointAC = [];
Handles.hPointPC = [];
Handles.hPointIH = [];
Handles.hPointEEG = [];
Handles.hTextEEG = [];
Handles.LocEEG = [];
Handles.HiddenChannels = [];
Handles.isEditFiducials = 1;
Handles.isEditVolume = 1;
Handles.isEditChannels = 0;
Handles.isOverlay = 1;
Handles.isEeg = 0;
Handles.isEegLabels = 1;
Handles.isModifiedMri = 0;
end
%% =======================================================================================
% ===== FIGURE CALLBACKS ================================================================
% =======================================================================================
%% ===== RESIZE CALLBACK =====
function ResizeCallback(hFig, varargin)
% Get figure position and size in pixels
figPos = get(hFig, 'Position');
% Get figure Handles
Handles = bst_figures('GetFigureHandles', hFig);
% Scale figure
Scaling = bst_get('InterfaceScaling') / 100;
% Configuration
if ~Handles.jCheckViewSliders.isSelected()
sliderH = 0;
titleH = 0;
else
sliderH = 20 .* Scaling;
titleH = 25 .* Scaling;
end
% Get colorbar
hColorbar = findobj(hFig, '-depth', 1, 'Tag', 'Colorbar');
% Reserve space for the colorbar
if ~isempty(hColorbar)
colorbarMargin = 45 .* Scaling;
else
colorbarMargin = 0;
end
% Positioning of the 4 quadrants of the figure:
% [ Coronal | Sagittal ]
% [ Axial | Options ]
blockSize = [floor((figPos(3) - colorbarMargin)/2), floor(figPos(4)/2)];
posS = [blockSize(1)+1, blockSize(2)+1, blockSize(1), blockSize(2)];
posA = [ 1, 1, blockSize(1), blockSize(2)];
posC = [ 1, blockSize(2)+1, blockSize(1), blockSize(2)];
posO = [blockSize(1)+1, 1, blockSize(1), blockSize(2)];
% Position all the basic blocks
set(Handles.axs, 'Position', max([1 1 1 1], posS + [0, sliderH, 0, -(sliderH + titleH)]));
set(Handles.axa, 'Position', max([1 1 1 1], posA + [0, sliderH, 0, -(sliderH + titleH)]));
set(Handles.axc, 'Position', max([1 1 1 1], posC + [0, sliderH, 0, -(sliderH + titleH)]));
set(Handles.panelOptions, 'Position', max([1 1 1 1], posO + [0, 0, colorbarMargin, 0]));
set(Handles.panelTitleSagittal, 'Position', max([1 1 1 1], [posS(1), posS(2)+posS(4)-titleH, posS(3), titleH]));
set(Handles.panelTitleAxial, 'Position', max([1 1 1 1], [posA(1), posA(2)+posA(4)-titleH, posA(3), titleH]));
set(Handles.panelTitleCoronal, 'Position', max([1 1 1 1], [posC(1), posC(2)+posC(4)-titleH, posC(3), titleH]));
set(Handles.sliderSagittal, 'Position', max([1 1 1 1], [posS(1), posS(2), posS(3), sliderH]));
set(Handles.sliderAxial, 'Position', max([1 1 1 1], [posA(1), posA(2), posA(3), sliderH]));
set(Handles.sliderCoronal, 'Position', max([1 1 1 1], [posC(1), posC(2), posC(3), sliderH]));
% Resize colorbar
if ~isempty(hColorbar)
colorbarWidth = 15 .* Scaling;
posColor = [...
figPos(3) - colorbarMargin, ...
posS(2) + sliderH + 15 .* Scaling, ...
colorbarWidth, ...
posS(4) - sliderH - titleH - 15 .* Scaling];
% Reposition the colorbar
set(hColorbar, 'Units', 'pixels', 'Position', max([1 1 1 1], posColor));
end
% === UPDATE IMAGE RATIOS ===
% Get MRI display size
sMri = panel_surface('GetSurfaceMri', hFig);
if ~isempty(sMri)
FOV = size(sMri.Cube(:,:,:,1)) .* sMri.Voxsize;
% Update views
SetupView(Handles.axs, [FOV(2),FOV(3)], [], []);
SetupView(Handles.axc, [FOV(1),FOV(3)], [], []);
SetupView(Handles.axa, [FOV(1),FOV(2)], [], []);
end
end
%% ===== SET FIGURE STATUS =====
function SetFigureStatus(hFig, isEditFiducials, isEditVolume, isOverlay, isEeg, updateLandmarks)
% Parse inputs
if (nargin < 6) || isempty(updateLandmarks)
updateLandmarks = 0;
end
if (nargin < 5) || isempty(isEeg)
isEeg = [];
end
if (nargin < 4) || isempty(isOverlay)
isOverlay = [];
end
if (nargin < 3) || isempty(isEditVolume)
isEditVolume = [];
end
% Get figure handles
Handles = bst_figures('GetFigureHandles', hFig);
% Check for modifications
isChanged = 0;
if ~isempty(isEditFiducials) && (isEditFiducials ~= Handles.isEditFiducials)
Handles.isEditFiducials = isEditFiducials;
isChanged = 1;
end
if ~isempty(isEditVolume) && (isEditVolume ~= Handles.isEditVolume)
Handles.isEditVolume = isEditVolume;
isChanged = 1;
end
if ~isempty(isOverlay) && (isOverlay ~= Handles.isOverlay)
Handles.isOverlay = isOverlay;
isChanged = 1;
end
if ~isempty(isEeg) && (isEeg ~= Handles.isEeg)
Handles.isEeg = isEeg;
isChanged = 1;
end
% If no modification was made: return
if ~isChanged
return;
end
% Warning if surfaces or recordings
SubjectFile = getappdata(hFig, 'SubjectFile');
sSubject = bst_get('Subject', SubjectFile);
sStudies = bst_get('StudyWithSubject', SubjectFile);
if ((~isempty(isEditFiducials) && isEditFiducials) || (~isempty(isEditVolume) && isEditVolume)) && ((~isempty(sSubject) && ~isempty(sSubject.Surface)) || (~isempty(sStudies) && any(~cellfun(@isempty, {sStudies.Channel}))))
isConfirm = java_dialog('confirm', [...
'Surfaces or MEG/EEG recordings have already been imported for subject "' sSubject.Name '".' 10 10 ...
'Editing the MRI orientation or the position of the NAS/LPA/RPA anatomical fiducials' 10 ...
'might break the coregistration between the different files, you might have to ' 10 ...
'import everything again. THERE IS NO UNDO BUTTON - MAKE A BACKUP FIRST.' 10 10 ...
'Are you sure you want to edit the MRI volume now?'], 'Edit MRI');
if ~isConfirm
Handles.isEditVolume = 0;
Handles.isEditFiducials = 0;
end
end
% Update figure handles
bst_figures('SetFigureHandles', hFig, Handles);
% Update controls: Fiducials
Handles.jPanelCS.setVisible(Handles.isEditFiducials);
Handles.jPanelCSHidden.setVisible(~Handles.isEditFiducials);
Handles.jButtonView3DHead.setVisible(Handles.isEditFiducials);
% Close 3D head figure if it was opened during editing.
if ~Handles.isEditFiducials && isfield(Handles, 'hView3DHeadFig') && ~isempty(Handles.hView3DHeadFig) && ishandle(Handles.hView3DHeadFig)
close(Handles.hView3DHeadFig);
end
% Update controls: Edit volume
Handles.jButtonRotateS.setVisible(Handles.isEditVolume);
Handles.jButtonRotateA.setVisible(Handles.isEditVolume);
Handles.jButtonRotateC.setVisible(Handles.isEditVolume);
Handles.jButtonFlipS.setVisible(Handles.isEditVolume);
Handles.jButtonFlipA.setVisible(Handles.isEditVolume);
Handles.jButtonFlipC.setVisible(Handles.isEditVolume);
Handles.jButtonPermuteS.setVisible(Handles.isEditVolume);
Handles.jButtonPermuteA.setVisible(Handles.isEditVolume);
Handles.jButtonPermuteC.setVisible(Handles.isEditVolume);
% Update controls: Validation buttons
isValid = (Handles.isEditFiducials || Handles.isEditVolume || Handles.isEeg);
Handles.jButtonCancel.setVisible(isValid)
Handles.jButtonSave.setVisible(isValid);
% Update controls: Overlay
Handles.jCheckMipFunctional.setVisible(Handles.isOverlay || Handles.isEeg);
% Update fiducials/other landmarks
if updateLandmarks
sMri = panel_surface('GetSurfaceMri', hFig);
UpdateVisibleLandmarks(sMri, Handles);
UpdateVisibleSensors3D(hFig);
end
end
%% ===== KEYBOAD CALLBACK =====
function FigureKeyPress_Callback(hFig, keyEvent)
global TimeSliderMutex;
% ===== PROCESS BY CHARACTERS =====
switch (keyEvent.Character)
% === SCOUTS : GROW/SHRINK ===
case '+'
ButtonZoom_Callback(hFig, '+');
case '-'
ButtonZoom_Callback(hFig, '-');
case {'=', 'equal'}
ApplyCoordsToAllFigures(hFig, 'mni');
case '*'
ApplyCoordsToAllFigures(hFig, 'scs');
otherwise
% ===== PROCESS BY KEYS =====
switch (keyEvent.Key)
% === LEFT, RIGHT, PAGEUP, PAGEDOWN ===
case {'leftarrow', 'rightarrow', 'pageup', 'pagedown', 'home', 'end'}
if isempty(TimeSliderMutex) || ~TimeSliderMutex
panel_time('TimeKeyCallback', keyEvent);
end
% === UP/DOWN: SCROLL SLIDES ===
case 'uparrow'
MouseWheel_Callback(hFig, [], [], 1);
case 'downarrow'
MouseWheel_Callback(hFig, [], [], -1);
% === DATABASE NAVIGATOR ===
case {'f1', 'f2', 'f3', 'f4', 'f6'}
bst_figures('NavigatorKeyPress', hFig, keyEvent);
% CTRL+D : Dock figure
case 'd'
if ismember('control', keyEvent.Modifier)
isDocked = strcmpi(get(hFig, 'WindowStyle'), 'docked');
bst_figures('DockFigure', hFig, ~isDocked);
end
% CTRL+I : Save as image
case 'i'
if ismember('control', keyEvent.Modifier)
out_figure_image(hFig);
end
% CTRL+J : Open as image
case 'j'
if ismember('control', keyEvent.Modifier)
out_figure_image(hFig, 'Viewer');
end
% CTRL+S : Set electrode position
case 's'
if ismember('control', keyEvent.Modifier)
SetElectrodePosition(hFig);
end
% CTRL+E : Set electrode labels visible
case 'e'
if ismember('control', keyEvent.Modifier)
SetLabelVisible(hFig, []);
end
% M : Jump to maximum
case 'm'
JumpMaximum(hFig);
% C : Toggle crosshairs visibility
case 'c'
checkCrosshair_Callback(hFig);
% === SCROLL MRI CUTS ===
case {'x','y','z','1','2','3','4','5','6'}
% Amount to scroll: +1 (no modifier) or -1 (shift key)
if ismember(keyEvent.Key, {'x','y','z'})
if ismember('shift', keyEvent.Modifier)
value = -1;
else
value = 1;
end
end
% Get dimension
switch (keyEvent.Key)
case 'x', dim = 1;
case 'y', dim = 2;
case 'z', dim = 3;
case '1', dim = 2; value = 1;
case '2', dim = 2; value = -1;
case '3', dim = 1; value = 1;
case '4', dim = 1; value = -1;
case '5', dim = 3; value = 1;
case '6', dim = 3; value = -1;
end
% Get Mri and figure Handles
[sMri, TessInfo, iTess, iMri] = panel_surface('GetSurfaceMri', hFig);
Handles = bst_figures('GetFigureHandles', hFig);
% Change position of slices
TessInfo(iTess).CutsPosition(dim) = TessInfo(iTess).CutsPosition(dim) + value;
% Update interface (Surface tab and MRI figure)
figure_mri('SetLocation', 'voxel', sMri, Handles, TessInfo(iTess).CutsPosition);
end
end
end
%% ===== SLIDER CALLBACK =====
function sliderClicked_Callback(hFig, iSlider, ev)
if ~ev.getSource.getModel.getValueIsAdjusting
% Update MRI display
UpdateMriDisplay(hFig, iSlider);
end
end
%% ===== CHECKBOX: MIP ANATOMY/FUNCTIONAL =====
function checkMip_Callback(hFig, varargin)
% Get figure Handles
Handles = bst_figures('GetFigureHandles', hFig);
% Get values for MIP
MriOptions = bst_get('MriOptions');
MriOptions.isMipAnatomy = Handles.jCheckMipAnatomy.isSelected();
MriOptions.isMipFunctional = Handles.jCheckMipFunctional.isSelected();
bst_set('MriOptions', MriOptions);
% Update slices display
UpdateMriDisplay(hFig);
end
%% ===== CHECKBOX: VIEW CROSSHAIR =====
function checkCrosshair_Callback(hFig, varargin)
% Get figure Handles
Handles = bst_figures('GetFigureHandles', hFig);
% Get all the crosshairs in the figure
hCrosshairs = [Handles.crosshairCoronalH, Handles.crosshairCoronalV, ...
Handles.crosshairSagittalH, Handles.crosshairSagittalV, ...
Handles.crosshairAxialH, Handles.crosshairAxialV];
% Update crosshairs visibility
if all(arrayfun(@(c) strcmp(c,'off'),get(hCrosshairs,'Visible')))
set(hCrosshairs, 'Visible', 'on');
Handles.jCheckViewCrosshair.setSelected(1);
else
set(hCrosshairs, 'Visible', 'off');
Handles.jCheckViewCrosshair.setSelected(0);
end
% Also toggle cursor on 3D head figure.
if isfield(Handles, 'hView3DHeadFig') && ~isempty(Handles.hView3DHeadFig) && ishandle(Handles.hView3DHeadFig)
View3DHeadHandles = bst_figures('GetFigureHandles', Handles.hView3DHeadFig);
if Handles.jCheckViewCrosshair.isSelected
set(View3DHeadHandles.hMriPointsFid(4), 'Visible', 'on');
else
set(View3DHeadHandles.hMriPointsFid(4), 'Visible', 'off');
end
end
end
%% ===== CHECKBOX: VIEW SLIDERS =====
function checkViewControls_Callback(hFig, varargin)
% Get figure Handles
Handles = bst_figures('GetFigureHandles', hFig);
% Hide/Show sliders and title bars
hControls = [Handles.sliderAxial, Handles.sliderSagittal, Handles.sliderCoronal, Handles.panelTitleAxial, Handles.panelTitleSagittal, Handles.panelTitleCoronal];
if Handles.jCheckViewSliders.isSelected()
set(hControls, 'Visible', 'on');
else
set(hControls, 'Visible', 'off');
end
% Call resize callback
ResizeCallback(hFig);
end
%% ===== ORIENT: NEURO/RADIO =====
function orientation_Callback(hFig, varargin)
% Get figure Handles
Handles = bst_figures('GetFigureHandles', hFig);
% Get values
isRadio = Handles.jRadioRadiological.isSelected();
% Save value in user preferences
MriOptions = bst_get('MriOptions');
MriOptions.isRadioOrient = isRadio;
bst_set('MriOptions', MriOptions);
% If is radio
if isRadio
set([Handles.axs,Handles.axc,Handles.axa],'XDir', 'reverse');
else
set([Handles.axs,Handles.axc,Handles.axa],'XDir', 'normal');
end
drawnow;
end
%% ===== BUTTON ZOOM =====
function ButtonZoom_Callback(hFig, action, param)
% Parse inputs
if (nargin < 3) || isempty(param)
param = 1.5;
end
% Get figure Handles
sMri = panel_surface('GetSurfaceMri', hFig);
Handles = bst_figures('GetFigureHandles', hFig);
% Get current axis position
mmCoord = GetLocation('mri', sMri, Handles) .* 1000;
% Zoom factor
switch (action)
case '+', Factor = 1 ./ param;
case '-', Factor = param;
case 'reset', Factor = 0;
end
% Prepare list to process
hAxesList = [Handles.axs, Handles.axc, Handles.axa];
axesCoord = [mmCoord([2 3]); mmCoord([1 3]); mmCoord([1 2])];
% Loop on axes
for i = 1:length(hAxesList)
hAxes = hAxesList(i);
% Get initial axis limits
XLimInit = getappdata(hAxes, 'XLimInit');
YLimInit = getappdata(hAxes, 'YLimInit');
% Get current axis limits
XLim = get(hAxes, 'XLim');
YLim = get(hAxes, 'YLim');
% Get new window length
XLim = axesCoord(i,1) + (XLim(2)-XLim(1)) * Factor * [-.5, .5];
YLim = axesCoord(i,2) + (YLim(2)-YLim(1)) * Factor * [-.5, .5];
Len = [XLim(2)-XLim(1), YLim(2)-YLim(1)];
% Get orientation labels
hLabelOrientL = findobj(hAxes, '-depth', 1, 'Tag', 'LabelOrientL');
hLabelOrientR = findobj(hAxes, '-depth', 1, 'Tag', 'LabelOrientR');
% If window length is larger that initial: restore initial
if any(Len == 0) || ((Len(1) >= XLimInit(2)-XLimInit(1)) || (Len(2) >= YLimInit(2)-YLimInit(1))) || (abs(Len(1) - (XLimInit(2)-XLimInit(1))) < 1e-2) || (abs(Len(2) - YLimInit(2)-YLimInit(1)) < 1e-2)
XLim = XLimInit;
YLim = YLimInit;
% Restore orientation labels
set([hLabelOrientL, hLabelOrientR], 'Visible', 'on');
else
% Move view to have a full image (X)
if (XLim(1) < XLimInit(1))
XLim = XLimInit(1) + [0, Len(1)];
elseif (XLim(2) > XLimInit(2))
XLim = XLimInit(2) + [-Len(1), 0];
end
% Move view to have a full image (Y)
if (YLim(1) < YLimInit(1))
YLim = YLimInit(1) + [0, Len(2)];
elseif (YLim(2) > YLimInit(2))
YLim = YLimInit(2) + [-Len(2), 0];
end
% Hide orientation labels
set([hLabelOrientL, hLabelOrientR], 'Visible', 'off');
end
set(hAxes, 'XLim', XLim, 'YLim', YLim);
end
end
%% ===== BUTTON SET COORDINATES =====
function ButtonSetCoordinates_Callback(hFig)
% Get coordinates from the user
res = java_dialog('input', {'<HTML>Enter the [x,y,z] coordinates in only one of<BR>the coordinate systems below (millimeters).<BR><BR>MRI coordinates:', 'SCS coordinates:', 'World coordinates:', 'MNI coordinates:'}, 'Set coordinates', [], {'', '', '', ''});
% If user cancelled: return
if isempty(res) || (length(res) < 3)
return
end
% Get new values
MRI = str2num(res{1}) / 1000;
SCS = str2num(res{2}) / 1000;
World = str2num(res{3}) / 1000;
MNI = str2num(res{4}) / 1000;
% Get Mri and figure Handles
sMri = panel_surface('GetSurfaceMri', hFig);
Handles = bst_figures('GetFigureHandles', hFig);
% Convert coordinates
if (length(MRI) == 3)
% Keep MRI values unchanged
elseif (length(SCS) == 3)
MRI = cs_convert(sMri, 'scs', 'mri', SCS);
elseif (length(World) == 3)
MRI = cs_convert(sMri, 'world', 'mri', World);
elseif (length(MNI) == 3)
MRI = cs_convert(sMri, 'mni', 'mri', MNI);
else
return;
end
% Error message
if isempty(MRI)
bst_error('The requested coordinates system is not available.', 'Coordinates conversions', 0);
return;
end
% Move the slices
SetLocation('mri', sMri, Handles, MRI);
end
%% ===== BUTTON VIEW 3D HEAD =====
function ButtonView3DHead_Callback(hFig)
% global GlobalData;
% Get Mri and figure Handles
[sMri,TessInfo,iTess,iMri] = panel_surface('GetSurfaceMri', hFig); %#ok<ASGLU>
Handles = bst_figures('GetFigureHandles', hFig);
% Could use bst_figures('GetFigureWithSurface') to look for existing figure, but
% seems much simpler to save its handle in the MRI Viewer figure.
if ~isfield(Handles, 'hView3DHeadFig') || isempty(Handles.hView3DHeadFig) || ~ishandle(Handles.hView3DHeadFig)
% Save original fiducial coordinates (if any)
oldSCS = sMri.SCS;
% Define fake fiducials for creating the head surface
sMri.SCS.NAS = [0.5, 1, 0.5] .* size(sMri.Cube) .* sMri.Voxsize;
sMri.SCS.LPA = [0, 0.5, 0.5] .* size(sMri.Cube) .* sMri.Voxsize;
sMri.SCS.RPA = [1, 0.5, 0.5] .* size(sMri.Cube) .* sMri.Voxsize;
[Transf, sMri] = cs_compute(sMri, 'scs');
% Generate head surface
[Vertices, Faces] = tess_isohead(sMri, 20000, 0, 0, '');
% Convert coordinates back to MRI (mm) so that the head surface doesn't have
% to be updated when we move fiducials
Vertices = cs_convert(sMri, 'scs', 'mri', Vertices) * 1000;
% Create figure
SurfAlpha = .2;
Handles.hView3DHeadFig = view_surface_matrix(Vertices, Faces, SurfAlpha);
% Start coordinates selection
setappdata(Handles.hView3DHeadFig, 'isSelectingCoordinates', 1);
set(Handles.hView3DHeadFig, ...
'Pointer', 'cross', ...
'UserData', hFig, ...
'Tag', 'View3DHeadFig');
% Save 3D figure handle in the MRIViewer handles
bst_figures('SetFigureHandles', hFig, Handles);
% Get Brainstorm handles for 3D figure
View3DHeadHandles = bst_figures('GetFigureHandles', Handles.hView3DHeadFig);
View3DHeadHandles.hFig = Handles.hView3DHeadFig;
% Set default view from "front", but we're in MRI coords, so it's "left".
figure_3d('SetStandardView', View3DHeadHandles.hFig, 'left');
% Display fiducial points
FidNames = {'NAS', 'LPA', 'RPA'};
PtsColors = [0 .5 0; 0 .8 0; .4 1 .4; 1 1 0];
hAx = findobj(View3DHeadHandles.hFig, 'Tag', 'Axes3D');
for iFid = 1:length(FidNames)
% Display if possible the fiducials that were already saved
if (length(oldSCS.(FidNames{iFid})) == 3)
MriFidLoc = oldSCS.(FidNames{iFid});
else
MriFidLoc = sMri.SCS.(FidNames{iFid});
end
% Display fiducials, could switch to spheres if this doesn't work well.
View3DHeadHandles.hMriPointsFid(iFid) = line(MriFidLoc(:,1), MriFidLoc(:,2), MriFidLoc(:,3), ...
'Parent', hAx, ...
'LineWidth', 2, ...
'LineStyle', 'none', ...
'MarkerFaceColor', PtsColors(iFid,:), ...
'MarkerEdgeColor', PtsColors(iFid,:), ...
'MarkerSize', 7, ...
'Marker', 'o', ...
'Tag', 'MriPointsFid');
end
% Add cursor cross
iFid = 4;
CursorLoc = GetLocation('mri', sMri, Handles) * 1000;
View3DHeadHandles.hMriPointsFid(iFid) = line(CursorLoc(:,1), CursorLoc(:,2), CursorLoc(:,3), ...
'Parent', hAx, ...
'LineWidth', 2, ...
'LineStyle', 'none', ...
'MarkerEdgeColor', PtsColors(iFid,:), ...
'MarkerSize', 12, ...
'Marker', '+', ...
'Tag', 'ptCoordinates');
bst_figures('SetFigureHandles', View3DHeadHandles.hFig, View3DHeadHandles);
end
% Update current figure selection
if isfield(Handles, 'hView3DHeadFig') && ~isempty(Handles.hView3DHeadFig) && ishandle(Handles.hView3DHeadFig)
bst_figures('SetCurrentFigure', Handles.hView3DHeadFig, '3D');
end
end
%% =======================================================================================
% ===== EXTERNAL CALLBACKS ==============================================================
% =======================================================================================
%% ===== COLORMAP CHANGED =====
% Usage: ColormapChangedCallback(iDS, iFig)
function ColormapChangedCallback(iDS, iFig) %#ok<DEFNU>
global GlobalData;
panel_surface('UpdateSurfaceColormap', GlobalData.DataSet(iDS).Figure(iFig).hFigure);
end
%% ===== POPUP MENU =====
% Show a popup dialog
function DisplayFigurePopup(hFig)
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import org.brainstorm.icon.*;
global GlobalData;
% Create popup menu
jPopup = java_create('javax.swing.JPopupMenu');
% Get figure options
ColormapInfo = getappdata(hFig, 'Colormap');
isOverlay = any(ismember({'source','stat1','stat2','timefreq'}, ColormapInfo.AllTypes));
Handles = bst_figures('GetFigureHandles', hFig);
TessInfo = getappdata(hFig, 'Surface');
% Get figure and dataset
[hFig,iFig,iDS] = bst_figures('GetFigure', hFig);
% ==== Menu colormaps ====
% Create the colormaps menus
bst_colormaps('CreateAllMenus', jPopup, hFig, 0);
% === MRI Options ===
% Smooth factor
if isOverlay
MriOptions = bst_get('MriOptions');
jMenuMri = gui_component('Menu', jPopup, [], 'Overlay options', IconLoader.ICON_ANATOMY);
jItem0 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: None', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 0));
jItem1 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: 1', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 1));
jItem2 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: 2', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 2));
jItem3 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: 3', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 3));
jItem4 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: 4', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 4));
jItem5 = gui_component('radiomenuitem', jMenuMri, [], 'Smooth: 5', [], [], @(h,ev)figure_3d('SetMriSmooth', hFig, 5));
jItem0.setSelected(MriOptions.OverlaySmooth == 0);
jItem1.setSelected(MriOptions.OverlaySmooth == 1);
jItem2.setSelected(MriOptions.OverlaySmooth == 2);
jItem3.setSelected(MriOptions.OverlaySmooth == 3);
jItem4.setSelected(MriOptions.OverlaySmooth == 4);
jItem5.setSelected(MriOptions.OverlaySmooth == 5);
jMenuMri.addSeparator();
% MENU: Interpolation MRI/sources
% Interpolate values
jMenuInterp = gui_component('Menu', jMenuMri, [], 'Interpolation sources>MRI', IconLoader.ICON_ANATOMY);
jCheck = gui_component('checkboxmenuitem', jMenuInterp, [], 'Interpolate values', [], [], @(h,ev)figure_3d('SetGridSmooth', hFig, ~TessInfo.DataSource.GridSmooth));
jCheck.setSelected(TessInfo.DataSource.GridSmooth);
% Distance threshold
jMenuInterp.addSeparator();
jItem1 = gui_component('radiomenuitem', jMenuInterp, [], 'Distance threshold: 2mm', [], [], @(h,ev)figure_3d('SetDistanceThresh', hFig, 2));
jItem2 = gui_component('radiomenuitem', jMenuInterp, [], 'Distance threshold: 4mm', [], [], @(h,ev)figure_3d('SetDistanceThresh', hFig, 4));
jItem3 = gui_component('radiomenuitem', jMenuInterp, [], 'Distance threshold: 6mm', [], [], @(h,ev)figure_3d('SetDistanceThresh', hFig, 6));