Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
aad8a96
Extensive TOPAS workflow update:
Dec 5, 2021
64fad60
Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad in…
wahln Mar 15, 2022
1a4bfaf
Merge branch 'dev_VARBE_MC_merge_experimental'
Jun 15, 2022
f7ce1ee
Monte Carlo fix
Jun 21, 2022
edfef03
Merge additional MonteCarlo changes from dev_varRBErobOpt_experimental
Jun 23, 2022
4888568
Merge branch 'dev_VARBE_MC_merge_experimental' into dev_varRBErobOpt_…
Jul 29, 2022
5ac3cd7
Merge branch 'pamede/dev_MonteCarloRestructured'
Jul 29, 2022
0d0e61e
Merge branch 'pamede/dev_varRBErobOpt'
Jul 29, 2022
1d7e81e
added support for 4D
Aug 2, 2022
7101996
Replaced contains function by strfind for octave
Aug 3, 2022
8527e90
TOPAS Schneider Update
Aug 5, 2022
3de7537
Update ChangeLog.txt
Aug 5, 2022
80d1396
Merge branch 'dev_varRBErobOpt' into pr/536
wahln Sep 16, 2022
9b968e8
Update matRad_calcDoseDirectMC.m
Sep 19, 2022
2a80135
update direct dose calculation
wahln Sep 19, 2022
0bf81e2
fix wrong case in path
wahln Sep 19, 2022
ddb0454
fix compatibility issue in the MCemmittance class
wahln Sep 19, 2022
d9e4b21
fix fprintf error in octave due to non-escaped percentage character
wahln Sep 19, 2022
45b6517
Merge dev_varRBErobOpt_experimental -> dev_varRBErobOpt_Update
Sep 21, 2022
be032cc
bug fix for recent resampling update
Sep 22, 2022
dc9552e
MC dij update calcDoseDirect
Sep 22, 2022
37d3c58
Update to matRad_calcCubes.m
Sep 22, 2022
87bf5fe
Fix indent
wahln Sep 23, 2022
4a3e73a
Update to emittanceBaseData energyspread handling
Sep 22, 2022
1ee132d
Merge dev_varRBErobOpt_experimental
Oct 4, 2022
19e22df
reset to old bixelwidth-dependent dij sampling
wahln Oct 5, 2022
834bb1f
Merge branch 'master' into pr/536
wahln Oct 5, 2022
3610bf5
Update TopasConfig
Oct 12, 2022
4b59c62
Merge piastammer/dev_varRBErobOpt_photonsTopas into dev_varRBErobOpt_…
Oct 24, 2022
93233d1
Update MatRad_Config.m
Oct 24, 2022
2f53358
Finished merge of TopasConfig_Photons
Oct 24, 2022
0c2094d
Update TOPAS_beamSetup_Phasespace.txt.in
Oct 25, 2022
f328b96
fix props in MatRad_Config
wahln Oct 26, 2022
0af8238
small update to photons phasespace
Oct 26, 2022
c9d190e
Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad in…
wahln Oct 26, 2022
fe9adb8
added default beamProfile for photons
Oct 26, 2022
d1c34ab
Merge branch 'dev_varRBErobOpt_Update' of https://github.com/HomolkaN…
Oct 26, 2022
d0e246c
adjusted topas calcDose functions
Oct 26, 2022
ee58c3d
remove the MCsquare MU correction as it is no longer valid
wahln Oct 28, 2022
9b5c17a
some technical fixes
wahln Oct 28, 2022
d8588e1
change how emittance and energy spectrum should be represented in bas…
wahln Oct 28, 2022
b08ddc4
Merge branch 'dev_varRBErobOpt_Update' of https://github.com/HomolkaN…
wahln Oct 28, 2022
2f0b541
potential fix for testing
Nov 14, 2022
bb40eca
Update MatRad_TopasConfig.m
Nov 14, 2022
d6fd9f2
Update matRad_runTests.m
wahln Nov 17, 2022
147f058
Update matRad_runTests.m
Nov 18, 2022
926d700
Update .gitignore
JenHardt Nov 18, 2022
704d2c0
introduce ompMC class
Nov 18, 2022
c8fd302
Update matRad_calcPhotonDoseOmpMC.m
Nov 18, 2022
16c9610
otherwise out and log file are the same file
JenHardt Nov 18, 2022
277fef5
Phase space file starts at end of colimator
JenHardt Nov 18, 2022
b6188d1
SAD and wsl fix
JenHardt Nov 18, 2022
3355d05
Merge branch 'dev_varRBErobOpt_Update' of https://github.com/HomolkaN…
JenHardt Nov 18, 2022
93571e6
Update MatRad_TopasConfig.m
Nov 18, 2022
051dfdb
add different SADs for x and y to the base data class
wahln Nov 22, 2022
fcc026f
Merge branch 'dev_varRBErobOpt_Update' of https://github.com/HomolkaN…
wahln Nov 22, 2022
20626d1
Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad in…
wahln Nov 22, 2022
d81012d
make mex file compilation a static function
wahln Nov 22, 2022
348ba2f
remove weird slab file in scenarios folder
wahln Nov 22, 2022
63bb149
small fix wenn getting number of emittance gaussians from the weight …
wahln Nov 22, 2022
f1e446a
minor MC workflow fixes
Nov 23, 2022
3782e6c
Renamed classes to follow the naming scheme
Nov 30, 2022
093eb96
Delete protons_savedMatRadMachine.mat
Nov 30, 2022
74f4f5d
Update matRad_fluenceOptimization.m
Dec 1, 2022
0eb3d41
Update matRad_doseAcc.m
Dec 6, 2022
675ebcb
range scenario fix and loop simplification for MC
wahln Dec 19, 2022
cb16de9
Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad in…
wahln Dec 19, 2022
4453b5a
fix MU normalization
wahln Dec 19, 2022
a5352d9
Merge branch 'dev_varRBErobOpt' into pr/536
wahln Dec 19, 2022
cbc78d0
small fix for running index in MC scenario calculation
wahln Dec 19, 2022
aa9fb10
Merge branch 'dev_varRBErobOpt' into pr/536
wahln Dec 19, 2022
4e87571
typo fix in MCsquare dose calculation
wahln Dec 19, 2022
894211d
improve dicom import handling for RTPlan and RTDose
wahln Dec 21, 2022
3e427cf
Avoid erroring on opengl in matRadGUI
wahln Jan 19, 2023
d3625aa
Remove opengl software rendering query due to deprecation
wahln Jan 19, 2023
64ce14c
Merge pull request #536 from HomolkaN/dev_varRBErobOpt_Update
wahln Jan 24, 2023
5663803
fix missing extractBetween function in Octave
wahln Jan 25, 2023
b85ec2c
Downwards compatibility of biological model
wahln Jan 25, 2023
bbca13d
propDoseCals turned into single struct
remocristoforetti Feb 6, 2023
091f78b
fixes wrong detection of constraint bounds and jacobian structure whe…
wahln Feb 27, 2023
c0c8353
remove phsp-header
wahln Mar 7, 2023
375987a
Error message rectified and all error and warning messages use matRad…
amitantony Mar 23, 2023
bcbc8b7
fix passes ct struct instead of ct.cubeHU to matRad_plotVoiContourSlice
amitantony Mar 23, 2023
b2ce690
Merge pull request #602 from e0404/bug/601-bug-using-minmaxmeandose-c…
wahln Mar 23, 2023
add110e
Update tests.yml
wahln Jan 29, 2023
4f436df
ompMC interface and MCsquare interface - fix eval function for obtain…
wahln Jan 30, 2023
c274d6d
Recompiled Octave 6.4.0 mex files for windows and linux, updated scri…
wahln Feb 1, 2023
f0b7199
updated optimizer compilation scripts
wahln Feb 1, 2023
8e17c34
update compiled optimizers with static linking
wahln Feb 1, 2023
2c9b118
update compiled linux optimizer
wahln Feb 3, 2023
ef95ac3
option to disable function plot in optimization
wahln Feb 3, 2023
7060a3a
include rehash of file directory after linking the optimizer and adde…
wahln Feb 3, 2023
c3a673f
update workflow actions
wahln Feb 3, 2023
4b9a2fa
move scripts used during testing to github folder
wahln Feb 4, 2023
d4acb02
update scripts for github folder
wahln Feb 4, 2023
99336e0
adjust xvfb call in testing
wahln Feb 4, 2023
5a8c7f9
Revert "adjust xvfb call in testing"
wahln Feb 4, 2023
fe61134
use preinstallex xvfb in linux test
wahln Feb 6, 2023
0a03aee
fix path
wahln Feb 6, 2023
ab666aa
Update .gitignore
tobiasbecher Apr 3, 2023
9562b0c
Merge branch 'e0404:master' into dev_MixedModality_remo
remocristoforetti Apr 3, 2023
eb585f4
Merge branch 'dev_MixedModality_amit' into dev_MixedModality_remo
remocristoforetti Apr 3, 2023
eab8fc2
Merge branch 'master' into bug/605-bug-warning-and-error-messages-in-…
wahln Apr 5, 2023
d6238cd
Update tests.yml
wahln Apr 5, 2023
85f7cda
fix problem with constant property containing filepath
wahln Apr 6, 2023
711dc58
Merge branch 'master' into bug/606-matrad_plotvoicontourslice-tries-t…
amitantony Apr 11, 2023
8fb0fb8
displays parsed line in warning message
amitantony Apr 20, 2023
bb41c69
check installation of image processing toolbox
Apr 28, 2023
03cc52f
Merge pull request #617 from SakuMyl/master
wahln Apr 28, 2023
7456efc
Merge branch 'master' into bug/605-bug-warning-and-error-messages-in-…
wahln Apr 28, 2023
539dc94
Merge branch 'master' into bug/606-matrad_plotvoicontourslice-tries-t…
amitantony Apr 28, 2023
f7bded9
Merge pull request #607 from e0404/bug/605-bug-warning-and-error-mess…
wahln Apr 28, 2023
46d5f2c
Merge branch 'master' into bug/606-matrad_plotvoicontourslice-tries-t…
wahln Apr 28, 2023
58362ac
correct for reading x and y spot sizes from emittance data in topas i…
wahln May 10, 2023
19799c8
Fixed gradient Bug
tobiasbecher May 16, 2023
82742b0
Update .gitignore
tobiasbecher May 16, 2023
ebf4d57
Update
remocristoforetti May 19, 2023
36701bb
dummy load wInit
remocristoforetti May 19, 2023
b58def5
Update
remocristoforetti May 19, 2023
7ec4cf6
Update
remocristoforetti May 19, 2023
3bc314d
Bug fix, correction for effect prescription
remocristoforetti May 19, 2023
8f03510
Merge pull request #621 from tobiasbecher/dev_varRBErobOptGradient
wahln May 23, 2023
7481585
Merge branch 'dev_MixedModality' of https://github.com/e0404/matRad i…
remocristoforetti May 24, 2023
e29d7d8
Merge branch 'e0404:master' into dev_MixMod_effect_prescription_bugFix
remocristoforetti May 24, 2023
689eabe
Merge pull request #608 from e0404/bug/606-matrad_plotvoicontourslice…
amitantony May 26, 2023
2397e3f
Add latest supported release options for tests to cover for release c…
wahln May 26, 2023
0fe09aa
Update job name
wahln May 26, 2023
2f42625
Update job name for octave
wahln May 26, 2023
beaee4e
Merge branch 'master' into hotfix/fixTestEnvironment
wahln May 26, 2023
d6ea09a
Merge pull request #628 from e0404/hotfix/fixTestEnvironment
wahln May 30, 2023
d2da6e4
Merge branch 'master' of https://github.com/e0404/matRad into dev_var…
wahln May 30, 2023
a531a2d
Fix wrong test folder in tests.yml
wahln May 30, 2023
153ba54
explicit start of parallel pool in testing workflow
wahln May 30, 2023
871e0b6
Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad in…
wahln May 30, 2023
48ca910
revert explicit start of parpool in testing pipeline
wahln May 30, 2023
a7e72fa
add empirical correction for MCS in air when approximating beam model
wahln Jun 6, 2023
6a746ee
fix variable names in example 12
wahln Jun 6, 2023
1bab14d
fix for the spot size air MCS correction
wahln Jun 6, 2023
c5dd9eb
appendresultgui now either overwrites or always appends the identifier
wahln Jun 6, 2023
3e7952a
AppendResultGUI now creates consistent fieldnames
wahln Jun 7, 2023
f9569ea
Merge branch 'dev_MixedModality' of https://github.com/e0404/matRad i…
remocristoforetti Jun 12, 2023
71506ea
Merge branch 'dev_MixMod_effect_prescription_bugFix' of https://githu…
remocristoforetti Jun 12, 2023
c0dcbdb
clean fluence optimization from loading wInit
remocristoforetti Jun 12, 2023
6835c93
gradientChecker default to zero
remocristoforetti Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions IO/matRad_readNRRD.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

