forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matRad_directApertureOptimization.m
106 lines (90 loc) · 3.85 KB
/
matRad_directApertureOptimization.m
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
function [optResult,optimizer] = matRad_directApertureOptimization(dij,cst,apertureInfo,optResult,pln)
% matRad function to run direct aperture optimization
%
% call
% o[optResult,info] = matRad_directApertureOptimization(dij,cst,apertureInfo,optResult,pln,visBool)
%
% input
% dij: matRad dij struct
% cst: matRad cst struct
% apertureInfo: aperture shape info struct
% optResult: resultGUI struct to which the output data will be added, if
% this field is empty optResult struct will be created
% (optional)
% pln: matRad pln struct
% visBool: plots the objective function value in dependence of the
% number of iterations
%
% output
% optResult: struct containing optimized fluence vector, dose, and
% shape info
% info: struct containing information about optimization
%
% References
% [1] http://dx.doi.org/10.1118/1.4914863
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global matRad_cfg;
matRad_cfg = MatRad_Config.instance();
% adjust overlap priorities
cst = matRad_setOverlapPriorities(cst);
% check & adjust objectives and constraints internally for fractionation
for i = 1:size(cst,1)
for j = 1:numel(cst{i,6})
obj = cst{i,6}{j};
%In case it is a default saved struct, convert to object
%Also intrinsically checks that we have a valid optimization
%objective or constraint function in the end
if ~isa(obj,'matRad_DoseOptimizationFunction')
try
obj = matRad_DoseOptimizationFunction.createInstanceFromStruct(obj);
catch
matRad_cfg.dispError('cst{%d,6}{%d} is not a valid Objective/constraint! Remove or Replace and try again!',i,j);
end
end
obj = obj.setDoseParameters(obj.getDoseParameters()/pln.numOfFractions);
cst{i,6}{j} = obj;
end
end
% resizing cst to dose cube resolution
cst = matRad_resizeCstToGrid(cst,dij.ctGrid.x,dij.ctGrid.y,dij.ctGrid.z,...
dij.doseGrid.x,dij.doseGrid.y,dij.doseGrid.z);
% update aperture info vector
apertureInfo = matRad_OptimizationProblemDAO.matRad_daoVec2ApertureInfo(apertureInfo,apertureInfo.apertureVector);
%Use Dose Projection only
backProjection = matRad_DoseProjection();
optiProb = matRad_OptimizationProblemDAO(backProjection,apertureInfo);
if ~isfield(pln.propOpt,'optimizer')
pln.propOpt.optimizer = 'IPOPT';
end
switch pln.propOpt.optimizer
case 'IPOPT'
optimizer = matRad_OptimizerIPOPT;
case 'fmincon'
optimizer = matRad_OptimizerFmincon;
otherwise
matRad_cfg.dispWarning('Optimizer ''%s'' not known! Fallback to IPOPT!',pln.propOpt.optimizer);
optimizer = matRad_OptimizerIPOPT;
end
% Run IPOPT.
optimizer = optimizer.optimize(apertureInfo.apertureVector,optiProb,dij,cst);
wOpt = optimizer.wResult;
% update the apertureInfoStruct and calculate bixel weights
apertureInfo = matRad_OptimizationProblemDAO.matRad_daoVec2ApertureInfo(apertureInfo,wOpt);
% logging final results
matRad_cfg.dispInfo('Calculating final cubes...\n');
resultGUI = matRad_calcCubes(apertureInfo.bixelWeights,dij,cst);
resultGUI.w = apertureInfo.bixelWeights;
resultGUI.wDAO = apertureInfo.bixelWeights;
resultGUI.apertureInfo = apertureInfo;