forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatRadGUI.m
More file actions
3285 lines (2750 loc) · 111 KB
/
Copy pathmatRadGUI.m
File metadata and controls
3285 lines (2750 loc) · 111 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
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.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% abort for octave
if exist('OCTAVE_VERSION','builtin');
fprintf('matRad GUI not available for Octave.\n');
return;
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
% --- 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)
% enable opengl software rendering to visualize linewidths properly
if ispc || isunix
opengl software
elseif ismac
% opengl is not supported
end
if ~isdeployed
currFolder = fileparts(mfilename('fullpath'));
else
currFolder = [];
end
% Choose default command line output for matRadGUI
handles.output = hObject;
%show matrad logo
axes(handles.axesLogo)
[im, ~, alpha] = imread([currFolder filesep 'dicomImport' filesep 'matrad_logo.png']);
f = image(im);
axis equal off
set(f, 'AlphaData', alpha);
% show dkfz logo
axes(handles.axesDKFZ)
[im, ~, alpha] = imread([currFolder filesep 'dicomImport' filesep 'DKFZ_Logo.png']);
f = image(im);
axis equal off;
set(f, 'AlphaData', alpha);
% set callback for scroll wheel function
set(gcf,'WindowScrollWheelFcn',@matRadScrollWheelFcn);
% change color of toobar
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
handles.legendTable.String{1} = 'not data loaded';
%initialize maximum dose for visualization to Zero
handles.maxDoseVal = 0;
handles.IsoDose.Levels = 0;
handles.plotColorbar = 1;
%seach for availabes machines
handles.Modalities = {'photons','protons','carbon'};
for i = 1:length(handles.Modalities)
pattern = [handles.Modalities{1,i} '_*'];
if isdeployed
Files = dir([ctfroot filesep 'matRad' filesep pattern]);
else
Files = dir([fileparts(mfilename('fullpath')) filesep pattern]);
end
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.005;
handles.IsoDose.NewIsoDoseFlag = false;
handles.TableChanged = false;
handles.State = 0;
%% parse variables from base workspace
AllVarNames = evalin('base','who');
try
if ismember('ct',AllVarNames) && ismember('cst',AllVarNames)
ct = evalin('base','ct');
cst = evalin('base','cst');
setCstTable(handles,cst);
handles.State = 1;
% check if contours are precomputed
if size(cst,2) < 7
cst = precomputeContours(ct,cst);
assignin('base','cst',cst);
end
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
%set plan if available - if not create one
try
if ismember('pln',AllVarNames) && handles.State > 0
setPln(handles);
elseif handles.State > 0
getPlnFromGUI(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
resultGUI = evalin('base','resultGUI');
if ~isfield(resultGUI,'isoDoseContours')
handles = precomputeIsoDoseLevels(handles);
end
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
if handles.State > 0
set(handles.sliderSlice,'Min',1,'Max',ct.cubeDim(handles.plane),...
'Value',ceil(ct.cubeDim(handles.plane)/2),...
'SliderStep',[1/(ct.cubeDim(handles.plane)-1) 1/(ct.cubeDim(handles.plane)-1)]);
% define context menu for structures
for i = 1:size(cst,1)
if cst{i,5}.Visible
handles.VOIPlotFlag(i) = true;
else
handles.VOIPlotFlag(i) = false;
end
end
end
% Update handles structure
handles.profileOffset = 0;
UpdateState(handles)
handles.rememberCurrAxes = false;
UpdatePlot(handles)
handles.rememberCurrAxes = true;
guidata(hObject, handles);
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)
try
[FileName, FilePath] = uigetfile('*.mat');
if FileName == 0 % user pressed cancel --> do nothing.
return;
end
% 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
% clear state and read new data
handles.State = 0;
load([FilePath FileName]);
handles.legendTable.String = {'no data loaded'};
catch
handles = showWarning(handles,'LoadMatFileFnc: Could not load *.mat file');
guidata(hObject,handles);
UpdatePlot(handles);
UpdateState(handles);
return
end
try
setCstTable(handles,cst);
handles.TableChanged = false;
set(handles.popupTypeOfPlot,'Value',1);
% precompute contours
cst = precomputeContours(ct,cst);
assignin('base','ct',ct);
assignin('base','cst',cst);
catch
handles = showError(handles,'LoadMatFileFnc: Could not load selected data');
end
try
if exist('pln','var')
% assess plan from loaded *.mat file
assignin('base','pln',pln);
setPln(handles);
else
% assess plan variable from GUI
getPlnFromGUI(handles);
setPln(handles);
end
handles.State = 1;
catch
handles.State = 0;
end
% check if a optimized plan was loaded
if exist('stf','var')
assignin('base','stf',stf);
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
% set slice slider
handles.plane = get(handles.popupPlane,'value');
if handles.State >0
set(handles.sliderSlice,'Min',1,'Max',ct.cubeDim(handles.plane),...
'Value',round(ct.cubeDim(handles.plane)/2),...
'SliderStep',[1/(ct.cubeDim(handles.plane)-1) 1/(ct.cubeDim(handles.plane)-1)]);
end
if handles.State > 0
% define context menu for structures
for i = 1:size(cst,1)
if cst{i,5}.Visible
handles.VOIPlotFlag(i) = true;
else
handles.VOIPlotFlag(i) = false;
end
end
end
UpdateState(handles);
handles.rememberCurrAxes = false;
UpdatePlot(handles);
handles.rememberCurrAxes = true;
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
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;
if ~isdeployed
matRadRootDir = fileparts(mfilename('fullpath'));
addpath(fullfile(matRadRootDir,'dicomImport'))
end
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
if ~isdeployed
matRadRootDir = fileparts(mfilename('fullpath'));
addpath(fullfile(matRadRootDir,'IO'))
end
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);
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')};
switch RadIdentifier
case 'photons'
set(handles.vmcFlag,'Value',0);
set(handles.vmcFlag,'Enable','on')
set(handles.radbtnBioOpt,'Value',0);
set(handles.radbtnBioOpt,'Enable','off');
set(handles.btnTypBioOpt,'Enable','off');
set(handles.btnSetTissue,'Enable','off');
set(handles.btnRunSequencing,'Enable','on');
set(handles.btnRunDAO,'Enable','on');
set(handles.txtSequencing,'Enable','on');
set(handles.editSequencingLevel,'Enable','on');
case 'protons'
set(handles.vmcFlag,'Value',0);
set(handles.vmcFlag,'Enable','off')
set(handles.radbtnBioOpt,'Value',0);
set(handles.radbtnBioOpt,'Enable','off');
set(handles.btnTypBioOpt,'Enable','off');
set(handles.btnSetTissue,'Enable','off');
set(handles.btnRunSequencing,'Enable','off');
set(handles.btnRunDAO,'Enable','off');
set(handles.txtSequencing,'Enable','off');
set(handles.editSequencingLevel,'Enable','off');
case 'carbon'
set(handles.vmcFlag,'Value',0);
set(handles.vmcFlag,'Enable','off')
set(handles.radbtnBioOpt,'Value',1);
set(handles.radbtnBioOpt,'Enable','on');
set(handles.btnTypBioOpt,'Enable','on');
set(handles.btnSetTissue,'Enable','on');
set(handles.btnRunSequencing,'Enable','off');
set(handles.btnRunDAO,'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)
% switched from carbon to photons or protons -> in case of bio. opt
% some cubes have to be deleted from the resultGUI struct
if strcmp(pln.radiationMode,'carbon') && ~strcmp(contents(get(hObject,'Value')),'carbon')
try
AllVarNames = evalin('base','who');
if ismember('resultGUI',AllVarNames)
resultGUI = evalin('base','resultGUI');
resultGUI = rmfield(resultGUI,'effect');
resultGUI = rmfield(resultGUI,'alpha');
resultGUI = rmfield(resultGUI,'beta');
resultGUI = rmfield(resultGUI,'RBE');
resultGUI = rmfield(resultGUI,'RBExDose');
assignin('base','resultGUI',resultGUI)
end
catch
assignin('base','resultGUI',resultGUI)
end
UpdatePlot(handles);
end
getPlnFromGUI(handles);
handles.State = 1;
UpdateState(handles);
guidata(hObject,handles);
end
end
% --- Executes on button press in radbtnBioOpt.
function radbtnBioOpt_Callback(hObject, ~, handles)
% hObject handle to radbtnBioOpt (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 radbtnBioOpt
getPlnFromGUI(handles);
if get(hObject,'Value')
set(handles.btnTypBioOpt,'Enable','on');
set(handles.btnSetTissue,'Enable','on');
else
set(handles.btnTypBioOpt,'Enable','off');
set(handles.btnSetTissue,'Enable','off');
end
if handles.State > 0
handles.State = 1;
UpdateState(handles);
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');
pause(0.1);
uiTable_CellEditCallback(hObject,[],handles);
pause(0.3);
%% get cst from table
if ~getCstTable(handles);
return
end
% 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.gantryAngles) ~= length(pln.couchAngles)
handles = showWarning(handles,warndlg('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,'isoCenter')
handles = showWarning(handles,warning('no iso center set - using center of gravity based on structures defined as TARGET'));
pln.isoCenter = matRad_getIsoCenter(evalin('base','cst'),evalin('base','ct'));
assignin('base','pln',pln);
elseif ~get(handles.checkIsoCenter,'Value')
pln.isoCenter = str2num(get(handles.editIsoCenter,'String'));
end
catch ME
handles = showError(handles,{'CalcDoseCallback: Error in preprocessing!',ME.message});
% change state from busy to normal
set(Figures, 'pointer', 'arrow');
set(InterfaceObj,'Enable','on');
guidata(hObject,handles);
return;
end
% generate steering file
try
stf = matRad_generateStf(evalin('base','ct'),...
evalin('base','cst'),...
evalin('base','pln'));
assignin('base','stf',stf);
catch ME
handles = showError(handles,{'CalcDoseCallback: Error in steering file generation!',ME.message});
% 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')
if get(handles.vmcFlag,'Value') == 0
dij = matRad_calcPhotonDose(evalin('base','ct'),stf,pln,evalin('base','cst'));
elseif get(handles.vmcFlag,'Value') == 1
dij = matRad_calcPhotonDoseVmc(evalin('base','ct'),stf,pln,evalin('base','cst'));
end
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;
UpdatePlot(handles);
UpdateState(handles);
guidata(hObject,handles);
catch ME
handles = showError(handles,{'CalcDoseCallback: Error in dose calculation!',ME.message});
% 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)
defaultFontSize = 8;
currAxes = axis;
AxesHandlesCT_Dose = gobjects(0);
AxesHandlesVOI = gobjects(0);
AxesHandlesIsoDose = gobjects(0);
if handles.State == 0
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
if handles.State > 2
Result = evalin('base','resultGUI');
end
if exist('Result','var')
if ~isempty(Result) && ~isempty(ct.cube)
if isfield(Result,'RBE')
Result.RBETruncated10Perc = Result.RBE;
Result.RBETruncated10Perc(Result.physicalDose<0.1*...
max(Result.physicalDose(:))) = 0;
end
DispInfo =fieldnames(Result);
for i = 1:size(DispInfo,1)
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 later on
DispInfo{i,2}=true;
DisablePlot = {'RBETruncated10Perc'};
if strcmp(DispInfo{i,1},DisablePlot)
DispInfo{i,2}=false;
end
% 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
end
end
set(handles.popupDisplayOption,'String',fieldnames(Result));
if sum(strcmp(handles.SelectedDisplayOption,fieldnames(Result))) == 0
handles.SelectedDisplayOption = 'physicalDose';
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'));
%% plot ct
if ~isempty(ct) && get(handles.popupTypeOfPlot,'Value')==1
cla(handles.axesFig);
axes(handles.axesFig);
if plane == 1 % Coronal plane
ct_rgb = ind2rgb(uint8(63*(squeeze(ct.cube{1}(slice,:,:)/max(ct.cube{1}(:))))),bone);
elseif plane == 2 % sagittal plane
ct_rgb = ind2rgb(uint8(63*(squeeze(ct.cube{1}(:,slice,:)/max(ct.cube{1}(:))))),bone);
elseif plane == 3 % Axial plane
ct_rgb = ind2rgb(uint8(63*(squeeze(ct.cube{1}(:,:,slice)/max(ct.cube{1}(:))))),bone);
end
axes(handles.axesFig)
AxesHandlesCT_Dose(end+1) = imagesc(ct_rgb);
end
%% plot dose cube
if handles.State >2 && get(handles.popupTypeOfPlot,'Value')== 1
% if the selected display option doesn't exist then simply display
% the first cube of the Result struct
if ~isfield(Result,handles.SelectedDisplayOption)
CubeNames = fieldnames(Result);
handles.SelectedDisplayOption = CubeNames{1,1};
end
mVolume = getfield(Result,handles.SelectedDisplayOption);
% make sure to exploit full color range
mVolume(mVolume<handles.CutOffLevel*max(mVolume(:))) = 0;
% %% dose colorwash
if ~isempty(mVolume)&& ~isvector(mVolume)
if handles.maxDoseVal == 0
handles.maxDoseVal = max(mVolume(:));
set(handles.txtMaxDoseVal,'String',num2str(handles.maxDoseVal))
end
dose = mVolume./handles.maxDoseVal;
dose(dose>1) = 1;
% Save RGB indices for dose in zslice´s voxels.
if plane == 1 % Coronal plane
dose_slice = squeeze(dose(slice,:,:));
elseif plane == 2 % sagittal plane
dose_slice = squeeze(dose(:,slice,:));
elseif plane == 3 % Axial plane
dose_slice = squeeze(dose(:,:,slice));
end
axes(handles.axesFig)
dose_rgb = ind2rgb(uint8(63*dose_slice),jet);
% plot dose distribution
hDose = imagesc('CData',dose_rgb,'Parent',handles.axesFig);
AxesHandlesCT_Dose(end+1) = hDose;
if get(handles.radiobtnDose,'Value')
if strcmp(get(handles.popupDisplayOption,'String'),'RBETruncated10Perc')
set(hDose,'AlphaData', .6*(double(dose_slice)>0.1));
else
set(hDose,'AlphaData', .6*(double(dose_slice)>handles.CutOffLevel));
end
else
set(hDose,'AlphaData', 0) ;
end
% plot colorbar
if handles.plotColorbar == 1;
v=version;
if str2double(v(1:3))>=8.5
cBarHandel = colorbar(handles.axesFig,'colormap',jet,'FontSize',defaultFontSize,'yAxisLocation','right');
else
cBarHandel = colorbar('peer',handles.axesFig,'FontSize',defaultFontSize,'yAxisLocation','right');
end
Idx = find(strcmp(handles.SelectedDisplayOption,DispInfo(:,1)));
set(get(cBarHandel,'ylabel'),'String', [DispInfo{Idx,1} ' ' DispInfo{Idx,3} ],'fontsize',defaultFontSize);
% do not interprete as tex syntax
set(get(cBarHandel,'ylabel'),'interpreter','none');
if isempty(strfind(handles.SelectedDisplayOption,'RBE'))
set(cBarHandel,'YLim',[0 handles.maxDoseVal]);
caxis(handles.axesFig,[0,handles.maxDoseVal])
else
set(cBarHandel,'YLim',[0 handles.maxDoseVal]);
caxis(handles.axesFig,[0,handles.maxDoseVal])
end
end
end
axes(handles.axesFig)
text(0,0,'','units','norm') % fix for line width ...
%% plot iso dose lines
if get(handles.radiobtnIsoDoseLines,'Value')
% get current isoDoseLevels
vLevels = handles.IsoDose.Levels;
if any(handles.isoDoseContours{slice,plane}(:))
% plot precalculated contourc data
colors = jet;
colors = colors(round(63*vLevels(vLevels <= handles.maxDoseVal)./handles.maxDoseVal),:);
%colors = colors(round(63*vLevels./max(vLevels)),:);
lower = 1; % lower marks the beginning of a section
while lower-1 ~= size(handles.isoDoseContours{slice,plane},2);
steps = handles.isoDoseContours{slice,plane}(2,lower); % number of elements of current line section
AxesHandlesIsoDose(end+1) = line(handles.isoDoseContours{slice,plane}(1,lower+1:lower+steps),...
handles.isoDoseContours{slice,plane}(2,lower+1:lower+steps),...
'Color',colors(vLevels(:) == handles.isoDoseContours{slice,plane}(1,lower),:),'LineWidth',1.5,'Parent',handles.axesFig);
if get(handles.radiobtnIsoDoseLinesLabels,'Value') == 1
text(handles.isoDoseContours{slice,plane}(1,lower+1),...
handles.isoDoseContours{slice,plane}(2,lower+1),...
num2str(handles.isoDoseContours{slice,plane}(1,lower)),'Parent',handles.axesFig)
end
lower = lower+steps+1;
end
end
end
end
%% plot VOIs
axes(handles.axesFig)
if get(handles.radiobtnContour,'Value') && get(handles.popupTypeOfPlot,'Value')==1 && handles.State>0
colors = colorcube;
colors = colors(round(linspace(1,63,size(cst,1))),:);
for s = 1:size(cst,1)
if ~strcmp(cst{s,3},'IGNORED') && handles.VOIPlotFlag(s)
% plot precalculated contourc data
if any(cst{s,7}{slice,plane}(:))
lower = 1; % lower marks the beginning of a section
while lower-1 ~= size(cst{s,7}{slice,plane},2);
hold on
steps = cst{s,7}{slice,plane}(2,lower); % number of elements of current line section
AxesHandlesVOI(end+1) = line(cst{s,7}{slice,plane}(1,lower+1:lower+steps),...
cst{s,7}{slice,plane}(2,lower+1:lower+steps),...
'Color',colors(s,:),'LineWidth',2.0,'Parent',handles.axesFig);
lower = lower+steps+1;
end
end
end
end
end
%% Set axis labels and plot iso center
FlagIsoCenterVisible = false;
vIsoCenter = round(pln.isoCenter./[ct.resolution.x ct.resolution.y ct.resolution.z]);
if plane == 3% Axial plane
if ~isempty(pln)
vIsoCenterPlot = [vIsoCenter(1) vIsoCenter(2)];
if vIsoCenter(3) == slice
FlagIsoCenterVisible = true;
end
set(handles.axesFig,'XTick',0:50/ct.resolution.x:1000);
set(handles.axesFig,'YTick',0:50/ct.resolution.y:1000);
set(handles.axesFig,'XTickLabel',0:50:1000*ct.resolution.x);
set(handles.axesFig,'YTickLabel',0:50:1000*ct.resolution.y);
xlabel('x [mm]','FontSize',defaultFontSize)
ylabel('y [mm]','FontSize',defaultFontSize)
title(['axial plane z = ' num2str(ct.resolution.z*slice) ' [mm]'],'FontSize',defaultFontSize)
else
xlabel('x [voxels]','FontSize',defaultFontSize)
ylabel('y [voxels]','FontSize',defaultFontSize)
title('axial plane','FontSize',defaultFontSize)
end
elseif plane == 2 % Sagittal plane
if ~isempty(pln)
vIsoCenterPlot = [vIsoCenter(3) vIsoCenter(2)];
if vIsoCenter(2) == slice
FlagIsoCenterVisible = true;
end
set(handles.axesFig,'XTick',0:50/ct.resolution.z:1000)
set(handles.axesFig,'YTick',0:50/ct.resolution.y:1000)
set(handles.axesFig,'XTickLabel',0:50:1000*ct.resolution.z)
set(handles.axesFig,'YTickLabel',0:50:1000*ct.resolution.y)
xlabel('z [mm]','FontSize',defaultFontSize);
ylabel('y [mm]','FontSize',defaultFontSize);
title(['sagittal plane x = ' num2str(ct.resolution.y*slice) ' [mm]'],'FontSize',defaultFontSize)
else
xlabel('z [voxels]','FontSize',defaultFontSize)
ylabel('y [voxels]','FontSize',defaultFontSize)