Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e867f80
first very rough draft of sequecing class with SiochiLeaf Implementation
JenHardt Jun 27, 2025
c4a105a
Merge branch 'dev' into dev_Sequencing
JenHardt Jun 27, 2025
87ddbe3
Merge branch 'dev' into dev_Sequencing
JenHardt Aug 1, 2025
3c43496
updates to sequencing
JenHardt Aug 1, 2025
dcb8749
continuationof sequencing
JenHardt Aug 29, 2025
9331425
Merge branch 'dev' into dev_Sequencing
JenHardt Feb 25, 2026
bb931d3
Update ompMC
JenHardt Feb 27, 2026
4bbfe0f
delete old files
JenHardt Feb 27, 2026
b777135
updated 3d conformal
JenHardt Feb 27, 2026
68ea49a
part of class now
JenHardt Feb 27, 2026
cb40953
part of ion sequencer class
JenHardt Feb 27, 2026
f4e74e4
removed unused opt result
JenHardt Feb 27, 2026
460f8ba
updated DAO example
JenHardt Feb 27, 2026
5bdd747
remove unnecessary update ResultGUi
JenHardt Feb 27, 2026
dd36310
set fill empty Bixels to true to fix DAO issue with empty bixels
JenHardt Feb 27, 2026
6e7ca5b
restore Files
JenHardt Mar 4, 2026
a307a62
revert files
JenHardt Mar 4, 2026
dc96b20
revert files
JenHardt Mar 4, 2026
f28cf64
updates test
JenHardt Mar 6, 2026
2a138b5
fill empty bixels only for photons so not to interfer so much and upd…
JenHardt Mar 6, 2026
f1fca5a
changing of names
JenHardt Mar 6, 2026
d511408
updates of old functions
JenHardt Mar 6, 2026
cbbed97
merge dev branch
JenHardt Mar 19, 2026
aaea936
merge dev
JenHardt Mar 20, 2026
5b6e8a8
octave6fix
JenHardt Mar 20, 2026
8a17097
merge dev
JenHardt May 11, 2026
cc221de
Merge branch 'dev' into pr/891
wahln Jun 3, 2026
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
296 changes: 153 additions & 143 deletions examples/matRad_example10_4DphotonRobust.m

Large diffs are not rendered by default.

62 changes: 33 additions & 29 deletions examples/matRad_example11_helium.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,48 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% In this example we will show
%% In this example we will show
% (i) how to load patient data into matRad
% (ii) how to setup a helium dose calculation
% (iii) how to inversely optimize the pencil beam intensities directly from command window in MATLAB.
% (ii) how to setup a helium dose calculation
% (iii) how to inversely optimize the pencil beam intensities directly from command window in MATLAB.

%% set matRad runtime configuration
matRad_rc
matRad_rc;

%% Patient Data Import
load('BOXPHANTOM.mat');

%% Treatment Plan
% The next step is to define your treatment plan labeled as 'pln'. This
% structure requires input from the treatment planner and defines the most
% The next step is to define your treatment plan labeled as 'pln'. This
% structure requires input from the treatment planner and defines the most
% important cornerstones of your treatment plan.

%%
% First of all, we need to define what kind of radiation modality we would
% like to use. Possible values are photons, protons or carbon. In this
% example we would like to use protons for treatment planning. Next, we
% need to define a treatment machine to correctly load the corresponding
% need to define a treatment machine to correctly load the corresponding
% base data. matRad features generic base data in the file
% 'proton_Generic.mat'; consequently the machine has to be set accordingly
pln.radiationMode = 'helium';
pln.radiationMode = 'helium';
pln.machine = 'Generic';
pln.multScen = 'nomScen';

% Define the flavor of biological optimization for treatment planning along
% with the quantity that should be used for optimization. As we use helium,
% we follow a data-driven RBE parametrization to obtbain the variable
% relative biological effectiveness.
% we follow a data-driven RBE parametrization to obtbain the variable
% relative biological effectiveness.
pln.bioModel = 'HEL';


