-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nifti_studio_3D.m
2042 lines (1935 loc) · 93.4 KB
/
nifti_studio_3D.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 [handles] = nifti_studio_3D(varargin)
% NIfTI Studio 3D
% A GUI for 3D rendering NIfTI images (file types: .nii, .nii.gz, .img/.hdr)
%
% Author:
% Elliot Layden, The University of Chicago, 2016-19
%
% Cite:
% Layden, E. A. (2019). NIfTI Studio: A Matlab Toolbox for MRI Image
% Editing and Visualization.
%
% All inputs are in the form of name-value pair arguments. They may go in
% any order, as long as each input is preceded by the correct input name in
% single quotes and a comma (e.g., 'background', image_1, 'ROI', image_2, etc...).
%
% Main Inputs:
% 'background', Multiple input types allowed:
% 1. char/string full-path-to or filename of
% a 3D NIfTI (.nii,.nii.gz) or .img/.hdr pair (specified
% referencing only the .img file)
% -note: It is best practice to specify the full
% path to the file, using,
% e.g. "background = fullfile(<path>,<filename>);".
% 3. timeSeries can be specified as a column vector or as
% a 2D matrix, wherein each column of the matrix
% represents a distinct time series (useful for either
% the case of multiple ROIs or multiple scans/subjects).
% 4. timeSeries can be specified as an already
% loaded image structure as returned by load_nii or
% load_untouch_nii, or as a 4D time series image matrix.
% -note: this option is incompatible with multiple
% time series
% 5. if timeSeries is not specified or is specified as
% empty [], the program will request the user to first
% specify the # of scans/subjects, then the user will be
% prompted to select the appropriate files (either as
% multiple 3D images per scan/subject, or as a single 4D
% image per scan/subject).
% 'background_colors', same input types as background, denoting a 3D image
% of size equal to 'background'; values of voxels
% denote voxelwise colors to be applied to brain
% surface; color scheme can be later changed by
% changing the colormap or color axis in GUI
%
% 'ROI', -Character/String: specified as a filename for a 3D
% image of ROIs, denoted by sequential integer voxel
% values.
% -Cell Array: wherein each cell contains the
% subscript indices of an ROI (row: voxel #; column:
% [x,y,z] subscripts).
%
% 'ROI_colors', same input types as 'ROI', denoting a 3D image
% of size equal to 'ROI'; values of voxels
% denote voxelwise colors to be applied to ROI
% surfaces; color scheme can be later changed by
% changing the colormap or color axis in GUI;
% 'ROI_colors' should denote color values for all ROIs;
% input supercedes any colors denoted by
% 'background_colors' for regions of ROIs
%
% 'connmat', a cell array (one cell per scan) containing a 2D
% matrix (rows = time points; cols = nuisance
% variables); this option can be useful, e.g., if one
% needs to regress out subject-specific motion
% parameters from the data, or if one wants to
% investigate the effect made on correlation matrices
% by different preprocessing options
%
% 'connmat_thresh', a 1x2 vector specifying (1) a threshold for negative
% edges (edges must be lower than this value to be
% displayed), and (2) a threshold for positive edges
% (edges must be higher than this value to be displayed)
%
% 'titles',
%
% TOOLS:
%
% Rotation:
% Pitch (uparrow,downarrow)
% Yaw (leftarrow,rightarrow)
% Roll ('e','r')
% Zoom:
% -smooth zoom (click + drag left (out) or right (in)),
% -click zoom (left click (zoom in), shift + left click (zoom out), right
% click (additional options)
% Pan: click and drag, or use up/down/right/left arrow keys
%
% ADDITIONAL OPTIONS:
%
% File Options:
% 'insert_axes' % existing axes handle(s) (must be a vector of equal length to size(connmat,3)); will plot inside these axes instead of creating new
% 'print' % char: filepath with extension to automatically print to (allowable extensions are .png, .bmp, .tiff)
% 'print_res' % integer specifying dpi (default: 300 dpi)
%
% % View Options (views start from view([180,0]), Anterior)
% 'pitch' % specified in degrees
% 'yaw' % specified in degrees
% 'roll' % specified in degrees (settings below supercede pitch, yaw, roll)
% 'view_spec' % [n_axes x 2 matrix] specifying [azimuth, elevation] (default: view(3), Matlab's default 3D view)
% 'view_angle' % [n_axes x 1 vector] see camva.m for details (can be used to zoom)
% 'cam_pos' % [n_axes x 3 (x,y,z) matrix] see campos.m for details (can be used to pan)
% 'cam_roll' % [n_axes x 1 vector] see camroll.m (can be used for rolling image, as in pitch-yaw-roll)
%
% % Display Options:
% 'roi_labels' % [numrois x 1 cell array] specifying roi labels (not yet enabled)
% 'roi_colors' % [numrois x 3 matrix] specifying RGB color values for each ROI
% 'roi_cmap' % string denoting colormap over which to distribute ROI
% colors (if used, 'roi_colors' input is ignored; default:
% 'jet')
% 'edge_cmap' % string denoting colormap over which to distribute ROI
% colors (if used, 'edge_color' input is ignored; default:
% 'Blue-White-Red')
% 'edge_clim', % [1 x 2] vector denoting color limits for edges
% default: [min, max]
% 'edge_thick_lim', % [1 x 2] vector denoting the min & max absolute values
% for edge thickness mapping; both values must be >= 0, as
% these values are used for mapping the thickness of both
% positive & negative connections
% 'edge_color' % [1 x 3 rgb color vector]; sets all edge colors to single
% color
% 'edge_colors' % [size(connmat,1) x size(connmat,2) x 3 (rbg values)
% matrix] of colors for edges; if used, connmat should be >0
% for any edges present and <=0 for any edges to be ignored
% 'vox_thresh' % numerical value indicating minimum voxel intensity for
% background image (default: 0)
% 'effect' % string specifying effect name (options: 'Normal','Emphasis',
% 'Sketch','Shiny','Metal','Flat')
% 'background_color' % [1x3 vector] RBG color vector
% 'lock_axes' % logical 1/0 (if a multi-axes plot, should rotation, pan,
% zoom, etc. be locked between axes?)
% 'show_axes' % logical 1/0 (display axes, including axes ticks, axes
% labels, etc.)
% 'show_grid' % logical 1/0 (display gridlines?)
% 'xlim', % specify [vector: lower,upper] xlimits of plots in voxel units
% 'ylim', % specify [vector: lower,upper] ylimits of plots in voxel units
% 'zlim', % specify [vector: lower,upper] zlimits of plots in voxel units
% 'axes_color' % [1x3 vector] RBG color vector (default: [.2,.2,.2])
% 'grid_color' % [1x3 vector] RBG color vector (default: [.15,.15,.15])
% 'measure' % string: 'physical', 'voxel' (unit of measure for axes ticks)
% 'physical_units' % string denoting physical units (e.g., mm); if left
% blank, will attempt to determine based on NIfTI / .hdr input
% 'isovalue', % for forming isosurface, see isosurface.m function (default: .5)
% 'patch_reduce_factor' % after forming isosurface, the faces/vertices are
% reduced to a 'patch_reduce_factor' fraction of
% the original number (i.e., .2 = 20% of original
% faces/vertices
%
% % More Display Options:
% 'brightness' % numeric ranging from 0 to 1 (controls color of background lighting) (default: 1)
% 'light_axis' % string: 'x','y', or 'z' (controls which axis light originates from) (default: x)
% 'background_alpha' % numeric ranging from 0 (transparent) to 1 (opaque) (controls transparency of main image/background; default: .5)
% 'roi_alpha' % numeric ranging from 0 (transparent) to 1 (opaque) (controls transparency of ROIs; default: .6)
% 'edge_alpha' % numeric ranging from 0 (transparent) to 1 (opaque) (controls transparency of edges/connections; default: 1)
% 'background_smoothness' % numeric ranging from 1 to 8 (controls extent to which image surface is smoothed; default: 5)
% 'roi_smoothness' % numeric ranging from 1 to 8 (default: 3)
% 'edge_thickness' % numeric ranging from 1 to 20 (default: 7)
% 'sphere_size' % numeric ranging from 0 to 15; (i.e., radius in voxels; default: 4)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n_ticks = 10; % number of tick labels
% Waitbar:
h_wait = waitbar(0, 'Please wait...', 'Name', 'NIfTI Studio 3D');
try
wbch = allchild(h_wait);
jp = wbch(1).JavaPeer;
jp.setIndeterminate(1);
catch
end
% Identify Function Path and Add Helper Scripts:
script_fullpath = mfilename('fullpath');
[script_path,~,~] = fileparts(script_fullpath);
addpath(genpath(script_path))
% Retrieve name-value pair inputs:
inputs = varargin;
parsed_inputs = struct('background',[],'background_colors',[],'ROI',[],...
'ROI_colors',[],'connmat',[],'connmat_thresh',[0,0],'titles',[],...
'insert_axes',[],'print',[],'print_res',300,'view_spec',[],...
'view_angle',[],'cam_pos',[],'cam_roll',[],'roi_labels',[],...
'roi_colors',[],'roi_cmap',[],'vox_thresh',0,'effect',[],...
'background_color',[1,1,1],'lock_axes',1,'show_axes',1,'show_grid',0,...
'axes_color',.2*ones(1,3),'grid_color',.15*ones(1,3),'unit_measure',[],...
'physical_units','','brightness',1,'light_axis','x','background_alpha',...
.5,'roi_alpha',.8,'edge_alpha',1,'background_smoothness',5,...
'roi_smoothness',3,'edge_thickness',7,'edge_cmap',[],'edge_color',[],...
'sphere_size',[],'roi_type',[],'menu_on',1,'pitch',0,'yaw',0,'roll',0,...
'xlim',[],'ylim',[],'zlim',[],'edge_colors',[],'isovalue',.5,...
'patch_reduce_factor', .2, 'edge_clim',[],'edge_thick_lim',[]); % defaults
poss_input = {'background','background_colors','ROI','ROI_colors',...
'connmat','connmat_thresh','titles','insert_axes','print','print_res',...
'view_spec','view_angle','cam_pos','cam_roll','roi_labels',...
'roi_colors','roi_cmap','vox_thresh','effect','background_color',...
'lock_axes','show_axes','show_grid','axis_color','grid_color',...
'unit_measure','physical_units','brightness','light_axis',...
'background_alpha','roi_alpha','edge_alpha','background_smoothness',...
'roi_smoothness','edge_thickness','edge_cmap','edge_color',...
'sphere_size','roi_type','menu_on','pitch','yaw','roll','xlim','ylim',...
'zlim','edge_colors','isovalue','patch_reduce_factor','edge_clim',...
'edge_thick_lim'}; % 47 possible inputs
input_ind = zeros(1,length(poss_input));
for i = 1:length(poss_input)
j = find(strcmp(poss_input{i},inputs));
if ~isempty(j)
input_ind(i) = j;
input1 = inputs{input_ind(i)+1};
parsed_inputs.(poss_input{i}) = input1;
end
end
roi_patch = [];
% Declare Main Variables:
background = parsed_inputs.background;
ROI = parsed_inputs.ROI;
roi_type = 1;
connmat = parsed_inputs.connmat;
connmat_thresh = parsed_inputs.connmat_thresh;
titles = parsed_inputs.titles;
vox_thresh = parsed_inputs.vox_thresh;
isovalue = parsed_inputs.isovalue;
patch_reduce_factor = parsed_inputs.patch_reduce_factor;
rotate_on = true;
zoom_on = false;
pan_on = false;
% Load Background Image
if ~isempty(background)
switch class(background)
case 'char'
try
back_img = load_nii(background);
catch
try
back_img = load_untouch_nii(background);
warning('Non-orthogonal shearing detected in affine matrix of background image. Loaded successfully without applying affine.')
catch
error('Error: failed to load background image')
end
end
imdat = back_img.img;
case 'struct'
try
imdat = background.img;
back_img = background;
catch
error('If input ''background'' is structure, should contain field ''.img''.')
end
otherwise
if isnumeric(background)
imdat = background;
back_img = [];
else
error('Input ''background'' not recognized.')
end
physical_units = 'unknown';
pixdim = ones(1,3);
origin = size(imdat)./2;
end
else
[background, background_path] = uigetfile({'*.nii';'*.nii.gz';'*.img'},...
'Select a 3D image:','MultiSelect','off');
if background_path==0 % Cancel
disp('User cancelled action.'); return;
end
if ischar(background)
try
back_img = load_nii(fullfile(background_path,background));
catch
try
back_img = (fullfile(background_path,background));
warning('Non-orthogonal shearing detected in affine matrix of background image. Loaded successfully without applying affine.')
catch
error('Error: failed to load background image')
end
end
imdat = back_img.img;
end
end
dim = size(imdat);
% Determine Units:
if ~isempty(back_img)
pixdim = back_img.hdr.dime.pixdim(2:4);
try
origin = back_img.hdr.hist.originator(1:3);
switch bitand(back_img.hdr.dime.xyzt_units, 7) % see xform_nii.m, extra_nii_hdr.m
case 1, physical_units = '(m)';
case 2, physical_units = '(mm)';
case 3, physical_units = '(microns)';
otherwise, physical_units = '';
end
catch
warning('Could not obtain origin.')
physical_units = '';
origin = back_img.hdr.dime.dim(2:4)/2;
warning('Failed to retrieve voxel units.')
end
if any(origin == 0)
warning('Could not obtain origin.')
origin = back_img.hdr.dime.dim(2:4)/2;
end
end
% Load Background Voxel-wise Color Data if Available
background_voxel_colors=[];
if ~isempty(parsed_inputs.background_colors)
[background_voxel_colors,~,~] = load_ROI(parsed_inputs.background_colors,dim,'background_colors');
background_voxel_colors(imdat<vox_thresh) = nan;
background_cmin = min(background_voxel_colors(:));
background_cmax = max(background_voxel_colors(:));
end
% Generate Background Patch Data:
imdat(imdat==0) = nan; phys_dim = pixdim.*dim;
% [x,y,z] = ndgrid(linspace(0,phys_dim(1),dim(1)),...
% linspace(0,phys_dim(2),dim(2)),...
% linspace(0,phys_dim(3),dim(3)));
[x,y,z] = ndgrid(1:dim(1),1:dim(2),1:dim(3));
XYZ = reshape([x(:),y(:),z(:),ones(numel(x),1)],...
size(x,1),size(x,2),size(x,3),[]);
if ~isempty(parsed_inputs.background_colors)
main_patch = isosurface(XYZ(:,:,:,1),XYZ(:,:,:,2),XYZ(:,:,:,3), ...
imdat>=vox_thresh, isovalue, background_voxel_colors);
else
main_patch = isosurface(XYZ(:,:,:,1),XYZ(:,:,:,2),XYZ(:,:,:,3), ...
imdat>=vox_thresh, isovalue);
end
main_patch = reducepatch(main_patch, patch_reduce_factor);
A = double(sparse(repmat(main_patch.faces,3,1),repmat(main_patch.faces,1,3), 1)>0);
A = sparse(1:size(A,1),1:size(A,1),1./sum(A,2))*A;
main_vertices = cell(1,8); main_vertices{1} = main_patch.vertices;
for n = 2:8
main_vertices{n} = A*main_vertices{n-1};
end
% Check connmat input and generate axes positions:
if ~isempty(connmat)
n_axes = size(connmat,3);
handles.axes = zeros(1,n_axes);
if n_axes==2
n_rows = 1; n_cols = 2;
row_l = 0; col_l = [0,.5]; row_s = 1; col_s = .499;
elseif n_axes==3
n_rows = 1; n_cols = 3;
row_l = 0; col_l = [0,.333,.666]; row_s = 1; col_s = .332;
elseif n_axes==4
n_rows = 2; n_cols = 2;
row_l = [.5,0]; col_l = [0,.5]; row_s = .499; col_s = .499;
elseif n_axes<=6
n_rows = 2; n_cols = 3;
row_l = [.5,0]; col_l = [0,.333,.666]; row_s = .499; col_s = .332;
elseif n_axes<=8
n_rows = 2; n_cols = 4;
row_l = [.5,0]; col_l = [0,.25,.5,.75]; row_s = .499; col_s = .249;
elseif n_axes<=12
n_rows = 3; n_cols = 4;
row_l = [.666,.333,0]; col_l = [0,.25,.5,.75]; row_s = .332; col_s = .249;
else
warning('Max 12 axes (correlation matrices) are allowed at this time.')
n_rows = 3; n_cols = 4; n_axes = 12;
row_l = [.666,.333,0]; col_l = [0,.25,.5,.75]; row_s = .332; col_s = .249;
end
% Determine Positions:
ax_pos = zeros(n_axes,4); count = 0;
for row = 1:n_rows
for col = 1:n_cols
count = count + 1;
ax_pos(count,:) = [col_l(col),row_l(row),col_s,row_s];
end
end
else
n_axes = 1; handles.axes = 12.32324;
end
% Load ROI Image & Create Patch Data:
if ~isempty(ROI)
[roidat, numrois, roi_dim] = load_ROI(ROI, dim, 'ROI');
roidat(roidat==0) = nan; % roi_dim = size(roidat); numrois = max(roidat(:));
% disp(['Num ROIs: ', num2str(numrois)]) %TODO
% Load ROI Voxel-wise Color Data if Available
if ~isempty(parsed_inputs.ROI_colors)
[roi_voxel_colors, ~, ~] = load_ROI(parsed_inputs.ROI_colors, dim, 'ROI_colors');
else
roi_voxel_colors = roidat;
end
% Map colors to indices:
num_roi_colors = 200; %min(300, numel(unique(roi_voxel_colors((roi_voxel_colors(:)~=0) + (~isnan(roi_voxel_colors(:))) == 2))));
roi_voxel_clim = [min(roi_voxel_colors(:)), max(roi_voxel_colors(:))];
roi_voxel_color_ind = min(num_roi_colors, round( (num_roi_colors-1) * (roi_voxel_colors - roi_voxel_clim(1)) / (abs(diff(roi_voxel_clim))) ) + 1);
% roi_voxel_color_ind(imdat < vox_thresh) = nan;
roi_voxel_color_ind(roidat == 0) = nan;
roi_voxel_colors = roi_voxel_color_ind;
% disp(['ROI colors: ', num2str(numel(unique((roi_voxel_colors((roi_voxel_colors(:)~=0) + (~isnan(roi_voxel_colors(:))) == 2)))))]) %TODO
% Create Patches:
if numrois > 0
if all(roi_dim==dim)
cmap = jet(num_roi_colors);
roi_patch = struct('p',cell(1,numrois),'sphere',cell(1,numrois));
roi_colors = zeros(numrois,3);
roi_vertices = cell(numrois,8);
for i = 1:numrois
roi_patch(i).p = isosurface(XYZ(:,:,:,1),XYZ(:,:,:,2),XYZ(:,:,:,3), ...
roidat==i, isovalue, roi_voxel_colors);
A = double(sparse(repmat(roi_patch(i).p.faces,3,1),...
repmat(roi_patch(i).p.faces,1,3), 1)>0);
A = sparse(1:size(A,1),1:size(A,1),1./sum(A,2))*A;
roi_vertices{i,1} = roi_patch(i).p.vertices;
for n = 2:8
roi_vertices{i,n} = A*roi_vertices{i,n-1};
end
roi_colors(i,:) = cmap(round((i/numrois)*num_roi_colors),:);
end
else
warning('ROI dimensions do not match background dimensions.')
end
end
handles.ROI_patches = zeros(n_axes, numrois); % Patch Object Handles
n_conn = numrois*(numrois-1)/2;
h_line = zeros(n_axes,n_conn);
else
roi_patch = []; connmat = []; h_line = []; numrois = 0;
end
% Parse titles
if isempty(parsed_inputs.titles)
titles = cell(1,n_axes);
else
if ischar(parsed_inputs.titles)
titles = {parsed_inputs.titles};
elseif iscell(parsed_inputs.titles)
titles = parsed_inputs.titles;
end
end
%% Additional Options
% Check for valid 'insert_axes':
if ~isempty(parsed_inputs.insert_axes)
insert_axes = parsed_inputs.insert_axes;
dont_use = 0;
if length(insert_axes) ~= n_axes
warning('Input ''insert_axes'' is not of equal length to size(connmat,3); generating new axes instead.')
dont_use = 1;
else % additional checking
for i = 1:n_axes
if ~isgraphics(insert_axes(i),'axes')
dont_use = 1;
warning('One (or more) axes supplied in input ''insert_axes'' is not a valid axes object; generating new axes instead.')
break;
end
end
end
if dont_use
handles.axes = repmat(91.38372, n_axes, 1);
parsed_inputs.insert_axes = [];
else
handles.axes = insert_axes;
end
end
background_color = parsed_inputs.background_color;
lock_axes = parsed_inputs.lock_axes;
show_axes = parsed_inputs.show_axes;
show_grid = parsed_inputs.show_grid;
axes_color = parsed_inputs.axes_color;
grid_color = parsed_inputs.grid_color;
if ~isempty(parsed_inputs.physical_units) && ischar(parsed_inputs.physical_units)
physical_units = parsed_inputs.physical_units;
end
brightness = parsed_inputs.brightness;
background_alpha = parsed_inputs.background_alpha;
roi_alpha = parsed_inputs.roi_alpha;
edge_alpha = parsed_inputs.edge_alpha;
background_smoothness = parsed_inputs.background_smoothness;
roi_smoothness = parsed_inputs.roi_smoothness;
edge_thickness = parsed_inputs.edge_thickness;
sphere_size = parsed_inputs.sphere_size;
if isempty(sphere_size); sphere_size = 4; end
% Initialize Handles & Options:
handles = struct('figure',[],'axes',[],'titles',[],'background_patches',[],...
'ROI_patches',[],'linkObj',[],'lighting',[]);
handles.figure = 10.28173;
handles.axes = repmat(10.28173,1,n_axes);
handles.titles = repmat(10.28173,1,n_axes);
handles.background_patches = repmat(10.28173,1,n_axes);
handles.ROI_patches = repmat(10.28173,1,n_axes);
handles.linkObj = 33.121348;
handles.lighting = repmat(10.385820,n_axes,2);
lighting_check = repmat(28.17373,1,3);
h_more_opts_fig = 82.28277;
h_colorbar_fig = 28.332737;
ROI_colorbar_fig = 37.163224;
h_edge_colorbar_fig = 28.17278;
background_colors = [1,1,1;0,0,0;.2,.6,.7;0,0,1;1,0,0;0,1,0;0,1,1;1,0,1;1,1,0];
roi_single_colors = [1,0,0;0,0,1;0,1,0;0,1,1;1,0,1;1,1,0;0,0,0];
roi_cmap_options = {'jet','hot','cool','hsv','bone','colorcube','copper',...
'spring','summer','winter','pink','gray'};
%% Initialize Figure & Menus
if isempty(parsed_inputs.insert_axes)
handles.figure = figure('menubar','none','color',background_color,'numbertitle',...
'off','name','NIfTI Studio 3D','units','norm','Position',[.215,.099,.595,.802]); % .25,.16,.51,.69
else
handles.figure = get(parsed_inputs.insert_axes,'Parent');
set(handles.figure,'color',background_color);
end
figure(handles.figure)
if parsed_inputs.menu_on
file_menu = uimenu(handles.figure,'Label','File');
uimenu(file_menu,'Label','Save Figure','Callback',@save_figure_callback);
uimenu(file_menu,'Label','Print Image','Callback',{@print_callback,0});
uimenu(file_menu,'Label','Write Background as .STL (3D Printing)','Callback',@write_stl)
tool_menu = uimenu(handles.figure,'Label','Tools');
h_tools(1) = uimenu(tool_menu,'Label','Rotate','Checked','on','Callback',{@change_tool,1});
h_tools(2) = uimenu(tool_menu,'Label','Zoom','Callback',{@change_tool,2});
h_tools(3) = uimenu(tool_menu,'Label','Pan','Callback',{@change_tool,3});
uimenu(tool_menu,'Label','Camera Toolbar','Checked','off','Callback',@add_camera_toolbar);
view_menu = uimenu(handles.figure,'Label','View');
h_views(1) = uimenu(view_menu,'Label','Left (Y-Z)','Callback',{@change_view,1});
h_views(2) = uimenu(view_menu,'Label','Right (Y-Z)','Callback',{@change_view,2});
h_views(3) = uimenu(view_menu,'Label','Anterior (X-Z)','Callback',{@change_view,3});
h_views(4) = uimenu(view_menu,'Label','Posterior (X-Z)','Callback',{@change_view,4});
h_views(5) = uimenu(view_menu,'Label','Superior (X-Y)','Callback',{@change_view,5});
h_views(6) = uimenu(view_menu,'Label','Inferior (X-Y)','Callback',{@change_view,6});
display_menu = uimenu(handles.figure,'Label','Display');
effects_menu = uimenu(display_menu,'Label','Effects');
h_effects(1) = uimenu(effects_menu,'Label','Normal','Checked','on','Callback',{@change_effects,1});
h_effects(2) = uimenu(effects_menu,'Label','Emphasis','Callback',{@change_effects,2});
h_effects(3) = uimenu(effects_menu,'Label','Sketch','Callback',{@change_effects,3});
h_effects(4) = uimenu(effects_menu,'Label','Shiny','Callback',{@change_effects,4});
h_effects(5) = uimenu(effects_menu,'Label','Metal','Callback',{@change_effects,5});
h_effects(6) = uimenu(effects_menu,'Label','Flat','Callback',{@change_effects,6});
background_menu = uimenu(display_menu,'Label','Background Color');
h_background(1) = uimenu(background_menu,'Label','White','Checked','on','Callback',{@change_background,1});
h_background(2) = uimenu(background_menu,'Label','Black','Callback',{@change_background,2});
h_background(3) = uimenu(background_menu,'Label','Aqua','Callback',{@change_background,3});
h_background(4) = uimenu(background_menu,'Label','Blue','Callback',{@change_background,4});
h_background(5) = uimenu(background_menu,'Label','Red','Callback',{@change_background,5});
h_background(6) = uimenu(background_menu,'Label','Green','Callback',{@change_background,6});
h_background(7) = uimenu(background_menu,'Label','Cyan','Callback',{@change_background,7});
h_background(8) = uimenu(background_menu,'Label','Magenta','Callback',{@change_background,8});
h_background(9) = uimenu(background_menu,'Label','Yellow','Callback',{@change_background,9});
h_background(10) = uimenu(background_menu,'Label','More...','Callback',{@change_background,10});
axes_menu = uimenu(display_menu,'Label','Axes Options');
if n_axes>1; uimenu(axes_menu,'Label','Lock Axes','Checked','on','Callback',@change_lock_axes); end
if parsed_inputs.show_axes
uimenu(axes_menu,'Label','Show Axes','Checked','on','Callback',@change_show_axes);
else
uimenu(axes_menu,'Label','Show Axes','Checked','off','Callback',@change_show_axes);
end
if parsed_inputs.show_grid
menu_grid = uimenu(axes_menu,'Label','Show Grid','Checked','on','Callback',@change_show_grid);
else
menu_grid = uimenu(axes_menu,'Label','Show Grid','Checked','off','Callback',@change_show_grid);
end
axes_limits_menu = uimenu(axes_menu,'Label','Axes Limits');
uimenu(axes_limits_menu,'Label','X Limits','Callback',{@change_axes_limits,1});
uimenu(axes_limits_menu,'Label','Y Limits','Callback',{@change_axes_limits,2});
uimenu(axes_limits_menu,'Label','Z Limits','Callback',{@change_axes_limits,3});
menu_axes_color = uimenu(axes_menu,'Label','Color');
h_ax_color(1) = uimenu(menu_axes_color,'Label','Grey','Checked','on','Callback',{@change_axes_color,1});
h_ax_color(2) = uimenu(menu_axes_color,'Label','Black','Checked','off','Callback',{@change_axes_color,2});
h_ax_color(3) = uimenu(menu_axes_color,'Label','White','Checked','off','Callback',{@change_axes_color,3});
measurements_menu = uimenu(display_menu,'Label','Measurements');
h_units(1) = uimenu(measurements_menu,'Label','Physical Units','Checked','on','Callback',{@change_units,1});
h_units(2) = uimenu(measurements_menu,'Label','Voxels','Checked','off','Callback',{@change_units,2});
uimenu(display_menu,'Label','More...','Callback',@more_display_options);
if ~isempty(parsed_inputs.background_colors)
background_menu = uimenu(handles.figure,'Label','Main Surface');
uimenu(background_menu,'Label','Color Limits','Callback',@change_background_clim);
background_color_spec_menu = uimenu(background_menu,'Label','Color Spectrum');
background_color_spec(1) = uimenu(background_color_spec_menu,'Label','jet','Checked','on','Callback',{@background_cmap_callback,1});
background_color_spec(2) = uimenu(background_color_spec_menu,'Label','Blue-White-Red','Callback',{@background_cmap_callback,2});
background_color_spec(3) = uimenu(background_color_spec_menu,'Label','Red-Blue','Callback',{@background_cmap_callback,3});
background_color_spec(4) = uimenu(background_color_spec_menu,'Label','hot','Callback',{@background_cmap_callback,4});
background_color_spec(5) = uimenu(background_color_spec_menu,'Label','cool','Callback',{@background_cmap_callback,5});
background_color_spec(6) = uimenu(background_color_spec_menu,'Label','hsv','Callback',{@background_cmap_callback,6});
background_color_spec(7) = uimenu(background_color_spec_menu,'Label','bone','Callback',{@background_cmap_callback,7});
background_color_spec(8) = uimenu(background_color_spec_menu,'Label','colorcube','Callback',{@background_cmap_callback,8});
background_color_spec(9) = uimenu(background_color_spec_menu,'Label','copper','Callback',{@background_cmap_callback,9});
background_color_spec(10) = uimenu(background_color_spec_menu,'Label','spring','Callback',{@background_cmap_callback,10});
background_color_spec(11) = uimenu(background_color_spec_menu,'Label','summer','Callback',{@background_cmap_callback,11});
background_color_spec(12) = uimenu(background_color_spec_menu,'Label','winter','Callback',{@background_cmap_callback,12});
background_color_spec(13) = uimenu(background_color_spec_menu,'Label','pink','Callback',{@background_cmap_callback,13});
background_color_spec(14) = uimenu(background_color_spec_menu,'Label','gray','Callback',{@background_cmap_callback,14});
end
if ~isempty(roi_patch)
rois_menu = uimenu(handles.figure,'Label','ROIs');
roi_type_menu = uimenu(rois_menu,'Label','Type');
ROI_patches_types(1) = uimenu(roi_type_menu,'Label','Clusters','Checked','on','Callback',{@change_rois,1});
ROI_patches_types(2) = uimenu(roi_type_menu,'Label','Spheres','Checked','off','Callback',{@change_rois,2,sphere_size});
roi_colors_menu = uimenu(rois_menu,'Label','Color Scheme');
roi_single_colors_menu = uimenu(roi_colors_menu,'Label','Single Color');
ROI_patches_single_colors(1) = uimenu(roi_single_colors_menu,'Label','Red','Callback',{@change_roi_single_colors,1});
ROI_patches_single_colors(2) = uimenu(roi_single_colors_menu,'Label','Blue','Callback',{@change_roi_single_colors,2});
ROI_patches_single_colors(3) = uimenu(roi_single_colors_menu,'Label','Green','Callback',{@change_roi_single_colors,3});
ROI_patches_single_colors(4) = uimenu(roi_single_colors_menu,'Label','Cyan','Callback',{@change_roi_single_colors,4});
ROI_patches_single_colors(5) = uimenu(roi_single_colors_menu,'Label','Magenta','Callback',{@change_roi_single_colors,5});
ROI_patches_single_colors(6) = uimenu(roi_single_colors_menu,'Label','Yellow','Callback',{@change_roi_single_colors,6});
ROI_patches_single_colors(7) = uimenu(roi_single_colors_menu,'Label','Black','Callback',{@change_roi_single_colors,7});
ROI_patches_single_colors(8) = uimenu(roi_single_colors_menu,'Label','More...','Callback',{@change_roi_single_colors,8});
roi_color_spectrum_menu = uimenu(roi_colors_menu,'Label','Color Spectrum');
ROI_patches_color_spec(1) = uimenu(roi_color_spectrum_menu,'Label','jet','Callback',{@roi_colormap_callback,1});
ROI_patches_color_spec(2) = uimenu(roi_color_spectrum_menu,'Label','Red-Blue','Callback',{@roi_colormap_callback,2});
ROI_patches_color_spec(3) = uimenu(roi_color_spectrum_menu,'Label','Blue-White-Red','Callback',{@roi_colormap_callback,3});
ROI_patches_color_spec(4) = uimenu(roi_color_spectrum_menu,'Label','hot','Callback',{@roi_colormap_callback,4});
ROI_patches_color_spec(5) = uimenu(roi_color_spectrum_menu,'Label','cool','Callback',{@roi_colormap_callback,5});
ROI_patches_color_spec(6) = uimenu(roi_color_spectrum_menu,'Label','hsv','Callback',{@roi_colormap_callback,6});
ROI_patches_color_spec(7) = uimenu(roi_color_spectrum_menu,'Label','bone','Callback',{@roi_colormap_callback,7});
ROI_patches_color_spec(8) = uimenu(roi_color_spectrum_menu,'Label','colorcube','Callback',{@roi_colormap_callback,8});
ROI_patches_color_spec(9) = uimenu(roi_color_spectrum_menu,'Label','copper','Callback',{@roi_colormap_callback,9});
ROI_patches_color_spec(10) = uimenu(roi_color_spectrum_menu,'Label','spring','Callback',{@roi_colormap_callback,10});
ROI_patches_color_spec(11) = uimenu(roi_color_spectrum_menu,'Label','summer','Callback',{@roi_colormap_callback,11});
ROI_patches_color_spec(12) = uimenu(roi_color_spectrum_menu,'Label','winter','Callback',{@roi_colormap_callback,12});
ROI_patches_color_spec(13) = uimenu(roi_color_spectrum_menu,'Label','pink','Callback',{@roi_colormap_callback,13});
ROI_patches_color_spec(14) = uimenu(roi_color_spectrum_menu,'Label','gray','Callback',{@roi_colormap_callback,14});
end
if ~isempty(connmat)
edges_menu = uimenu(handles.figure,'Label','Connections');
uimenu(edges_menu,'Label','Color Limits','Callback',@change_edges_clim);
edge_colors_menu = uimenu(edges_menu,'Label','Color Scheme');
edges_single_colors_menu = uimenu(edge_colors_menu,'Label','Single Color');
h_edges_single_colors(1) = uimenu(edges_single_colors_menu,'Label','Red','Callback',{@change_edges_single_colors,1});
h_edges_single_colors(2) = uimenu(edges_single_colors_menu,'Label','Blue','Callback',{@change_edges_single_colors,2});
h_edges_single_colors(3) = uimenu(edges_single_colors_menu,'Label','Green','Callback',{@change_edges_single_colors,3});
h_edges_single_colors(4) = uimenu(edges_single_colors_menu,'Label','Cyan','Callback',{@change_edges_single_colors,4});
h_edges_single_colors(5) = uimenu(edges_single_colors_menu,'Label','Magenta','Callback',{@change_edges_single_colors,5});
h_edges_single_colors(6) = uimenu(edges_single_colors_menu,'Label','Yellow','Callback',{@change_edges_single_colors,6});
h_edges_single_colors(7) = uimenu(edges_single_colors_menu,'Label','Black','Callback',{@change_edges_single_colors,7});
h_edges_single_colors(8) = uimenu(edges_single_colors_menu,'Label','More...','Callback',{@change_edges_single_colors,8});
edges_color_spec_menu = uimenu(edge_colors_menu,'Label','Color Spectrum');
edges_color_spec(1) = uimenu(edges_color_spec_menu,'Label','Blue-White-Red','Checked','on','Callback',{@edges_colormap_callback,1});
edges_color_spec(2) = uimenu(edges_color_spec_menu,'Label','Red-Blue','Callback',{@edges_colormap_callback,2});
edges_color_spec(3) = uimenu(edges_color_spec_menu,'Label','jet','Callback',{@edges_colormap_callback,3});
edges_color_spec(4) = uimenu(edges_color_spec_menu,'Label','hot','Callback',{@edges_colormap_callback,4});
edges_color_spec(5) = uimenu(edges_color_spec_menu,'Label','cool','Callback',{@edges_colormap_callback,5});
edges_color_spec(6) = uimenu(edges_color_spec_menu,'Label','spring','Callback',{@edges_colormap_callback,6});
edges_color_spec(7) = uimenu(edges_color_spec_menu,'Label','summer','Callback',{@edges_colormap_callback,7});
edges_color_spec(8) = uimenu(edges_color_spec_menu,'Label','winter','Callback',{@edges_colormap_callback,8});
edges_color_spec(9) = uimenu(edges_color_spec_menu,'Label','bone','Callback',{@edges_colormap_callback,9});
edges_color_spec(10) = uimenu(edges_color_spec_menu,'Label','copper','Callback',{@edges_colormap_callback,10});
edges_color_spec(11) = uimenu(edges_color_spec_menu,'Label','pink','Callback',{@edges_colormap_callback,11});
edges_color_spec(12) = uimenu(edges_color_spec_menu,'Label','gray','Callback',{@edges_colormap_callback,12});
uimenu(edges_menu,'Label','Connection Thickness','Callback',@more_display_options)
end
end
%% Plot:
handles.background_patches = repmat(38.3827,1,n_axes);
for axes_iter = 1:n_axes
% Initialize Axes and Plot Background Patch
if isempty(parsed_inputs.insert_axes)
if ~isgraphics(handles.axes(axes_iter),'axes') % don't create if supplied by user
if n_axes==1
handles.axes(axes_iter) = axes('parent',handles.figure,'position',[0,0,1,1],'NextPlot','add');
else
handles.axes(axes_iter) = axes('Parent',handles.figure,'Position',ax_pos(axes_iter,:),'NextPlot','add');
hold(handles.axes(axes_iter),'on')
end
else
hold(handles.axes(axes_iter),'on')
end
else
handles.axes(axes_iter) = parsed_inputs.insert_axes;
end
main_patch.vertices = main_vertices{background_smoothness};
if ~isempty(parsed_inputs.background_colors)
handles.background_patches(axes_iter) = patch(main_patch,'parent',...
handles.axes(axes_iter),'edgecolor','none','facevertexcdata',...
main_patch.facevertexcdata,'facecolor','interp',...
'AlphaDataMapping','none','FaceLighting','gouraud','FaceAlpha',...
background_alpha);
% isonormals(imdat,handles.background_patches(axes_iter))
else
handles.background_patches(axes_iter) = patch(main_patch,'parent',...
handles.axes(axes_iter),'edgecolor','none','facevertexcdata',...
repmat([1 1 1],size(main_patch.vertices,1),1),'facecolor','interp',...
'AlphaDataMapping','none','FaceLighting','gouraud','FaceAlpha',...
background_alpha); % 'gouraud' is for viewing curved surfaces
% isonormals(imdat,handles.background_patches(axes_iter))
end
% axis(handles.axes(axes_iter),'equal'); % sets axes to larger than the image (whereas 'tight' fits tightly around)
if isempty(parsed_inputs.view_spec)
view(3); % Matlab's default 3D view angle
end
handles.lighting(axes_iter,1) = light('Position',[-1,0,0],'Visible','on','parent',handles.axes(axes_iter));
handles.lighting(axes_iter,2) = light('Position',[1,0,0],'Visible','on','parent',handles.axes(axes_iter));
set(handles.axes(axes_iter),'units','norm','color',background_color,'xcolor',...
[.5,.5,.5],'ycolor',[.5,.5,.5],'zcolor',[.5,.5,.5]);
xlabel(handles.axes(axes_iter),['X ',physical_units]);
ylabel(handles.axes(axes_iter),['Y ',physical_units]);
zlabel(handles.axes(axes_iter),['Z ',physical_units]);
if show_grid; grid(handles.axes(axes_iter),'on');
else
grid(handles.axes(axes_iter),'off');
end
if show_axes; set(handles.axes(axes_iter),'Visible','on');
else
set(handles.axes(axes_iter),'Visible','off');
end
set(handles.figure,'WindowKeyPressFcn',@keypress_callback)
% rotate3d(handles.axes(axes_iter),'on') % default tool
% Plot ROI Patch:
if ~isempty(roi_patch)
hold on;
for i = 1:numrois
roi_patch(i).p.vertices = roi_vertices{i, roi_smoothness}; %#ok
handles.ROI_patches(axes_iter,i) = patch(roi_patch(i).p,...
'Parent',handles.axes(axes_iter),'EdgeColor','none','FaceVertexCData',...
cmap(round(roi_patch(i).p.facevertexcdata), :),'FaceColor','interp',...
'AlphaDataMapping','none','FaceLighting','gouraud','FaceAlpha',roi_alpha);
% else
% handles.ROI_patches(axes_iter,i) = patch(roi_patch(i).p,...
% 'Parent',handles.axes(axes_iter),'EdgeColor','none','FaceVertexCData',...
% repmat(roi_colors(i,:),size(roi_patch(i).p.vertices,1),1),'FaceColor','interp',...
% 'AlphaDataMapping','none','FaceLighting','gouraud','FaceAlpha',roi_alpha);
% end
end
end
% 3D Line Plots (Edges):
if nargin>2 && ~isempty(connmat)
% Color Mapping:
connmat1 = connmat(:,:,axes_iter);
conndat = connmat1(triu(true(numrois),1));
non_nan = ((conndat<=connmat_thresh(1))+(conndat>=connmat_thresh(2)))>0;
conndat(~non_nan) = nan;
m = 200;
% Color Mapping
if ~isempty(parsed_inputs.edge_clim)
cmin = parsed_inputs.edge_clim(1);
cmax = parsed_inputs.edge_clim(2);
else
cmin = min(conndat); cmax = max(conndat);
end
conndat_norm = min(m,round((m-1)*(conndat-cmin)/(cmax-cmin))+1);
conndat_norm(conndat_norm<=0) = 1; % assure no negative or 0 indices
conndat_norm(~non_nan) = nan;
rb_cmap = bluewhitered(m,cmin,cmax);
conndat_cmap = zeros(numrois); conndat_cmap(triu(true(numrois),1)) = conndat_norm;
conndat_cmap = conndat_cmap + conndat_cmap';
% Thickness Mapping:
conndat_abs = abs(conndat);
% Thickness Mapping:
conndat_abs = abs(conndat);
if ~isempty(parsed_inputs.edge_thick_lim)
cmin_abs = parsed_inputs.edge_thick_lim(1);
cmax_abs = parsed_inputs.edge_thick_lim(2);
else
cmin_abs = min(conndat_abs); cmax_abs = max(conndat_abs);
end
conndat_thick_norm = min(edge_thickness,round((edge_thickness-1)*(conndat_abs-cmin_abs)/(cmax_abs-cmin_abs))+1);
conndat_thick_norm(conndat_thick_norm<=0) = 1; % assure no negative or 0 indices
conndat_thick_norm(~non_nan) = nan;
conndat_tmap = zeros(numrois); conndat_tmap(triu(true(numrois),1)) = conndat_thick_norm;
conndat_tmap = conndat_tmap + conndat_tmap';
% Plot Lines:
count = 0;
for i = 1:numrois-1
for j = i+1:numrois
if ~isnan(conndat_cmap(i,j))
count = count+1;
coords = zeros(2,3);
coords(1,:) = mean(roi_patch(i).p.vertices);
coords(2,:) = mean(roi_patch(j).p.vertices);
% h_line(axes_iter,count) = plot3(ax1(axes_iter),coords(:,1),coords(:,2),coords(:,3),'Color',...
% rb_cmap(conndat_cmap(i,j),:),'LineWidth',conndat_tmap(i,j),'AlignVertexCenters','on');
h_line(axes_iter,count) = patchline(coords(:,1),coords(:,2),coords(:,3),...
'edgecolor',rb_cmap(conndat_cmap(i,j),:),...
'LineWidth',conndat_tmap(i,j),'Parent',handles.axes(axes_iter),'edgealpha',edge_alpha);
end
end
end
end
if ~isempty(titles)
for axes_iter3 = 1:n_axes
handles.titles(axes_iter3) = title(titles{axes_iter3},'Parent',handles.axes(axes_iter3));
end
end
set(handles.axes(axes_iter),'YDir','normal')
end
% Lock Multiple Axes if Requested
if lock_axes && n_axes>1
handles.linkObj = linkprop(handles.axes,{'CameraPosition','CameraTarget',...
'CameraViewAngle','View','PlotBoxAspectRatio','XLim','YLim',...
'ZLim','XTick','XTickLabel','YTick','YTickLabel','ZTick',...
'ZTickLabel'});
end
%% Do additional things if requested by inputs:
% Change view options based on user input:
view([180,0])
if parsed_inputs.pitch~=0
nifti_camorbit(handles.axes,parsed_inputs.pitch,0,'direction','x')
end
if parsed_inputs.yaw~=0
nifti_camorbit(handles.axes,parsed_inputs.yaw,0,'direction','z')
end
if parsed_inputs.roll~=0
nifti_camorbit(handles.axes,parsed_inputs.roll,0,'direction','y')
end
% View Specification:
if ~isempty(parsed_inputs.view_spec) && all(size(parsed_inputs.view_spec)==[n_axes,2])
for i = 1:n_axes
view(handles.axes(i),parsed_inputs.view_spec(i,:))
end
end
% View Angle
if ~isempty(parsed_inputs.view_angle) && (length(parsed_inputs.view_angle)==n_axes)
for i = 1:n_axes
camva(handles.axes(i),parsed_inputs.view_angle(i))
end
end
% Camera Position
if ~isempty(parsed_inputs.cam_pos) && all(size(parsed_inputs.cam_pos)==[n_axes,3])
for i = 1:n_axes
campos(handles.axes(i),parsed_inputs.cam_pos(i,:))
end
end
% Camera Roll
if ~isempty(parsed_inputs.cam_roll) && (length(parsed_inputs.cam_roll)==n_axes)
for i = 1:n_axes
% axes(handles.axes(i)) %#ok
% camroll(parsed_inputs.cam_roll(i))
roll_nifti(handles.axes(i),parsed_inputs.cam_roll(i))
end
end
% Change ROI Colors:
if ~isempty(parsed_inputs.roi_colors) && all(size(parsed_inputs.roi_colors)==[numrois,3])
roi_colors = parsed_inputs.roi_colors;
change_rois([],[],2,sphere_size)
end
% Change ROI Color Spec:
if ~isempty(parsed_inputs.roi_cmap) && ischar(parsed_inputs.roi_cmap)
cind = strfind(roi_cmap_options,parsed_inputs.roi_cmap);
which_color = [];
for jx = 1:length(cind)
if ~isempty(cind{jx})
which_color = jx;
break;
end
end
if ~isempty(which_color)
hObject = struct('Label',parsed_inputs.roi_cmap);
roi_colormap_callback(hObject,[],which_color)
else
warning('No available ROI colormap found for input ''roi_cmap''.')
end
end
% Change Edge Colors (Single Color):
if ~isempty(parsed_inputs.edge_color)
if length(parsed_inputs.edge_color)==3
change_edges_single_colors([],[],[],parsed_inputs.edge_color)
else
warning('Input ''edge_color'' should be a single 1x3 RGB vector')
end
end
% Change Edge Color Spec
if ~isempty(parsed_inputs.edge_cmap)
if ischar(parsed_inputs.edge_cmap)
hobject = struct('Label',parsed_inputs.edge_cmap);
switch parsed_inputs.edge_cmap
case 'Blue-White-Red', edges_colormap_callback(hobject,[],1)
case 'Red-Blue', edges_colormap_callback(hobject,[],2)
case 'jet', edges_colormap_callback(hobject,[],3)
case 'hot', edges_colormap_callback(hobject,[],4)
case 'cool', edges_colormap_callback(hobject,[],5)
case 'spring', edges_colormap_callback(hobject,[],6)
case 'summer', edges_colormap_callback(hobject,[],7)
case 'winter', edges_colormap_callback(hobject,[],8)
case 'bone', edges_colormap_callback(hobject,[],9)
case 'copper', edges_colormap_callback(hobject,[],10)
case 'pink', edges_colormap_callback(hobject,[],11)
case 'gray', edges_colormap_callback(hobject,[],12)
otherwise
warning('Input ''edge_colormap'' not found, using default.')
end
else
warning('''edge_cmap'' should be a string denoting a valid Matlab colormap or ''Blue-White-Red'' or ''Red-Blue''')
end
end
% Change Sphere Size:
if ~isempty(parsed_inputs.sphere_size)
hObject = struct('Value',sphere_size);
change_sphere_size(hObject)
end
% Change ROI Type:
if ~isempty(parsed_inputs.roi_type)
switch parsed_inputs.roi_type
case 'cluster'
roi_type = 1;
change_rois([],[],roi_type,[])
case 'sphere'
roi_type = 2;
change_rois([],[],roi_type,sphere_size)
end
end
% Change Effects (can be specific to each axes)
if ~isempty(parsed_inputs.effect) && ischar(parsed_inputs.effect) && ~strcmpi('Normal',parsed_inputs.effect)
effect_options = {'Normal','Emphasis','Sketch','Shiny','Metal','Flat'};
which_effect = [];
for jx = 1:length(effect_options)
TF = strcmpi(effect_options{jx},parsed_inputs.effect); % case insensitive
if TF
which_effect = jx;
break;
end
end
if ~isempty(which_effect)
change_effects([],[],which_effect)
else
warning('No available effect found for input ''effect''.')
end
end
% Change unit of measure if specified:
if ~isempty(parsed_inputs.unit_measure) && ischar(parsed_inputs.unit_measure)
if strcmpi('Voxel',parsed_inputs.unit_measure)
change_units([],[],2)
elseif strcmpi('Physical',parsed_inputs.unit_measure)
else
warning('Invalid input for ''unit_measure''; disregarded')
end
end
% Change Light Axis:
if ~isempty(parsed_inputs.light_axis) && ischar(parsed_inputs.light_axis)
if strcmpi('x',parsed_inputs.light_axis)
elseif strcmpi('y',parsed_inputs.light_axis)
change_light([],[],2)
elseif strcmpi('z',parsed_inputs.light_axis)
change_light([],[],3)
else
warning('Invalid input for ''light_axis'' (should be ''x'',''y'', or ''z'').')
end
end
% Change Brightness:
if brightness~=1
if parsed_inputs.brightness>=0 && parsed_inputs.brightness<=1
hobject = struct('Value',parsed_inputs.brightness);
change_brightness(hobject)
else
warning('Invalid input for ''brightness'' (should be 0 =< brightness <= 1).')
end
end
% Change Edge Colors if specified:
if ~isempty(parsed_inputs.edge_colors) && isnumeric(parsed_inputs.edge_colors)
% upgrade this function
% Delete Lines:
for axes_iterx = 1:n_axes
for ix1 = 1:size(h_line,2)
if isgraphics(h_line(axes_iterx,ix1),'patch')
delete(h_line(axes_iterx,ix1));
end
end
end
% Plot Lines:
count = 0;
for ix1 = 1:numrois-1
for jx1 = ix1+1:numrois
if connmat(ix1,jx1)>0
count = count+1;
coords = zeros(2,3);
coords(1,:) = mean(roi_patch(ix1).p.vertices);
coords(2,:) = mean(roi_patch(jx1).p.vertices);
h_line(axes_iterx,count) = patchline(coords(:,1),coords(:,2),coords(:,3),...
'edgecolor',squeeze(parsed_inputs.edge_colors(ix1,jx1,:)),...
'LineWidth',5,...
'Parent',handles.axes(axes_iterx),'edgealpha',edge_alpha);
end
end
end
% for axes_iterx = 1:n_axes
% count = 0;