matRad_cfg = MatRad_Config.instance();

% Open file.
hFile = fopen(filename, 'r');
if hFile <= 0
error('Could not open NRRD file!');
matRad_cfg.dispError('Could not open NRRD file!');
end
cleaner = onCleanup(@() fclose(hFile));

%% Determine NRRD Version
nrrdLine = fgetl(hFile);
regTokens = regexp(nrrdLine,'NRRD00(?:\.)?0([1-5])','tokens');
if isempty(regTokens)
error('Invalid Header line! Could not identify NRRD version!');
matRad_cfg.dispError('Invalid Header line! Could not identify NRRD version!');
end
nrrdVersion = str2num(regTokens{1}{1});

if nrrdVersion > 5
error('NRRD version > 5 not supported!');
matRad_cfg.dispError('NRRD version > 5 not supported!');
end

%% Read header
Expand All @@ -60,15 +62,15 @@
%Parse the line
lineContent = regexp(currentLine, '(.+):(=|\s)(.+)', 'tokens');
if isempty(lineContent)
warning(['Could not parse line: "' lineContent '"']);
matRad_cfg.dispWarning(['Could not parse line: "' currentLine '"']);
elseif isequal(lineContent{1}{2},' ') %space after colon refers to "field"
nrrdMetaData.fields{end+1,1} = lineContent{1}{1}; %Fieldname
nrrdMetaData.fields{end,2} = lineContent{1}{3}; %Information
elseif isequal(lineContent{1}{2},'=') %= after colon refers to key-value pair
nrrdMetaData.keys{end+1,1} = lineContent{1}{1}; %Key
nrrdMetaData.keys{end,2} = lineContent{1}{3}; %Value
else
warning(['Could not parse line: "' lineContent '"']);
matRad_cfg.dispWarning(['Could not parse line: "' currentLine '"']);
end
end
currentLine = fgetl(hFile);
Expand All @@ -85,7 +87,7 @@
endianFieldIx = find(ismember(nrrdMetaData.fields(:,1),'endian'));
if ~isempty(endianFieldIx)
if ~isequal(nrrdMetaData.fields{endianFieldIx,2},'little') && ~isequal(nrrdMetaData.fields{endianFieldIx,2},'big')
error(['Datatype is ' datatype ', thus endian information is required but could not be interpreted!']);
matRad_cfg.dispError(['Datatype is ' datatype ', thus endian information is required but could not be interpreted!']);
end;
%Now we compare the file endian to the system endian
%First acquire system endian
Expand All @@ -101,36 +103,36 @@
doSwapBytes = true;
end
else
error(['Datatype is ' datatype ', thus endian information is required but could not be found!']);
matRad_cfg.dispError(['Datatype is ' datatype ', thus endian information is required but could not be found!']);
end
end
metadata.datatype = datatype;

