matRad_writeVTK

Purpose ^

matRad function to write vtk cubes

Synopsis ^

function matRad_writeVTK(filepath,cube,metadata)

Description ^

 matRad function to write vtk cubes
 
 call
   matRad_writeVTK(filepath,cube,metadata)

 input
   filepath:   full filename (with extension)
   cube:       3D array to be written into file
   metadata:   struct of metadata. Writer will wrap the existing metadata 
               to VTK standard-specific fields 
               Necessary fieldnames are:
               - resolution: [x y z]
               - datatype: numeric MATLAB-Datatype

 output
   file will be written to disk

 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 matRad_writeVTK(filepath,cube,metadata)
0002 % matRad function to write vtk cubes
0003 %
0004 % call
0005 %   matRad_writeVTK(filepath,cube,metadata)
0006 %
0007 % input
0008 %   filepath:   full filename (with extension)
0009 %   cube:       3D array to be written into file
0010 %   metadata:   struct of metadata. Writer will wrap the existing metadata
0011 %               to VTK standard-specific fields
0012 %               Necessary fieldnames are:
0013 %               - resolution: [x y z]
0014 %               - datatype: numeric MATLAB-Datatype
0015 %
0016 % output
0017 %   file will be written to disk
0018 %
0019 % References
0020 %   -
0021 %
0022 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 %
0024 % Copyright 2015 the matRad development team.
0025 %
0026 % This file is part of the matRad project. It is subject to the license
0027 % terms in the LICENSE file found in the top-level directory of this
0028 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0029 % of the matRad project, including this file, may be copied, modified,
0030 % propagated, or distributed except according to the terms contained in the
0031 % LICENSE file.
0032 %
0033 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 
0035 % Sanity checks and restrictions
0036 dimensions = size(cube);
0037 if numel(dimensions) ~= 3
0038     error('Sorry! matRad only supports 3-dimensional VTK output');
0039 end
0040 
0041 fid = fopen(filepath, 'wb');
0042 if fid <= 0
0043     error('Could not open VTK destination file!');
0044 end
0045 cleaner = onCleanup(@() fclose(fid));
0046 
0047 %We perform
0048 if isfield(metadata,'axisPermutation')
0049     cube = permute(cube,metadata.axisPermutation);
0050 end
0051 
0052 
0053 fprintf(fid, '# vtk DataFile Version 3.0\n');
0054 fprintf(fid, 'vtk output\n');
0055 fprintf(fid, 'BINARY\n');
0056 fprintf(fid, 'DATASET STRUCTURED_POINTS\n');
0057 fprintf(fid, 'DIMENSIONS    %d   %d   %d\n', dimensions(1),dimensions(2),dimensions(3));
0058 fprintf(fid, 'SPACING    %f   %f   %f\n',metadata.resolution(1),metadata.resolution(2),metadata.resolution(3));
0059 fprintf(fid, 'ORIGIN    %f   %f   %f\n',metadata.imageOrigin(1),metadata.imageOrigin(2),metadata.imageOrigin(3));
0060 fprintf(fid, 'POINT_DATA   %d\n',prod(dimensions));
0061 if isfield(metadata,'dataName')
0062     dataName = metadata.dataName;
0063 else
0064     dataName = 'scalars';
0065 end
0066 fprintf(fid, 'SCALARS %s %s\n',dataName,metadata.datatype);
0067 fprintf(fid, 'LOOKUP_TABLE default\n');
0068 fwrite(fid,cube,metadata.datatype,'b');
0069 
0070 end
0071 
0072

| Generated by m2html © 2005