%%
% Now we have to set the remaining plan parameters.
pln.numOfFractions = 30;
pln.propStf.gantryAngles = [0];
pln.propStf.couchAngles = [0];
pln.propStf.bixelWidth = 5;
pln.propStf.isoCenter = matRad_getIsoCenter(cst,ct,0);
pln.propOpt.runDAO = 0;
pln.propOpt.runSequencing = 0;
pln.propStf.numOfBeams = numel(pln.propStf.gantryAngles);
pln.propStf.isoCenter = ones(pln.propStf.numOfBeams, 1) * matRad_getIsoCenter(cst, ct, 0);
pln.propStf.isoCenter = matRad_getIsoCenter(cst, ct, 0);

% dose calculation settings
pln.propDoseCalc.doseGrid.resolution.x = 5; % [mm]
Expand All @@ -73,27 +72,32 @@
pln.propOpt.quantityOpt = 'effect';

%% Generate Beam Geometry STF
stf = matRad_generateStf(ct,cst,pln);
stf = matRad_generateStf(ct, cst, pln);

%% Dose Calculation
% Lets generate dosimetric information by pre-computing dose influence
% matrices for unit beamlet intensities. Having dose influences available
% allows for subsequent inverse optimization.
dij = matRad_calcParticleDose(ct,stf,pln,cst);
% Lets generate dosimetric information by pre-computing dose influence
% matrices for unit beamlet intensities. Having dose influences available
% allows for subsequent inverse optimization.
dij = matRad_calcParticleDose(ct, stf, pln, cst);

%% Inverse Optimization for IMPT
% The goal of the fluence optimization is to find a set of bixel/spot
% weights which yield the best possible dose distribution according to the
% The goal of the fluence optimization is to find a set of bixel/spot
% weights which yield the best possible dose distribution according to the
% clinical objectives and constraints underlying the radiation treatment
resultGUI = matRad_fluenceOptimization(dij,cst,pln);
resultGUI = matRad_fluenceOptimization(dij, cst, pln);

%% Plot the Resulting Dose Slice
% Let's plot the transversal iso-center dose slice
slice = matRad_world2cubeIndex(pln.propStf.isoCenter(1,:),ct);
slice = matRad_world2cubeIndex(pln.propStf.isoCenter(1, :), ct);
slice = slice(3);
figure
subplot(121),imagesc(resultGUI.physicalDose(:,:,slice)),colorbar,colormap(jet),title('physical dose')
subplot(122),imagesc(resultGUI.RBExDose(:,:,slice)),colorbar,colormap(jet),title('RBExDose')



figure;
subplot(121);
imagesc(resultGUI.physicalDose(:, :, slice));
colorbar;
colormap(jet);
title('physical dose');
subplot(122);
imagesc(resultGUI.RBExDose(:, :, slice));
colorbar;
colormap(jet);
title('RBExDose');
2 changes: 0 additions & 2 deletions examples/matRad_example13_fitAnalyticalParticleBaseData.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@
pln.propOpt.optimizer = 'IPOPT';
pln.propOpt.bioOptimization = 'none'; % none: physical optimization; const_RBExDose; constant RBE of 1.1;
% LEMIV_effect: effect-based optimization; LEMIV_RBExDose: optimization of RBE-weighted dose
pln.propOpt.runDAO = false; % 1/true: run DAO, 0/false: don't / will be ignored for particles
pln.propOpt.runSequencing = false; % 1/true: run sequencing, 0/false: don't / will be ignored for particles and also triggered by runDAO below

% retrieve scenarios for dose calculation and optimziation
pln.multScen = matRad_multScen(ct,'nomScen');
Expand Down
40 changes: 18 additions & 22 deletions examples/matRad_example14_spotRemoval.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

clear;
%% set matRad runtime configuration
matRad_rc; %If this throws an error, run it from the parent directory first to set the paths
matRad_rc; % If this throws an error, run it from the parent directory first to set the paths

%% Patient Data Import
% Let's begin with a clear Matlab environment and import the prostate
Expand All @@ -24,18 +24,18 @@
load('PROSTATE.mat');

