matRad_writeCube

Purpose ^

matRad wrapper for Cube export

Synopsis ^

function [saved_metadata] = matRad_writeCube(filepath,cube,datatype,metadata)

Description ^

 matRad wrapper for Cube export
 
 call
   [saved_metadata] = matRad_writeCube(filepath,cube,meta)

 input
   filepath:                   full output path. needs the right extension
                               to choose the appropriate writer
   cube:                       cube that is to be written
   datatype:                   MATLAB numeric datatype
   metadata:                   meta-information in struct. 
                               Necessary fieldnames are:
                               - resolution: [x y z]
                               Optional:
                               - axisPermutation (matRad default [2 1 3])
                               - coordinateSystem (matRad default 'LPS')
                               - imageOrigin (as used in DICOM)
                               - dataUnit (i.e. Gy..)
                               - dataName (i.e. dose, ED, ...)
                               - compress (true/false)
                                 (default chosen by writer)


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

 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 [saved_metadata] = matRad_writeCube(filepath,cube,datatype,metadata)
0002 % matRad wrapper for Cube export
0003 %
0004 % call
0005 %   [saved_metadata] = matRad_writeCube(filepath,cube,meta)
0006 %
0007 % input
0008 %   filepath:                   full output path. needs the right extension
0009 %                               to choose the appropriate writer
0010 %   cube:                       cube that is to be written
0011 %   datatype:                   MATLAB numeric datatype
0012 %   metadata:                   meta-information in struct.
0013 %                               Necessary fieldnames are:
0014 %                               - resolution: [x y z]
0015 %                               Optional:
0016 %                               - axisPermutation (matRad default [2 1 3])
0017 %                               - coordinateSystem (matRad default 'LPS')
0018 %                               - imageOrigin (as used in DICOM)
0019 %                               - dataUnit (i.e. Gy..)
0020 %                               - dataName (i.e. dose, ED, ...)
0021 %                               - compress (true/false)
0022 %                                 (default chosen by writer)
0023 %
0024 %
0025 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 %
0027 % Copyright 2015 the matRad development team.
0028 %
0029 % This file is part of the matRad project. It is subject to the license
0030 % terms in the LICENSE file found in the top-level directory of this
0031 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0032 % of the matRad project, including this file, may be copied, modified,
0033 % propagated, or distributed except according to the terms contained in the
0034 % LICENSE file.
0035 %
0036 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037 
0038 %% Sanity checks
0039 [filedir,filename,ext] = fileparts(filepath);
0040 if ~exist(filedir,'dir')
0041     error(['Directory ' filedir ' does not exist!']);
0042 end
0043 
0044 %No Special characters in filename (allow only _ and alphanumeric
0045 %characters
0046 robustFileName = filename(isstrprop(filename,'alphanum') | filename == '_');
0047 if ~strcmp(robustFileName,filename)
0048     warning(['Changing filename from ''' filename ''' to ''' robustFileName ''' to get rid of special characters!']);
0049     filepath = fullfile(filedir,[robustFileName ext]);
0050 end
0051 
0052 %% Prepare Metadata
0053 %if the field is not set, we assume standard matRad x-y swap
0054 if ~isfield(metadata,'axisPermutation')
0055     %cube = permute(cube,[2 1 3]); %This should be done in the writer based
0056     %on the axis permutation field
0057     metadata.axisPermutation = [2 1 3]; %Default Matlab axis permutation
0058 end
0059 %use the matrad coordinate system
0060 if ~isfield(metadata,'coordinateSystem')
0061     metadata.coordinateSystem = 'LPS';  %Matlab coordinate system
0062 end
0063 %If there is no image origin set, center the image
0064 imageExtent = metadata.resolution .* size(cube);
0065 if ~isfield(metadata,'imageOrigin')
0066     metadata.imageOrigin = zeros(1,numel(imageExtent)) - (imageExtent/2);
0067 end
0068 %we can also store the center
0069 if ~isfield(metadata,'imageCenter')
0070     metadata.imageCenter = metadata.imageOrigin + (imageExtent/2);
0071 end
0072 
0073 
0074 metadata.datatype = datatype;
0075     
0076 %% Choose writer
0077 %So far we only have an nrrd writer
0078 switch ext
0079     case '.nrrd'
0080         matRad_writeNRRD(filepath,cube,metadata);
0081     case '.vtk'
0082         matRad_writeVTK(filepath,cube,metadata);
0083     case '.mha'
0084         matRad_writeMHA(filepath,cube,metadata);
0085     otherwise
0086         errordlg(['No writer found for extension "' ext '"']);
0087 end
0088 
0089 fprintf('File written to %s...\n',filepath);
0090 saved_metadata = metadata;
0091 
0092 
0093 end
0094

| Generated by m2html © 2005