matRad_importDicom

Purpose ^

matRad wrapper function to import a predefined set of dicom files

Synopsis ^

function [ct, cst, pln, resultGUI] = matRad_importDicom( files, dicomMetaBool )

Description ^

 matRad wrapper function to import a predefined set of dicom files 
 into matRad's native data formats
 
 call
 [ct, cst, pln, resultGUI] = matRad_importDicom( files )  
 [ct, cst, pln, resultGUI] = matRad_importDicom( files, dicomMetaBool )

 input
   files:          list of files to be imported (will contain cts and rt
                   structure set)
   dicomMetaBool:  (boolean, optional) import complete dicomInfo and
                   patientName

 output
   ct:        matRad ct struct
   cst:       matRad cst struct
   pln:       matRad plan struct
   resultGUI: matRad result struct holding data for visualization in GUI

 References
   -

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2015 the matRad development team. 
 
 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.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Source code ^

0001 function [ct, cst, pln, resultGUI] = matRad_importDicom( files, dicomMetaBool )
0002 % matRad wrapper function to import a predefined set of dicom files
0003 % into matRad's native data formats
0004 %
0005 % call
0006 % [ct, cst, pln, resultGUI] = matRad_importDicom( files )
0007 % [ct, cst, pln, resultGUI] = matRad_importDicom( files, dicomMetaBool )
0008 %
0009 % input
0010 %   files:          list of files to be imported (will contain cts and rt
0011 %                   structure set)
0012 %   dicomMetaBool:  (boolean, optional) import complete dicomInfo and
0013 %                   patientName
0014 %
0015 % output
0016 %   ct:        matRad ct struct
0017 %   cst:       matRad cst struct
0018 %   pln:       matRad plan struct
0019 %   resultGUI: matRad result struct holding data for visualization in GUI
0020 %
0021 % References
0022 %   -
0023 %
0024 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 %
0026 % Copyright 2015 the matRad development team.
0027 %
0028 % This file is part of the matRad project. It is subject to the license
0029 % terms in the LICENSE file found in the top-level directory of this
0030 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0031 % of the matRad project, including this file, may be copied, modified,
0032 % propagated, or distributed except according to the terms contained in the
0033 % LICENSE file.
0034 %
0035 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 [env, ~] = matRad_getEnvironment();
0038     
0039 %%
0040 if ~exist('dicomMetaBool','var')
0041   dicomMetaBool = true;
0042 end
0043 
0044 %%
0045 h = waitbar(0,'Please wait...');
0046 %h.WindowStyle = 'Modal';
0047 steps = 2;
0048 
0049 %% import ct-cube
0050 waitbar(1 / steps)
0051 resolution.x = files.resx;
0052 resolution.y = files.resy;
0053 resolution.z = files.resz; % [mm] / lps coordinate system
0054 if files.useDoseGrid && isfield(files,'rtdose')
0055     % get grid from dose cube
0056     if verLessThan('matlab','9')
0057         doseInfo = dicominfo(files.rtdose{1,1});
0058     else
0059         doseInfo = dicominfo(files.rtdose{1,1},'UseDictionaryVR',true);
0060     end
0061     doseGrid{1} = doseInfo.ImagePositionPatient(1) + doseInfo.ImageOrientationPatient(1) * ...
0062                                                      doseInfo.PixelSpacing(1) * double(0:doseInfo.Columns - 1);
0063     doseGrid{2} = doseInfo.ImagePositionPatient(2) + doseInfo.ImageOrientationPatient(5) * ...
0064                                                      doseInfo.PixelSpacing(2) * double(0:doseInfo.Rows - 1);
0065     doseGrid{3} = doseInfo.ImagePositionPatient(3) + doseInfo.GridFrameOffsetVector(:)';
0066 
0067     % get ct on grid
0068     ct = matRad_importDicomCt(files.ct, resolution, dicomMetaBool,doseGrid); 
0069 
0070 else
0071     ct = matRad_importDicomCt(files.ct, resolution, dicomMetaBool); 
0072 end
0073 
0074 if ~isempty(files.rtss)
0075     
0076     %% import structure data
0077     waitbar(2 / steps)
0078     structures = matRad_importDicomRtss(files.rtss{1},ct.dicomInfo);
0079     close(h)
0080 
0081     %% creating structure cube
0082     h = waitbar(0,'Please wait...');
0083     %h.WindowStyle = 'Modal';
0084     steps = numel(structures);
0085     for i = 1:numel(structures)
0086         % computations take place here
0087         waitbar(i / steps)
0088         fprintf('creating cube for %s volume...\n', structures(i).structName);
0089         structures(i).indices = matRad_convRtssContours2Indices(structures(i),ct);
0090     end
0091     fprintf('finished!\n');
0092     close(h)
0093 
0094     %% creating cst
0095     cst = matRad_createCst(structures);
0096 
0097 else
0098     
0099     cst = matRad_dummyCst(ct);
0100     
0101 end
0102 
0103 %% determine pln parameters
0104 if isfield(files,'rtplan')
0105     if ~(cellfun(@isempty,files.rtplan(1,:)))
0106         pln = matRad_importDicomRTPlan(ct, files.rtplan, dicomMetaBool);
0107     end
0108 end
0109 
0110 %% import stf
0111 if isfield(files,'rtplan')
0112     if ~(cellfun(@isempty,files.rtplan(1,:)))
0113         if (strcmp(pln.radiationMode,'protons') || strcmp(pln.radiationMode,'carbon'))
0114             %% import steering file
0115             % pln output because bixelWidth is determined via the stf
0116             [stf, pln] = matRad_importDicomSteeringParticles(ct, pln, files.rtplan);
0117         elseif strcmp(pln.radiationMode, 'photons') && isfield(pln.propStf,'collimation')
0118             % return correct angles in pln
0119             [stf, pln] = matRad_importDicomSteeringPhotons(pln);
0120         else
0121             warning('No support for DICOM import of steering information for this modality.');
0122         end
0123     end
0124 end
0125 
0126 %% import dose cube
0127 if isfield(files,'rtdose')
0128     % check if files.rtdose contains a path and is labeld as RTDose
0129     % only the first two elements are relevant for loading the rt dose
0130     if ~(cellfun(@isempty,files.rtdose(1,1:2))) 
0131         fprintf('loading Dose files \n', structures(i).structName);
0132         % parse plan in order to scale dose cubes to a fraction based dose
0133         if exist('pln','var')
0134             if isfield(pln,'numOfFractions')
0135                 resultGUI = matRad_importDicomRTDose(ct, files.rtdose, pln);
0136             end
0137         else
0138             resultGUI = matRad_importDicomRTDose(ct, files.rtdose);
0139         end
0140         if size(resultGUI) == 0
0141            clear resultGUI;
0142         end
0143     end
0144 end
0145 
0146 %% put weight also into resultGUI
0147 if exist('stf','var') && exist('resultGUI','var')
0148     resultGUI.w = [];
0149     for i = 1:size(stf,2)
0150         resultGUI.w = [resultGUI.w; [stf(i).ray.weight]'];
0151     end
0152 end
0153 
0154 %% save ct, cst, pln, dose
0155 matRadFileName = [files.ct{1,3} '.mat']; % use default from dicom
0156 [FileName,PathName] = uiputfile('*','Save as...',matRadFileName);
0157 if ischar(FileName)
0158     % delete unnecessary variables
0159     switch env
0160     case 'MATLAB'
0161         clearvars -except ct cst pln stf resultGUI FileName PathName;
0162     case 'OCTAVE' 
0163         clear -x ct cst pln stf resultGUI FileName PathName;
0164     end
0165     % save all except FileName and PathName
0166     save([PathName, FileName], '-regexp', '^(?!(FileName|PathName)$).','-v7.3');
0167 end

| Generated by m2html © 2005