Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface/python #658

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions IO_stf.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function status = IO_stf(path)

stf_init = load(strcat(path,'stf_with_separate_rays.mat'), 'stf');
ray_init = load(strcat(path,'stf_with_separate_rays.mat'), 'rays');

%%
stf = [stf_init.stf{:}];
ray = cell(size(ray_init.rays, 2), 1);

for i=1:size(ray_init.rays, 2)
ray{i} = [ray_init.rays{i}{:}];
end

for i=1:size(ray_init.rays, 2)
stf(i).ray = ray{i};
end

%%
save(strcat(path,'stf.mat'), 'stf')

status = 'STF written';

end
4 changes: 2 additions & 2 deletions examples/matRad_example2_photons.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
% Let's generate dosimetric information by pre-computing dose influence
% matrices for unit beamlet intensities. Having dose influences available
% allows subsequent inverse optimization.
dij = matRad_calcPhotonDose(ct,stf,pln,cst);
dij = matRad_calcPhotonDoseMC(ct,stf,pln,cst,1000);

%% Inverse Optimization for IMRT
% The goal of the fluence optimization is to find a set of beamlet/pencil
Expand All @@ -155,7 +155,7 @@
% treatment. Once the optimization has finished, trigger once the GUI to
% visualize the optimized dose cubes.
resultGUI = matRad_fluenceOptimization(dij,cst,pln);
matRadGUI;
%matRadGUI;

%% Plot the Resulting Dose Slice
% Let's plot the transversal iso-center dose slice
Expand Down
14 changes: 9 additions & 5 deletions matRad_callFromPython.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
function matRad_callFromPython(functionName, outputName, varargin)
function matRad_callFromPython(functionName, outputName, inputPath, outputPath, varargin)
%matRad_callFromPython Function that uses temporary mat file to call any function from within python

for i=1:length(varargin)
load(varargin{i});
var=varargin{i}(1:end-4);
functionVars{i}=var;
if contains(string(varargin{i}), string('.mat'))
load(strcat(inputPath, varargin{i}));
[path, var, ext]=fileparts(varargin{i});
functionVars{i}=var;
else
functionVars{i} = num2str(varargin{i});
end
end

execFunc = sprintf('%s = %s(%s);', outputName, functionName, strjoin(functionVars,','));
Expand All @@ -14,6 +18,6 @@ function matRad_callFromPython(functionName, outputName, varargin)
%end

eval(execFunc);
save(strcat(outputName,'.mat'), outputName);
save(strcat(outputPath, outputName,'.mat'), outputName);

end
10 changes: 9 additions & 1 deletion matRad_generateStf.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
end
end

disp(length(V));

% Remove double voxels
V = unique(V);
% generate voi cube for targets
Expand Down Expand Up @@ -115,6 +117,10 @@
% Define steering file like struct. Prellocating for speed.
stf = struct;

save('coordsX_vox', 'coordsX_vox');
save('coordsY_vox', 'coordsY_vox');
save('coordsZ_vox', 'coordsZ_vox');

% loop over all angles
for i = 1:length(pln.propStf.gantryAngles)

Expand All @@ -123,6 +129,8 @@
coordsX = coordsX_vox*ct.resolution.x - pln.propStf.isoCenter(i,1);
coordsY = coordsY_vox*ct.resolution.y - pln.propStf.isoCenter(i,2);
coordsZ = coordsZ_vox*ct.resolution.z - pln.propStf.isoCenter(i,3);

save('coordsX', 'coordsX');

% Save meta information for treatment plan
stf(i).gantryAngle = pln.propStf.gantryAngles(i);
Expand Down Expand Up @@ -182,7 +190,7 @@

rayPos = [x,y,z];
end

% remove double rays
rayPos = unique(rayPos,'rows');

Expand Down
15 changes: 11 additions & 4 deletions matRad_saveStructs.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function status = matRad_saveStructs(path)
function status = matRad_saveStructs(load_path, save_path, engine)
% matRad_saveStructs Mat file transfer for python interface
%
% input
Expand All @@ -18,10 +18,17 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

load(path);
load(load_path);

save('ct.mat', 'ct');
save('cst.mat', 'cst');
if engine=='matlab'
save(append(save_path, 'ct.mat'), 'ct');
save(append(save_path, 'cst.mat'), 'cst');
else
save(append(save_path, 'ct.mat'), '-mat7-binary', 'ct');
save(append(save_path, 'ct.mat'), '-mat7-binary', 'cst');
end

%Choosing the engine is necessary because Octave has trouble reading .mat files. Doesn't recognize them as binary.

status = 'Files written';

Expand Down