Skip to content

Commit

Permalink
Merge piastammer/dev_varRBErobOpt_photonsTopas into dev_varRBErobOpt_…
Browse files Browse the repository at this point in the history
…Update

This is a preliminary implementation. Next, I will implement this properly into the updated TOPAS structure.

commit 0b82924
Author: pia.stammer <[email protected]>
Date:   Fri Oct 21 16:09:00 2022 +0200

    Added phase space source
    *need testing!*
    -load phase space from source file SIEMENS_PRIMUS_6.0_0.10_15.0x15.0 available at https://www-nds.iaea.org/phsp/photon/SIEMENS_Primus_6MV/
    -added beamProfile 'phasespace' and appropriate input file
    -no pencil beam scanning supported, only single angle/position atm
    ToDo: Check geometry, especially distances between nozzle, phase space, MLC and patient (surface/isocenter?)

commit 5ee5467
Author: Noa Homolka <[email protected]>
Date:   Fri Sep 16 17:19:28 2022 +0200

    PhotonTOPAS Update

    - export leafWidth from aperture2collimation
    - small bug with additional "end" fix in ParticleDoseMCtopas
    - added switch for uniform weights in case of ~calcDoseDirect
    - changed materialConversion to 'RSP'
    - renamed numOfLeaves and leafTimes parameters for easier understanding
    - Translated MLC so that the Nozzle lies at beginning of MLC, not centered

commit d43b80c
Author: pia.stammer <[email protected]>
Date:   Fri Sep 16 14:47:50 2022 +0200

    Reduced size of source, increased number of histories

commit 9067aa9
Author: pia.stammer <[email protected]>
Date:   Fri Sep 16 11:31:06 2022 +0200

    Add uniform source and rotate MLC

commit e7031b1
Author: Noa Homolka <[email protected]>
Date:   Fri Sep 16 10:30:36 2022 +0200

    disabled tracking of MCrun folder

commit 23b517a
Author: pia.stammer <[email protected]>
Date:   Fri Sep 16 09:57:44 2022 +0200

    Status 2nd Hackday: Some corrections, TOPAS runs through, results mediocre

commit bd68b3b
Author: pia.stammer <[email protected]>
Date:   Fri Jun 10 17:00:17 2022 +0200

    Initial commit: Added MLC shape capabilities for TOPAS
    - shapes generated by matRad_aperture2collimation are written into TOPAS config file
    - use class matRad_TopasConfigPhotons with "virtualGaussian" beam and "mlc" Multileaf collimator set-up if corresponding info exists
    - TOPAS config files for several beams, rays, leafs and shapes are created and run through
    !!Caution: Results not yet validated!!

commit c6dd0cb
Author: Niklas Wahl <[email protected]>
Date:   Fri Apr 29 09:49:26 2022 +0200

    added basic photon infrastructure

commit df91e40
Merge: e0ffefe ea37a85
Author: Niklas Wahl <[email protected]>
Date:   Wed Apr 20 16:08:04 2022 +0200

    Merge branch 'dev_varRBErobOpt' of https://github.com/e0404/matRad into dev_varRBErobOpt

    # Conflicts:
    #	MatRad_Config.m
    #	dicom/hlutLibrary/matRad_default.hlut
    #	examples/matRad_example6_protonsNoise.m
    #	matRad_calcDoseInitBeam.m
    #	matRad_calcParticleDose.m
    #	matRad_calcPhotonDose.m
    #	matRad_fluenceOptimization.m
    #	matRad_setOverlapPriorities.m
  • Loading branch information
HomolkaN committed Oct 24, 2022
1 parent 3610bf5 commit 4b59c62
Show file tree
Hide file tree
Showing 13 changed files with 1,198 additions and 378 deletions.
6 changes: 4 additions & 2 deletions MatRad_Config.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function setDefaultProperties(obj)
% Set default histories for MonteCarlo here if necessary
% obj.propMC.defaultNumHistories = 100;

%obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_proton_engine = 'MatRad_MCsquareConfig';
obj.propMC.default_carbon_engine = 'MatRad_TopasConfig';

Expand Down Expand Up @@ -239,7 +239,7 @@ function setDefaultPropertiesForTesting(obj)
% Set default histories for MonteCarlo
obj.propMC.defaultNumHistories = 100;

%obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_photon_engine = 'ompMC';
obj.propMC.default_proton_engine = 'MatRad_MCsquareConfig';
obj.propMC.default_carbon_engine = 'MatRad_TopasConfig';