else
error('Could not find required "type" field!');
matRad_cfg.dispError('Could not find required "type" field!');
end

%Check for the always required image dimension
dimFieldIx = find(ismember(nrrdMetaData.fields(:,1), 'dimension'));
if ~isempty(dimFieldIx)
[metadata.dimension,success] = str2num(nrrdMetaData.fields{dimFieldIx,2});
if ~success
error('Could not read required dimension field');
matRad_cfg.dispError('Could not read required dimension field');
end
else
error('Could not find required "dimension" field!');
matRad_cfg.dispError('Could not find required "dimension" field!');
end

%Check for size / dim length
sizeFieldIx = find(ismember(nrrdMetaData.fields(:,1), 'sizes'));
if ~isempty(sizeFieldIx)
sizes = textscan(nrrdMetaData.fields{sizeFieldIx,2},'%d');
if numel(sizes{1}) ~= metadata.dimension || ~all(sizes{1} > 0)
error('Incorrect size definition!');
matRad_cfg.dispError('Incorrect size definition!');
end
metadata.cubeDim = sizes{1}';
else
error('Could not find required "dimension" field!');
matRad_cfg.dispError('Could not find required "dimension" field!');
end

%Check for resolution
Expand All @@ -140,7 +142,7 @@
if ~isempty(spacingFieldIx)
resolutions = textscan(nrrdMetaData.fields{spacingFieldIx,2},'%f');
if numel(resolutions{1}) ~= metadata.dimension
error('Incorrect spacings definition');
matRad_cfg.dispError('Incorrect spacings definition');
end
metadata.resolution = resolutions{1}';

