forked from andersonwinkler/PALM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palm_viewsurf.m
723 lines (643 loc) · 25.5 KB
/
palm_viewsurf.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
function fighandle = palm_viewsurf(varargin)
% Simple visualisation of surface results still in Octave/MATLAB.
% The principles are generally similar to those of the tool "dpx2map.m",
% described here:
% https://brainder.org/2013/07/28/displaying-vertexwise-and-facewise-brain-maps/
%
% Usage:
% h = palm_viewsurf( ...
% { lh_dat_file, rh_dat_file }, ...
% { lh_srf_file, rh_srf_file }, ...
% Name, Value, ...)
%
% The first argument is a cell-array with two elements: the first is the
% filename of the data to visualise for the left hemisphere, the second is
% the filename of the data for the right hemisphere.
%
% The second argument is also a cell-array with two elements: the first
% is the surface file for the left hemisphere, the second is the surface
% file for the right hemisphere.
%
% File formats for these inputs are those accepted by PALM.
%
% All subsequent arguments are supplied as pairs "Name,Value", as typical
% in many MATLAB/Octave commands. Accepted Names and descriptions are:
%
% MapName : A MATLAB/Octave colourmap (default: 'viridis').
% DataRange : Interval to be used to define the colourscale [min max].
% If not specified, it uses the min and max of the DPX file.
% ShowRange : Interval to be shown (coloured) [min max]. If not specified,
% it uses the same as datarange.
% Dual : True/False. If true, applies the map to the values of no
% overlap between datarange and showrange. Useful for
% thresholded positive+negative maps. Default is false.
% ColourGap : Colour for values that off the colourscale, including NaN.
% Default is light gray, 25%, i.e. [.75 .75 .75];
% COption : True/False. The behavior varies if 'dual' is true or not.
% - For 'dual' = true:
% If coption is false, don't rescale the extremities of the
% colourmap. Default is true, i.e., produce a higher contrast.
% - For 'dual' = false:
% If coption is false, show the out-of-range values with the
% colour specified by 'colourgap'. Default is true, so the
% out-of-range values are shown with the extremities of the
% colourmap.
% MapSize : Maximum number of colours in the colourmap. Default 2^16.
% Title : Title of the figure (to appear at the top of the colourbar).
% Layout : How to distribute the brain views in the page? The
% following layouts are available:
% - 'Simple' : A simple layout meant to be interactively
% explored using the MATLAB/Octave figure tools.
% - 'Cardinal' : Show 4 views (lateral and medial of left and right
% hemispheres), plus colorbar in the centre.
% - 'Left' : Left hemisphere only (lateral and medial).
% - 'Right' : Right hemisphere only (lateral and medial).
% - 'Strip' : Similar to cardinal but shows all views in a
% single row. Useful for stacking subjects.
% - 'Publication' : A well rounded layout, meant to be (nearly) ready
% for publication. It always includes a colourbar.
% - 'Worsley' : The layout proposed by K. Worsley. Always includes
% a colourbar.
% Background : A 3-element vector of the RGB color of the background.
% Default is [1 1 1] (white).
% CamLight : Boolean indicating whether a light should be placed in the
% same location as the camera.
% Lightning : Lighting mode. Valid options are:
% - 'None'
% - 'Flat'
% - 'Gouraud'
% Material : Material mode. Valid options are:
% - 'Dull'
% - 'Shiny'
% - 'Metal'
% Shading : Shading mode. Valid options are:
% - 'Flat'
% - 'Interp'
% - 'Faceted'
% ColourBar : Boolean indicating whether the colour bar should be shown.
% Note that for the 'publication' and 'worsley' layouts, the
% colour bar is always shown.
%
% Example:
% freesurfer_dir = getenv('FREESURFER_DIR');
% data = { ...
% fullfile(freesurfer_dir,'subjects','fsaverage','surf','lh.thickness'), ...
% fullfile(freesurfer_dir,'subjects','fsaverage','surf','rh.thickness') };
% surfs = { ...
% fullfile(freesurfer_dir,'subjects','fsaverage','surf','lh.pial'), ...
% fullfile(freesurfer_dir,'subjects','fsaverage','surf','rh.pial') };
% palm_viewsurf(data,surfs,'layout','cardinal','background',[.5 .5 .5],'colormap','inferno');
%
% _____________________________________
% Anderson M. Winkler
% National Institutes of Health
% Mar/2021
% http://brainder.org
% Defaults
opts.mapname = 'viridis';
opts.datarange = []; % clim, datarange
opts.showrange = [];
opts.dual = false;
opts.colourgap = [.75 .75 .75];
opts.coption = true;
opts.mapsize = 2^14;
opts.title = '';
opts.layout = 'publication';
opts.background = [1 1 1];
opts.camlight = true;
opts.lightning = 'gouraud'; % {'none', 'flat', 'gouraud'}
opts.material = 'dull'; % {'shiny', 'dull', 'metal'}
opts.shading = 'interp'; % {'flat', 'interp', 'faceted'}
opts.colourbar = true;
% Parse inputs and check for most common errors.
dat = varargin{1};
srf = varargin{2};
for a = 3:2:nargin
opts.(lower(varargin{a})) = varargin{a + 1};
end
if numel(opts.datarange) ~= 2 && ~ isempty(opts.datarange)
error('The supplied DataRange has to be a two-element vector, or be empty.');
end
if numel(opts.showrange) ~= 2 && ~ isempty(opts.showrange)
error('The supplied ShowRange has to be a two-element vector, or be empty.');
end
if numel(opts.background) ~= 3 || numel(opts.colourgap) ~= 3
error('The supplied ColourGap or Background has to be a two-element vector, or be empty.');
end
if ~ islogical(opts.dual) || ~ islogical(opts.coption)
error('The supplied Dual or COption must be a logical type (i.e., true/false).');
end
if ~ ischar(opts.title)
error('The supplied Title must be a string.');
end
if ~ islogical(opts.camlight)
error('The CamLight option must be a logical type (i.e., true/false).');
end
if ~ any(strcmpi(opts.lightning,{'none','flat','gouraud'}))
error('Unknown Lightning style: %s',opts.lightning);
end
if ~ any(strcmpi(opts.material,{'shiny','dull','metal'}))
error('Unknown Material style: %s',opts.material);
end
if ~ any(strcmpi(opts.shading,{'flat','interp','faceted'}))
error('Unknown Shading style: %s',opts.shading);
end
if ~ islogical(opts.colourbar)
error('The Colourbar option must be a logical type (i.e., true/false).');
end
if strcmpi(opts.layout,'worsley')
opts.mapname = 'spectral';
end
if palm_isoctave && opts.mapsize > 2^14
error('Octave cannot plot more than 2^14 = 32768 colors.');
end
% Ensure we gave the programs needed to read the data
palm_checkprogs;
% Read input files
dat{1} = palm_miscread(dat{1});
dat{2} = palm_miscread(dat{2});
srf{1} = palm_miscread(srf{1});
srf{2} = palm_miscread(srf{2});
% Merge left and right hemispheres (to be treated as a "third" hemisphere)
srf{3}.data.vtx = vertcat(srf{1}.data.vtx,srf{2}.data.vtx);
srf{3}.data.fac = vertcat(srf{1}.data.fac,srf{2}.data.fac+size(srf{1}.data.vtx,1));
dat{3}.data = vertcat(dat{1}.data,dat{2}.data);
for h = 1:3
dat{h}.data = squeeze(dat{h}.data);
end
% Open a new figure window. The handle will be returned.
fighandle = figure;
% Ensure data and colour ranges are well behaved
if isempty(opts.datarange)
iinf = isinf(dat{3}.data);
inan = isnan(dat{3}.data);
iidx = ~(iinf | inan);
opts.datarange = [min(dat{3}.data(iidx)) max(dat{3}.data(iidx))];
end
if isempty(opts.showrange)
opts.showrange = opts.datarange;
end
opts.showrange(1) = max(opts.showrange(1),opts.datarange(1));
opts.showrange(2) = min(opts.showrange(2),opts.datarange(2));
for h = 1:numel(dat)
infneg = isinf(dat{h}.data) & dat{h}.data < 0;
infpos = isinf(dat{h}.data) & dat{h}.data > 0;
dat{h}.data(infneg) = opts.datarange(1);
dat{h}.data(infpos) = opts.datarange(2);
end
% Define the colourmap
if opts.dual
if opts.coption
neg = opts.showrange(1) - opts.datarange(1);
cen = opts.showrange(2) - opts.showrange(1);
pos = opts.datarange(2) - opts.showrange(2);
tot = opts.datarange(2) - opts.datarange(1);
fracs = round([neg cen pos]./tot*opts.mapsize);
maptmp = eval(sprintf('%s(%d)',opts.mapname,fracs(1)+fracs(3)));
map = nan(opts.mapsize,3);
map(1:fracs(1),:) = maptmp(1:fracs(1),:);
map(fracs(1)+1:fracs(1)+fracs(2),:) = repmat(opts.colourgap,[fracs(2) 1]);
map(fracs(1)+fracs(2)+1:sum(fracs),:) = maptmp(fracs(1)+1:fracs(1)+fracs(3),:);
else
map = eval(sprintf('%s(%d)',opts.mapname,opts.mapsize));
idxmin = round((opts.showrange(1) - opts.datarange(1)) / (opts.datarange(2) - opts.datarange(1)) * (opts.mapsize - 1) + 1);
idxmax = round((opts.showrange(2) - opts.datarange(1)) / (opts.datarange(2) - opts.datarange(1)) * (opts.mapsize - 1) + 1);
map(idxmin:idxmax,:) = repmat(opts.colourgap,[idxmax-idxmin+1 1]);
end
else
neg = opts.showrange(1) - opts.datarange(1);
cen = opts.showrange(2) - opts.showrange(1);
pos = opts.datarange(2) - opts.showrange(2);
tot = opts.datarange(2) - opts.datarange(1);
fracs = round([neg cen pos]./tot*opts.mapsize);
maptmp = eval(sprintf('%s(%d)',opts.mapname,fracs(2)));
map = nan(opts.mapsize,3);
map(fracs(1)+1:fracs(1)+fracs(2),:) = maptmp;
if opts.coption
map(1:fracs(1),:) = repmat(maptmp(1,:),[fracs(1) 1]);
map(fracs(1)+fracs(2)+1:sum(fracs),:) = repmat(maptmp(fracs(2),:),[fracs(3) 1]);
else
map(1:fracs(1),:) = repmat(opts.colourgap,[fracs(1) 1]);
map(fracs(1)+fracs(2)+1:sum(fracs),:) = repmat(opts.colourgap,[fracs(3) 1]);
end
end
colormap(map)
% Render using the selected layout
switch opts.layout
case 'simple'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.45;
% First panel (right frontal view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(-245,20);
useopts(opts,fighandle);
% Second panel (left frontal view)
ax(2) = axes('Position',[0.525 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(245,20);
useopts(opts,fighandle);
% Deal with the colourbar
if opts.colourbar
cb = colorbar('Location','SouthOutside');
set(cb,'Position',[0.35 0.085 0.3 0.02]);
end
case 'cardinal'
% Auxiliary variables for the sizes of each panel
h = 0.5;
w = 0.5;
% Upper-left panel (left lateral view)
ax(1) = axes('Position',[0 0.5 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Upper-right panel (right lateral view)
ax(2) = axes('Position',[0.5 0.5 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Lower-left panel (left medial view)
ax(3) = axes('Position',[0 0 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Lower-right panel (right medial view)
ax(4) = axes('Position',[0.5 0 w h]);
trisurf(srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Deal with the colourbar
if opts.colourbar
cb = colorbar('Location','South');
set(cb,'Position',[0.35 0.475 0.3 0.02]);
end
case 'left'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.45;
% First panel (left lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Second panel (left medial view)
ax(2) = axes('Position',[0.525 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'right'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.45;
% First panel (right lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Second panel (right medial view)
ax(2) = axes('Position',[0.525 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'leftlateral'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.95;
% First panel (right lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'leftmedial'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.95;
% First panel (right lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'rightlateral'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.95;
% First panel (right lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'rightmedial'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.95;
% First panel (right lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'strip'
% Auxiliary variables for the sizes of each panel
h = 0.95;
w = 0.2;
% First panel (left lateral view)
ax(1) = axes('Position',[0.025 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Second panel (right lateral view)
ax(2) = axes('Position',[0.275 0.025 w h]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Third panel (left medial view)
ax(3) = axes('Position',[0.525 0.025 w h]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Fourth panel (right medial view)
ax(4) = axes('Position',[0.775 0.025 w h]);
trisurf(srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% This mode has no colourbar
opts.colourbar = false;
case 'publication'
% A more symmetric layout than Worsley's (see below)
% Auxiliary variables for the sizes of each panel
h = 0.39;
w = 0.4;
xyz_range = max(srf{3}.data.vtx,[],1) - min(srf{3}.data.vtx,[],1);
wb = h/xyz_range(2)*xyz_range(1)*3/4;
hb = h/xyz_range(2)*xyz_range(1);
% Upper-left panel (left lateral view)
ax(1) = axes('Position',[0.055 0.62 h*3/4 w]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Upper-center panel (top view)
ax(2) = axes('Position',[0.3 0.58 w h]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(0,90);
useopts(opts,fighandle);
% Upper-right panel (right lateral view)
ax(3) = axes('Position',[1-0.055-h*3/4 0.62 h*3/4 w]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Middle-left panel (frontal view)
ax(4) = axes('Position',[0.055 0.345 wb hb]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(180,0);
useopts(opts,fighandle);
% Middle-right panel (occipital view)
ax(5) = axes('Position',[1-0.055-wb 0.345 wb hb]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(0,0);
useopts(opts,fighandle);
% Lower-left panel (left medial view)
ax(6) = axes('Position',[0.055 -0.015 h*3/4 w]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Lower-center panel (bottom view)
ax(7) = axes('Position',[0.3 0.03 w h]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(180,-90);
useopts(opts,fighandle);
% Lower-right panel (right medial view)
ax(8) = axes('Position',[1-0.055-h*3/4 -0.015 h*3/4 w]);
trisurf(srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% This layout always includes a colourbar
cb = colorbar('Location','South');
if isempty(opts.title)
set(cb,'Position',[0.35 0.49 0.3 0.03]);
else
set(cb,'Position',[0.35 0.48 0.3 0.03]);
end
case 'worsley'
% This is the layout originally proposed by Keith Worsley
% (McGill University, circa 2005).
% Auxiliary variables for the sizes of each panel
h = 0.39;
w = 0.4;
xyz_range = max(srf{3}.data.vtx,[],1) - min(srf{3}.data.vtx,[],1);
wb = h/xyz_range(2)*xyz_range(1)*3/4;
hb = h/xyz_range(2)*xyz_range(1);
% Upper-left panel (left lateral view)
ax(1) = axes('Position',[0.055 0.62 h*3/4 w]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Upper-center panel (top view)
ax(2) = axes('Position',[0.3 0.58 w h]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(0,90);
useopts(opts,fighandle);
% Upper-right panel (right lateral view)
ax(3) = axes('Position',[1-0.055-h*3/4 0.62 h*3/4 w]);
trisurf(...
srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Middle-left panel (left medial view)
ax(4) = axes('Position',[0.055 0.29 h*3/4 w]);
trisurf(...
srf{1}.data.fac,...
srf{1}.data.vtx(:,1),srf{1}.data.vtx(:,2),srf{1}.data.vtx(:,3),...
dat{1}.data,...
'EdgeColor','None');
view(90,0);
useopts(opts,fighandle);
% Middle-center panel (bottom view)
ax(5) = axes('Position',[0.3 0.18 w h]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(0,-90);
useopts(opts,fighandle);
% Middle-right panel (right medial view)
ax(6) = axes('Position',[1-0.055-h*3/4 0.29 h*3/4 w]);
trisurf(srf{2}.data.fac,...
srf{2}.data.vtx(:,1),srf{2}.data.vtx(:,2),srf{2}.data.vtx(:,3),...
dat{2}.data,'EdgeColor','None');
view(-90,0);
useopts(opts,fighandle);
% Lower-left panel (frontal view)
ax(7) = axes('Position',[0.055 0.02 wb hb]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(180,0);
useopts(opts,fighandle);
% Lower-right panel (occipital view)
ax(8) = axes('Position',[1-0.055-wb 0.03 wb hb]);
trisurf(...
srf{3}.data.fac,...
srf{3}.data.vtx(:,1),srf{3}.data.vtx(:,2),srf{3}.data.vtx(:,3),...
dat{3}.data,...
'EdgeColor','None');
view(0,0);
useopts(opts,fighandle);
% This layout always includes a colourbar
cb = colorbar('Location','South');
set(cb,'Position',[0.35 0.085 0.3 0.03]);
otherwise
error('Unknown layout style %s.\n',opts.layout)
end
% Deal with the colour limits
for i=1:length(ax)
set(ax(i),'CLim',opts.datarange);
end
% Deal with the colourbar
if opts.colourbar
set(cb,'XAxisLocation','Bottom');
set(get(cb,'Title'),'String',opts.title);
end
function useopts(opts,fighandle) % ==================================================
daspect([1 1 1]);
axis tight;
axis vis3d off;
box off
if strcmpi(opts.layout,'worsley')
set(fighandle,'Color',[1 1 1],'InvertHardcopy','Off');
camlight;
lighting ('gouraud');
material ('shiny');
shading ('interp');
else
set(fighandle,'Color',opts.background,'InvertHardcopy','Off');
if opts.camlight
camlight;
end
lighting (opts.lightning);
material (opts.material);
shading (opts.shading);
end