forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatRad_Config.m
More file actions
213 lines (174 loc) · 8.19 KB
/
MatRad_Config.m
File metadata and controls
213 lines (174 loc) · 8.19 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
classdef MatRad_Config < handle
%MatRad_Config MatRad Configuration class
% This class is used globally through Matlab to handle default values and
% logging and is declared as global matRad_cfg.
% Usage:
% matRad_cfg = MatRad_Config.instance();
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2019 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.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties
logLevel = 3;
propDoseCalc;
propOpt;
propMC;
propStf;
keepLog = false;
disableGUI = false;
end
properties (SetAccess = private)
messageLog = {};
end
properties (Constant)
matRadRoot = fileparts(mfilename('fullpath'));
end
methods (Access = private)
function obj = MatRad_Config()
%MatRad_Config Constructs an instance of this class.
% The configuration is implemented as a singleton and used globally
% Therefore its constructor is private
% For instantiation, use the static MatRad_Config.instance();
obj.reset();
end
end
methods
function reset(obj)
obj.setDefaultProperties();
end
function setDefaultProperties(obj)
obj.propStf.defaultLongitudinalSpotSpacing = 3;
obj.propStf.defaultAddMargin = true; %expand target for beamlet finding
obj.propDoseCalc.defaultResolution = struct('x',3,'y',3,'z',3); %[mm]
obj.propDoseCalc.defaultLateralCutOff = 0.995; %[rel.]
obj.propDoseCalc.defaultGeometricCutOff = 50; %[mm]
obj.propDoseCalc.defaultSsdDensityThreshold = 0.05; %[rel.]
obj.propDoseCalc.defaultUseGivenEqDensityCube = false; %Use the given density cube ct.cube and omit conversion from cubeHU.
obj.propDoseCalc.defaultIgnoreOutsideDensities = true; %Ignore densities outside of cst contours
obj.propOpt.defaultMaxIter = 500;
obj.propMC.ompMC_defaultHistories = 1e6;
obj.propMC.ompMC_defaultOutputVariance = false;
obj.propMC.particles_defaultHistories = 2e4;
obj.propMC.direct_defaultHistories = 1e6;
%obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_proton_engine = 'MCsquare';
obj.propMC.topas_defaultNumBatches = 5;
obj.disableGUI = false;
end
%%For testing
function setDefaultPropertiesForTesting(obj)
obj.logLevel = 1; %Omit output except errors
obj.propStf.defaultLongitudinalSpotSpacing = 20;
obj.propStf.defaultAddMargin = true; %expand target for beamlet finding
obj.propDoseCalc.defaultResolution = struct('x',5,'y',6,'z',7); %[mm]
obj.propDoseCalc.defaultGeometricCutOff = 20;
obj.propDoseCalc.defaultLateralCutOff = 0.8;
obj.propDoseCalc.defaultSsdDensityThreshold = 0.05;
obj.propDoseCalc.defaultUseGivenEqDensityCube = false; %Use the given density cube ct.cube and omit conversion from cubeHU.
obj.propDoseCalc.defaultIgnoreOutsideDensities = true;
obj.propOpt.defaultMaxIter = 10;
obj.propMC.ompMC_defaultHistories = 100;
obj.propMC.ompMC_defaultOutputVariance = true;
obj.propMC.particles_defaultHistories = 100;
obj.propMC.direct_defaultHistories = 100;
%obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_proton_engine = 'MCsquare';
obj.propMC.topas_defaultNumBatches = 5;
obj.disableGUI = true;
end
function dispDebug(obj,formatSpec,varargin)
%dispDebug wrapper for debug messages forwarded to displayToConsole
obj.displayToConsole('debug',formatSpec,varargin{:});
end
function dispInfo(obj,formatSpec,varargin)
%dispInfo wrapper for standard / info output forwarded to displayToConsole
obj.displayToConsole('info',formatSpec,varargin{:});
end
function dispError(obj,formatSpec,varargin)
%dispError wrapper for error messages forwarded to displayToConsole
obj.displayToConsole('error',formatSpec,varargin{:});
end
function dispWarning(obj,formatSpec,varargin)
%dispWarning wrapper for warning messages forwarded to displayToConsole
obj.displayToConsole('warning',formatSpec,varargin{:});
end
function displayToConsole(obj,type,formatSpec,varargin)
%displayToConsole lowest-level logging function for matRad.
% input
% type: type of the log information. Needs to be one of 'error', 'warning', 'info' or 'debug'.
% formatSpec: string to print using format specifications similar to fprintf
% varargin: variables according to formatSpec
if nargin < 4
forwardArgs = {formatSpec};
else
forwardArgs = {formatSpec,varargin{:}};
end
if obj.keepLog
obj.messageLog{end+1,1} = upper(type);
obj.messageLog{end,2} = sprintf(forwardArgs{:});
end
switch type
case {'error'}
if obj.logLevel >= 1
error(forwardArgs{:});
end
case{'warning'}
if obj.logLevel >= 2
warning(forwardArgs{:});
end
case{'info'}
if obj.logLevel >= 3
fprintf(forwardArgs{:});
end
case{'debug'}
if obj.logLevel >= 4
forwardArgs{1} = ['DEBUG: ' forwardArgs{1}];
fprintf(forwardArgs{:});
end
otherwise
error('Log type %s not defined!',type);
end
end
function obj = writeLogToFile(obj,filename)
%writeLogToFile writes the log kept in MatRad_Config to file.
% Note that the switch keepLog must be enabled for MatRad_Config to store all logging output.
singleString = '%s: %s\n';
fID = fopen(filename,'w');
fprintf(fID,repmat(singleString,1,size(obj.messageLog,1)),obj.messageLog{:});
fclose(fID);
end
function set.logLevel(obj,newLogLevel)
%%Property set methods for logLevel
minLevel = 1;
maxLevel = 4;
if newLogLevel >= minLevel && newLogLevel <= maxLevel
obj.logLevel = newLogLevel;
else
obj.dispError('Invalid log level. Value must be between %d and %d',minLevel,maxLevel);
end
end
end
methods(Static)
function obj = instance()
%instance creates a singleton instance of MatRad_Config
% In MatRad_Config, the constructor is private to make sure only on global instance exists.
% Call this static functino to get or create an instance of the matRad configuration class
persistent uniqueInstance;
if isempty(uniqueInstance)
obj = MatRad_Config();
uniqueInstance = obj;
else
obj = uniqueInstance;
end
end
end
end