Expand All @@ -167,14 +169,14 @@
currentAxis = find(vectors{c});

if numel(find(vectors{c})) ~= 1
error('Sorry! We currently only support spaces with cartesian basis!');
matRad_cfg.dispError('Sorry! We currently only support spaces with cartesian basis!');
end
metadata.axisPermutation(c) = currentAxis*sign(vectors{c}(currentAxis));
metadata.resolution(c) = vectors{c}(currentAxis);
end

else
warning('No Resolution Information available');
matRad_cfg.dispWarning('No Resolution Information available');
end

%find the origin if we have one
Expand Down Expand Up @@ -202,7 +204,7 @@
data_fileFieldIx = find(ismember(nrrdMetaData.fields(:,1), 'data file'));
datafileFieldIx = find(ismember(nrrdMetaData.fields(:,1), 'datafile'));
if ~isempty(data_fileFieldIx) || ~isempty(datafileFieldIx)
error('Sorry! We currently do not support detached data files!');
matRad_cfg.dispError('Sorry! We currently do not support detached data files!');
%Proposed workflow:
%check for data file
%close file
Expand All @@ -215,15 +217,15 @@
%Check for encoding
encodingFieldIx = find(ismember(nrrdMetaData.fields(:,1), 'encoding'));
if isempty(encodingFieldIx)
error('Could not find required "encoding" field!');
matRad_cfg.dispError('Could not find required "encoding" field!');
end
switch nrrdMetaData.fields{encodingFieldIx,2}
case 'raw'
cube = fread(hFile,prod(metadata.cubeDim), metadata.datatype);
case {'txt','text','ascii'}
cube = cast(fscanf(hFile,'%f'),metadata.datatype);
case 'hex'
error('Sorry: NRRD hex file not yet supported!');
matRad_cfg.dispError('Sorry: NRRD hex file not yet supported!');
case {'gz','gzip'}
compressedByteArray = fread(hFile, inf, 'uint8');

