Browse Source

- Refresh voxels added in goal def UI
- NLP_optimizer now accepts previous results via line call

MEDPHYSICS\pferjancic 3 years ago
parent
commit
b821d40adb

+ 19 - 3
WiscPlanPhotonkV125/matlab_frontend/NLP_optimizer_v3.m

@@ -15,7 +15,7 @@ function [D_full, w_fin, Geometry, optGoal] = NLP_optimizer_v3(varargin)
 % Inputs:
 %       () OR
 %       (Pat_path, path2goal) OR
-%       (Pat_path, path2goal, beamlet_weights)
+%       (Pat_path, path2goal, path2NLP_result)
 %   Pat_path, path2goal = strings to patient folder and optimal goals
 %   beamlet_weights = initial beamlet weights
 %   
@@ -24,6 +24,7 @@ function [D_full, w_fin, Geometry, optGoal] = NLP_optimizer_v3(varargin)
 % 
 % Made by Peter Ferjancic 1. May 2018
 % Last updated: 1. April 2019
+dialogue_box = 'no';
 
 if nargin<2
     load('WiscPlan_preferences.mat')
@@ -32,14 +33,22 @@ if nargin<2
     
     path2geometry = [Pat_path, '\matlab_files\Geometry.mat'];
     path2goal = [Goal_path, Goal_file];
+elseif nargin ==2
+    Pat_path = varargin{1};
+    path2geometry = [Pat_path, '\matlab_files\Geometry.mat'];
+    path2goal = varargin{2};
+    [Goal_path,Goal_file,ext] = fileparts(path2goal);
 else
     Pat_path = varargin{1};
     path2geometry = [Pat_path, '\matlab_files\Geometry.mat'];
     path2goal = varargin{2};
     [Goal_path,Goal_file,ext] = fileparts(path2goal);
+    path2NLPres = varargin{3};
+    load(path2NLPres);
+    dialogue_box = 'pass';
+    pre_beamWeights = 'yS';
 end
 
