matRad_DicomExporter

Purpose ^

Synopsis ^

This is a script file.

Description ^

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 classdef matRad_DicomExporter < handle
0002     % matRad_DicomExporter matRad class to handle a dicom export.
0003     %
0004     %
0005     % Example on how to use the matRad_DicomExport class
0006     %
0007     % dcmExpObj          = matRad_DicomExporter;   % create instance of matRad_DicomExporter
0008     % dcmExpObj.dicomDir = 'pathAsString';         % set the output path for the Dicom export
0009     % dcmExp.matRad_exportDicom();                 % run the export
0010     %
0011     %
0012     % References
0013     %   -
0014     %
0015     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016     %
0017     % Copyright 2020 the matRad development team.
0018     %
0019     % This file is part of the matRad project. It is subject to the license
0020     % terms in the LICENSE file found in the top-level directory of this
0021     % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0022     % of the matRad project, including this file, may be copied, modified,
0023     % propagated, or distributed except according to the terms contained in the
0024     % LICENSE file.
0025     %
0026     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0027 
0028     properties
0029        
0030         %output folder
0031         dicomDir = ['.' filesep];
0032         
0033         % matRad structures to export
0034         ct = [];
0035         cst = [];
0036         stf = [];
0037         pln = [];
0038         resultGUI = [];
0039         
0040         % Study & Patient Dicom Information
0041         PatientID
0042         PatientName
0043         PatientPosition
0044         PatientBirthDate = '';
0045         PatientSex = '';
0046         StudyID
0047         StudyDate
0048         StudyTime
0049         StudyInstanceUID
0050         FrameOfReferenceUID
0051         
0052         %Operator
0053         OperatorsName
0054         
0055         % ct
0056         ctFilePrefix = 'ct_slice_';
0057         ctMeta
0058         ctSliceMetas
0059         ctExportStatus
0060         
0061         % rtstruct
0062         rtssFileName = 'RTStruct';
0063         rtssMeta
0064         rtssExportStatus
0065         
0066         % RTdose
0067         rtDoseFilePrefix = 'RTDose_';
0068         rtDoseNames
0069         rtDoseMetas
0070         rtDoseExportStatus
0071         
0072         % some dictionaries
0073         externalContourDict = {'EXTERNAL','BODY','PATIENT'}; %Names to identify external contours
0074         targetPtvDict = {'PTV','MARGIN'};
0075         targetCtvDict = {'CTV'};
0076         targetGtvDict = {'GTV','TUMOR'};
0077     end
0078     
0079     methods
0080         function obj = matRad_DicomExporter(ct,cst,pln,stf,resultGUI)
0081             %matRad_DicomExporter Construct an instance of this class
0082             %   Can be called with the structures. If no argument is given,
0083             %   all structures will be read from the base workspace
0084             
0085             
0086             matRad_cfg = MatRad_Config.instance();  
0087             
0088             env = matRad_getEnvironment();
0089             if strcmp(env,'OCTAVE')
0090                 %Octave needs the DICOM package
0091                 try
0092                     pkg load dicom;
0093                 catch
0094                     matRad_cfg.dispError('The DICOM export requires the octave-forge package "dicom"!\n');
0095                 end
0096             end
0097             
0098             if nargin == 0
0099                 try
0100                     obj.ct = evalin('base','ct');
0101                 catch
0102                     matRad_cfg.dispInfo('matRad_DicomExporter: No CT found in workspace.\n');
0103                 end
0104                 try
0105                     obj.cst = evalin('base','cst');
0106                 catch
0107                     matRad_cfg.dispInfo('matRad_DicomExporter: No cst found in workspace.\n');
0108                 end
0109                 try
0110                     obj.pln = evalin('base','pln');
0111                 catch
0112                     matRad_cfg.dispDebug('matRad_DicomExporter: No pln found in workspace.\n');
0113                 end
0114                 try
0115                     obj.stf = evalin('base','stf');
0116                 catch
0117                     matRad_cfg.dispDebug('matRad_DicomExporter: No stf found in workspace.\n');
0118                 end
0119                 try
0120                     obj.resultGUI = evalin('base','resultGUI');
0121                 catch
0122                 end
0123             else
0124                 if exist('ct','var')
0125                     obj.ct = ct;
0126                 end
0127                 if exist('cst','var')
0128                     obj.cst = cst;
0129                 end
0130                 if exist('pln','var')
0131                     obj.pln = pln;
0132                 end
0133                 if exist('stf','var')
0134                     obj.stf = stf;
0135                 end
0136                 if exist('resultGUI','var')
0137                     obj.pln = resultGUI;
0138                 end
0139             end
0140             
0141             obj = obj.generateDefaultDicomData();
0142         end
0143         
0144         function obj = generateDefaultDicomData(obj)
0145             % generateDefaultDicomData Fill Patient & Study dicom info
0146                         
0147             date    = now;
0148             dateStr = datestr(date,'yyyymmdd');
0149             timeStr = datestr(date,'HHMMSS');
0150             
0151             obj.PatientID = ['matRad_default_patient_' dateStr];
0152             obj.PatientName = obj.dicomName();
0153             obj.OperatorsName = obj.dicomName();
0154             
0155             obj.StudyID = ['matRad_' dateStr];
0156             obj.StudyDate = dateStr;
0157             obj.StudyTime = timeStr;
0158             obj.StudyInstanceUID = dicomuid;
0159             
0160             % coordinates
0161             obj.FrameOfReferenceUID = dicomuid;
0162             
0163             if isfield(obj.ct,'dicomInfo') && isfield(obj.ct.dicomInfo,'PatientPosition')
0164                obj.PatientPosition = obj.ct.dicomInfo.PatientPosition;
0165             else
0166                obj.PatientPosition = 'HFS'; %matRad default coordinate system
0167             end
0168         end
0169         
0170         obj = matRad_exportDicom(obj)
0171         
0172         obj = matRad_exportDicomCt(obj)
0173         
0174         obj = matRad_exportDicomRTStruct(obj)
0175         
0176         obj = matRad_exportDicomRTPlan(obj)
0177         
0178         obj = matRad_exportDicomRTDoses(obj)
0179         
0180     end
0181     
0182     methods (Static)
0183         function sarray = addStruct2StructArray(sarray,s,i)
0184             %addStruct2StructArray Helper function to assign structs
0185             %   When assigning structs to a struct array, there is usually
0186             %   an error. This method works around this error by assigning
0187             %   a struct s to the structure array sarray field by field at
0188             %   position i.
0189             %
0190             %call
0191             %   sarray = matRad_DicomExporter.matRad_exportDicomRTStruct(sarray,s,i)
0192             %
0193             %Input:
0194             %   sarray: structure array to add struct s to
0195             %   s:      struct to add to sarray
0196             %   i:      optional index. if not given, s is appended
0197             
0198             if nargin < 3
0199                 i = numel(sarray)+1;
0200             end
0201             fnames = fieldnames(s);
0202             sarray(i).(fnames{1}) = s.(fnames{1});
0203             if length(fnames) > 1
0204                 for k = 2:length(fnames)
0205                     sarray(i).(fnames{k}) = s.(fnames{k});
0206                 end
0207             end
0208         end
0209                 
0210         function meta = assignDefaultMetaValue(meta,fn,default,displayBool)
0211             %assignDefaultMetaValue Helper function to default meta values
0212             %   When meta information is already given, it may not be
0213             %   overwritten by a default value. This function automatically
0214             %   checks for a value and optionally prints to console
0215             %
0216             %call
0217             %   meta = matRad_DicomExporter.assignDefaultMetaValue(meta,fn,default,displayBool)
0218             %
0219             %Input:
0220             %   meta:           structure with dicom meta information
0221             %   fn:             meta fieldname
0222             %   default:        default value to assign
0223             %   displayBool:    optional request for console output.
0224             %
0225             %Output:
0226             %   meta:           meta struct with default value or value
0227             %                   that was already there before
0228             
0229             if nargin < 4
0230                 displayBool = true;
0231             end
0232             
0233             if ~isfield(meta,fn)
0234                 meta.(fn) = default;
0235                 
0236                 if isnumeric(default)
0237                     default = num2str(default);
0238                 elseif isstruct(default)
0239                     default = '';
0240                 end
0241                 
0242                 if displayBool
0243                     fprintf('No value set for ''%s'', using default value ''%s''\n',fn,default);
0244                 end
0245             end
0246         end
0247         
0248         function name = dicomName(family,given,middle,prefix,suffix)
0249             if nargin < 5
0250                 suffix = '';
0251             end
0252             if nargin < 4
0253                 prefix = '';
0254             end
0255             if nargin < 3
0256                 middle = '';
0257             end
0258             if nargin < 2
0259                 given = '';
0260             end
0261             if nargin < 1
0262                 family = '';
0263             end
0264             
0265             name.FamilyName = family;
0266             name.GivenName = given;
0267             name.MiddleName = middle;
0268             name.NamePrefix = prefix;
0269             name.NameSuffix = suffix;
0270             
0271             env = matRad_getEnvironment();
0272             if strcmp(env,'OCTAVE')
0273                 name = strjoin(struct2cell(name));
0274             end
0275             
0276         end
0277     end
0278     
0279     
0280 end
0281

| Generated by m2html © 2005