/
ea_convis.m
1330 lines (1023 loc) · 45.1 KB
/
ea_convis.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = ea_convis(varargin)
% EA_CONVIS MATLAB code for ea_convis.fig
% EA_CONVIS, by itself, creates a new EA_CONVIS or raises the existing
% singleton*.
%
% H = EA_CONVIS returns the handle to a new EA_CONVIS or the handle to
% the existing singleton*.
%
% EA_CONVIS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EA_CONVIS.M with the given input arguments.
%
% EA_CONVIS('Property','Value',...) creates a new EA_CONVIS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ea_convis_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ea_convis_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ea_convis
% Last Modified by GUIDE v2.5 30-Sep-2016 17:26:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ea_convis_OpeningFcn, ...
'gui_OutputFcn', @ea_convis_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ea_convis is made visible.
function ea_convis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ea_convis (see VARARGIN)
set(hObject,'Name','Connectome Results');
% Choose default command line output for ea_anatomycontrol
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ea_anatomycontrol wait for user response (see UIRESUME)
% uiwait(handles.convis);
resultfig=varargin{1};
options=varargin{2};
setappdata(handles.convis,'resultfig',resultfig);
setappdata(handles.convis,'options',options);
setappdata(resultfig,'convis',handles.convis);
refreshcv(handles);
function refreshcv(varargin)
handles=varargin{1};
hold=0; % do refresh seed coordinates
apply=0;
if nargin>1
hold=varargin{2};
end
if nargin>2
apply=varargin{3};
end
options=getappdata(handles.convis,'options');
if isempty(options)
convis=getappdata(handles.convis,'convis');
options=getappdata(convis,'options');
set(0,'CurrentFigure',convis);
else
convis=handles.convis;
end
set(convis,'name','Processing...');
drawnow
%% init figure
[directory,pdirectory,selectedparc]=ea_cvinitgui(handles,options);
%% initialize controls
ea_initvatlevel(handles,directory,selectedparc,options);
ea_initseedlevel(handles,directory,pdirectory,selectedparc,options);
filesare=ea_initvoxellevel(handles,pdirectory);
ea_initmatlevel(handles,directory,pdirectory,selectedparc,options);
%% check if sliding window view is possible (timecourses are set as a modality somewhere)
mmc=get(handles.matmodality,'String');
vmc=get(handles.vatmodality,'String');
vomc=get(handles.voxmodality,'String');
if isempty(strfind(mmc{get(handles.matmodality,'Value')},'_tc')) && ...
isempty(strfind(vmc{get(handles.vatmodality,'Value')},'_tc')) && ...
isempty(strfind(vomc{get(handles.voxmodality,'Value')},'_tc')) % no timeseries selected.
cv_disabletime(handles);
else
cv_enabletime(handles);
end
if apply % update elvis
%% retrieve and delete prior results
resultfig=ea_cvcleanup(handles);
pV=getappdata(handles.convis,'pV');
pX=getappdata(handles.convis,'pX');
ea_deleteML(resultfig,handles,options);
if ~hold
[xmm,ymm,zmm]=getcoordinates(pV,pX,get(handles.matseed,'Value'));
set(handles.xmm,'String',num2str(xmm)); set(handles.ymm,'String',num2str(ymm)); set(handles.zmm,'String',num2str(zmm));
set(handles.matseed,'ForegroundColor',[0,0,0]);
end
%% now show results
if get(handles.vizvat,'Value'); % show voxel-level results
ea_cvshowvatresults(resultfig,pX,directory,filesare,handles,pV,selectedparc,options);
else
ea_deletePL(resultfig,'PL','vat');
end
if get(handles.vizgraph,'Value'); % show voxel-level results
ea_cvshowvoxresults(resultfig,directory,filesare,handles,pV,selectedparc,options);
end
if get(handles.vizmat,'Value'); % show seed-based-connectivity results
ea_cvshowseedbasedresults(resultfig,directory,pV,pX,selectedparc,handles,options);
else
ea_deletePL(resultfig,'PL','mat');
end
if get(handles.wmatedges,'Value') || get(handles.wmatnodes,'Value'); % show matrix-level results
ea_cvshowmatresults(resultfig,directory,selectedparc,handles,options);
end
if (get(handles.vizmat,'Value') || get(handles.vizvat,'Value')) && get(handles.timecircle,'Value') && strcmp(get(handles.timecircle,'Enable'),'on') % cycle over time..
pause(0.1);
refreshcv(handles);
end
end
set(convis,'name','Connectome Results');
function ea_deleteML(resultfig,handles,options)
ML=getappdata(resultfig,'ML');
if isempty(ML)
return
end
try delete(ML.pedges); end
try delete(ML.pnodes); end
try delete(ML.hn); end
try delete(ML.nnodes); end
% delete matrix level stuff here.
function ea_cvshowmatresults(resultfig,directory,selectedparc,handles,options)
% show matrix level stuff here.
ML=cv_build_graph_fig(resultfig,directory,selectedparc,handles,options);
setappdata(resultfig,'ML',ML);
function ea_initmatlevel(handles,directory,pdirectory,selectedparc,options)
pmdirs=dir([pdirectory,'*_CM.mat']);
cnt=1;
modlist=cell(0);
for pmdir=1:length(pmdirs)
[~,modlist{cnt}]=fileparts(pmdirs(pmdir).name);
cnt=cnt+1;
end
if ~exist('modlist','var')
%cv_disablewmats(handles);
else
%cv_enablewmats(handles);
modlist{end+1}='Choose...';
set(handles.wmatmodality,'String',modlist);
end
if get(handles.wmatmodality,'Value')>length(get(handles.wmatmodality,'String'))
set(handles.wmatmodality,'Value',length(get(handles.wmatmodality,'String')));
end
mods=get(handles.wmatmodality,'String');
if ~strcmp('Choose...',mods{get(handles.wmatmodality,'Value')});
set(handles.chosenwmatstr,'String','');
end
function ea_cvshowvoxresults(resultfig,directory,filesare,handles,pV,selectedparc,options)
mo_ds=get(handles.voxmodality,'String');
mo_d=mo_ds{get(handles.voxmodality,'Value')};
gV=spm_vol([directory,'connectomics',filesep,selectedparc,filesep,'graph',filesep,filesare{get(handles.voxmetric,'Value')},mo_d,'.nii']);
gX=spm_read_vols(gV);
thresh=get(handles.voxthresh,'String');
if strcmp(thresh,'auto');
thresh=nanmean(gX(:))+1*nanstd(gX(:));
else
thresh=str2double(thresh);
end
set(handles.voxthreshis,'String',num2str(thresh));
graphsurf=ea_showconnectivitypatch(resultfig,gV,gX,thresh,[],[],[],1,0);
setappdata(resultfig,'graphsurf',graphsurf);
function ea_cvshowseedbasedresults(resultfig,directory,pV,pX,selectedparc,handles,options)
%mV=pV; % duplicate labeling handle
%mX=pX; % duplicate labeling data
% determine if CM/TC or fiberset is selected
matmodality=get(handles.matmodality,'String');
matmodality=matmodality{get(handles.matmodality,'Value')};
if ~isempty(strfind(matmodality,'_CM')) || ~isempty(strfind(matmodality,'_tc'))
ea_deletePL(resultfig,'PL','mat');
ea_cvshowmatresultsCMTC(resultfig,directory,pV,pX,handles,options);
else % use fiberset
% fibers filename
switch matmodality
case 'Patient-specific fiber tracts'
fibersfile=[directory,options.prefs.FTR_normalized];
otherwise
fibersfile=[ea_getconnectomebase('dmri'),matmodality,'.mat'];
end
% seed filename
seed=ea_load_nii([options.earoot,'templates',filesep,'labeling',filesep,selectedparc,'.nii']);
% delete everything but set selected parcellation to 1.
oseed=seed.img;
seed.img(:)=0;
seed.img(round(oseed)==get(handles.matseed,'Value'))=1;
targetsfile=ea_load_nii([options.earoot,'templates',filesep,'labeling',filesep,selectedparc,'.nii']);
targetsfile.img(round(targetsfile.img)==get(handles.matseed,'Value'))=0;
thresh=get(handles.matthresh,'String');
options.writeoutstats=0;
options.writeoutpm=1;
[changedstates,ret]=ea_checkfschanges(resultfig,fibersfile,seed,targetsfile,thresh,'mat');
if ~ret % something has changed since last time.
ea_deletePL(resultfig,'PL','mat');
[~,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seed,targetsfile,thresh,1,options,'',changedstates,'mat',get(handles.vizmat_regs,'Value'),get(handles.vizmat_labs,'Value'));
set(handles.matthreshis,'String',num2str(thresh));
end
end
function ea_cvshowmatresultsCMTC(resultfig,directory,pV,pX,handles,options)
pX=round(pX);
mms=get(handles.matmodality,'String');
parcs=get(handles.labelpopup,'String');
CM=load([directory,'connectomics',filesep,parcs{get(handles.labelpopup,'Value')},filesep,mms{get(handles.matmodality,'Value')}]);
fn=fieldnames(CM);
CM=eval(['CM.',fn{1},';']);
if ~isempty(strfind(mms{get(handles.matmodality,'Value')},'_tc'))
% timecourses selected: need to create a CM first. In this case, the variable CM is
% not a connectivity matrix but time-courses!
timedim=size(CM,1);
tiwindow=get(handles.timewindow,'String');
tiframe=get(handles.timeframe,'String');
if strcmp(tiwindow,'all') || strcmp(tiframe,'all')
% use whole CM
CM=corrcoef(CM);
else
tiframe=str2double(tiframe); tiwindow=str2double(tiwindow);
% check if selected time window is possible:
if (tiframe+tiwindow)>timedim || tiframe<1 % end is reached
set(handles.timeframe,'String','1'); tiframe=1; % reset timeframe to 1
if tiwindow>size(CM,1)
set(handles.timewindow,'String','1'); tiwindow=1;
end
end
CM=corrcoef(CM(tiframe:tiframe+tiwindow,:)); % actual correlation
if get(handles.timecircle,'Value')
% make a step to next timeframe (prepare next iteration).
if (tiframe+tiwindow+1)>timedim
set(handles.timeframe,'String','1')
else
set(handles.timeframe,'String',num2str(tiframe+1))
end
end
end
end
currentseed=get(handles.matseed,'Value');
seedcon=CM(currentseed,:);
thresh=get(handles.matthresh,'String');
if strcmp(thresh,'auto');
thresh=nanmean(seedcon)+1*nanstd(seedcon);
else
thresh=str2double(thresh);
end
tseedcon=seedcon;
tseedcon(tseedcon<thresh)=0;
tseedcon(currentseed)=0;
mX=pX;
for cs=1:length(tseedcon) % assign each voxel of the corresponding cluster with the entries in tseedcon. Fixme, this should be doable wo forloop..
mX(ismember(round(pX),cs))=tseedcon(cs);
end
sX=ismember(round(pX),currentseed);
set(handles.matthreshis,'String',num2str(thresh));
matsurf=ea_showconnectivitypatch(resultfig,pV,mX,thresh,[],[],[],1,0);
seedsurf=ea_showseedpatch(resultfig,pV,sX,options);
setappdata(resultfig,'matsurf',matsurf);
setappdata(resultfig,'seedsurf',seedsurf);
function [directory,pdirectory,selectedparc]=ea_cvinitgui(handles,options)
%% init/modify UI controls:
% parcellation popup:
pdirs=dir([options.earoot,filesep,'templates',filesep,'labeling',filesep,'*.nii']);
cnt=1;
for pdir=1:length(pdirs)
[~,parcs{cnt}]=fileparts(pdirs(pdir).name);
cnt=cnt+1;
end
set(handles.labelpopup,'String',parcs);
if get(handles.labelpopup,'Value')>length(get(handles.labelpopup,'String'));
set(handles.labelpopup,'Value',length(get(handles.labelpopup,'String')));
end
selectedparc=parcs{get(handles.labelpopup,'Value')};
pdirectory=[options.root,options.patientname,filesep,'connectomics',filesep,selectedparc,filesep];
% check if selected parcellation exists for patient data as well:
directory=[options.root,options.patientname,filesep];
pdirs=dir([directory,'connectomics',filesep]);
cnt=1;
parcs=cell(1);
parcs{1}='';
for pdir=1:length(pdirs)
if pdirs(pdir).isdir && ~strcmp(pdirs(pdir).name,'.') && ~strcmp(pdirs(pdir).name,'..')
parcs{cnt}=pdirs(pdir).name;
cnt=cnt+1;
end
end
if ~ismember({selectedparc},parcs)
cv_enablevats(handles);
%
end
function ea_initseedlevel(handles,directory,pdirectory,selectedparc,options)
%% init matrix level controls:
% dMRI:
cnt=1;
% check if pat-specific fibertracts are present:
if exist([directory,options.prefs.FTR_normalized],'file');
modlist{cnt}='Patient-specific fiber tracts';
cnt=cnt+1;
end
% check for canonical fiber sets
fdfibs=dir([ea_getconnectomebase('dmri'),'*.mat']);
for fdf=1:length(fdfibs)
[~,fn]=fileparts(fdfibs(fdf).name);
modlist{cnt}=fn;
cnt=cnt+1;
end
pmdirs=dir([pdirectory,'*_CM.mat']);
for pmdir=1:length(pmdirs)
[~,modlist{end+1}]=fileparts(pmdirs(pmdir).name);
end
tcdirs=dir([pdirectory,'*_tc.mat']);
for tcdir=1:length(tcdirs)
[~,modlist{end+1}]=fileparts(tcdirs(tcdir).name);
end
if ~exist('modlist','var')
cv_disablevats(handles);
cv_disablemats(handles);
else
cv_enablevats(handles);
cv_enablemats(handles);
end
set(handles.matmodality,'String',modlist);
if get(handles.matmodality,'Value')>length(get(handles.matmodality,'String'));
set(handles.matmodality,'Value',length(get(handles.matmodality,'String')));
end
% parcellation scheme
aID = fopen([options.earoot,'templates',filesep,'labeling',filesep,selectedparc,'.txt']);
atlas_lgnd=textscan(aID,'%d %s');
% store selected parcellation in figure:
% store pV and pX in figure
pV=spm_vol([options.earoot,'templates',filesep,'labeling',filesep,selectedparc,'.nii']);
pX=spm_read_vols(pV);
setappdata(handles.convis,'pV',pV);
setappdata(handles.convis,'pX',pX);
%d=length(atlas_lgnd{1}); % how many ROI.
mm=get(handles.matmodality,'String');
set(handles.matseed,'String',[atlas_lgnd{2}]);
if get(handles.matseed,'Value')>length(get(handles.matseed,'String'));
set(handles.matseed,'Value',length(get(handles.matseed,'String')));
end
function [filesare,labelsare,mods]=ea_initvoxellevel(handles,pdirectory)
%% init voxel level controls:
% Metric:
filesare{1}='';
if exist([pdirectory,'graph'],'file')
testits={'deg_','eig_','eff_','sfs_'};
labelits={'degree centrality','eigenvector centrality','nodal efficiency','structure function similarity'};
cnt=1;
for ti=1:length(testits)
tdir=dir([pdirectory,'graph',filesep,testits{ti},'*.nii']);
if ~isempty(tdir)
filesare{cnt}=testits{ti}; % present filetypes
labelsare{cnt}=labelits{ti}; % present labelnames
cnt=cnt+1;
end
end
if ~isempty(labelsare)
set(handles.voxmetric,'String',labelsare);
if get(handles.voxmetric,'Value')>length(get(handles.voxmetric,'String'));
set(handles.voxmetric,'Value',length(get(handles.voxmetric,'String')));
end
cv_enablevoxs(handles);
else
cv_disablevoxs(handles);
end
else
cv_disablevoxs(handles);
end
% Modality:
if exist('filesare','var')
selectedmetric=get(handles.voxmetric,'Value');
selectedprefix=filesare{selectedmetric}; % deg_, eig_, eff_ or sfs_
fis=dir([pdirectory,'graph',filesep,selectedprefix,'*.nii']);
cnt=1;
mods{1}='';
for fi=1:length(fis)
mods{cnt}=fis(fi).name(5:end);
[~,mods{cnt}]=fileparts(mods{cnt}); % remove .nii extension
cnt=cnt+1;
end
set(handles.voxmodality,'String',mods);
if get(handles.voxmodality,'Value')>length(get(handles.voxmodality,'String'));
set(handles.voxmodality,'Value',length(get(handles.voxmodality,'String')));
end
end
function ea_initvatlevel(handles,directory,selectedparc,options)
modlist=ea_genmodlist(directory,selectedparc,options);
%% VATs:
vdirs=dir([directory,'stimulations']);
cnt=1;
vdicell=cell(0);
for vdir=1:length(vdirs)
if vdirs(vdir).isdir && ~strcmp(vdirs(vdir).name(1),'.')
vdicell{cnt}=vdirs(vdir).name;
cnt=cnt+1;
end
end
%% set popup strings
if isempty(modlist)
set(handles.vatmodality,'String','No connectivity data found...');
else
set(handles.vatmodality,'String',modlist);
end
%% correct for wrong selections in popup menus.
if get(handles.vatmodality,'Value')>length(modlist) % probably user has changed parcellation..
set(handles.vatmodality,'Value',1);
end
if get(handles.vatseed,'Value')>length(get(handles.vatseed,'String'));
set(handles.vatseed,'Value',1);
end
%% handle empty popup cases:
if isempty(vdicell)
set(handles.vatseed,'String','No stimulation found...');
else
set(handles.vatseed,'String',vdicell);
end
if isempty(vdicell) || isempty(modlist)
cv_disablevats(handles)
else
cv_enablevats(handles)
%% check if left/right VATs are present
stimfolder=vdicell{get(handles.vatseed,'Value')};
vatdir=dir([directory,'stimulations',filesep,stimfolder,filesep,'*.nii']);
for vt=1:length(vatdir)
vatcell{vt}=vatdir(vt).name;
end
set(handles.rvatcheck,'Enable', ea_getonofftruefalse(ismember('vat_right.nii',vatcell)));
set(handles.lvatcheck,'Enable', ea_getonofftruefalse(ismember('vat_left.nii',vatcell)));
if strcmp(get(handles.rvatcheck,'Enable'),'off')
set(handles.rvatcheck,'Value', 0);
end
if strcmp(get(handles.lvatcheck,'Enable'),'off')
set(handles.lvatcheck,'Value', 0);
end
end
function oo=ea_getonofftruefalse(tf)
oo='off';
if tf
oo='on';
end
function resultfig=ea_cvcleanup(handles)
%% recruit handles from prior results from figure
resultfig=getappdata(handles.convis,'resultfig');
matsurf=getappdata(resultfig,'matsurf');
vatsurf=getappdata(resultfig,'vatsurf');
seedsurf=getappdata(resultfig,'seedsurf');
vatseedsurf=getappdata(resultfig,'vatseedsurf');
graphsurf=getappdata(resultfig,'graphsurf');
%% delete any prior results
try delete(matsurf); catch
for l=1:length(matsurf)
try delete(matsurf{l}); end
end
end
try delete(vatseedsurf); catch
for l=1:length(vatseedsurf)
try delete(vatseedsurf{l}); end
end
end
try delete(vatsurf); catch
for l=1:length(vatsurf)
try delete(vatsurf{l}); end
end
end
try delete(seedsurf); end
try delete(graphsurf); end
%% fiber results are only cleaned if really triggered (since they take quite long).
%% helperfunctions to enable/disable GUI parts.
function cv_enablevats(handles)
% set(handles.labelpopup,'Enable','on');
% set(handles.vizgraph,'Enable','off');
% set(handles.voxmodality,'Enable','off');
%
% set(handles.voxmetric,'Enable','off');
% set(handles.voxthresh,'Enable','off');
% set(handles.vizmat,'Enable','off');
% set(handles.matmodality,'Enable','off');
% set(handles.matseed,'Enable','off');
% set(handles.xmm,'Enable','off');
% set(handles.ymm,'Enable','off');
% set(handles.zmm,'Enable','off');
% set(handles.matthresh,'Enable','off');
% set(handles.timewindow,'Enable','off');
% set(handles.timeframe,'Enable','off');
% set(handles.timecircle,'Enable','off');
set(handles.vatmodality,'Enable','on');
set(handles.vatseed,'Enable','on');
set(handles.vatthresh,'Enable','on');
set(handles.vatthreshis,'Enable','on');
set(handles.lvatcheck,'Enable','on');
set(handles.rvatcheck,'Enable','on');
set(handles.vizvat,'Enable','on');
function cv_disablevoxs(handles)
set(handles.vizgraph,'Enable','off');
set(handles.voxmodality,'Enable','off');
set(handles.voxmetric,'Enable','off');
set(handles.voxthresh,'Enable','off');
function cv_enablevoxs(handles)
set(handles.vizgraph,'Enable','on');
set(handles.voxmodality,'Enable','on');
set(handles.voxmetric,'Enable','on');
set(handles.voxthresh,'Enable','on');
function cv_disablemats(handles)
set(handles.matmodality,'Enable','off');
set(handles.matseed,'Enable','off');
set(handles.xmm,'Enable','off');
set(handles.ymm,'Enable','off');
set(handles.zmm,'Enable','off');
set(handles.matthresh,'Enable','off');
set(handles.timewindow,'Enable','off');
set(handles.timeframe,'Enable','off');
set(handles.timecircle,'Enable','off');
function cv_disablewmats(handles)
set(handles.vizwmat,'Enable','off');
set(handles.wmatmodality,'Enable','off');
set(handles.wmatnodes,'Enable','off');
set(handles.wmatedges,'Enable','off');
set(handles.wmatthresh,'Enable','off');
function cv_enablewmats(handles)
set(handles.vizwmat,'Enable','on');
set(handles.wmatmodality,'Enable','on');
set(handles.wmatnodes,'Enable','on');
set(handles.wmatedges,'Enable','on');
set(handles.wmatthresh,'Enable','on');
function cv_enablemats(handles)
set(handles.labelpopup,'Enable','on');
set(handles.matmodality,'Enable','on');
set(handles.matseed,'Enable','on');
set(handles.xmm,'Enable','on');
set(handles.ymm,'Enable','on');
set(handles.zmm,'Enable','on');
set(handles.matthresh,'Enable','on');
set(handles.timewindow,'Enable','on');
set(handles.timeframe,'Enable','on');
set(handles.timecircle,'Enable','on');
function cv_disabletime(handles)
%set(handles.matthresh,'Enable','off');
set(handles.timewindow,'Enable','off');
set(handles.timeframe,'Enable','off');
set(handles.timecircle,'Enable','off');
function cv_enabletime(handles)
%set(handles.matthresh,'Enable','on');
set(handles.timewindow,'Enable','on');
set(handles.timeframe,'Enable','on');
set(handles.timecircle,'Enable','on');
function cv_disablevats(handles)
set(handles.vizvat,'Enable','off');
set(handles.vatmodality,'Enable','off');
set(handles.vatseed,'Enable','off');
set(handles.lvatcheck,'Enable','off');
set(handles.rvatcheck,'Enable','off');
set(handles.vatthresh,'Enable','off');
% --- Outputs from this function are returned to the command line.
function varargout = ea_convis_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in voxmetric.
function voxmetric_Callback(hObject, eventdata, handles)
% hObject handle to voxmetric (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns voxmetric contents as cell array
% contents{get(hObject,'Value')} returns selected item from voxmetric
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function voxmetric_CreateFcn(hObject, eventdata, handles)
% hObject handle to voxmetric (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in vizgraph.
function vizgraph_Callback(hObject, eventdata, handles)
% hObject handle to vizgraph (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of vizgraph
refreshcv(handles);
function voxthresh_Callback(hObject, eventdata, handles)
% hObject handle to voxthresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of voxthresh as text
% str2double(get(hObject,'String')) returns contents of voxthresh as a double
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function voxthresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to voxthresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in matseed.
function matseed_Callback(hObject, eventdata, handles)
% hObject handle to matseed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns matseed contents as cell array
% contents{get(hObject,'Value')} returns selected item from matseed
pV=getappdata(handles.convis,'pV');
pX=getappdata(handles.convis,'pX');
[xmm,ymm,zmm]=getcoordinates(pV,pX,get(handles.matseed,'Value'));
set(handles.xmm,'String',num2str(xmm)); set(handles.ymm,'String',num2str(ymm)); set(handles.zmm,'String',num2str(zmm));
set(handles.matseed,'ForegroundColor',[0,0,0]);
refreshcv(handles);
function [xmm,ymm,zmm]=getcoordinates(pV,pX,ix)
if ix<1
xmm=nan; ymm=nan; zmm=nan;
return
end
[xx,yy,zz]=ind2sub(size(pX),find(round(pX)==ix));
XYZ=[xx,yy,zz];
centrvx=[mean(XYZ,1),1];
centrmm=pV.mat*centrvx';
xmm=centrmm(1); ymm=centrmm(2); zmm=centrmm(3);
function [ix,err]=setcoordinates(handles)
% set seed selection based on manual coordinate entry.
pV=getappdata(handles.convis,'pV');
pX=getappdata(handles.convis,'pX');
xmm=str2double(get(handles.xmm,'String'));
ymm=str2double(get(handles.ymm,'String'));
zmm=str2double(get(handles.zmm,'String'));
err=0;
XYZmm=[xmm,ymm,zmm,1]';
XYZvox=pV.mat\XYZmm;
ix=0;
try
ix=pX(round(XYZvox(1)),round(XYZvox(2)),round(XYZvox(3)));
end
if ~ix
ix=nan;
err=1;
end
if ~err
set(handles.matseed,'Value',ix);
set(handles.matseed,'ForegroundColor',[0,0,0]);
else
set(handles.matseed,'ForegroundColor',[1,0,0]);
end
% --- Executes during object creation, after setting all properties.
function matseed_CreateFcn(hObject, eventdata, handles)
% hObject handle to matseed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in matmodality.
function matmodality_Callback(hObject, eventdata, handles)
% hObject handle to matmodality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns matmodality contents as cell array
% contents{get(hObject,'Value')} returns selected item from matmodality
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function matmodality_CreateFcn(hObject, eventdata, handles)
% hObject handle to matmodality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function matthresh_Callback(hObject, eventdata, handles)
% hObject handle to matthresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of matthresh as text
% str2double(get(hObject,'String')) returns contents of matthresh as a double
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function matthresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to matthresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in vizmat.
function vizmat_Callback(hObject, eventdata, handles)
% hObject handle to vizmat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of vizmat
refreshcv(handles);
function timewindow_Callback(hObject, eventdata, handles)
% hObject handle to timewindow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of timewindow as text
% str2double(get(hObject,'String')) returns contents of timewindow as a double
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function timewindow_CreateFcn(hObject, eventdata, handles)
% hObject handle to timewindow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in timecircle.
function timecircle_Callback(hObject, eventdata, handles)
% hObject handle to timecircle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of timecircle
refreshcv(handles);
function timeframe_Callback(hObject, eventdata, handles)
% hObject handle to timeframe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of timeframe as text
% str2double(get(hObject,'String')) returns contents of timeframe as a double
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function timeframe_CreateFcn(hObject, eventdata, handles)
% hObject handle to timeframe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in voxmodality.
function voxmodality_Callback(hObject, eventdata, handles)
% hObject handle to voxmodality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns voxmodality contents as cell array
% contents{get(hObject,'Value')} returns selected item from voxmodality
refreshcv(handles);
% --- Executes during object creation, after setting all properties.
function voxmodality_CreateFcn(hObject, eventdata, handles)
% hObject handle to voxmodality (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function xmm_Callback(hObject, eventdata, handles)
% hObject handle to xmm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of xmm as text
% str2double(get(hObject,'String')) returns contents of xmm as a double
setcoordinates(handles);
refreshcv(handles,1);
% --- Executes during object creation, after setting all properties.