%% Treatment Plan
% The next step is to define your treatment plan labeled as 'pln'. This
% structure requires input from the treatment planner and defines the most
% The next step is to define your treatment plan labeled as 'pln'. This
% structure requires input from the treatment planner and defines the most
% important cornerstones of your treatment plan.

%%
% First of all, we need to define what kind of radiation modality we would
% like to use. Possible values are photons, protons or carbon. In this
% example we would like to use protons for treatment planning. Next, we
% need to define a treatment machine to correctly load the corresponding
% need to define a treatment machine to correctly load the corresponding
% base data. matRad features generic base data in the file
% 'proton_Generic.mat'; consequently the machine has to be set accordingly
pln.radiationMode = 'protons';
pln.radiationMode = 'protons';
pln.machine = 'Generic';
pln.bioModel = 'constRBE';
pln.multScen = 'nomScen';
Expand All @@ -45,45 +45,43 @@
% alongside the physical dose. Therefore you need to activate the
% corresponding option during dose calculcation
pln.propDoseCalc.calcLET = 0;

%%
% Now we have to set the remaining plan parameters.
pln.numOfFractions = 30;
pln.propStf.gantryAngles = [90 270];
pln.propStf.couchAngles = [0 0];
pln.propStf.bixelWidth = 3;
pln.propStf.isoCenter = matRad_getIsoCenter(cst,ct,0);
pln.propOpt.runDAO = 0;
pln.propOpt.runSequencing = 0;
pln.propStf.isoCenter = matRad_getIsoCenter(cst, ct, 0);

% dose calculation settings
pln.propDoseCalc.doseGrid.resolution.x = 5; % [mm]
pln.propDoseCalc.doseGrid.resolution.y = 5; % [mm]
pln.propDoseCalc.doseGrid.resolution.z = 5; % [mm]

%% Generate Beam Geometry STF
stf = matRad_generateStf(ct,cst,pln);
stf = matRad_generateStf(ct, cst, pln);

%% Dose Calculation
% Lets generate dosimetric information by pre-computing dose influence
% matrices for unit beamlet intensities. Having dose influences available
% allows for subsequent inverse optimization.
dij = matRad_calcParticleDose(ct,stf,pln,cst);
% Lets generate dosimetric information by pre-computing dose influence
% matrices for unit beamlet intensities. Having dose influences available
% allows for subsequent inverse optimization.
dij = matRad_calcParticleDose(ct, stf, pln, cst);

%% Inverse Optimization for IMPT
% The goal of the fluence optimization is to find a set of bixel/spot
% weights which yield the best possible dose distribution according to the
% The goal of the fluence optimization is to find a set of bixel/spot
% weights which yield the best possible dose distribution according to the
% clinical objectives and constraints underlying the radiation treatment
pln.propOpt.quantityOpt = quantityOpt;
resultGUI = matRad_fluenceOptimization(dij,cst,pln);
resultGUI = matRad_fluenceOptimization(dij, cst, pln);

%% Spot removal
% instantiate spot removal class
spotRemover = matRad_SpotRemovalDij(dij,resultGUI.w);
spotRemover = matRad_SpotRemovalDij(dij, resultGUI.w);

spotRemover.removalMode = 'relative';
spotRemover.propSpotRemoval.relativeThreshold = 0.05;
resultGUI2 = spotRemover.reoptimize(cst,pln);
resultGUI2 = spotRemover.reoptimize(cst, pln);

% numOfRemovedSpots = sr_cfg.numOfRemovedSpots;

Expand All @@ -93,6 +91,4 @@
% weightLogical = sr_cfg.getLogical;

%% Plot difference of the doses
matRad_compareDose(resultGUI.RBExDose,resultGUI2.RBExDose,ct,cst);


matRad_compareDose(resultGUI.RBExDose, resultGUI2.RBExDose, ct, cst);
64 changes: 32 additions & 32 deletions examples/matRad_example16_photonMC_MLC.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% In this example we will show
%% In this example we will show
% (i) how to load patient data into matRad
% (ii) how to setup a photon dose calculation based on the VMC++ Monte Carlo algorithm
% (iii) how to inversely optimize the beamlet intensities directly from command window in MATLAB.
% (ii) how to setup a photon dose calculation based on the VMC++ Monte Carlo algorithm
% (iii) how to inversely optimize the beamlet intensities directly from command window in MATLAB.
% (iv) how to visualize the result