Expand All @@ -242,7 +244,7 @@
javaByteOutputStream.close();
javaUnpackSuccessful = true;
catch
warning('Java unpacking failed... using temporary files!');
matRad_cfg.dispWarning('Java unpacking failed... using temporary files!');
end
end
if ~javaUnpackSuccessful
Expand All @@ -252,7 +254,7 @@
hFileTmp = fopen(tmpFile, 'wb');

if hFileTmp <= 0
error('Could not open temporary file for GZIP!');
matRad_cfg.dispError('Could not open temporary file for GZIP!');
end

fwrite(hFileTmp, compressedByteArray, 'uint8');
Expand All @@ -264,16 +266,16 @@
%Read the uncompressed file
hFileTmp = fopen(tmpName, 'rb');
if hFileTmp <= 0
error('Could not open unpacked file!');
matRad_cfg.dispError('Could not open unpacked file!');
end
cleanTmpFile = onCleanup(@() fclose(hFileTmp));

cube = fread(hFileTmp, prod(metadata.cubeDim), metadata.datatype);
end
case {'bz2','bzip2'}
error('Sorry: bzip compression not yet supported!');
matRad_cfg.dispError('Sorry: bzip compression not yet supported!');
otherwise
error(['Undefined NRRD encoding scheme: ' nrrdMetaData.encoding]);
matRad_cfg.dispError(['Undefined NRRD encoding scheme: ' nrrdMetaData.encoding]);
end

