forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matRadGUI.m
4280 lines (3493 loc) · 150 KB
/
matRadGUI.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 = matRadGUI(varargin)
% matRad GUI
%
% call
% MATRADGUI, by itself, creates a new MATRADGUI or raises the existing
% singleton*.
%
% H = MATRADGUI returns the handle to a new MATRADGUI or the handle to
% the existing singleton*.
%
% MATRADGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MATRADGUI.M with the given input arguments.
%
% MATRADGUI('Property','Value',...) creates a new MATRADGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before matRadGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to matRadGUI_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
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2015 the matRad development team.
%
% This file is part of the matRad project. It is subject to the license
% terms in the LICENSE file found in the top-level directory of this
% distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
% of the matRad project, including this file, may be copied, modified,
% propagated, or distributed except according to the terms contained in the
% LICENSE file.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
matRad_cfg = MatRad_Config.instance();
if matRad_cfg.disableGUI
matRad_cfg.dispInfo('matRad GUI disabled in matRad_cfg!\n');
return;
end
if ~isdeployed
matRadRootDir = fileparts(mfilename('fullpath'));
addpath(genpath(matRadRootDir));
end
[env, versionString] = matRad_getEnvironment();
% abort for octave
switch env
case 'MATLAB'
case 'OCTAVE'
matRad_cfg.dispInfo(['matRad GUI not available for ' env ' ' versionString ' \n']);
return;
otherwise
matRad_cfg.dispInfo('not yet tested');
end
% Begin initialization code - DO NOT EDIT
% set platform specific look and feel
if ispc
lf = 'com.sun.java.swing.plaf.windows.WindowsLookAndFeel';
elseif isunix
lf = 'com.jgoodies.looks.plastic.Plastic3DLookAndFeel';
elseif ismac
lf = 'com.apple.laf.AquaLookAndFeel';
end
javax.swing.UIManager.setLookAndFeel(lf);
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @matRadGUI_OpeningFcn, ...
'gui_OutputFcn', @matRadGUI_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
function handles = resetGUI(hObject, handles, varargin)
% enable opengl software rendering to visualize linewidths properly
if ispc
opengl software
elseif ismac
% opengl is not supported
end
% Choose default command line output for matRadGUI
handles.output = hObject;
%show matrad logo
axes(handles.axesLogo)
[im, ~, alpha] = imread('matrad_logo.png');
f = image(im);
axis equal off
set(f, 'AlphaData', alpha);
% show dkfz logo
axes(handles.axesDKFZ)
[im, ~, alpha] = imread('DKFZ_Logo.png');
f = image(im);
axis equal off;
set(f, 'AlphaData', alpha);
% turn off the datacursormode (since it does not allow to set scrolling
% callbacks
handles.dcm_obj = datacursormode(handles.figure1);
set(handles.dcm_obj,'DisplayStyle','window');
if strcmpi(get(handles.dcm_obj,'Enable'),'on')
set(handles.dcm_obj,'Enable','off');
end
%Add the callback for the datacursor display
set(handles.dcm_obj,'UpdateFcn',@dataCursorUpdateFunction);
% set callback for scroll wheel function
set(gcf,'WindowScrollWheelFcn',@matRadScrollWheelFcn);
% change color of toobar but only the first time GUI is started
if handles.initialGuiStart
hToolbar = findall(hObject,'tag','uitoolbar1');
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jToolbar.setBorderPainted(false);
color = java.awt.Color.gray;
% Remove the toolbar border, to blend into figure contents
jToolbar.setBackground(color);
% Remove the separator line between toolbar and contents
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
jFrame = get(handle(hObject),'JavaFrame');
jFrame.showTopSeparator(false);
jtbc = jToolbar.getComponents;
for idx=1:length(jtbc)
jtbc(idx).setOpaque(false);
jtbc(idx).setBackground(color);
for childIdx = 1 : length(jtbc(idx).getComponents)
jtbc(idx).getComponent(childIdx-1).setBackground(color);
end
end
end
set(handles.legendTable,'String',{'no data loaded'});
% clear VOIPlotFlag
if isfield(handles,'VOIPlotFlag')
handles = rmfield(handles,'VOIPlotFlag');
end
%seach for availabes machines
handles.Modalities = {'photons','protons','carbon'};
for i = 1:length(handles.Modalities)
pattern = [handles.Modalities{1,i} '_*'];
if isdeployed
baseroot = [ctfroot filesep 'matRad'];
else
baseroot = fileparts(mfilename('fullpath'));
end
Files = dir([baseroot filesep 'basedata' filesep pattern]);
for j = 1:length(Files)
if ~isempty(Files)
MachineName = Files(j).name(numel(handles.Modalities{1,i})+2:end-4);
if isfield(handles,'Machines')
if sum(strcmp(handles.Machines,MachineName)) == 0
handles.Machines{size(handles.Machines,2)+1} = MachineName;
end
else
handles.Machines = cell(1);
handles.Machines{1} = MachineName;
end
end
end
end
set(handles.popUpMachine,'String',handles.Machines);
vChar = get(handles.editGantryAngle,'String');
if strcmp(vChar(1,1),'0') && length(vChar)==6
set(handles.editGantryAngle,'String','0');
end
vChar = get(handles.editCouchAngle,'String');
if strcmp(vChar(1,1),'0') && length(vChar)==3
set(handles.editCouchAngle,'String','0')
end
%%
% handles.State=0 no data available
% handles.State=1 ct cst and pln available; ready for dose calculation
% handles.State=2 ct cst and pln available and dij matric(s) are calculated;
% ready for optimization
% handles.State=3 plan is optimized
% if plan is changed go back to state 1
% if table VOI Type or Priorities changed go to state 1
% if objective parameters changed go back to state 2
handles.CutOffLevel = 0.01; % relative cut off level for dose vis
handles.IsoDose.NewIsoDoseFlag = false;
handles.TableChanged = false;
handles.State = 0;
handles.doseOpacity = 0.6;
handles.IsoDose.Levels = 0;
handles.dispWindow = cell(3,2); % first dimension refers to the selected
% do not calculate / suggest isoCenter new by default
set(handles.checkIsoCenter, 'Value', 0);
set(handles.editIsoCenter,'Enable','on')
% suppose no ct cube in HU is available (because no ct could be available)
handles.cubeHUavailable = false;
% initial startup finished
handles.initialGuiStart = false;
guidata(hObject, handles);
% eof resetGUI
% --- Initializes the slice slider for the current ct & isocenter (or sets
% it to default)
function initViewSliceSlider(handles)
% handles structure with handles and user data (see GUIDATA)
if handles.State > 0
ct = evalin('base', 'ct');
%Helpers for managing the resolution and Matlab xy permutation
planePermute = [2 1 3];
ctRes = [ct.resolution.x ct.resolution.y ct.resolution.z];
planePermIx = planePermute(handles.plane);
planeDim = ct.cubeDim(handles.plane);
%Try to select the slice from defined isocenter
try
if evalin('base','exist(''pln'',''var'')')
currPln = evalin('base','pln');
if sum(currPln.propStf.isoCenter(:)) ~= 0
%currSlice = round((currPln.propStf.isoCenter(1,planePermIx)+ctRes(planePermix)/2)/ctRes(planePermIx))-1;
currSlice = round(currPln.propStf.isoCenter(1,planePermIx) / ctRes(planePermIx));
else
currSlice = 0;
end
end
catch
currSlice = 0; %Set to zero for next if
end
%If no isocenter or wrong value, choose central slice
if currSlice < 1 || currSlice > planeDim
currSlice = ceil(planeDim/2);
end
set(handles.sliderSlice,'Min',1,'Max',planeDim,...
'Value',currSlice,...
'SliderStep',[1/(planeDim-1) 1/(planeDim-1)]);
else
% reset slider when nothing is loaded
set(handles.sliderSlice,'Min',0,'Max',1,'Value',0,'SliderStep',[1 1]);
end
function handles = reloadGUI(hObject, handles, ct, cst)
AllVarNames = handles.AllVarNames;
if nargin >=3 && ismember('ct',AllVarNames)
% compute HU values
if ~isfield(ct, 'cubeHU')
ct = matRad_electronDensitiesToHU(ct);
assignin('base','ct',ct);
end
if ~isfield(ct, 'cubeHU')
handles.cubeHUavailable = false;
else
handles.cubeHUavailable = true;
end
end
%set plan if available - if not create one
try
if ismember('pln',AllVarNames) && handles.State > 0
% check if you are working with a valid pln
pln = evalin('base','pln');
if ~isfield(pln,'propStf')
handles = showWarning(handles,'GUI OpeningFunc: Overwriting outdated pln format with default GUI pln');
evalin('base','clear pln');
getPlnFromGUI(handles);
end
setPln(handles);
elseif handles.State > 0
getPlnFromGUI(handles);
setPln(handles);
end
catch
handles.State = 0;
handles = showError(handles,'GUI OpeningFunc: Could not set or get pln');
end
% check for dij structure
if ismember('dij',AllVarNames)
handles.State = 2;
end
% check for optimized results
if ismember('resultGUI',AllVarNames)
handles.State = 3;
end
% set some default values
if handles.State == 2 || handles.State == 3
set(handles.popupDisplayOption,'String','physicalDose');
handles.SelectedDisplayOption ='physicalDose';
handles.SelectedDisplayOptionIdx=1;
else
handles.resultGUI = [];
set(handles.popupDisplayOption,'String','no option available');
handles.SelectedDisplayOption='';
handles.SelectedDisplayOptionIdx=1;
end
% precompute iso dose lines
if handles.State == 3
handles = updateIsoDoseLineCache(handles);
end
%per default the first beam is selected for the profile plot
handles.selectedBeam = 1;
handles.plane = get(handles.popupPlane,'Value');
handles.DijCalcWarning = false;
% set slice slider
initViewSliceSlider(handles);
% define context menu for structures
if handles.State > 0
for i = 1:size(cst,1)
if cst{i,5}.Visible
handles.VOIPlotFlag(i) = true;
else
handles.VOIPlotFlag(i) = false;
end
end
end
%Initialize colormaps and windows
handles.doseColorMap = 'jet';
handles.ctColorMap = 'bone';
handles.cMapSize = 64;
handles.cBarChanged = true;
%Set up the colormap selection box
availableColormaps = matRad_getColormap();
set(handles.popupmenu_chooseColormap,'String',availableColormaps);
currentCtMapIndex = find(strcmp(availableColormaps,handles.ctColorMap));
currentDoseMapIndex = find(strcmp(availableColormaps,handles.doseColorMap));
if handles.State >= 1
set(handles.popupmenu_chooseColormap,'Value',currentCtMapIndex);
end
if handles.State >= 3
set(handles.popupmenu_chooseColormap,'Value',currentDoseMapIndex);
end
% Update handles structure
handles.profileOffset = 0;
UpdateState(handles)
axes(handles.axesFig)
handles.rememberCurrAxes = false;
UpdatePlot(handles)
handles.rememberCurrAxes = true;
guidata(hObject, handles);
% eof reloadGUI
% --- Executes just before matRadGUI is made visible.
function matRadGUI_OpeningFcn(hObject, ~, handles, varargin)
%#ok<*DEFNU>
%#ok<*AGROW>
% 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 matRadGUI (see VARARGIN)
% variable to check whether GUI is opened or just refreshed / new data
% loaded, since resetGUI needs to distinguish at one point
handles.initialGuiStart = true;
p = inputParser;
addParameter(p,'devMode',false,@validateModeValue);
addParameter(p,'eduMode',false,@validateModeValue);
p.KeepUnmatched = true; %No error with incorrect parameters
parse(p,varargin{:});
parsedInput = p.Results;
if ischar(parsedInput.devMode) || isstring(parsedInput.devMode)
parsedInput.devMode = str2double(parsedInput.devMode);
end
if ischar(parsedInput.eduMode) || isstring(parsedInput.eduMode)
parsedInput.eduMode = str2double(parsedInput.eduMode);
end
%If devMode is true, error dialogs will include the full stack trace of the error
%If false, only the basic error message is shown (works for errors that
%handle the MException object)
handles.devMode = logical(parsedInput.devMode);
if handles.devMode
disp('matRadGUI starting in developer mode!');
end
%Enables simple educational mode which removes certain functionality from
%the GUI
handles.eduMode = logical(parsedInput.eduMode);
if handles.eduMode
disp('matRadGUI starting in educational mode!');
end
set(handles.radiobtnPlan,'value',0);
if handles.eduMode
%Visisbility in Educational Mode
eduHideHandles = {handles.radiobutton3Dconf,...
handles.btnRunDAO,...
handles.pushbutton_importFromBinary,...
handles.btnLoadDicom,...
handles.btn_export,...
handles.importDoseButton};
eduDisableHandles = {handles.editCouchAngle,handles.popUpMachine};
cellfun(@(h) set(h,'Visible','Off'),eduHideHandles);
cellfun(@(h) set(h,'Enable','Off'),eduDisableHandles);
end
%Alter matRad Version string positioning
vString = matRad_version();
vPos = get(handles.text15,'Position');
urlPos = get(handles.text31,'Position');
btnPos = get(handles.btnAbout,'Position');
%vPos([1 3]) = urlPos([1 3]);
vPos([1 3]) = [0 1];
vPos(4) = vPos(4)*1.25;
btnPos(2) = 0.05;
urlPos(2) = btnPos(2)+btnPos(4)+0.05;
vPos(2) = urlPos(2) + urlPos(4) + 0.05;
vPos(4) = 0.98 - vPos(2);
set(handles.btnAbout,'Position',btnPos);
set(handles.text31,'String','www.matRad.org','Position',urlPos,'Enable','inactive','ButtonDownFcn', @(~,~) web('www.matrad.org','-browser'));
set(handles.text15,'String',vString,'Position',vPos);
handles = resetGUI(hObject, handles);
%% parse variables from base workspace
AllVarNames = evalin('base','who');
handles.AllVarNames = AllVarNames;
try
if ismember('ct',AllVarNames) && ismember('cst',AllVarNames)
ct = evalin('base','ct');
cst = evalin('base','cst');
%cst = setCstTable(handles,cst);
cst = generateCstTable(handles,cst);
handles.State = 1;
cst = matRad_computeVoiContoursWrapper(cst,ct);
assignin('base','cst',cst);
elseif ismember('ct',AllVarNames) && ~ismember('cst',AllVarNames)
handles = showError(handles,'GUI OpeningFunc: could not find cst file');
elseif ~ismember('ct',AllVarNames) && ismember('cst',AllVarNames)
handles = showError(handles,'GUI OpeningFunc: could not find ct file');
end
catch
handles = showError(handles,'GUI OpeningFunc: Could not load ct and cst file');
end
if ismember('ct',AllVarNames) && ismember('cst',AllVarNames)
handles = reloadGUI(hObject, handles, ct, cst);
else
handles = reloadGUI(hObject, handles);
end
guidata(hObject, handles);
%Validates the attributes for the command line Modes
function validateModeValue(x)
%When passed from OS terminal (or inline in Command Window) everything is a string
if isdeployed || ischar(x) || isstring(x)
x=str2double(x);
end
validateattributes(x,{'logical','numeric'},{'scalar','binary'});
function Callback_StructVisibilty(source,~)
handles = guidata(findobj('Name','matRadGUI'));
contextUiChildren = get(get(handles.figure1,'UIContextMenu'),'Children');
Idx = find(strcmp(get(contextUiChildren,'Label'),get(source,'Label')));
if strcmp(get(source,'Checked'),'on')
set(contextUiChildren(Idx),'Checked','off');
else
set(contextUiChildren(Idx),'Checked','on');
end
%guidata(findobj('Name','matRadGUI'), handles);
UpdatePlot(handles);
% --- Outputs from this function are returned to the command line.
function varargout = matRadGUI_OutputFcn(~, ~, 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;
% set focus on error dialog
if isfield(handles,'ErrorDlg')
figure(handles.ErrorDlg)
end
% --- Executes on button press in btnLoadMat.
function btnLoadMat_Callback(hObject, ~, handles)
% hObject handle to btnLoadMat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName, FilePath] = uigetfile('*.mat');
if FileName == 0 % user pressed cancel --> do nothing.
return;
end
handles = resetGUI(hObject, handles);
try
% delete existing workspace - parse variables from base workspace
AllVarNames = evalin('base','who');
RefVarNames = {'ct','cst','pln','stf','dij','resultGUI'};
for i = 1:length(RefVarNames)
if sum(ismember(AllVarNames,RefVarNames{i}))>0
evalin('base',['clear ', RefVarNames{i}]);
end
end
% read new data
load([FilePath FileName]);
set(handles.legendTable,'String',{'no data loaded'});
set(handles.popupDisplayOption,'String','no option available');
catch ME
handles = showError(handles,'LoadMatFileFnc: Could not load *.mat file',ME);
guidata(hObject,handles);
UpdateState(handles);
UpdatePlot(handles);
return
end
try
generateCstTable(handles,cst);
handles.TableChanged = false;
set(handles.popupTypeOfPlot,'Value',1);
cst = matRad_computeVoiContoursWrapper(cst,ct);
assignin('base','ct',ct);
assignin('base','cst',cst);
handles.State = 1;
catch ME
handles = showError(handles,'LoadMatFileFnc: Could not load *.mat file',ME);
end
% check if a optimized plan was loaded
if exist('stf','var')
assignin('base','stf',stf);
end
if exist('pln','var')
assignin('base','pln',pln);
end
if exist('dij','var')
assignin('base','dij',dij);
end
% if exist('stf','var') && exist('dij','var')
% handles.State = 2;
% end
if exist('resultGUI','var')
assignin('base','resultGUI',resultGUI);
% handles.State = 3;
% handles.SelectedDisplayOption ='physicalDose';
end
% recheck current workspace variables
AllVarNames = evalin('base','who');
handles.AllVarNames = AllVarNames;
if ismember('ct',AllVarNames) && ismember('cst',AllVarNames)
handles = reloadGUI(hObject, handles, ct, cst);
else
handles = reloadGUI(hObject, handles);
end
guidata(hObject,handles);
% --- Executes on button press in btnLoadDicom.
function btnLoadDicom_Callback(hObject, ~, handles)
% hObject handle to btnLoadDicom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
% delete existing workspace - parse variables from base workspace
set(handles.popupDisplayOption,'String','no option available');
AllVarNames = evalin('base','who');
RefVarNames = {'ct','cst','pln','stf','dij','resultGUI'};
for i = 1:length(RefVarNames)
if sum(ismember(AllVarNames,RefVarNames{i}))>0
evalin('base',['clear ', RefVarNames{i}]);
end
end
handles.State = 0;
matRad_importDicomGUI;
catch
handles = showError(handles,'DicomImport: Could not import data');
end
UpdateState(handles);
guidata(hObject,handles);
% --- Executes on button press in btn_export.
function btn_export_Callback(hObject, eventdata, handles)
% hObject handle to btn_export (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
matRad_exportGUI;
catch
handles = showError(handles,'Could not export data');
end
UpdateState(handles);
guidata(hObject,handles);
function editBixelWidth_Callback(hObject, ~, handles)
% hObject handle to editBixelWidth (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 editBixelWidth as text
% str2double(get(hObject,'String')) returns contents of editBixelWidth as a double
getPlnFromGUI(handles);
if handles.State > 0
handles.State = 1;
UpdateState(handles);
guidata(hObject,handles);
end
function editGantryAngle_Callback(hObject, ~, handles)
% hObject handle to editGantryAngle (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 editGantryAngle as text
% str2double(get(hObject,'String')) returns contents of editGantryAngle as a double
getPlnFromGUI(handles);
if handles.State > 0
handles.State = 1;
UpdateState(handles);
UpdatePlot(handles);
guidata(hObject,handles);
end
function editCouchAngle_Callback(hObject, ~, handles)
% hObject handle to editCouchAngle (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 editCouchAngle as text
% str2double(get(hObject,'String')) returns contents of editCouchAngle as a double
getPlnFromGUI(handles);
if handles.State > 0
handles.State = 1;
UpdateState(handles);
guidata(hObject,handles);
end
% --- Executes on selection change in popupRadMode.
function popupRadMode_Callback(hObject, eventdata, handles)
% hObject handle to popupRadMode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
checkRadiationComposition(handles);
contents = cellstr(get(hObject,'String'));
RadIdentifier = contents{get(hObject,'Value')};
contentPopUp = get(handles.popMenuBioOpt,'String');
switch RadIdentifier
case 'photons'
set(handles.popMenuBioOpt,'Enable','off');
ix = find(strcmp(contentPopUp,'none'));
set(handles.popMenuBioOpt,'Value',ix);
set(handles.btnSetTissue,'Enable','off');
set(handles.btnRunSequencing,'Enable','on');
set(handles.btnRunDAO,'Enable','on');
set(handles.radiobutton3Dconf,'Enable','on');
set(handles.txtSequencing,'Enable','on');
set(handles.editSequencingLevel,'Enable','on');
case 'protons'
set(handles.popMenuBioOpt,'Enable','on');
ix = find(strcmp(contentPopUp,'const_RBExD'));
set(handles.popMenuBioOpt,'Value',ix);
set(handles.btnSetTissue,'Enable','on');
set(handles.btnSetTissue,'Enable','off');
set(handles.btnRunSequencing,'Enable','off');
set(handles.btnRunDAO,'Enable','off');
set(handles.radiobutton3Dconf,'Enable','off');
set(handles.txtSequencing,'Enable','off');
set(handles.editSequencingLevel,'Enable','off');
case 'carbon'
set(handles.popMenuBioOpt,'Enable','on');
ix = find(strcmp(contentPopUp,'LEMIV_RBExD'));
set(handles.popMenuBioOpt,'Value',ix);
set(handles.btnSetTissue,'Enable','on');
set(handles.btnRunSequencing,'Enable','off');
set(handles.btnRunDAO,'Enable','off');
set(handles.radiobutton3Dconf,'Enable','off');
set(handles.txtSequencing,'Enable','off');
set(handles.editSequencingLevel,'Enable','off');
end
if handles.State > 0
pln = evalin('base','pln');
if handles.State > 0 && ~strcmp(contents(get(hObject,'Value')),pln.radiationMode)
% new radiation modality is photons -> just keep physicalDose
if strcmp(contents(get(hObject,'Value')),'photons')
try
AllVarNames = evalin('base','who');
if ismember('resultGUI',AllVarNames)
resultGUI = evalin('base','resultGUI');
if isfield(resultGUI,'alpha'); resultGUI = rmfield(resultGUI,'alpha'); end
if isfield(resultGUI,'beta'); resultGUI = rmfield(resultGUI,'beta'); end
if isfield(resultGUI,'RBExDose'); resultGUI = rmfield(resultGUI,'RBExDose');end
if isfield(resultGUI,'RBE'); resultGUI = rmfield(resultGUI,'RBE'); end
assignin('base','resultGUI',resultGUI);
handles = updateIsoDoseLineCache(handles);
end
catch
end
elseif strcmp(contents(get(hObject,'Value')),'protons')
try
AllVarNames = evalin('base','who');
if ismember('resultGUI',AllVarNames)
resultGUI = evalin('base','resultGUI');
if isfield(resultGUI,'alpha'); resultGUI = rmfield(resultGUI,'alpha');end
if isfield(resultGUI,'beta'); resultGUI = rmfield(resultGUI,'beta'); end
if isfield(resultGUI,'RBE'); resultGUI = rmfield(resultGUI,'RBE'); end
assignin('base','resultGUI',resultGUI);
handles = updateIsoDoseLineCache(handles);
end
catch
end
end
guidata(hObject,handles);
UpdatePlot(handles);
getPlnFromGUI(handles);
handles.State = 1;
UpdateState(handles);
end
guidata(hObject,handles);
end
% --- Executes on button press in btnCalcDose.
function btnCalcDose_Callback(hObject, ~, handles)
% hObject handle to btnCalcDose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% http://stackoverflow.com/questions/24703962/trigger-celleditcallback-before-button-callback
% http://www.mathworks.com/matlabcentral/newsreader/view_thread/332613
% wait some time until the CallEditCallback is finished
% Callback triggers the cst saving mechanism from GUI
try
% indicate that matRad is busy
% change mouse pointer to hour glass
Figures = gcf;%findobj('type','figure');
set(Figures, 'pointer', 'watch');
drawnow;
% disable all active objects
InterfaceObj = findobj(Figures,'Enable','on');
set(InterfaceObj,'Enable','off');
% read plan from gui and save it to workspace
% gets also IsoCenter from GUI if checkbox is not checked
getPlnFromGUI(handles);
% get default iso center as center of gravity of all targets if not
% already defined
pln = evalin('base','pln');
if length(pln.propStf.gantryAngles) ~= length(pln.propStf.couchAngles)
handles = showWarning(handles,'number of gantryAngles != number of couchAngles');
end
%%
if ~checkRadiationComposition(handles)
fileName = [pln.radiationMode '_' pln.machine];
handles = showError(handles,errordlg(['Could not find the following machine file: ' fileName ]));
guidata(hObject,handles);
return;
end
%% check if isocenter is already set
if ~isfield(pln.propStf,'isoCenter')
handles = showWarning(handles,'no iso center set - using center of gravity based on structures defined as TARGET');
pln.propStf.isoCenter = ones(pln.propStf.numOfBeams,1) * matRad_getIsoCenter(evalin('base','cst'),evalin('base','ct'));
assignin('base','pln',pln);
elseif ~get(handles.checkIsoCenter,'Value')
if ~strcmp(get(handles.editIsoCenter,'String'),'multiple isoCenter')
pln.propStf.isoCenter = ones(pln.propStf.numOfBeams,1)*str2num(get(handles.editIsoCenter,'String'));
end
end
catch ME
handles = showError(handles,'CalcDoseCallback: Error in preprocessing!',ME);
% change state from busy to normal
set(Figures, 'pointer', 'arrow');
set(InterfaceObj,'Enable','on');
guidata(hObject,handles);
return;
end
% generate steering file
try
currPln = evalin('base','pln');
% if we run 3d conf opt -> hijack runDao to trigger computation of
% connected bixels
if strcmp(pln.radiationMode,'photons') && get(handles.radiobutton3Dconf,'Value')
currpln.propOpt.runDAO = true;
end
stf = matRad_generateStf(evalin('base','ct'),...
evalin('base','cst'),...
currPln);
assignin('base','stf',stf);
catch ME
handles = showError(handles,'CalcDoseCallback: Error in steering file generation!',ME);
% change state from busy to normal
set(Figures, 'pointer', 'arrow');
set(InterfaceObj,'Enable','on');
guidata(hObject,handles);
return;
end
% carry out dose calculation
try
if strcmp(pln.radiationMode,'photons')
dij = matRad_calcPhotonDose(evalin('base','ct'),stf,pln,evalin('base','cst'));
elseif strcmp(pln.radiationMode,'protons') || strcmp(pln.radiationMode,'carbon')
dij = matRad_calcParticleDose(evalin('base','ct'),stf,pln,evalin('base','cst'));
end
% assign results to base worksapce
assignin('base','dij',dij);
handles.State = 2;
handles.TableChanged = false;
UpdateState(handles);
UpdatePlot(handles);
guidata(hObject,handles);
catch ME
handles = showError(handles,'CalcDoseCallback: Error in dose calculation!',ME);
% change state from busy to normal
set(Figures, 'pointer', 'arrow');
set(InterfaceObj,'Enable','on');
guidata(hObject,handles);
return;
end
% change state from busy to normal
set(Figures, 'pointer', 'arrow');
set(InterfaceObj,'Enable','on');
guidata(hObject,handles);
%% plots ct and distributions
function UpdatePlot(handles)
%profile on;
axes(handles.axesFig);
% this is necessary to prevent multiple callbacks of update plot drawing on
% top of each other in matlab <2014
drawnow;
defaultFontSize = 8;
currAxes = axis(handles.axesFig);
AxesHandlesCT_Dose = gobjects(0);
AxesHandlesVOI = cell(0);
AxesHandlesIsoDose = gobjects(0);
if handles.State == 0
cla reset
return
elseif handles.State > 0
ct = evalin('base','ct');
cst = evalin('base','cst');
pln = evalin('base','pln');
end
%% state 3 indicates that a optimization has been performed
AllVarNames = evalin('base','who');
if ismember('resultGUI',AllVarNames)
Result = evalin('base','resultGUI');
end
if exist('Result','var')
if ~isempty(Result) && ~isempty(ct.cubeHU) && ~isfield(handles,'DispInfo')
DispInfo = fieldnames(Result);
for i = 1:size(DispInfo,1)
% delete weight vectors in Result struct for plotting
if isstruct(Result.(DispInfo{i,1})) || isvector(Result.(DispInfo{i,1}))
Result = rmfield(Result,DispInfo{i,1});
DispInfo{i,2}=false;
else
%second dimension indicates if it should be plotted
DispInfo{i,2} = true;
% determine units
if strfind(DispInfo{i,1},'physicalDose')
DispInfo{i,3} = '[Gy]';
elseif strfind(DispInfo{i,1},'alpha')
DispInfo{i,3} = '[Gy^{-1}]';
elseif strfind(DispInfo{i,1},'beta')
DispInfo{i,3} = '[Gy^{-2}]';
elseif strfind(DispInfo{i,1},'RBExD')
DispInfo{i,3} = '[Gy(RBE)]';
elseif strfind(DispInfo{i,1},'LET')
DispInfo{i,3} = '[keV/um]';
else
DispInfo{i,3} = '[a.u.]';
end
DispInfo{i,4} = []; % optional for the future: color range for plotting
DispInfo{i,5} = []; % optional for the future: min max values
end
end
set(handles.popupDisplayOption,'String',fieldnames(Result));
if sum(strcmp(handles.SelectedDisplayOption,fieldnames(Result))) == 0
handles.SelectedDisplayOption = DispInfo{find([DispInfo{:,2}],1,'first'),1};
end
set(handles.popupDisplayOption,'Value',find(strcmp(handles.SelectedDisplayOption,fieldnames(Result))));
end
end
%% set and get required variables
plane = get(handles.popupPlane,'Value');
slice = round(get(handles.sliderSlice,'Value'));
hold(handles.axesFig,'on');
if get(handles.popupTypeOfPlot,'Value')==1
set(handles.axesFig,'YDir','Reverse');
end
%% Remove colorbar?