Expand Down Expand Up @@ -402,6 +402,8 @@ function getEnvironment(obj)
else
if isfield(pln,'radiationMode') && ~isempty(pln.radiationMode)
switch pln.radiationMode
case 'photons'
configName = obj.propMC.default_photon_engine;
case 'protons'
configName = obj.propMC.default_proton_engine;
otherwise
Expand Down
130 changes: 130 additions & 0 deletions matRad_aperture2collimation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
function [pln,stf] = matRad_aperture2collimation(pln,stf,sequencing,apertureInfo)
% matRad function to convert sequencing information / aperture information
% into collimation information in pln and stf for field-based dose
% calculation
%
% call
% [pln,stf] = matRad_aperture2collimation(pln,stf,sequencing,apertureInfo)
%
% input
% pln: pln file used to generate the sequenced plan
% stf: stf file used to generate the sequenced plan
% sequencing: sequencing information (from resultGUI)
% apertureInfo: apertureInfo (from resultGUI)
%
% output
% pln: matRad pln struct with collimation information
% stf: matRad stf struct with shapes instead of beamlets
%
% References
% -
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2022 the matRad development team.
% Author: wahln
%
% 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.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Debug visualization
visBool = false;

bixelWidth = apertureInfo.bixelWidth;
leafWidth = bixelWidth;
convResolution = 0.5; %[mm]

%The collimator limits are infered here from the apertureInfo. This could
%be handled differently by explicitly storing collimator info in the base
%data?
symmetricMLClimits = vertcat(apertureInfo.beam.MLCWindow);
symmetricMLClimits = max(abs(symmetricMLClimits));
fieldWidth = 2*max(symmetricMLClimits);

%modify basic pln variables
pln.propStf.bixelWidth = 'field';
pln.propStf.collimation.convResolution = 0.5; %[mm]
pln.propStf.collimation.fieldWidth = fieldWidth;
pln.propStf.collimation.leafWidth = leafWidth;

%
%[bixelFieldX,bixelFieldY] = ndgrid(-fieldWidth/2:bixelWidth:fieldWidth/2,-fieldWidth/2:leafWidth:fieldWidth/2);
[convFieldX,convFieldY] = meshgrid(-fieldWidth/2:convResolution:fieldWidth/2);

%TODO: Not used in calcPhotonDose but imported from DICOM
%pln.propStf.collimation.Devices ...
%pln.propStf.collimation.numOfFields
%pln.propStf.collimation.beamMeterset

for iBeam = 1:numel(stf)
stfTmp = stf(iBeam);
beamSequencing = sequencing.beam(iBeam);
beamAperture = apertureInfo.beam(iBeam);

stfTmp.bixelWidth = 'field';

nShapes = beamSequencing.numOfShapes;

stfTmp.numOfRays = 1;%
stfTmp.numOfBixelsPerRay = nShapes;
stfTmp.totalNumOfBixels = nShapes;

ray = struct();
ray.rayPos_bev = [0 0 0];
ray.targetPoint_bev = [0 stfTmp.SAD 0];
ray.weight = 1;
ray.energy = stfTmp.ray(1).energy;
ray.beamletCornersAtIso = stfTmp.ray(1).beamletCornersAtIso;
ray.rayCorners_SCD = stfTmp.ray(1).rayCorners_SCD;

%ray.shape = beamSequencing.sum;
shapeTotalF = zeros(size(convFieldX));

ray.shapes = struct();
for iShape = 1:nShapes
currShape = beamAperture.shape(iShape);
activeLeafPairPosY = beamAperture.leafPairPos;
F = zeros(size(convFieldX));
if visBool
hF = figure; imagesc(F); title(sprintf('Beam %d, Shape %d',iBeam,iShape)); hold on;
end
for iLeafPair = 1:numel(activeLeafPairPosY)
posY = activeLeafPairPosY(iLeafPair);
ixY = convFieldY >= posY-leafWidth/2 & convFieldY < posY + leafWidth/2;
ixX = convFieldX >= currShape.leftLeafPos(iLeafPair) & convFieldX < currShape.rightLeafPos(iLeafPair);
ix = ixX & ixY;
F(ix) = 1;
if visBool
figure(hF); imagesc(F); drawnow; pause(0.1);
end
end

if visBool
pause(1); close(hF);
end

F = F*currShape.weight;
shapeTotalF = shapeTotalF + F;

ray.shapes(iShape).convFluence = F;
ray.shapes(iShape).shapeMap = currShape.shapeMap;
ray.shapes(iShape).weight = currShape.weight;
ray.shapes(iShape).leftLeafPos = currShape.leftLeafPos;
ray.shapes(iShape).rightLeafPos = currShape.rightLeafPos;
ray.shapes(iShape).leafPairCenterPos = activeLeafPairPosY;
end

ray.shape = shapeTotalF;
ray.weight = ones(1,nShapes);
stfTmp.ray = ray;

stf(iBeam) = stfTmp;
end


Loading

0 comments on commit 4b59c62

Please sign in to comment.