%% set matRad runtime configuration
matRad_rc %If this throws an error, run it from the parent directory first to set the paths
matRad_rc; % If this throws an error, run it from the parent directory first to set the paths

%% Patient Data Import
% Let's begin with a clear Matlab environment and import the boxphantom
% into your workspace.
% into your workspace.
load('BOXPHANTOM.mat');

%% Treatment Plan
% The next step is to define your treatment plan labeled as 'pln'. This
% The next step is to define your treatment plan labeled as 'pln'. This
% structure requires input from the treatment planner and defines the most
% important cornerstones of your treatment plan.

pln.radiationMode = 'photons';
pln.radiationMode = 'photons';
pln.machine = 'Generic';
pln.numOfFractions = 30;
pln.propStf.gantryAngles = [0:72:359];
pln.propStf.couchAngles = [0 0 0 0 0];
%pln.propStf.gantryAngles = [0];
%pln.propStf.couchAngles = [0];
% pln.propStf.gantryAngles = [0];
% pln.propStf.couchAngles = [0];
pln.propStf.bixelWidth = 10;
pln.propStf.isoCenter = matRad_getIsoCenter(cst,ct,0);
% Enable sequencing and direct aperture optimization (DAO).
pln.propOpt.runSequencing = 1;
pln.propOpt.runDAO = 1;
pln.propStf.isoCenter = matRad_getIsoCenter(cst, ct, 0);

quantityOpt = 'physicalDose';
modelName = 'none';
quantityOpt = 'physicalDose';
modelName = 'none';

% retrieve bio model parameters
pln.bioModel = matRad_bioModel(pln.radiationMode,quantityOpt, modelName);
pln.bioModel = matRad_bioModel(pln.radiationMode, quantityOpt, modelName);

% retrieve scenarios for dose calculation and optimziation
pln.multScen = matRad_NominalScenario(ct);
Expand All @@ -59,40 +56,43 @@
pln.propDoseCalc.doseGrid.resolution.z = 3; % [mm]

%% Generate Beam Geometry STF
stf = matRad_generateStf(ct,cst,pln);
stf = matRad_generateStf(ct, cst, pln);

%% Dose Calculation

dij = matRad_calcDoseInfluence(ct,cst,stf,pln);
dij = matRad_calcDoseInfluence(ct, cst, stf, pln);

%% Inverse Optimization for IMRT
pln.propOpt.quantityOpt = quantityOpt;
resultGUI = matRad_fluenceOptimization(dij,cst,pln);
resultGUI = matRad_fluenceOptimization(dij, cst, pln);
%% Sequencing
% This is a multileaf collimator leaf sequencing algorithm that is used in
% order to modulate the intensity of the beams with multiple static
% segments, so that translates each intensity map into a set of deliverable
% This is a multileaf collimator leaf sequencing algorithm that is used in
% order to modulate the intensity of the beams with multiple static
% segments, so that translates each intensity map into a set of deliverable
% aperture shapes.
resultGUI = matRad_siochiLeafSequencing(resultGUI,stf,dij,5,1);
[pln,stf] = matRad_aperture2collimation(pln,stf,resultGUI.sequencing,resultGUI.apertureInfo);
resultGUI = matRad_sequencing(resultGUI, stf, pln, dij);
[pln, stf] = matRad_aperture2collimation(pln, stf, resultGUI.sequencing, resultGUI.sequencing.apertureInfo);

