123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- function varargout = goal_def_UI(varargin)
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @goal_def_test_OpeningFcn, ...
- 'gui_OutputFcn', @goal_def_test_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
- function goal_def_test_OpeningFcn(hObject, eventdata, handles, varargin)
- handles.output = hObject;
- disp('varargin')
- if numel(varargin) == 0
- load('WiscPlan_preferences.mat')
- [handles.Data.Geo_fileName,handles.Data.Geo_path,FilterIndex] = uigetfile([WiscPlan_preferences.patientDataPath '\matlab_files\*.mat'], 'Select Geometry file')
- load([handles.Data.Geo_path, handles.Data.Geo_fileName])
- end
- for i = 1: numel(Geometry.ROIS)
- handles.uitable1.ColumnFormat{2}{i} = Geometry.ROIS{i}.name;
- end
- handles.uitable1.ColumnFormat{5}{1} = 'min';
- handles.uitable1.ColumnFormat{5}{2} = 'max';
- handles.uitable1.ColumnFormat{5}{3} = 'min_sq';
- handles.uitable1.ColumnFormat{5}{4} = 'max_sq';
- handles.uitable1.ColumnFormat{5}{5} = 'LeastSquare';
- handles.uitable1.ColumnFormat{5}{6} = 'min_perc_Volume';
- handles.uitable1.ColumnFormat{5}{7} = 'max_perc_Volume';
- handles.uitable1.Data = handles.uitable1.Data(1,:);
- handles.uitable1.Data{1} = 'Goal 1';
- handles.uitable1.Data{2} = 'Target';
- handles.uitable1.Data{3} = 'Fixed dose';
- handles.uitable1.Data{4} = '60';
- handles.uitable1.Data{5} = 'min_sq';
- handles.uitable1.Data{6} = 100;
- handles.uitable1.Data{7} = 'null';
- guidata(hObject, handles);
- end
- function varargout = goal_def_test_OutputFcn(hObject, eventdata, handles)
- varargout{1} = handles.output;
- end
- function addRow_Callback(hObject, eventdata, handles)
- handles.uitable1.Data{end+1, 1} = ['Goal ' num2str(size(handles.uitable1.Data,1)+1)];
- end
- function removeRow_Callback(hObject, eventdata, handles)
- newTable = handles.uitable1.Data;
- rowToDelete = str2double(handles.Remove_row_N.String);
- if rowToDelete>size(newTable, 2)
- disp(['No row ' num2str(rowToDelete)])
- else
- newTable(rowToDelete,:) = [];
- handles.uitable1.Data = newTable;
- end
- end
- function Remove_row_N_Callback(hObject, eventdata, handles)
- num = str2double(handles.Remove_row_N.String);
- if isnan(num)
- disp('You''re a silly goose. Enter a number.')
- elseif num<1
- disp('Row number must be greater than 0')
- num = 1;
- handles.Remove_row_N.String = 1;
- else
- r = rem(num, 1);
- if r ~= 0
- disp('Enter an integer, duh.')
- num = round(num);
- handles.Remove_row_N.String = round(num);
- end
- disp(num)
- end
- end
- function Save_goal_button_Callback(hObject, eventdata, handles)
- Save_goal_function(handles);
- end
- function Save_goal_function(handles)
- [file,path,indx] = uiputfile([handles.Data.Geo_path, '*.mat'],'Choose where to save OptGoals');
- OptGoals.geometryPath = [handles.Data.Geo_path handles.Data.Geo_fileName];
- disp('Loading Geometry ...')
- load([OptGoals.geometryPath])
- OptGoals.data={};
- for i = 1 : size(handles.uitable1.Data, 1)
-
-
- goal_i.name = handles.uitable1.Data{i,1};
-
- goal_i.ROI_name = handles.uitable1.Data{i,2};
-
- for j = 1:size(Geometry.ROIS,2)
- if strcmp(Geometry.ROIS{j}.name, handles.uitable1.Data{i,2})
- goal_i.ROI_idx = Geometry.ROIS{j}.ind;
- break
- end
- if j == size(Geometry.ROIS,2)
- error(['Invalid ROI name selected in goal ' num2str(i)])
- end
- end
-
- goal_i.imgDim = size(Geometry.data);
-
- if strcmp (handles.uitable1.Data{i,3}, 'Fixed dose')
- goal_i.D_final = str2double(handles.uitable1.Data{i,4}) * ones(size(Geometry.data));
- elseif strcmp (handles.uitable1.Data{i,3}, 'Dose map')
- warning('Works only for NRRD (for now)')
-
- dose_in = nrrdread(handles.uitable1.Data{i,4});
- goal_i.D_final = dose_in(goal_i.ROI_idx);
-
-
- end
-
- goal_i.function = handles.uitable1.Data{i,5};
-
- goal_i.opt_weight = handles.uitable1.Data{i,6} / numel(goal_i.ROI_idx);
-
- goal_i.optionalParam = handles.uitable1.Data{i,7};
-
- goal_i.dvh_col = [0.9, 0.2, 0.2];
-
- OptGoals.data{end+1}=goal_i;
- end
- disp('-- all OptGoals exported!')
- OptGoals.goals = [handles.uitable1.Data];
- save( [path, file], 'OptGoals')
- end
- function Load_goal_button_Callback(hObject, eventdata, handles)
- [file,path,indx] = uigetfile([handles.Data.Geo_path, '*.mat'],'Choose OptGoals to load');
- load( [path, file])
- disp('load goal')
- handles.uitable1.Data = OptGoals.goals;
- end
- function uitable1_CellEditCallback(hObject, eventdata, handles)
- if eventdata.Indices(2) == 3;
- mode = handles.uitable1.Data{eventdata.Indices(1), eventdata.Indices(2)}
- switch mode
- case 'Dose map'
- [FileName,PathName,FilterIndex] = uigetfile('F:\021_WiscPlan_data\FET_repeat_005_1\matlab_files\*.mat', 'Select dose reference file')
- warning('loading of said profile comes here')
- handles.uitable1.Data{eventdata.Indices(1), 4} = [PathName, FileName];
-
- case 'Fixed dose'
- answer = inputdlg('Enter desired goal dose');
- handles.uitable1.Data{eventdata.Indices(1), 4} = answer{1};
-
- otherwise
- error('This doesnt work')
- end
- end
- end
|