%maybe we need to correct the byte ordering (endian)
Expand Down Expand Up @@ -327,7 +329,7 @@
case 'double'
datatype = 'double';
otherwise
error('Could not identify datatype for NRRD data');
matRad_cfg.dispError('Could not identify datatype for NRRD data');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was fixed with #607. try to merge master into your branch for this

end

end
Expand Down
5 changes: 4 additions & 1 deletion dicom/matRad_scanDicomImportFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
%% get all files in search directory

% dicom import needs image processing toolbox -> check if available
v = ver;
if ~license('checkout','image_toolbox')
matRad_cfg.dispError('image processing toolbox and/or corresponding licence not available');
matRad_cfg.dispError('Image Processing Toolbox and/or corresponding license not available');
elseif ~any(strcmp('Image Processing Toolbox', {v.Name}))
matRad_cfg.dispError('Image Processing Toolbox not installed');
end

fileList = matRad_listAllFiles(patDir);
Expand Down
2 changes: 1 addition & 1 deletion matRad_fluenceOptimization.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
optimizer = matRad_OptimizerIPOPT;
end


optimizer.options.max_iter = 10000;
optimizer = optimizer.optimize(wInit,optiProb,dij,cst);

wOpt = optimizer.wResult;
Expand Down
16 changes: 13 additions & 3 deletions matRad_fluenceOptimizationJO.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [resultGUI,optimizer] = matRad_fluenceOptimizationJO(dij,cst,pln,wInit)
function [resultGUI,optimizer] = matRad_fluenceOptimizationJO(dij,cst,pln,wInit,loadwInit)
% matRad inverse planning wrapper function
%
% call
Expand Down Expand Up @@ -106,7 +106,11 @@
else
numOfModalities = 1;
end
if exist('wInit','var')

if ~exist('wInit', 'var')
wInit = [];
end
if ~isempty(wInit) %can never happen now
%do nothing as wInit was passed to the function
matRad_cfg.dispInfo('chosen provided wInit!\n');

