|  | @@ -11,12 +11,9 @@ function [D_full, w_fin, Geometry, optGoal] = NLP_beamlet_optimizer
 | 
	
		
			
				|  |  |  % Outputs: full dose image dose: D_full, optimal beamlet weights: w_fin
 | 
	
		
			
				|  |  |  %
 | 
	
		
			
				|  |  |  % Made by Peter Ferjancic 1. May 2018
 | 
	
		
			
				|  |  | -% Last updated: 1. May 2018
 | 
	
		
			
				|  |  | +% Last updated: 14. August 2018
 | 
	
		
			
				|  |  |  % Inspired by Ana Barrigan's REGGUI optimization procedures
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -% To-do:
 | 
	
		
			
				|  |  | -% - Add robusness aspect (+take worst case scenario, see REGGUI)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  N_fcallback1 = 5000;
 | 
	
		
			
				|  |  |  N_fcallback2 = 200000;
 | 
	
		
			
				|  |  |  patient = 'gbm_005';
 | 
	
	
		
			
				|  | @@ -24,19 +21,14 @@ patient = 'gbm_005';
 | 
	
		
			
				|  |  |  switch patient
 | 
	
		
			
				|  |  |      case 'patient'
 | 
	
		
			
				|  |  |          patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData';
 | 
	
		
			
				|  |  | -        blet_in_beam=5; % this is the number of beamlets in a beam. Called "Mxp" in helicalDosecalcSetup
 | 
	
		
			
				|  |  |      case 'tomoPhantom'
 | 
	
		
			
				|  |  | -        patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData';
 | 
	
		
			
				|  |  | -        blet_in_beam=7; % this is the number of beamlets in a beam. Called "Mxp" in helicalDosecalcSetup
 | 
	
		
			
				|  |  | +        patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData';        
 | 
	
		
			
				|  |  |      case 'phantom_HD'
 | 
	
		
			
				|  |  |          patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PD_HD_dicomPhantom';
 | 
	
		
			
				|  |  | -        blet_in_beam=20; % this is the number of beamlets in a beam. Called "Mxp" in helicalDosecalcSetup
 | 
	
		
			
				|  |  |      case 'doggo'
 | 
	
		
			
				|  |  |          patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData_dog5_3';
 | 
	
		
			
				|  |  | -        blet_in_beam=5; % this is the number of beamlets in a beam. Called "Mxp" in helicalDosecalcSetup
 | 
	
		
			
				|  |  |      case 'gbm_005'
 | 
	
		
			
				|  |  | -        patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\gbm_aus_Data';
 | 
	
		
			
				|  |  | -        blet_in_beam=7; % this is the number of beamlets in a beam. Called "Mxp" in helicalDosecalcSetup
 | 
	
		
			
				|  |  | +        patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\data\PatientData_ozzy1';
 | 
	
		
			
				|  |  |      otherwise
 | 
	
		
			
				|  |  |          error('invalid case')
 | 
	
		
			
				|  |  |  end
 | 
	
	
		
			
				|  | @@ -89,30 +81,10 @@ close(wbar2)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  %% -- OPTIMIZATION TARGETS --
 | 
	
		
			
				|  |  | -switch patient
 | 
	
		
			
				|  |  | -    case 'patient'
 | 
	
		
			
				|  |  | -%         optGoal = make_ROI_goals(Geometry, beamlets);
 | 
	
		
			
				|  |  | -%         optGoal_beam = make_ROI_goals(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | -%         N_beamlets_in_beam = 10;
 | 
	
		
			
				|  |  | -    case 'tomoPhantom'   
 | 
	
		
			
				|  |  | -        optGoal = make_ROI_goals_2(Geometry, beamlets);
 | 
	
		
			
				|  |  | -        optGoal_beam = make_ROI_goals_2(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | -        N_beamlets_in_beam = 7;
 | 
	
		
			
				|  |  | -    case 'phantom_HD'
 | 
	
		
			
				|  |  | -        optGoal = make_ROI_goals(Geometry, beamlets);
 | 
	
		
			
				|  |  | -        optGoal_beam = make_ROI_goals(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | -    case 'doggo'
 | 
	
		
			
				|  |  | -%         optGoal = make_ROI_goals_DOG(Geometry, beamlets);
 | 
	
		
			
				|  |  | -%         optGoal_beam = make_ROI_goals_DOG(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | +make_ROI_goals(Geometry, beamlets, beamlets_joined, patient);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +[optGoal, optGoal_beam, optGoal_idx, targetMinMax_idx] = get_ROI_goals(patient);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        optGoal = make_ROI_goals_DOG_2(Geometry, beamlets);
 | 
	
		
			
				|  |  | -        optGoal_beam = make_ROI_goals_DOG_2(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | -    case 'gbm_005'
 | 
	
		
			
				|  |  | -        optGoal = make_ROI_goals_gbm_005(Geometry, beamlets);
 | 
	
		
			
				|  |  | -        optGoal_beam = make_ROI_goals_gbm_005(Geometry, beamlets_joined);
 | 
	
		
			
				|  |  | -    otherwise
 | 
	
		
			
				|  |  | -        error('invalid case')
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  |  % -- make them robust --
 | 
	
		
			
				|  |  |  RO_params=0;
 | 
	
		
			
				|  |  |  optGoal_beam = make_robust_optGoal(optGoal_beam, RO_params, beamlets_joined);
 | 
	
	
		
			
				|  | @@ -176,26 +148,7 @@ D_full = reshape(beamlets * w_fin, size(Geometry.data));
 | 
	
		
			
				|  |  |  %% save outputs
 | 
	
		
			
				|  |  |  NLP_result.dose = D_full;
 | 
	
		
			
				|  |  |  NLP_result.weights = w_fin;
 | 
	
		
			
				|  |  | -% save('C:\010-work\003_localGit\WiscPlan_v2\data\PatientData\matlab_files\NLP_result.mat', 'NLP_result');
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -switch patient
 | 
	
		
			
				|  |  | -    case 'patient'
 | 
	
		
			
				|  |  | -        optGoal_idx=[1,2];
 | 
	
		
			
				|  |  | -        targetMinMax_idx=[1,3];
 | 
	
		
			
				|  |  | -    case 'tomoPhantom'   
 | 
	
		
			
				|  |  | -        optGoal_idx=[1,3];
 | 
	
		
			
				|  |  | -        targetMinMax_idx=[1,2];
 | 
	
		
			
				|  |  | -    case 'phantom_HD'
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    case 'doggo'
 | 
	
		
			
				|  |  | -        optGoal_idx=[1,2];
 | 
	
		
			
				|  |  | -        targetMinMax_idx=[1,3];
 | 
	
		
			
				|  |  | -    case 'gbm_005'
 | 
	
		
			
				|  |  | -        optGoal_idx=[1,3];
 | 
	
		
			
				|  |  | -        targetMinMax_idx=[1,2];
 | 
	
		
			
				|  |  | -    otherwise
 | 
	
		
			
				|  |  | -        error('invalid case')
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | +save([patient_dir '\matlab_files\NLP_result.mat'], 'NLP_result');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  plot_DVH(D_full, optGoal, optGoal_idx, targetMinMax_idx)
 | 
	
		
			
				|  |  |  colorwash(Geometry.data, D_full);
 | 
	
	
		
			
				|  | @@ -229,6 +182,7 @@ function penalty = eval_f(x, optGoal, nrs_i, sss_i, rrs_i)
 | 
	
		
			
				|  |  |      % for each condition
 | 
	
		
			
				|  |  |      for goal_i = 1:numel(optGoal)
 | 
	
		
			
				|  |  |          switch optGoal{goal_i}.function
 | 
	
		
			
				|  |  | +            % min, max, min_sq, max_sq, LeastSquare, min_perc_Volume, max_perc_Volume
 | 
	
		
			
				|  |  |              case 'min'
 | 
	
		
			
				|  |  |                  % penalize if achieved dose is lower than target dose
 | 
	
		
			
				|  |  |                  d_penalty = 1.0e0 * sum(max(0, ...
 | 
	
	
		
			
				|  | @@ -320,391 +274,6 @@ function show_joint_beamlets(beamlets, IMGsize, Beam_list)
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -% ---- MAKE ROI GOALS ----
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 2}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 2}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 60;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 2}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 2}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 65;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 0.8 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'ROI 1_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 3}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 3}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 10;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals_2(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 2}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 2}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 62;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target_alpha = 1.00;
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 2}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 2}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 63;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target_alpha = 1.05;
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'ROI 1_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 3}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 3}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 10;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_4.name = 'Ring_max';
 | 
	
		
			
				|  |  | -    goal_4.ROI_name = Geometry.ROIS{1, 6}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 6}.ind;
 | 
	
		
			
				|  |  | -    goal_4.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_4.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_4.D_final = 56;
 | 
	
		
			
				|  |  | -    goal_4.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_4.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_4.target   = ones(numel(ROI_idx), 1) * goal_4.D_final;
 | 
	
		
			
				|  |  | -    goal_4.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_4.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_4;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals_DOG(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 62;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min_sq';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Doggo_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 20;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 0.2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 63;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'Doggo_max2';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 50;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals_DOG_2(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 62;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min_sq';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target_alpha = 1.00;
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Doggo_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 20;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 0.2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 63;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target_alpha = 1.05;
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_4.name = 'Doggo_max2';
 | 
	
		
			
				|  |  | -    goal_4.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_4.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_4.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_4.D_final = 50;
 | 
	
		
			
				|  |  | -    goal_4.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_4.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_4.target   = ones(numel(ROI_idx), 1) * goal_4.D_final;
 | 
	
		
			
				|  |  | -    goal_4.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_4.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_4;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals_DOG_3(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 62;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min_perc_Volume';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target_alpha = 1.00;
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Doggo_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 20;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_2.targetImg   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 0.2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 63;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max_perc_Volume';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target_alpha = 1.05;
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 0.5 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_4.name = 'Doggo_max2';
 | 
	
		
			
				|  |  | -    goal_4.ROI_name = Geometry.ROIS{1, 4}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 4}.ind;
 | 
	
		
			
				|  |  | -    goal_4.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_4.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_4.D_final = 50;
 | 
	
		
			
				|  |  | -    goal_4.function = 'max_sq';
 | 
	
		
			
				|  |  | -    goal_4.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_4.target   = ones(numel(ROI_idx), 1) * goal_4.D_final;
 | 
	
		
			
				|  |  | -    goal_4.opt_weight = 1 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_4.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_4;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  | -function optGoal = make_ROI_goals_gbm_005(Geometry, beamlets)
 | 
	
		
			
				|  |  | -    optGoal={};
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_1.name = 'Target_min';
 | 
	
		
			
				|  |  | -    goal_1.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_1.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_1.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_1.D_final = 60;
 | 
	
		
			
				|  |  | -    goal_1.function = 'min';
 | 
	
		
			
				|  |  | -    goal_1.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_1.target   = ones(numel(ROI_idx), 1) * goal_1.D_final;
 | 
	
		
			
				|  |  | -    goal_1.opt_weight = 10 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_1.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_1;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_2.name = 'Target_max';
 | 
	
		
			
				|  |  | -    goal_2.ROI_name = Geometry.ROIS{1, 1}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 1}.ind;
 | 
	
		
			
				|  |  | -    goal_2.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_2.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_2.D_final = 65;
 | 
	
		
			
				|  |  | -    goal_2.function = 'max';
 | 
	
		
			
				|  |  | -    goal_2.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_2.target   = ones(numel(ROI_idx), 1) * goal_2.D_final;
 | 
	
		
			
				|  |  | -    goal_2.opt_weight = 0.8 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_2.dvh_col = [0.9, 0.2, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_2;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    % -- START DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -    goal_3.name = 'RING 1_max';
 | 
	
		
			
				|  |  | -    goal_3.ROI_name = Geometry.ROIS{1, 3}.name;
 | 
	
		
			
				|  |  | -    ROI_idx = Geometry.ROIS{1, 3}.ind;
 | 
	
		
			
				|  |  | -    goal_3.ROI_idx = ROI_idx;
 | 
	
		
			
				|  |  | -    goal_3.imgDim = size(Geometry.data);
 | 
	
		
			
				|  |  | -    goal_3.D_final = 10;
 | 
	
		
			
				|  |  | -    goal_3.function = 'max';
 | 
	
		
			
				|  |  | -    goal_3.beamlets_pruned = beamlets(ROI_idx, :);
 | 
	
		
			
				|  |  | -    goal_3.target   = ones(numel(ROI_idx), 1) * goal_3.D_final;
 | 
	
		
			
				|  |  | -    goal_3.opt_weight = 2 / numel(ROI_idx); % normalize to volume of target area
 | 
	
		
			
				|  |  | -    goal_3.dvh_col = [0.2, 0.9, 0.2]; % color of the final DVH plot
 | 
	
		
			
				|  |  | -    % assign target
 | 
	
		
			
				|  |  | -    optGoal{end+1}=goal_3;
 | 
	
		
			
				|  |  | -    % -- END DEFINITION OF GOAL --
 | 
	
		
			
				|  |  | -   
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  % ---- MAKE ROI ROBUST ----
 | 
	
		
			
				|  |  |  function optGoal = make_robust_optGoal(optGoal, RO_params, beamlets);
 | 
	
	
		
			
				|  | @@ -722,8 +291,8 @@ function optGoal = make_robust_optGoal(optGoal, RO_params, beamlets);
 | 
	
		
			
				|  |  |      shift_mag = 1; % vox of shift
 | 
	
		
			
				|  |  |      nrs_scene_list={[0,0,0]};
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    sss_scene_list={[0,0,0]};
 | 
	
		
			
				|  |  | -%     sss_scene_list={[0,0,0], [-shift_mag,0,0], [shift_mag,0,0], [0,-shift_mag,0], [0,shift_mag,0]};
 | 
	
		
			
				|  |  | +%     sss_scene_list={[0,0,0]};
 | 
	
		
			
				|  |  | +    sss_scene_list={[0,0,0], [-shift_mag,0,0], [shift_mag,0,0], [0,-shift_mag,0], [0,shift_mag,0]};
 | 
	
		
			
				|  |  |  %     sss_scene_list={[0,0,0], [-shift_mag,0,0], [shift_mag,0,0], [0,-shift_mag,0], [0,shift_mag,0],...
 | 
	
		
			
				|  |  |  %         [-shift_mag*2,0,0], [shift_mag*2,0,0], [0,-shift_mag*2,0], [0,shift_mag*2,0]};
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -795,6 +364,3 @@ end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 |