%% Aperture visualization
% Use a matrad function to visualize the resulting aperture shapes
matRad_visApertureInfo(resultGUI.apertureInfo)
matRad_visApertureInfo(resultGUI.sequencing.apertureInfo);
%% Plot the Resulting Dose Slice
% Just let's plot the transversal iso-center dose slice
slice = matRad_world2cubeIndex(pln.propStf.isoCenter(1,:),ct);
slice = matRad_world2cubeIndex(pln.propStf.isoCenter(1, :), ct);
slice = slice(3);
figure,
imagesc(resultGUI.physicalDose(:,:,slice)),colorbar, colormap(jet)
figure;
imagesc(resultGUI.physicalDose(:, :, slice));
colorbar;
colormap(jet);

%% Dose Calculation
%resultGUI_MC = matRad_calcDoseInfluence(ct,cst,stf,pln);
% resultGUI_MC = matRad_calcDoseInfluence(ct,cst,stf,pln);
pln.propDoseCalc.engine = 'TOPAS';
pln.propDoseCalc.beamProfile = 'phasespace';
pln.propDoseCalc.externalCalculation = 'write';
resultGUI_MC = matRad_calcDoseForward(ct,cst,stf,pln,resultGUI.w);
resultGUI_MC = matRad_calcDoseForward(ct, cst, stf, pln, resultGUI.w);

%% readout
waitforbuttonpress; %We will wait since we do need to do the external calculation first
waitforbuttonpress; % We will wait since we do need to do the external calculation first
pln.propDoseCalc.externalCalculation = resultGUI_MC.meta.TOPASworkingDir;
resultGUI_MC = matRad_calcDoseForward(ct,cst,stf,pln,resultGUI.w);
resultGUI_MC = matRad_calcDoseForward(ct, cst, stf, pln, resultGUI.w);
24 changes: 11 additions & 13 deletions examples/matRad_example17_biologicalModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
pln.propStf.gantryAngles = 0;
pln.propStf.couchAngles = 0;
pln.propStf.bixelWidth = 5;
pln.propStf.isoCenter = matRad_getIsoCenter(cst,ct,0);
pln.propOpt.runDAO = 0;
pln.propSeq.runSequencing = 0;
pln.propStf.isoCenter = matRad_getIsoCenter(cst, ct, 0);

% dose calculation settings
pln.propDoseCalc.doseGrid.resolution.x = 8;
pln.propDoseCalc.doseGrid.resolution.y = 8;
pln.propDoseCalc.doseGrid.resolution.z = 8;
pln.propDoseCalc.engine = 'HongPB';

%Optimization Settings
% Optimization Settings
pln.propOpt.quantityOpt = 'RBExDose';

%% stf
stf = matRad_generateStf(ct,cst,pln);
stf = matRad_generateStf(ct, cst, pln);

%% Dose calc

Expand All @@ -38,19 +36,19 @@

% We will compare the MCN model to constRBE.
% We will plan with the the MCN model.
pln.bioModel = matRad_MCNamara();
%alternative: pln.bioModel = matRad_bioModel(pln.radiationMode,'MCN');
%altnerative: pln.bioModel = 'MCN';
dij = matRad_calcDoseInfluence(ct,cst,stf,pln);
pln.bioModel = matRad_MCNamara();
% alternative: pln.bioModel = matRad_bioModel(pln.radiationMode,'MCN');
% altnerative: pln.bioModel = 'MCN';
dij = matRad_calcDoseInfluence(ct, cst, stf, pln);

%% Fluence optimization
resultGUI = matRad_fluenceOptimization(dij,cst,pln);
resultGUI = matRad_fluenceOptimization(dij, cst, pln);

%% Now let's recalculate with the constRBE model
pln.bioModel = matRad_ConstantRBE();
pln.bioModel.RBE = 1.1; %1.1 is standard, this is for illustration
pln.bioModel.RBE = 1.1; % 1.1 is standard, this is for illustration

resultGUI_recalc = matRad_calcDoseForward(ct,cst,stf,pln,resultGUI.w);
resultGUI_recalc = matRad_calcDoseForward(ct, cst, stf, pln, resultGUI.w);

%% Compare Dose distributions
matRad_compareDose(resultGUI.RBExDose,resultGUI_recalc.RBExDose,ct,cst);
matRad_compareDose(resultGUI.RBExDose, resultGUI_recalc.RBExDose, ct, cst);
Loading
Loading