-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathea_mercontrol.m
More file actions
executable file
·859 lines (675 loc) · 34.2 KB
/
ea_mercontrol.m
File metadata and controls
executable file
·859 lines (675 loc) · 34.2 KB
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
function varargout = ea_mercontrol(varargin)
%EA_MERCONTROL MATLAB code file for ea_mercontrol.fig
% EA_MERCONTROL, by itself, creates a new EA_MERCONTROL or raises the existing
% singleton*.
%
% H = EA_MERCONTROL returns the handle to a new EA_MERCONTROL or the handle to
% the existing singleton*.
%
% EA_MERCONTROL('Property','Value',...) creates a new EA_MERCONTROL using the
% given property value pairs. Unrecognized properties are passed via
% varargin to ea_mercontrol_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% EA_MERCONTROL('CALLBACK') and EA_MERCONTROL('CALLBACK',hObject,...) call the
% local function named CALLBACK in EA_MERCONTROL.M with the given input
% arguments.
%
% *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_mercontrol
% Last Modified by GUIDE v2.5 28-Jul-2017 15:26:39
% __________________________________________________________________________________
% Copyright (C) 2017 University of Pittsburgh, Brain Modulation Lab
%
% Ari Kappel
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ea_mercontrol_OpeningFcn, ...
'gui_OutputFcn', @ea_mercontrol_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
%%%%%%%%%%%%%%%%%% GUIDE-generated functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes just before ea_mercontrol is made visible.
function ea_mercontrol_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
clc
set(hObject, 'Name', 'MER Control',...
'CloseRequestFcn', @closefunction, 'KeyPressFcn', @ea_keypress)
% Choose default command line output for ea_mercontrol
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ea_mercontrol wait for user response (see UIRESUME)
% uiwait(handles.mercontrolfig);
if nargin==4 % trajectory object supplied
trajectory=varargin{1};
resultfig=trajectory.plotFigureH;
options=trajectory.options;
setappdata(hObject,'trajectory',trajectory);
else % classical way of opening MER control figure
resultfig=varargin{1};
options=varargin{2};
end
setappdata(hObject, 'resultfig', resultfig);
setappdata(hObject, 'options', options); % Keep a copy of options
% Get the MER State, set it to defaults if not supplied, and store it in appdata.
if exist('trajectory','var') && ~isempty(trajectory.merstruct)
merstruct=trajectory.merstruct;
else
merstruct = MERState();
merstruct.setOptions(options);
merstruct.clearData();
if exist('trajectory','var')
merstruct.Trajectory=trajectory;
end
merstruct.setDataToDefaults();
end
setappdata(hObject, 'merstruct', merstruct);
% merhandles is a struct array, each element has .side and .label (strings)
% for indexing, and .h (plotted object handle)
merhandles = struct('color_list', cat(1, options.prefs.mer.tract_info.color),...
'traj', struct('side', {}, 'label', {}, 'h', []),...
'markers', struct('side', {}, 'label', {}, 'depth', [], 'h', [], 'tag', []));
setappdata(hObject, 'merhandles', merhandles);
ea_gui_generate(handles); % Generate UI elements for each tract.
ea_resultfig_clear(handles); % Delete markers and mer trajectories.
ea_resultfig_update(handles); % Plot markers and trajs from data.
ea_mercontrol_updateall(handles); % Set GUI from data.
% --- Outputs from this function are returned to the command line.
function varargout = ea_mercontrol_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 pushtrackmer_left.
function pushtrackmer_left_Callback(hObject, eventdata, handles)
% hObject handle to pushtrackmer_left (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 pushtrackmer_left contents as cell array
% contents{get(hObject,'Value')} returns selected item from pushtrackmer_left
sidestr='left';
resultfig=getappdata(handles.mercontrolfig,'resultfig');
options=getappdata(handles.mercontrolfig,'options');
ea_trackmer(sidestr,resultfig,options)
% --- Executes during object creation, after setting all properties.
function pushtrackmer_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushtrackmer_left (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 pushimportrec_left.
function pushimportrec_left_Callback(hObject, eventdata, handles)
% hObject handle to pushimportrec_left (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 pushimportrec_left contents as cell array
% contents{get(hObject,'Value')} returns selected item from pushimportrec_left
sidestr='left'; side=2;
resultfig=getappdata(handles.mercontrolfig,'resultfig');
options=getappdata(handles.mercontrolfig,'options');
[Depth,Thresh,Tracts] = ea_readmer(fullfile(options.root,options.patientname,['Rec_',sidestr,'.mat']));
merlfp.(sidestr).Depth = Depth;
merlfp.(sidestr).Tracts = Tracts;
merlfp.(sidestr).Thresh = Thresh;
save(fullfile(options.root,options.patientname,'ea_recordings.mat'),'merlfp')
disp('Process DONE')
% --- Executes during object creation, after setting all properties.
function pushimportrec_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushimportrec_left (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 popupmedial_left.
function popupmedial_left_Callback(hObject, eventdata, handles)
% hObject handle to popupmedial_left (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 popupmedial_left contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmedial_left
% --- Executes during object creation, after setting all properties.
function popupmedial_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmedial_left (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 pushtrackmer_right.
function pushtrackmer_right_Callback(hObject, eventdata, handles)
% hObject handle to pushtrackmer_right (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 pushtrackmer_right contents as cell array
% contents{get(hObject,'Value')} returns selected item from pushtrackmer_right
% --- Executes during object creation, after setting all properties.
function pushtrackmer_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushtrackmer_right (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 pushimportrec_right.
function pushimportrec_right_Callback(hObject, eventdata, handles)
% hObject handle to pushimportrec_right (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 pushimportrec_right contents as cell array
% contents{get(hObject,'Value')} returns selected item from pushimportrec_right
% --- Executes during object creation, after setting all properties.
function pushimportrec_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushimportrec_right (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 popupmedial_right.
function popupmedial_right_Callback(hObject, eventdata, handles)
% hObject handle to popupmedial_right (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 popupmedial_right contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmedial_right
% --- Executes during object creation, after setting all properties.
function popupmedial_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmedial_right (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 popupimplantedtract_left.
function popupimplantedtract_left_Callback(hObject, eventdata, handles)
popupimplantedtract_helper(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function popupimplantedtract_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupimplantedtract_left (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 popupimplantedtract_right.
function popupimplantedtract_right_Callback(hObject, eventdata, handles)
popupimplantedtract_helper(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function popupimplantedtract_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupimplantedtract_right (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 editimplanteddepth_left_Callback(hObject, eventdata, handles)
editimplanteddepth_helper(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function editimplanteddepth_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to editimplanteddepth_left (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
function editimplanteddepth_right_Callback(hObject, eventdata, handles)
editimplanteddepth_helper(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function editimplanteddepth_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to editimplanteddepth_right (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 popupmermarkers_right.
function popupmermarkers_right_Callback(hObject, eventdata, handles)
% hObject handle to popupmermarkers_right (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 popupmermarkers_right contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmermarkers_right
% --- Executes during object creation, after setting all properties.
function popupmermarkers_right_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmermarkers_right (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 popupmermarkers_left.
function popupmermarkers_left_Callback(hObject, eventdata, handles)
% hObject handle to popupmermarkers_left (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 popupmermarkers_left contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmermarkers_left
% --- Executes during object creation, after setting all properties.
function popupmermarkers_left_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmermarkers_left (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 clearall.
function clearall_Callback(hObject, eventdata, handles)
% hObject handle to clearall (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ea_data_clear(handles); % Clears trajectories, depths, etc in merstruct.
ea_resultfig_clear(handles); % Delete markers and mer trajectories.
ea_mercontrol_updateall(handles); % Set GUI from data.
% --- Executes during object creation, after setting all properties.
function clearall_CreateFcn(hObject, eventdata, handles)
% hObject handle to clearall (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/delete.png']);
set(hObject,'CData',background);
% --- Executes on button press in setdefault.
function setdefault_Callback(hObject, eventdata, handles)
% hObject handle to setdefault (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ea_resultfig_clear(handles); % Delete markers and mer trajectories visualizations.
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.setDataToDefaults();
ea_resultfig_update(handles); % Plot markers and trajs from data.
ea_mercontrol_updateall(handles); % Set GUI from data.
% --- Executes during object creation, after setting all properties.
function setdefault_CreateFcn(hObject, eventdata, handles)
% hObject handle to setdefault (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/checkmark.png']);
set(hObject,'CData',background)
% --- Executes on button press in undomarker.
function undomarker_Callback(hObject, eventdata, handles)
% hObject handle to undomarker (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.undoMarker();
ea_resultfig_updatemarkers(handles); % Sync handles to match markers.
ea_mercontrol_updatemarkers(handles); % Enable/Disable marker gui elements.
% --- Executes during object creation, after setting all properties.
function undomarker_CreateFcn(hObject, eventdata, handles)
% hObject handle to undomarker (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/undo.png']);
set(hObject,'CData',background,'Value',0)
% --- Executes on button press in redomarker.
function redomarker_Callback(hObject, eventdata, handles)
% hObject handle to redomarker (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.redoMarker();
ea_resultfig_updatemarkers(handles); % Sync handles to match markers.
ea_mercontrol_updatemarkers(handles); % Enable/Disable marker gui elements.
% --- Executes during object creation, after setting all properties.
function redomarker_CreateFcn(hObject, eventdata, handles)
% hObject handle to redomarker (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/redo.png']);
set(hObject,'CData',background,'Value',0)
% --- Executes on button press in togglemarkertags.
function togglemarkertags_Callback(hObject, eventdata, handles)
% hObject handle to togglemarkertags (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 togglemarkertags
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
if get(hObject,'Value')
merstruct.Config.vis.tag_visible = 'on';
else
merstruct.Config.vis.tag_visible = 'off';
end
ea_resultfig_updatemarkers(handles);
% --- Executes during object creation, after setting all properties.
function togglemarkertags_CreateFcn(hObject, eventdata, handles)
% hObject handle to togglemarkertags (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/text.png']);
set(hObject,'CData',background,'Value',0)
% --- Executes on button press in loadstate.
function loadstate_Callback(hObject, eventdata, handles)
% hObject handle to loadstate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.load();
ea_resultfig_update(handles);
ea_mercontrol_updateall(handles);
% --- Executes during object creation, after setting all properties.
function loadstate_CreateFcn(hObject, eventdata, handles)
% hObject handle to loadstate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/import.png']);
set(hObject,'CData',background,'Value',0)
% --- Executes on button press in savestate.
function savestate_Callback(hObject, eventdata, handles)
% hObject handle to savestate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.save();
% --- Executes during object creation, after setting all properties.
function savestate_CreateFcn(hObject, eventdata, handles)
% hObject handle to savestate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
root = fileparts(which('ea_coregmr.m'));
background = imread([root,'/icons/export.png']);
set(hObject,'CData',background,'Value',0)
% --- Executes on button press in pushbutton_clear_checks.
function pushbutton_clear_checks_Callback(hObject, eventdata, handles)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.setTogglesToDefaults();
ea_mercontrol_updatetoggles(handles);
% --- Executes on button press in nexframeadj.
function nexframeadj_Callback(hObject, eventdata, handles)
% hObject handle to nexframeadj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Modal window for nexdrive rotation.
ea_nexframegui(handles.mercontrolfig);
%%%%%%%%%%%%%%%%% Custom functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ea_keypress(handles, event) %#ok<INUSL>
% this is the main keypress function for the mercontrolfig.
% Add event listeners here.
if ismember('shift', event.Modifier)
end
fprintf('Keypress ignored. Click on resultfig first.\n')
function closefunction(hObject, event) %#ok<INUSD>
handles = getappdata(hObject,'UsedByGUIData_m');
ea_resultfig_clear(handles);
ea_data_clear(handles);
delete(hObject)
function ea_gui_generate(handles)
% ea_gui_generate(handles)
% For each side, for each tract_inf, generates
% -display toggle button
% -position/depth edit box
% -keyboard control toggle
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
% Generate UI elements
width = handles.mainuipanel.Position(3)-5;
for side_str = {'left', 'right'}
bSide = strcmpi({merstruct.Config.MERTrajectory.side}, side_str);
side_tract_info = merstruct.Config.MERTrajectory(bSide);
% In mainuipanel...
% ...Add options to popupimplantedtract_left _right
uq_labels = unique({side_tract_info.label});
popup_string = cat(2, 'Set implanted...', uq_labels);
set(handles.(['popupimplantedtract_' side_str{:}]),...
'String', popup_string);
% ...Add togglebuttons next to texttoggle_left and _right (with callbacks)
anchor_pos = get(handles.(['texttoggle_' side_str{:}]), 'Position');
w_per = (width - anchor_pos(3) - anchor_pos(1)) / length(side_tract_info);
for tract_ix = 1:length(side_tract_info)
pos_str = side_tract_info(tract_ix).label;
new_pos = [anchor_pos(1) + anchor_pos(3) + (tract_ix-1)*w_per...
anchor_pos(2)-5 w_per 26];
uicontrol(handles.mainuipanel,...
'Style', 'togglebutton',...
'Tag', ['toggle' pos_str '_' side_str{:}],...
'String', pos_str,...
'Position', new_pos,...
'Units', 'pixels',...
'BackgroundColor', [1 1 1],...
'Value', 1,...
'Callback', @ea_updatetogglestate);
end
% ...Add edit boxes next to textpos_left and _right (with callbacks)
anchor_pos = get(handles.(['textpos_' side_str{:}]), 'Position');
w_per = (width - anchor_pos(3) - anchor_pos(1)) / length(side_tract_info);
for tract_ix = 1:length(side_tract_info)
pos_str = side_tract_info(tract_ix).label;
new_pos = [anchor_pos(1) + anchor_pos(3) + (tract_ix-1)*w_per...
anchor_pos(2)-5 w_per 26];
uicontrol(handles.mainuipanel,...
'Style', 'edit',...
'Tag', ['pos' pos_str '_' side_str{:}],...
'String', '0',...
'Position', new_pos,...
'Units', 'pixels',...
'BackgroundColor', [1 1 1],...
'Callback', @ea_updatepostext);
end
% In keyboardcontrolgroup...
% ...Add radiobuttons next to keytext_left and _right inside
anchor_pos = get(handles.(['textkey_' side_str{:}]), 'Position');
w_per = (width - anchor_pos(3) - anchor_pos(1)) / length(side_tract_info);
for tract_ix = 1:length(side_tract_info)
pos_str = side_tract_info(tract_ix).label;
new_pos = [anchor_pos(1) + anchor_pos(3) + (tract_ix-1)*w_per...
anchor_pos(2) w_per anchor_pos(4)];
uicontrol(handles.keyboardcontrolgroup,...
'Style', 'checkbox',...
'Tag', ['keycheck' pos_str '_' side_str{:}],...
'String', pos_str,...
'Position', new_pos,...
'Units', 'pixels',...
'BackgroundColor', [1 1 1],...
'Callback', @ea_keycheck);
end
end
function ea_keycheck(hObject, eventdata) %#ok<INUSD>
[side_strs, sid, track] = ea_detsidestr(hObject.Tag);
% Update the value
handles = guidata(hObject);
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
bSide = strcmpi({merstruct.Toggles.keycontrol.side}, side_strs{sid});
bLabel = strcmpi({merstruct.Toggles.keycontrol.label}, track);
merstruct.Toggles.keycontrol(bSide & bLabel).value = get(hObject,'Value') == get(hObject,'Max');
function ea_data_clear(handles, varargin)
% ea_clear_data(handles)
% Resets trajectories, depths, etc.
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.setDataToDefaults();
function ea_resultfig_clear(handles)
% ea_resultfig_clear(handles)
% Delete markers and plot empty 3dplot trajs.
ea_resultfig_clear_traj(handles);
ea_resultfig_clear_markers(handles);
function ea_resultfig_clear_traj(handles)
resultfig = getappdata(handles.mercontrolfig, 'resultfig');
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merhandles = getappdata(handles.mercontrolfig, 'merhandles');
if isvalid(resultfig)
% Get a list of tags for all the plotted items in resultfig.
curr_fig_items = resultfig.CurrentAxes.Children;
tag_array = arrayfun(@(x)x.Tag, curr_fig_items, 'UniformOutput', false)';
set(0, 'CurrentFigure', resultfig); hold on;
uqlabels = unique({merstruct.MERTrajectories.label}, 'stable');
for traj_ix = 1:length(merstruct.MERTrajectories)
traj = merstruct.MERTrajectories(traj_ix);
bH = strcmpi({merhandles.traj.side}, traj.side) & strcmpi({merhandles.traj.label}, traj.label);
delete([merhandles.traj(bH).h]);
merhandles.traj(bH) = [];
resid_items = curr_fig_items(strcmpi(tag_array, [traj.label '_' traj.side]));
if ~isempty(resid_items)
delete(resid_items);
end
% Create the plot handle.
% Because we aren't plotting anything, the object handle will remain
% empty. color and tag are ignored.
this_color = merhandles.color_list(strcmpi(uqlabels, traj.label), :);
h = plot3([], [], [], 'color', this_color,...
'linew', 5, 'tag', [traj.label '_' traj.side]);
merhandles.traj(end+1) = struct('side', traj.side, 'label', traj.label, 'h', h);
end
setappdata(handles.mercontrolfig, 'merhandles', merhandles);
end
function ea_resultfig_clear_markers(handles)
merhandles = getappdata(handles.mercontrolfig, 'merhandles');
for marker_ix = 1:length(merhandles.markers)
try delete(merhandles.markers(marker_ix).h); end
try delete(merhandles.markers(marker_ix).tag); end
merhandles.markers(marker_ix).h = [];
if isfield(merhandles.markers(marker_ix), 'tag')
merhandles.markers(marker_ix).tag = [];
end
end
setappdata(handles.mercontrolfig, 'merhandles', merhandles)
function ea_resultfig_update(handles)
% ea_resultfig_update(handles)
% Updates trajectory plot and markers plot from data.
ea_resultfig_updatetrajectories(handles);
ea_resultfig_updatemarkers(handles);
function ea_mercontrol_updateall(handles)
% ea_mercontrol_updateall(handles)
% Update GUI elements from data structs.
ea_mercontrol_updateimplanted(handles);
ea_mercontrol_updatetoggles(handles);
ea_mercontrol_updatemarkers(handles);
function ea_mercontrol_updatetoggles(handles)
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
ui_tags = {handles.mainuipanel.Children.Tag};
kcg_tags = {handles.keyboardcontrolgroup.Children.Tag};
for ts_ix = 1:length(merstruct.Toggles.togglestates)
ts = merstruct.Toggles.togglestates(ts_ix);
set(handles.mainuipanel.Children(strcmpi(ui_tags,...
['toggle', ts.label, '_', ts.side])), 'Value', ts.value);
end
for kc_ix = 1:length(merstruct.Toggles.keycontrol)
kc = merstruct.Toggles.keycontrol(kc_ix);
set(handles.keyboardcontrolgroup.Children(strcmpi(kcg_tags,...
['keycheck', kc.label, '_', kc.side])), 'Value', kc.value);
end
function editimplanteddepth_helper(hObject, eventdata, handles)
depth = str2double(get(hObject, 'String'));
str_parts = strsplit(eventdata.Source.Tag, '_');
[sidestr, side_ix, ~] = ea_detsidestr(str_parts{2});
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.updateDBSDepth(sidestr{side_ix}, depth);
ea_mercontrol_updateimplanted(handles, sidestr{side_ix});
ea_resultfig_updatetrajectories(handles, sidestr{side_ix});
function popupimplantedtract_helper(hObject, eventdata, handles) %#ok<INUSL>
str_parts = strsplit(hObject.Tag, '_');
[sidestr, side_ix, ~] = ea_detsidestr(str_parts{2});
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.updateDBSImplantTrack(sidestr{side_ix}, hObject.String{hObject.Value});
ea_resultfig_updatetrajectories(handles, sidestr{side_ix});
function ea_updatepostext(hObject, eventData) %#ok<INUSD>
% Called when one of the position text boxes is edited.
handles = guidata(hObject);
[side_strs, sid, track] = ea_detsidestr(hObject.Tag);
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
merstruct.updateTrajDepth(side_strs{sid}, track, str2double(get(hObject, 'String')));
ea_resultfig_updatetrajectories(handles);
function ea_updatetogglestate(hObject, eventdata) %#ok<INUSD>
% Called when one of the tract toggle buttons is pressed.
[side_strs, sid, track] = ea_detsidestr(hObject.Tag);
handles = guidata(hObject);
merstruct = getappdata(handles.mercontrolfig, 'merstruct');
bToggle = strcmpi({merstruct.Toggles.togglestates.side}, side_strs{sid}) ...
& strcmpi({merstruct.Toggles.togglestates.label}, track);
merstruct.Toggles.togglestates(bToggle).value = hObject.Value;
% Update the visual presentation
ea_resultfig_updatetrajectories(handles);
function [files,subs] = fdir(Path,ext)
% Returns contents of path as struct
% Option to keep only files with input extension
%
% Inputs:
%
%
% Ari Kappel, 2017
%
if isempty(Path) || ~exist('Path','var')
Path = pwd;
end
contents = dir(Path);
contents = contents(cellfun(@(x) isempty(regexp(x, '^\.', 'once')), {contents.name}));
if ~isempty({contents(~[contents.isdir]).name})
files = contents(~[contents.isdir]);
end
if ~isempty({contents([contents.isdir]).name})
subs = contents([contents.isdir]);
end
if nargin==2
files = files(~cellfun(@isempty, strfind({files.name},ext)));
end