goal_def_UI.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. function varargout = goal_def_UI(varargin)
  2. % GOAL_DEF_TEST MATLAB code for goal_def_test.fig
  3. % GOAL_DEF_TEST, by itself, creates a new GOAL_DEF_TEST or raises the existing
  4. % singleton*.
  5. %
  6. % H = GOAL_DEF_TEST returns the handle to a new GOAL_DEF_TEST or the handle to
  7. % the existing singleton*.
  8. %
  9. % GOAL_DEF_TEST('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in GOAL_DEF_TEST.M with the given input arguments.
  11. %
  12. % GOAL_DEF_TEST('Property','Value',...) creates a new GOAL_DEF_TEST or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before goal_def_test_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to goal_def_test_OpeningFcn via varargin.
  17. %
  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  19. % instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help goal_def_test
  23. % Last Modified by GUIDE v2.5 28-Mar-2019 16:16:14
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @goal_def_test_OpeningFcn, ...
  29. 'gui_OutputFcn', @goal_def_test_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. end
  42. % --- Executes just before goal_def_test is made visible.
  43. function goal_def_test_OpeningFcn(hObject, eventdata, handles, varargin)
  44. % This function has no output args, see OutputFcn.
  45. % hObject handle to figure
  46. % eventdata reserved - to be defined in a future version of MATLAB
  47. % handles structure with handles and user data (see GUIDATA)
  48. % varargin command line arguments to goal_def_test (see VARARGIN)
  49. % Choose default command line output for goal_def_test
  50. handles.output = hObject;
  51. %% GET THE INITIAL GEOMETRY DATA
  52. disp('varargin')
  53. if numel(varargin) == 0
  54. load('WiscPlan_preferences.mat')
  55. [handles.Data.Geo_fileName,handles.Data.Geo_path,FilterIndex] = uigetfile([WiscPlan_preferences.patientDataPath '\matlab_files\*.mat'], 'Select Geometry file')
  56. load([handles.Data.Geo_path, handles.Data.Geo_fileName])
  57. end
  58. %% POPULATE THE TABLE
  59. % == populate ROI options ==
  60. for i = 1: numel(Geometry.ROIS)
  61. handles.uitable1.ColumnFormat{2}{i} = Geometry.ROIS{i}.name;
  62. end
  63. % == populate function options ==
  64. handles.uitable1.ColumnFormat{5}{1} = 'min';
  65. handles.uitable1.ColumnFormat{5}{2} = 'max';
  66. handles.uitable1.ColumnFormat{5}{3} = 'min_sq';
  67. handles.uitable1.ColumnFormat{5}{4} = 'max_sq';
  68. handles.uitable1.ColumnFormat{5}{5} = 'LeastSquare';
  69. handles.uitable1.ColumnFormat{5}{6} = 'min_perc_Volume';
  70. handles.uitable1.ColumnFormat{5}{7} = 'max_perc_Volume';
  71. % == populate the first entry ==
  72. handles.uitable1.Data = handles.uitable1.Data(1,:);
  73. handles.uitable1.Data{1} = 'Goal 1';
  74. handles.uitable1.Data{2} = 'Target';
  75. handles.uitable1.Data{3} = 'Fixed dose';
  76. handles.uitable1.Data{4} = '60';
  77. handles.uitable1.Data{5} = 'min_sq';
  78. handles.uitable1.Data{6} = 100;
  79. handles.uitable1.Data{7} = 'null';
  80. % Update handles structure
  81. guidata(hObject, handles);
  82. % UIWAIT makes goal_def_test wait for user response (see UIRESUME)
  83. % uiwait(handles.figure1);
  84. end
  85. % --- Outputs from this function are returned to the command line.
  86. function varargout = goal_def_test_OutputFcn(hObject, eventdata, handles)
  87. % varargout cell array for returning output args (see VARARGOUT);
  88. % hObject handle to figure
  89. % eventdata reserved - to be defined in a future version of MATLAB
  90. % handles structure with handles and user data (see GUIDATA)
  91. % Get default command line output from handles structure
  92. varargout{1} = handles.output;
  93. end
  94. % --- Executes on button press in addRow.
  95. function addRow_Callback(hObject, eventdata, handles)
  96. % adds new empty row to table
  97. handles.uitable1.Data{end+1, 1} = ['Goal ' num2str(size(handles.uitable1.Data,1)+1)];
  98. end
  99. % --- Executes on button press in removeRow.
  100. function removeRow_Callback(hObject, eventdata, handles)
  101. % Removes row number selected by Remove_row_N
  102. newTable = handles.uitable1.Data;
  103. rowToDelete = str2double(handles.Remove_row_N.String);
  104. if rowToDelete>size(newTable, 2)
  105. disp(['No row ' num2str(rowToDelete)])
  106. else
  107. newTable(rowToDelete,:) = [];
  108. handles.uitable1.Data = newTable;
  109. end
  110. end
  111. function Remove_row_N_Callback(hObject, eventdata, handles)
  112. % Identifies what is the number for removing a row and checks validty of
  113. % input.
  114. num = str2double(handles.Remove_row_N.String);
  115. if isnan(num)
  116. disp('You''re a silly goose. Enter a number.')
  117. elseif num<1
  118. disp('Row number must be greater than 0')
  119. num = 1;
  120. handles.Remove_row_N.String = 1;
  121. else
  122. r = rem(num, 1);
  123. if r ~= 0
  124. disp('Enter an integer, duh.')
  125. num = round(num);
  126. handles.Remove_row_N.String = round(num);
  127. end
  128. disp(num)
  129. end
  130. end
  131. % --- Executes on button press in Save_goal_button.
  132. function Save_goal_button_Callback(hObject, eventdata, handles)
  133. % hObject handle to Save_goal_button (see GCBO)
  134. % eventdata reserved - to be defined in a future version of MATLAB
  135. % handles structure with handles and user data (see GUIDATA)
  136. Save_goal_function(handles);
  137. end
  138. function Save_goal_function(handles)
  139. % this function creates and outputs the OptGoals file
  140. [file,path,indx] = uiputfile([handles.Data.Geo_path, '*.mat'],'Choose where to save OptGoals');
  141. OptGoals.geometryPath = [handles.Data.Geo_path handles.Data.Geo_fileName];
  142. disp('Loading Geometry ...')
  143. load([OptGoals.geometryPath])
  144. % disp('Loading beamlets ...')
  145. % [beamlets, beamlets_joined, numBeamlet, numBeam, beam_i_list] = get_beam_lets(Geometry, Geometry.patient_dir);
  146. OptGoals.data={};
  147. for i = 1 : size(handles.uitable1.Data, 1)
  148. % -- START DEFINITION OF GOAL --
  149. % == goal name
  150. goal_i.name = handles.uitable1.Data{i,1};
  151. % == ROI name
  152. goal_i.ROI_name = handles.uitable1.Data{i,2};
  153. % == ROI index
  154. for j = 1:size(Geometry.ROIS,2)
  155. if strcmp(Geometry.ROIS{j}.name, handles.uitable1.Data{i,2})
  156. goal_i.ROI_idx = Geometry.ROIS{j}.ind;
  157. break
  158. end
  159. if j == size(Geometry.ROIS,2)
  160. error(['Invalid ROI name selected in goal ' num2str(i)])
  161. end
  162. end
  163. % == image dimensions
  164. goal_i.imgDim = size(Geometry.data);
  165. % == goal dose
  166. if strcmp (handles.uitable1.Data{i,3}, 'Fixed dose')
  167. goal_i.D_final = str2double(handles.uitable1.Data{i,4}) * ones(size(Geometry.data));
  168. elseif strcmp (handles.uitable1.Data{i,3}, 'Dose map')
  169. error('havent written this part yet')
  170. % loading of data comes here
  171. % matrix size checks
  172. end
  173. % == goal penalty function
  174. goal_i.function = handles.uitable1.Data{i,5};
  175. % == goal weight
  176. goal_i.opt_weight = handles.uitable1.Data{i,6} / numel(goal_i.ROI_idx); % normalize to volume of target area
  177. % == beamlets dose selection
  178. % goal_i.beamlets_pruned = beamlets(goal_i.ROI_idx, :);
  179. goal_i.optionalParam = handles.uitable1.Data{i,7};
  180. % -- END DEFINITION OF GOAL --
  181. goal_i.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
  182. % assign target
  183. OptGoals.data{end+1}=goal_i;
  184. end
  185. disp('-- all OptGoals exported!')
  186. OptGoals.goals = [handles.uitable1.Data];
  187. save( [path, file], 'OptGoals')
  188. end
  189. % --- Executes on button press in Load_goal_button.
  190. function Load_goal_button_Callback(hObject, eventdata, handles)
  191. % hObject handle to Load_goal_button (see GCBO)
  192. % eventdata reserved - to be defined in a future version of MATLAB
  193. % handles structure with handles and user data (see GUIDATA)
  194. [file,path,indx] = uigetfile([handles.Data.Geo_path, '*.mat'],'Choose OptGoals to load');
  195. load( [path, file])
  196. disp('load goal')
  197. handles.uitable1.Data = OptGoals.goals;
  198. end
  199. % --- Executes when entered data in editable cell(s) in uitable1.
  200. function uitable1_CellEditCallback(hObject, eventdata, handles)
  201. % hObject handle to uitable1 (see GCBO)
  202. % eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
  203. % Indices: row and column indices of the cell(s) edited
  204. % PreviousData: previous data for the cell(s) edited
  205. % EditData: string(s) entered by the user
  206. % NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
  207. % Error: error string when failed to convert EditData to appropriate value for Data
  208. % handles structure with handles and user data (see GUIDATA)
  209. if eventdata.Indices(2) == 3;
  210. mode = handles.uitable1.Data{eventdata.Indices(1), eventdata.Indices(2)}
  211. switch mode
  212. case 'Dose map'
  213. [FileName,PathName,FilterIndex] = uigetfile('F:\021_WiscPlan_data\FET_repeat_005_1\matlab_files\*.mat', 'Select dose reference file')
  214. warning('loading of said profile comes here')
  215. handles.uitable1.Data{eventdata.Indices(1), 4} = [PathName, FileName];
  216. case 'Fixed dose'
  217. answer = inputdlg('Enter desired goal dose');
  218. handles.uitable1.Data{eventdata.Indices(1), 4} = answer{1};
  219. otherwise
  220. error('This doesnt work')
  221. end
  222. end
  223. end