matRad_importDicomRtss

Purpose ^

matRad function to read the data of the selected dicomRT structure set file

Synopsis ^

function structures = matRad_importDicomRtss(filename,dicomInfo,visBool)

Description ^

 matRad function to read the data of the selected dicomRT structure set file 
 into a matlab struct
 
 call
   structures = matRad_importDicomRtss(filename,dicomInfo)
   structures = matRad_importDicomRtss(filename,dicomInfo,visBool)

 input
   filename:       name of the rtss file
   dicomInfo:      meta information from the dicom ct files for sanity
                   checks
   visBool:        (optional) turn on/off visualization

 output
   structures:     struct containing names, numbers, colors, and
                   coordinates of the polygon segmentations

 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 structures = matRad_importDicomRtss(filename,dicomInfo,visBool)
0002 % matRad function to read the data of the selected dicomRT structure set file
0003 % into a matlab struct
0004 %
0005 % call
0006 %   structures = matRad_importDicomRtss(filename,dicomInfo)
0007 %   structures = matRad_importDicomRtss(filename,dicomInfo,visBool)
0008 %
0009 % input
0010 %   filename:       name of the rtss file
0011 %   dicomInfo:      meta information from the dicom ct files for sanity
0012 %                   checks
0013 %   visBool:        (optional) turn on/off visualization
0014 %
0015 % output
0016 %   structures:     struct containing names, numbers, colors, and
0017 %                   coordinates of the polygon segmentations
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 fprintf('\nReading structures...');
0036 
0037 if nargin < 3
0038     visBool = 0;
0039 end
0040 
0041 % read dicom info (this includes already all data for the rtss)
0042 if verLessThan('matlab','9')
0043     structInfo = dicominfo(filename);
0044 else % apply 'UseVRHeuristic' option when available to use a to help read certain
0045      % noncompliant files which switch value representation (VR) modes incorrectly
0046     structInfo = dicominfo(filename,'UseVRHeuristic',false,'UseDictionaryVR',true);
0047 end
0048 
0049 % list the defined structures
0050 listOfDefStructs = fieldnames(structInfo.StructureSetROISequence);
0051 % list of contoured structures
0052 listOfContStructs = fieldnames(structInfo.ROIContourSequence);
0053 
0054 %% process structure data
0055 numOfDefStructs  = numel(listOfDefStructs);
0056 numOfContStructs = numel(listOfContStructs);
0057 
0058 for i = 1:numOfContStructs % loop over every structure
0059 
0060     % find the correct name
0061     for j = 1:numOfDefStructs
0062         if structInfo.ROIContourSequence.(listOfContStructs{i}).ReferencedROINumber ...
0063                 == structInfo.StructureSetROISequence.(listOfDefStructs{j}).ROINumber
0064             break;
0065         end
0066     end    
0067     structures(i).structName   = structInfo.StructureSetROISequence.(...
0068                                  listOfDefStructs{j}).ROIName;
0069                              
0070     structures(i).structNumber = structInfo.ROIContourSequence.(...
0071                                  listOfContStructs{i}).ReferencedROINumber;
0072     if isfield(structInfo.ROIContourSequence.(listOfContStructs{i}),'ROIDisplayColor')
0073         structures(i).structColor  = structInfo.ROIContourSequence.(...
0074                                      listOfContStructs{i}).ROIDisplayColor;  
0075     end
0076 
0077     if isfield(structInfo.ROIContourSequence.(...
0078                     listOfContStructs{i}), 'ContourSequence');
0079                 if ~isempty(structInfo.ROIContourSequence.(...
0080                                 listOfContStructs{i}).ContourSequence);
0081                     listOfSlices = fieldnames(structInfo.ROIContourSequence.(...
0082                                                 listOfContStructs{i}).ContourSequence);
0083                 else
0084                     warning(['Contour ' structures(i).structName ' is empty'])
0085                     continue;
0086                 end
0087     else
0088         warning(['Contour ' structures(i).structName ' is empty'])
0089         continue;
0090     end
0091     
0092     for j = 1:numel(listOfSlices)
0093         structSlice = structInfo.ROIContourSequence.(...
0094                 listOfContStructs{i}).ContourSequence.(listOfSlices{j});
0095         
0096         if strcmpi(structSlice.ContourGeometricType, 'POINT')
0097             continue;
0098         end
0099         
0100         % store the z-coordinate of this structure slice
0101         structX = structSlice.ContourData([1:3:end 1]);
0102         structY = structSlice.ContourData([2:3:end 2]);
0103         structZ = structSlice.ContourData([3:3:end 3]);
0104         
0105         % rounding to solve numerical problems with contour points not
0106         % being defined exactly in the same slice
0107         structZ = 1e-10*round(1e10*structZ);
0108         
0109         % sanity check 1
0110         if numel(unique(structZ)) > 1
0111             error('Detected contour points outside of single slice\n');
0112         end
0113         
0114         % sanity check 2
0115         if unique(structZ) > max(dicomInfo.SlicePositions) || unique(structZ) < min(dicomInfo.SlicePositions)
0116             warning(['Omitting contour data for ' structures(i).structName ' at slice position ' num2str(unique(structZ)) 'mm - no ct data available.\n']);
0117         else
0118             structures(i).item(j).points = [structX, structY, structZ];
0119         end
0120             
0121     end
0122     
0123 end
0124 
0125 %% visualization
0126 % show all structure points in a single plot
0127 if visBool
0128     figure;
0129     hold on
0130     for i = 1:numel(structures)
0131         plot3(structures(i).points(:,1),structures(i).points(:,2),...
0132             structures(i).points(:,3),'-',...
0133             'Color',structures(i).structColor ./ 255,'Displayname',structures(i).structName);
0134     end
0135     legend('show')
0136 end
0137 
0138 fprintf('finished!\n');
0139 
0140 
0141 end

| Generated by m2html © 2005