dicomrt_loadvoi.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function [cellVOI] = dicomrt_loadvoi(rtstruct_filename)
  2. % dicomrt_loadvoi(rtstruct_filename)
  3. %
  4. % Load Volumes Of Interests (VOIs) from dicom-rt export file.
  5. %
  6. % A=dicomrt_dvhcal('rtstruct_filename') load into A the VOIs
  7. % extracted from the file 'rtstruct_filename'
  8. %
  9. % VOIs are stored in a cell array with the following structure:
  10. %
  11. % -----------------------------
  12. % | [OAR 1] | [xyz contour 1] |
  13. % | -------------------
  14. % | | [xyz contour 2] |
  15. % | -------------------
  16. % | | ... |
  17. % | -------------------
  18. % | | [xyz contour n] |
  19. % -----------------------------
  20. % | ... | ... |
  21. % -----------------------------
  22. % | [OAR n] | [xyz contour 1] |
  23. % | -------------------
  24. % | | [xyz contour 2] |
  25. % | -------------------
  26. % | | ... |
  27. % | -------------------
  28. % | | [xyz contour n] |
  29. % -----------------------------
  30. %
  31. %
  32. % See also dicomrt_loaddose, dicomrt_loadct, dicomrt_dvhcal
  33. %
  34. % Copyright (C) 2002 Emiliano Spezi (emiliano.spezi@physics.org)
  35. % Get info file
  36. dictFlg = checkDictUse;
  37. if dictFlg
  38. rtstruct=dicominfo(rtstruct_filename,'dictionary', 'ES - IPT4.1CompatibleDictionary.mat');
  39. else
  40. rtstruct=dicominfo(rtstruct_filename);
  41. end
  42. %rtstruct=rtstruct_filename;
  43. % Get number of VOIs
  44. ROIContourSequence=fieldnames(rtstruct.ROIContourSequence);
  45. % Define cell array
  46. VOI=cell(size(ROIContourSequence,1),2);
  47. % Progress bar
  48. h = waitbar(0,['Loading progress:']);
  49. set(h,'Name','dicomrt_loadvoi: loading RTSTRUCT objects');
  50. for i=1:size(ROIContourSequence,1) % for i=1:(number of VOIs) ...
  51. voilabel=getfield(rtstruct.StructureSetROISequence,char(ROIContourSequence(i)),'ROIName');
  52. VOI{i,1}=voilabel; % get VOI's name
  53. try
  54. ncont_temp=fieldnames(getfield(rtstruct.ROIContourSequence,char(ROIContourSequence(i)), ...
  55. 'ContourSequence')); % get contour list per each VOI (temporary variable)
  56. catch
  57. warning(['ContourSequence not found for ROI: ', voilabel]);
  58. ncont_temp = [];
  59. end
  60. switch isempty(ncont_temp)
  61. case 0
  62. for j=1:size(ncont_temp,1) % for j=1:(number of contours) ...
  63. if j==1
  64. VOI{i,2}=cell(size(ncont_temp,1),1);
  65. end
  66. try
  67. NumberOfContourPoints=getfield(rtstruct.ROIContourSequence,char(ROIContourSequence(i)), ...
  68. 'ContourSequence', char(ncont_temp(j)),'NumberOfContourPoints');
  69. ContourData=getfield(rtstruct.ROIContourSequence,char(ROIContourSequence(i)), ...
  70. 'ContourSequence',char(ncont_temp(j)),'ContourData');
  71. x=dicomrt_mmdigit(ContourData(1:3:NumberOfContourPoints*3)*0.1,7);
  72. y=dicomrt_mmdigit(ContourData(2:3:NumberOfContourPoints*3)*0.1,7);
  73. z=dicomrt_mmdigit(ContourData(3:3:NumberOfContourPoints*3)*0.1,7);
  74. VOI{i,2}{j,1}=cat(2,x,y,z); % this is the same as VOI{i,2}{j,1}=[x,y,z];
  75. end
  76. end
  77. case 1
  78. % set dummy values. This will be deleted later dugin the import
  79. NumberOfContourPoints=1;
  80. ContourData=[0,0,0];
  81. x=0;
  82. y=0;
  83. z=0;
  84. VOI{i,2}{1,1}=cat(2,x,y,z);
  85. end
  86. waitbar(i/size(ROIContourSequence,1),h);
  87. ncont_temp=[];
  88. end
  89. % VOI cell generation complete
  90. % Store VOI in a cell array
  91. cellVOI=cell(3,1);
  92. cellVOI{1,1}=rtstruct;
  93. cellVOI{2,1}=VOI;
  94. cellVOI{3,1}=[];
  95. % Close progress bar
  96. close(h);