Expand Down Expand Up @@ -364,7 +368,13 @@
warning(['Optimizer ''' pln.propOpt.optimizer ''' not known! Fallback to IPOPT!']);
optimizer = matRad_OptimizerIPOPT;
end


if exist('loadwInit', 'var')
if loadwInit ==1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not entirely convinced this 'loadwInit' is a great way to manage stored initial weights as it could end up being quite messy in practice. i would take it out

load('wInit.mat');
end
end
optimizer.options.max_iter = 10000;
optimizer = optimizer.optimize(wInit,optiProb,dij,cst);

wOpt = optimizer.wResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,21 @@
%Only implemented for first scenario now
weightGradient = weightGradient + gProb{1};
end
gradientChecker = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please set default flag to zero and add comments

if gradientChecker == 1
f = matRad_objectiveFunction(optiProb,w,dij,cst);
epsilon = 1e-8;
ix = unique(randi([1 numel(w)],1,5));

for i=ix
wInit = w;
wInit(i) = wInit(i) + epsilon;
fDel= matRad_objectiveFunction(optiProb,wInit,dij,cst);
numGrad = (fDel - f)/epsilon;
diff = (numGrad/weightGradient(i) - 1)*100;
fprintf(['grad val #' num2str(i) ' - rel diff numerical and analytical gradient = ' num2str(diff) '\n']);
%fprintf([' any nan or zero for photons' num2str(sum(isnan(glog{1}))) ',' num2str(sum(~logical(glog{1}))) ' for protons: ' num2str(sum(isnan(glog{2}))) ',' num2str(sum(~logical(glog{2}))) '\n']);
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,43 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

matRad_cfg = MatRad_Config.instance();
% DOSE PROJECTION
bxidx = 1; %modality bixel index

% get current dose / effect / RBExDose vector
optiProb.BP.compute(dij,w);
d = optiProb.BP.GetResult();
% Obtain cumulative dose cube
[d{1}] = deal(zeros(dij.doseGrid.numOfVoxels,1));

for mod = 1: length(dij.original_Dijs)
wt = [];
% split the w for current modality
STrepmat = (~dij.spatioTemp(mod) + dij.spatioTemp(mod)*dij.numOfSTscen(mod));
wt = reshape(w(bxidx: bxidx+STrepmat*dij.original_Dijs{mod}.totalNumOfBixels-1),[dij.original_Dijs{mod}.totalNumOfBixels,STrepmat]);
% get current dose / effect / RBExDose vector
optiProb.BP.compute(dij.original_Dijs{mod},wt);
dt = optiProb.BP.GetResult();

% also get probabilistic quantities (nearly no overhead if empty)
[dExp,dOmega] = optiProb.BP.GetResultProb(); % NOTE: not sure what exactly to do for the dOmegas

%Index of nxt modality
bxidx = bxidx + STrepmat*dij.original_Dijs{mod}.totalNumOfBixels;
% Accumulat Dose for all scenarios FOR FUTURE REVIEW ON HOW TO COMBINE
% DIFFFERENT UNCERTAINTY SCENARIOS FOR DIFFERENT MODALITIES
% currently for ST optimization
for scen = 1:numel(dt)
d{scen} = d{scen} + sum(dt{scen}.*dij.STfractions{mod}',2);
end
end

% get the used scenarios
useScen = optiProb.BP.scenarios;
scenProb = optiProb.BP.scenarioProb;

% retrieve matching 4D scenarios
fullScen = cell(ndims(d),1);
[fullScen{:}] = ind2sub(size(d),useScen);
contourScen = fullScen{1};
fullScen = cell(ndims(dt),1);
[fullScen{:}] = ind2sub(size(dt),useScen);
contourScen = fullScen{1};

% Initializes constraints
c = [];
Expand All @@ -64,21 +88,25 @@
if isa(constraint,'DoseConstraints.matRad_DoseConstraint')

% rescale dose parameters to biological optimization quantity if required
doseParameter = constraint.getDoseParameters();
constraint = constraint.setDoseParameters(doseParameter./sum([dij.STfractions{:}]));

constraint = optiProb.BP.setBiologicalDosePrescriptions(constraint,cst{i,5}.alphaX,cst{i,5}.betaX);

doseParameter = constraint.getDoseParameters();
constraint = constraint.setDoseParameters(doseParameter.*sum([dij.STfractions{:}]));

% retrieve the robustness type
robustness = constraint.robustness;

switch robustness
case 'none' % if conventional opt: just sum objectives of nominal dose
d_i = d{1}(cst{i,4}{1});
c = [c; constraint.computeDoseConstraintFunction(d_i)];

case 'PROB' % if prob opt: sum up expectation value of objectives

d_i = dExp{1}(cst{i,4}{1});
c = [c; constraint.computeDoseConstraintFunction(d_i)];

case 'VWWC' % voxel-wise worst case - takes minimum dose in TARGET and maximum in OAR
contourIx = unique(contourScen);
if ~isscalar(contourIx)
Expand Down
Loading