diff --git a/IO_stf.m b/IO_stf.m new file mode 100644 index 000000000..9a8c1c8be --- /dev/null +++ b/IO_stf.m @@ -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 \ No newline at end of file diff --git a/examples/matRad_example2_photons.m b/examples/matRad_example2_photons.m index 328276735..4bbc84477 100644 --- a/examples/matRad_example2_photons.m +++ b/examples/matRad_example2_photons.m @@ -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 @@ -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 diff --git a/matRad_callFromPython.m b/matRad_callFromPython.m index 9bd8b5f65..f2f37f75c 100644 --- a/matRad_callFromPython.m +++ b/matRad_callFromPython.m @@ -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,',')); @@ -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 diff --git a/matRad_generateStf.m b/matRad_generateStf.m index f128f0db0..d3059e1f5 100644 --- a/matRad_generateStf.m +++ b/matRad_generateStf.m @@ -53,6 +53,8 @@ end end +disp(length(V)); + % Remove double voxels V = unique(V); % generate voi cube for targets @@ -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) @@ -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); @@ -182,7 +190,7 @@ rayPos = [x,y,z]; end - + % remove double rays rayPos = unique(rayPos,'rows'); diff --git a/matRad_saveStructs.m b/matRad_saveStructs.m index bfb3681b9..a756b04ce 100644 --- a/matRad_saveStructs.m +++ b/matRad_saveStructs.m @@ -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 @@ -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';