-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsunvs_display.m
637 lines (522 loc) · 22 KB
/
sunvs_display.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
function varargout = sunvs_display(Data, varargin)
%==========================================================================
% This function is used to display surfaces and brain networks.
%
%
% Syntax: function varargout = sunvs_display(Data, varargin)
%
% Input:
% Data:
% Directory & filename of the surfaces gifti (.gii) file.
%
% parameters:
% 'multisurf':
% load both hemispheres if possible.
% 0 = load single hemisphere (Default);
% 1 = load both hemisphere.
% 'useAverageSurf':
% Choose an average surface to display. This surface file will
% define the shape of meshed object.
% 'inflated', an inflated brain surface (Default);
% 'original', the surface mesh of the input data;
% 'central', central surface;
% 'IXI555', Template_T1_IXI555_MNI152_GS.gii released by CAT12;
% 'patch', surface patch released by CAT12.
% 'sphere', surface sphere.
% 'custom', custom average surface..
% 'useOverlay':
% Choose a gifti file to be the mesh overlay.
% 'none', no overlay mesh (Default);
% 'mc', curv infomation for fsaverage surface;
% 'a2009s', boundary infomation for a2009s_150 (Destrieux atlas);
% 'DK40', boundary infomation for DK40_70 (Desikan atlas);
% 'Fan', boundary infomation for Fan_210;
% 'MMP1', boundary infomation for MMP1_360;
% 'gordon', boundary infomation for MMP1_333;
% 'schaefer_17_100', boundary infomation for Schaefer_17Networks_100;
% 'schaefer_17_200', boundary infomation for Schaefer_17Networks_200;
% 'schaefer_17_400', boundary infomation for Schaefer_17Networks_400;
% 'schaefer_17_600', boundary infomation for Schaefer_17Networks_600;
% 'custom', custom overlay.
% 'useUnderlay':
% Choose a gifti file to be the mesh underlay, this underlay will
% be the underlay texture of the display object.
% 'none', no overlay mesh (Default);
% 'mc', curv infomation for fsaverage surface;
% 'a2009s', boundary infomation for a2009s_150 (Destrieux atlas);
% 'DK40', boundary infomation for DK40_70 (Desikan atlas);
% 'Fan', boundary infomation for Fan_210;
% 'MMP1', boundary infomation for MMP1_360;
% 'gordon', boundary infomation for MMP1_333;
% 'schaefer_17_100', boundary infomation for Schaefer_17Networks_100;
% 'schaefer_17_200', boundary infomation for Schaefer_17Networks_200;
% 'schaefer_17_400', boundary infomation for Schaefer_17Networks_400;
% 'schaefer_17_600', boundary infomation for Schaefer_17Networks_600;
% 'custom', custom underlay.
% 'TransParency':
% Set the transparency for surface object, a value which
% ranges from 0 to 1. The default value is 0.55
% 'view':
% Object display orientation
% 'l' = left, 'r' = right;
% 'a' = anterior, 'p' = posterior;
% 's' = superior (Default), 'i' = inferior.
% 'Colormap':
% Color look-up table, as a matrix of 3 columns.
% e.g. jet(16), hot(64), white(256), etc.
% 'imgprint':
% 0 = No output (Default);
% 1 = Output to 'imgprintDir' (see below), which is a directory
% you want the image to be output to.
% 'imgprintDir':
% A data path that you want the image to be output to. When the
% 'imgprint' is set to 1 and the value of 'imgprintDir' is unset,
% the output directory will be set as the current working directory.
%
% reference:
% Atlas - a2009s_150:
% Destrieux, C., Fischl, B., Dale, A. and Halgren, E., 2010. Automatic
% parcellation of human cortical gyri and sulci using standard anatomical
% nomenclature. Neuroimage, 53(1), pp.1-15.
%
% Atlas - DK40_70:
% Desikan, R.S., Ségonne, F., Fischl, B., Quinn, B.T., Dickerson, B.C.,
% Blacker, D., Buckner, R.L., Dale, A.M., Maguire, R.P., Hyman, B.T.
% and Albert, M.S., 2006. An automated labeling system for subdividing
% the human cerebral cortex on MRI scans into gyral based regions of
% interest. Neuroimage, 31(3), pp.968-980.
%
% Atlas - Fan_210:
% Fan, L., Li, H., Zhuo, J., Zhang, Y., Wang, J., Chen, L., Yang, Z.,
% Chu, C., Xie, S., Laird, A.R. and Fox, P.T., 2016. The human brainnetome
% atlas: a new brain atlas based on connectional architecture. Cerebral
% cortex, 26(8), pp.3508-3526.
%
% Atlas - HCP-MMP1:
% Glasser, M.F., Coalson, T.S., Robinson, E.C., Hacker, C.D., Harwell, J.,
% Yacoub, E., Ugurbil, K., Andersson, J., Beckmann, C.F., Jenkinson, M. and
% Smith, S.M., 2016. A multi-modal parcellation of human cerebral cortex.
% Nature, 536(7615), pp.171-178.
%
% Ningkai WANG, IBRR, SCNU, Guangzhou, 2020/08/28, [email protected]
%==========================================================================
%% Extension detection
[~, ~, ext] = fileparts(Data);
sinfo = cat_surf_info(Data, 1, 1);
switch ext
case '.gii'
otherwise
error('The SUNVS supports ''.gii'' file only!');
end
%% Add path
Dir_thisFunction = which('sunvs_display');
[PathF, ~, ~] = fileparts(Dir_thisFunction);
addpath([PathF filesep 'nodalBoundaryList']);
addpath([PathF filesep 'inflatedGiftiFiles']);
addpath([PathF filesep 'matFiles']);
%% Determine the template space
p = inputParser;
addParameter(p, 'templateSpace', '', @ischar);
p.KeepUnmatched = true;
parse(p, varargin{:});
job.templateSpace = p.Results.templateSpace;
switch job.templateSpace
case ''
g = gifti(Data);
if ~isfield(g,'faces')
prompt = 'Choose the template name:';
ListString = {'fsaverage_164k',...
'fs_LR_32k'...
'Custom'};
[SELECTION, ~] = listdlg('ListString', ListString,...
'SelectionMode','single', 'ListSize', [200,100], 'PromptString', prompt);
switch SELECTION
case 1
job.templateSpace = 'fsaverage_164k';
case 2
job.templateSpace = 'fs_LR_32k';
case 3
job.templateSpace = [];
end
else
facesData = int32(double(g.faces)); % for dealing with class 'file_array'
facesStructfs_LR_32k_lh = load('faces_fs_LR_32k_lh.mat');
facesStructfs_LR_32k_rh = load('faces_fs_LR_32k_rh.mat');
facesStructfsaverage_164k = load('faces_fsaverage_164k.mat');
facesStructfsaverage_patch_164k = load('faces_fsaverage_patch_164k.mat');
if isequal(facesData, facesStructfs_LR_32k_lh.faces);
job.templateSpace = 'fs_LR_32k';
elseif isequal(facesData, facesStructfs_LR_32k_rh.faces);
job.templateSpace = 'fs_LR_32k';
elseif isequal(facesData, facesStructfsaverage_164k.faces) ...
|| isequal(facesData, facesStructfsaverage_patch_164k.faces);
job.templateSpace = 'fsaverage_164k';
else
job.templateSpace = 'Others';
% if strcmpi(job.useOverlay,'none') || strcmpi(job.useUnderlay,'none')
% warning('Unknown template space detected, please DISABLE the underlay and overlay!!!');
% end
warning('Unknown template space detected, please DISABLE the underlay and overlay!!!');
end
end
case 'fsaverage_164k'
case 'fs_LR_32k'
end
%% Default parameters
job.default.useAverageSurf = 'inflated';
job.default.useOverlay = 'none';
job.default.useUnderlay = 'none';
job.default.TransParency = 0.45;
job.default.Colormap = hot(256);
job.default.SupportedUnderLay = {'a2009s','dk40','fan','mmp1','gordon',...
'schaefer_17_100','schaefer_17_200','schaefer_17_400','schaefer_17_600'};
switch job.templateSpace
case 'fsaverage_164k'
temFolder = 'templates_surfaces';
case 'fs_LR_32k'
temFolder = 'templates_surfaces_32k';
case 'Others'
temFolder = 'templates_surfaces';
end
Path_Boundary = fullfile(fileparts(which('sunvs_display')), 'nodalBoundaryList');
job.my.averageSurf.original = {Data};
job.my.averageSurf.central = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.central.freesurfer.gii')};
job.my.averageSurf.inflated = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.inflated.freesurfer.gii')};
job.my.averageSurf.IXI555 = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.central.Template_T1_IXI555_MNI152_GS.gii')};
job.my.averageSurf.patch = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.patch.freesurfer.gii')};
job.my.averageSurf.sphere = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.sphere.freesurfer.gii')};
job.my.Overlay.mc = {fullfile(spm('dir'), 'toolbox', 'cat12', temFolder, 'lh.mc.freesurfer.gii')};
switch job.templateSpace
case 'fsaverage_164k'
job.my.Overlay.a2009s = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_a2009s_150_fsaverage_164k.gii')};
job.my.Overlay.dk40 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_DK40_70_fsaverage_164k.gii')};
job.my.Overlay.fan = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Fan_210_fsaverage_164k.gii')};
job.my.Overlay.mmp1 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_MMP1_360_fsaverage_164k.gii')};
job.my.Overlay.gordon = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Gordon_333_fsaverage_164k.gii')};
job.my.Overlay.Schaefer_17_100 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Schaefer2018_17Networks_100_fsaverage_164k.gii')};
job.my.Overlay.Schaefer_17_200 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Schaefer2018_17Networks_200_fsaverage_164k.gii')};
job.my.Overlay.Schaefer_17_400 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Schaefer2018_17Networks_400_fsaverage_164k.gii')};
job.my.Overlay.Schaefer_17_600 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Schaefer2018_17Networks_600_fsaverage_164k.gii')};
case 'fs_LR_32k'
job.my.Overlay.a2009s = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_a2009s_150_fs_LR_32k.gii')};
job.my.Overlay.dk40 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_DK40_70_fs_LR_32k.gii')};
job.my.Overlay.fan = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_Fan_210_fs_LR_32k.gii')};
job.my.Overlay.mmp1 = {fullfile(Path_Boundary, 'lh.nodalBoundaryList_MMP1_360_fs_LR_32k.gii')};
end
job.my.Underlay = job.my.Overlay;
%% User input Parser
p = inputParser;
validScalar = @(x) isnumeric(x) && isscalar(x);
addParameter(p, 'multisurf', 0, validScalar);
addParameter(p, 'templateSpace', '', @ischar);
addParameter(p, 'useAverageSurf', job.default.useAverageSurf, @ischar);
addParameter(p, 'useOverlay', job.default.useOverlay, @ischar);
addParameter(p, 'useUnderlay', job.default.useUnderlay, @ischar);
addParameter(p, 'TransParency', job.default.TransParency, validScalar);
addParameter(p, 'rangeClip', [], @(x) isnumeric(x) && length(x)==2);
addParameter(p, 'rangeClim', [], @(x) isnumeric(x) && length(x)==2);
addParameter(p, 'Colormap', job.default.Colormap, @isnumeric);
addParameter(p, 'view', 'left', @ischar);
addParameter(p, 'imgprint', 0);
addParameter(p, 'imgprintDir', '');
parse(p, varargin{:});
job.multisurf = p.Results.multisurf;
job.useAverageSurf = p.Results.useAverageSurf;
job.useOverlay = p.Results.useOverlay;
job.useUnderlay = p.Results.useUnderlay;
job.TransParency = 1 - p.Results.TransParency;
job.rangeClip = p.Results.rangeClip;
job.rangeClim = p.Results.rangeClim;
job.Colormap = p.Results.Colormap;
job.view = p.Results.view;
job.imgprint = p.Results.imgprint;
job.imgprintDir = p.Results.imgprintDir;
switch lower(job.useAverageSurf)
case 'original'
job.averageSurf = job.my.averageSurf.original;
case 'central'
job.averageSurf = job.my.averageSurf.central;
case 'inflated'
job.averageSurf = job.my.averageSurf.inflated;
case 'ixi555'
job.averageSurf = job.my.averageSurf.IXI555;
case 'patch'
job.averageSurf = job.my.averageSurf.patch;
case 'sphere'
job.averageSurf = job.my.averageSurf.sphere;
case 'custom'
job.averageSurf = spm_select(1, 'mesh', 'Select Mesh files...');
otherwise
error('Invaild fsaverage');
end
switch lower(job.useOverlay)
case 'none'
case 'mc'
job.Overlay = job.my.Overlay.mc;
case job.default.SupportedUnderLay
job.Overlay = job.my.Overlay.(lower(job.useOverlay));
case 'custom'
job.Overlay = spm_select(1, 'mesh', 'Select Overlay files...');
otherwise
error('Invaild Overlay');
end
switch lower(job.useUnderlay)
case 'none'
case 'mc'
job.Underlay = job.my.Underlay.mc;
case job.default.SupportedUnderLay
job.Underlay = job.my.Underlay.(lower(job.useUnderlay));
case 'custom'
job.Underlay = {spm_select(1, 'mesh', 'Select Underlay files...')};
otherwise
error('Invaild Overlay');
end
%% Plot surface
H = plot_hemi(sinfo, job);
set(H.patch, 'FaceAlpha', job.TransParency);
% H = cat_surf_render('Colourmap', H, bone, 64); % change colormap
if nargout == 0
varargout{1} = [];
else
varargout{1} = H;
end
%% Colormap
H = cat_surf_render('ColourMap', H.axis, job.Colormap);
%% Add Range
if ~isempty(job.rangeClip)
rangeClip = job.rangeClip;
if rangeClip(1)==rangeClip(2) && rangeClip(1)>=0
rangeClip = rangeClip + 2.*[-eps eps];
elseif rangeClip(1)==rangeClip(2) && rangeClip(1)<0
rangeClip = rangeClip - 2.*[-eps eps];
end
if rangeClip(1)>rangeClip(2), rangeClip = fliplr(rangeClip); end
H = cat_surf_render('clip', H, rangeClip);
end
if ~isempty(job.rangeClim)
rangeClim = job.rangeClim;
if rangeClim(1)==rangeClim(2) && rangeClim(1)>=0
rangeClim = rangeClim + 2.*[-eps eps];
elseif rangeClim(1)==rangeClim(2) && rangeClim(1)<0
rangeClim = rangeClim - 2.*[-eps eps];
end
if rangeClim(1)>rangeClim(2), rangeClim = fliplr(rangeClim); end
H = cat_surf_render('clim', H, rangeClim);
end
%% view
switch lower(job.view)
case {'r', 'right'}, cat_surf_render('view', H, [ 90 0]); viewname = '.r';
case {'l', 'left'}, cat_surf_render('view', H, [ -90 0]); viewname = '.l';
case {'t', 's', 'top', 'superior'}, cat_surf_render('view', H, [ 0 90]); viewname = '.s';
case {'b', 'i', 'bottom', 'inferior'}, cat_surf_render('view', H, [-180 -90]); viewname = '.i';
case {'f', 'a', 'front', 'anterior'}, cat_surf_render('view', H, [-180 0]); viewname = '.a';
case {'p', 'back', 'posterior'}, cat_surf_render('view', H, [ 0 0]); viewname = '.p';
otherwise
if isnumeric(job.view) && size(job.view)==2
view(job.view);
viewname = sprintf('.%04dx%04d', mod(job.view, 360));
else
error('Unknown view.\n')
end
end
%% print image
if job.imgprint || ~isempty(job.imgprintDir)
if isempty(job.imgprintDir)
ppp = pwd;
else
ppp = job.imgprintDir;
end
if ~exist(ppp, 'dir')
mkdir(ppp);
end
[~, fname, ~] = fileparts(Data);
pfname = fullfile(ppp, sprintf('%s%s.%s', fname, viewname, 'tif'));
print(H.figure , '-dtiff' , '-r600', pfname );
end
end
%% plot single hemi
function [H, sinfo] = plot_hemi(sinfo, job)
for i = 1:length(sinfo)
sinfo(i) = rename_sinfo(sinfo(i));
switch job.useAverageSurf
case {'custom','original'}
sinfo(i).Pmesh = job.averageSurf;
otherwise
sinfo(i).Pmesh = cat_surf_rename(job.averageSurf, 'side', sinfo(i).side);
end
if strcmp('r',sinfo(i).side(1))
oside = ['l' sinfo(i).side(2)];
else
oside = ['r' sinfo(i).side(2)];
end
if job.multisurf
Pmesh = [sinfo(i).Pmesh cat_surf_rename(sinfo(i).Pmesh, 'side', oside)];
Pdata = [sinfo(i).Pdata cat_surf_rename(sinfo(i).Pdata, 'side', oside)];
else
Pmesh = sinfo(i).Pmesh;
Pdata = sinfo(i).Pdata;
end
H = cat_surf_render('disp', Pmesh, 'Pcdata', Pdata, 'results', -1);
%% add overlay
if isfield(job,'Overlay')
if job.multisurf
MhOverlay = combine_multisurf(job.Overlay{:});
updateTexture(H, MhOverlay);
else
ShOverlay = cat_surf_rename(job.Overlay, 'side', sinfo(i).side);
H = cat_surf_render('overlay', H, ShOverlay{:});
end
end
%% add underlay
if isfield(job, 'Underlay')
if job.multisurf
MhUnderlay = combine_multisurf(job.Underlay{:});
setappdata(H.patch, 'curvature', double(MhUnderlay.cdata));
setappdata(H.axis, 'handles', H);
d = getappdata(H.patch, 'data');
updateTexture(H, d);
else
ShUnderlay = cat_surf_rename(job.Underlay, 'side', sinfo(i).side);
H = cat_surf_render('underlay', H, ShUnderlay{:});
end
end
end
end
%% combine multi surface
function Mh = combine_multisurf(Mh)
sinfo = cat_surf_info(Mh, 1, 1);
sinfo = rename_sinfo(sinfo);
if strcmp('r', sinfo.side)
oside = ['l' sinfo.side(2)];
else
oside = ['r' sinfo.side(2)];
end
Moh = cat_surf_rename(Mh, 'side', oside);
Moh = Moh{:};
Mh = gifti(Mh);
Moh = gifti(Moh);
if isfield(Mh,'faces')
Mh.faces = [double(Mh.faces); double(Moh.faces) + size(double(Mh.vertices),1)];
end
if isfield(Mh,'vertices')
Mh.vertices = [double(Mh.vertices); double(Moh.vertices)];
end
if isfield(Mh,'cdata')
Mh.cdata = [double(Mh.cdata); double(Moh.cdata)];
end
end
%% search another hemi
function sinfo = rename_sinfo(sinfo)
if isempty(sinfo.side)
prompt = {'Enter hemi'};
dlgtitle = 'Input';
dims = [1 35];
definput = {'lh'};
answer = inputdlg(prompt, dlgtitle, dims, definput);
answer = answer{:};
switch lower(answer)
case {'lh', 'left', 'lh.', 'left.'}
sinfo.side = 'lh';
case {'rh', 'right', 'rh.', 'right.'}
sinfo.side = 'rh';
end
end
end
%% update texture of underlay and overlay
% From cat_surf_render
function C = updateTexture(H, v, col, texLight)
% Get colourmap
if ~exist('col', 'var'), col = getappdata(H.patch, 'colourmap'); end
if isempty(col), col = white(256); end
if ~exist('FaceColor', 'var'), FaceColor = 'interp'; end % default: interp
setappdata(H.patch, 'colourmap',col);
if ~exist('texLight', 'var'), texLight = 1; end
% Get curvature
curv = getappdata(H.patch, 'curvature');
if size(curv,2) == 1
th = 0.15;
curv((curv<-th)) = -th;
curv((curv>th)) = th;
curv = 0.5*(curv + th)/(2*th);
curv = 0.5 + repmat(curv,1,3);
end
% Project data onto surface mesh
if nargin < 2, v = []; end
if ischar(v)
[p,n,e] = fileparts(v);
if ~strcmp(e, '.mat') && ~strcmp(e, '.nii') && ~strcmp(e, '.gii') && ~strcmp(e, '.img') % freesurfer format
v = cat_io_FreeSurfer('read_surf_data', v);
else
if strcmp([n e], 'SPM.mat')
swd = pwd;
spm_figure('GetWin', 'Interactive');
[~,v] = spm_getSPM(struct('swd', p));
cd(swd);
else
try spm_vol(v); catch, v = gifti(v); end;
end
end
end
if isa(v,'gifti'), v = double(v.cdata); end
if isa(v,'file_array'), v = v(); end
if isempty(v)
v = zeros(size(curv))';
elseif ischar(v) || iscellstr(v) || isstruct(v)
v = spm_mesh_project(H.patch,v);
elseif isnumeric(v) || islogical(v)
if size(v, 2) == 1
v = v';
end
else
error('Unknown data type.');
end
v(isinf(v)) = NaN;
setappdata(H.patch, 'data', v);
% Create RGB representation of data according to colourmap
C = zeros(size(v, 2), 3);
clim = getappdata(H.patch, 'clim');
if isempty(clim), clim = [false NaN NaN]; end
mi = clim(2); ma = clim(3);
if any(v(:))
if size(col, 1) > 3 && size(col, 1) ~= size(v, 1)
if size(v,1) == 1
if ~clim(1), mi = min(v(:)); ma = max(v(:)); end
C = squeeze(ind2rgb(floor(((v(:) - mi)/(ma - mi)) * size(col, 1)), col));
elseif isequal(size(v),[size(curv, 1), 3])
C = v; v = v';
else
if ~clim(1), mi = min(v(:)); ma = max(v(:)); end
for i=1:size(v, 1)
C = C + squeeze(ind2rgb(floor(((v(i,:) - mi)/(ma - mi))*size(col, 1)), col));
end
end
else
if ~clim(1), ma = max(v(:)); end
for i = 1 : size(v, 1)
C = C + v(i, :)'/ma * col(i, :);
end
end
end
clip = getappdata(H.patch, 'clip');
if ~isempty(clip)
v(v > clip(2) & v < clip(3)) = NaN;
setappdata(H.patch, 'clip', [true clip(2) clip(3)]);
end
setappdata(H.patch, 'clim', [false mi ma]);
% Build texture by merging curvature and data
if size(curv, 1) == 1
curv = repmat(curv, 3, 1)';
end
if size(C, 1) ~= size(curv, 1)
error('Colordata does not fit to underlying mesh.');
end
C = repmat(~any(v, 1), 3, 1)' .* curv + repmat(any(v, 1), 3, 1)' .* C;
if texLight == 1
C = mapminmax(C')'.*1/16 + 0.9375;
end
set(H.patch, 'FaceVertexCData', C, 'FaceColor', FaceColor, 'CDataMapping', 'direct');
% Update colourbar
if isfield(H, 'colourbar')
cat_surf_render('Colourbar', H);
end
end