-dialogue_box = 'no'
 switch dialogue_box
     case 'yes'
         str = inputdlg({'N of iterations for initial calc', 'N of iterations for full calc', ...
@@ -52,6 +61,9 @@ switch dialogue_box
         N_fcallback1 = 1e5;
         N_fcallback2 = 2e6; % 500000;
         pre_beamWeights = 'n';
+    case 'pass'
+        N_fcallback1 = 1e5;
+        N_fcallback2 = 2e6; % 500000;
 end
 
 
@@ -65,6 +77,8 @@ switch pre_beamWeights
         if numel(all_beams) ~= numel(w_beamlets)
             error('Provided weight number does not match beamlet number!')
         end
+    case 'yS'
+        w_beamlets = NLP_result.weights;
     case 'n'
         disp('Initial beam weights will be calculated.')
 end
@@ -153,7 +167,8 @@ for i_goal = 1:size(OptGoals.goals,1)
                 optGoal{i_goal}.beamlets_pruned(i_supVox,:) = sparse(mean(beamlets(idxList, :),1));
 
                 if isfield(OptGoals.data{i_goal}, 'wgt_map')
-                    optGoal{i_goal}.vox_wgt(i_supVox) = sum(tabula_wgtmap(idxList));
+%                     optGoal{i_goal}.vox_wgt(i_supVox) = sum(tabula_wgtmap(idxList));
+                    optGoal{i_goal}.vox_wgt(i_supVox) = mean(tabula_wgtmap(idxList));
                 end
 
                 % -- make new indeces
@@ -202,6 +217,7 @@ options = optimoptions('fmincon');
 options.MaxFunctionEvaluations = N_fcallback1;
 options.Display = 'iter';
 options.PlotFcn = 'optimplotfval';
+options.MaxIterations = 100;
 % options.UseParallel = true;
 options.UseParallel = false;
 % options.OptimalityTolerance = 1e-9;

BIN
WiscPlanPhotonkV125/matlab_frontend/WiscPlan_preferences.mat


BIN
WiscPlanPhotonkV125/matlab_frontend/goal_def_UI.fig


+ 34 - 1
WiscPlanPhotonkV125/matlab_frontend/goal_def_UI.m

@@ -22,7 +22,7 @@ function varargout = goal_def_UI(varargin)
 
 % Edit the above text to modify the response to help goal_def_test
 
-% Last Modified by GUIDE v2.5 23-Oct-2020 12:55:21
+% Last Modified by GUIDE v2.5 04-Mar-2021 18:34:56
 
 % Begin initialization code - DO NOT EDIT
 gui_Singleton = 1;
@@ -379,6 +379,39 @@ end
 
 end
 
+% --- Executes on button press in voxRefresh.
+function voxRefresh_Callback(hObject, eventdata, handles)
+% hObject    handle to voxRefresh (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+
+% this call checks current ROI names and updates voxel numbers
+for j = 1:size(handles.uitable1.Data,1) % for entire table
+    for i = 1:size(handles.Data.Geometry.ROIS,2)
+        if strcmp(handles.Data.Geometry.ROIS{i}.name, handles.uitable1.Data{j,2})
+            ROI_idx_num = numel(handles.Data.Geometry.ROIS{i}.ind);
+            handles.uitable1.Data{j, 8} = ROI_idx_num;
+            disp(['a' num2str(j)])
+            break
+        end
+        if strcmp('-||-', handles.uitable1.Data{j,2})
+            ROI_idx_num = 0;
+            disp(['b' num2str(j)])
+            break
+        end
+        if i == size(handles.Data.Geometry.ROIS,2)
+    %         error(['Invalid ROI name selected in goal ' num2str(i)])
+            handles.uitable1.Data{j,2} = ['--> ' handles.uitable1.Data{j,2}];
+        end
+    end
+    
+end
+
+
+
+
+
+end
 
 
 function maxModulation_Callback(hObject, eventdata, handles)

+ 3 - 2
WiscPlanPhotonkV125/matlab_frontend/lab/XTPS.m

@@ -521,7 +521,8 @@ classdef XTPS < handle
             try
                 if ispc % MATLAB movefile() super slow on windows
                     % TODO confirm overwrite
-                    system(['move "' source_filename '" "' target_filename '"']);
+%                     system(['move "' source_filename '" "' target_filename '"']);
+                    system(['copy "' source_filename '" "' target_filename '"']);
                 else
                     movefile(source_filename, target_filename);
                 end
@@ -538,7 +539,7 @@ classdef XTPS < handle
             cd('C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\WiscPlanEXE')
             
             cmdline = ['.' filesep 'RDXoptimizer.exe "' fullfile(obj.patient_dir, 'optInput.txt') '"'];
-            msgbox(sprintf('Start optimization\nRun this if not started automatically:\n%s', cmdline));
+%             msgbox(sprintf('Start optimization\nRun this if not started automatically:\n%s', cmdline));
             if ispc
                 execline = ['cmd /c ' cmdline ' &'];
             elseif isunix

+ 3 - 2
WiscPlanPhotonkV125/matlab_frontend/resample_geometry.m

@@ -58,8 +58,9 @@ function resample_geometry(Geometry, Nx, Ny, Nz)
     mkdir([Geometry.patient_dir '\matlab_files']);
     save([Geometry.patient_dir '\matlab_files\Geometry.mat'], 'Geometry');
     
-    
-    if isfile([Geometry_old.patient_dir '\batch_dose_backup.bin'])
+    % resample beamlets
+    if false
+%     if isfile([Geometry_old.patient_dir '\batch_dose_backup.bin'])
         disp('calculated beamlet file found - resampling')
         
         % resample the beamlets file

+ 1 - 1
view_beamlet.m

@@ -4,7 +4,7 @@ blet1 = read_ryan_beamlets('F:\021_WiscPlan_data\DELETEME3\FRO_Beam1\scenario1\b
 blet2 = read_ryan_beamlets('F:\021_WiscPlan_data\DELETEME3\FRO_Beam1\scenario2\batch_dose.bin');
 
 
-idx = 110;
+idx = 420;
 
 tabula = zeros([blet1{idx}.x_count, blet1{idx}.y_count, blet1{idx}.z_count]);
 tabula(blet1{idx}.non_zero_indices)   = tabula(blet1{idx}.non_zero_indices)+blet1{idx}.non_zero_values;