SliceViewerPanel.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. classdef SliceViewerPanel < handle
  2. %SliceViewerPanel uipanel viewer to SliceViewerPanelSource
  3. %
  4. % SliceViewerPanel plots the content from SliceViewerPanelSource (SVPS).
  5. %
  6. % Coordinate/Orientation in detail:
  7. % zOrient = 1: Coronal, abscissa = dim3 = zmesh, ordinate = dim2 = ymesh
  8. % zOrient = 2: Sagittal, abscissa = dim3 = zmesh, ordinate = dim1 = xmesh
  9. % zOrient = 3: Transverse, abscissa = dim1 = xmesh, ordinate = dim2 = ymesh
  10. % or think as this:
  11. % zOrient = 1: image(zmesh, ymesh, Geometry.rhomw(slice,:,:))
  12. % zOrient = 2: image(zmesh, xmesh, Geometry.rhomw(:,slice,:))
  13. % zOrient = 3: image(xmesh, ymesh, Geometry.rhomw(:,:,slice))
  14. %
  15. % See also XTPS
  16. %
  17. % Author: Xiaohu Mo
  18. %===============================================================================
  19. properties
  20. hSVPS % handle to SliceViewerPanelSource
  21. zOrien % scroll along which dimension: 1=S; 2=C; 3=T
  22. % TODO should be private
  23. % handles to gui objects
  24. hPanel
  25. hAxis
  26. hSlider
  27. hEdit
  28. hLineH % horizontal TCS line
  29. hLineV % vertical TCS line
  30. hImage % image has CT and dose overlayed manually
  31. hCbar % colorbar handle
  32. hROIs % handle vector of overlay ROIs
  33. hDoseContours % handle vector of overlay isodose lines
  34. hDoseLegend % handle of legend of isodose lines
  35. end
  36. %===============================================================================
  37. %===============================================================================
  38. methods
  39. %-------------------------------------------------------------------------------
  40. function obj = SliceViewerPanel(hSVPS, zOrien, hPanelParent) % Constructor returns object
  41. obj.hSVPS = hSVPS;
  42. obj.zOrien = zOrien;
  43. obj.hPanel = uipanel('Parent', hPanelParent);
  44. obj.hAxis = axes('Parent', obj.hPanel);
  45. obj.hSlider = uicontrol(obj.hPanel, 'Style','slider');
  46. obj.hEdit = uicontrol(obj.hPanel, 'Style','edit');
  47. obj.hImage = image('Parent', obj.hAxis);
  48. obj.hLineH = line('Parent', obj.hAxis, 'XData', [], 'YData', []);
  49. obj.hLineV = line('Parent', obj.hAxis, 'XData', [], 'YData', []);
  50. obj.hCbar = [];
  51. obj.hDoseContours = [];
  52. obj.hDoseLegend = [];
  53. % Callback passes 3 args: (obj, src, evt)
  54. set(obj.hSlider, 'Callback', @obj.Slider_Callback);
  55. set(obj.hEdit, 'Callback', @obj.Edit_Callback);
  56. % Properties
  57. axis(obj.hAxis, 'off');
  58. set(obj.hImage, 'CData', [], 'CDataMapping', 'scaled');
  59. set(obj.hLineH, 'HitTest', 'off', 'Color', 'red');
  60. set(obj.hLineV, 'HitTest', 'off', 'Color', 'red');
  61. set([obj.hPanel obj.hSlider obj.hEdit], ...
  62. 'Background', get(get(obj.hPanel, 'Parent'), 'Color'));
  63. % Add Listener
  64. addlistener(obj.hSVPS, 'POI', 'PostSet', @obj.handleEvent);
  65. addlistener(obj.hSVPS, 'Geometry', 'PostSet', @obj.handleEvent);
  66. addlistener(obj.hSVPS, 'dosedisp', 'PostSet', @obj.handleEvent);
  67. addlistener(obj.hSVPS, 'ctWindow', 'PostSet', @obj.handleEvent);
  68. addlistener(obj.hSVPS, 'TCSVisible', 'PostSet', @obj.handleEvent);
  69. end % function SliceViewerPanel
  70. %-------------------------------------------------------------------------------
  71. function set_layout(obj, src, evt)
  72. % Set widget positions and sizes
  73. set([obj.hPanel obj.hAxis obj.hSlider obj.hEdit], 'Unit', 'normalized');
  74. padding = [0.01 0.01];
  75. setPositionXY(obj.hAxis, [0 1], [0.1 1], padding);
  76. setPositionXY(obj.hSlider, [0 0.8], [0 0.1], padding, 1.5, 'characters');
  77. setPositionXY(obj.hEdit, [0.8 1], [0 0.1], padding, 1.5, 'characters');
  78. end
  79. %-------------------------------------------------------------------------------
  80. function handleEvent(obj, src, evt)
  81. switch src.Name
  82. case 'POI'
  83. obj.redraw_lines();
  84. % redraw only changed dimension
  85. if obj.hSVPS.POI(obj.zOrien) ~= obj.hSVPS.prev_POI(obj.zOrien)
  86. obj.redraw_image();
  87. % obj.redraw_contour();
  88. obj.redraw_overlay();
  89. end
  90. case {'Geometry' 'ctWindow' 'ROIdisp' 'dosedisp'}
  91. % redraw all
  92. obj.redraw_image();
  93. % obj.redraw_contour();
  94. obj.redraw_overlay();
  95. case 'TCSVisible'
  96. % redraw line
  97. obj.redraw_lines();
  98. end
  99. end
  100. %-------------------------------------------------------------------------------
  101. function Slider_Callback(obj, src, evt)
  102. % check value, update Edit and Axis
  103. value = round(get(obj.hSlider, 'Value'));
  104. set(obj.hSlider, 'Value', value);
  105. set(obj.hEdit, 'String', num2str(value));
  106. obj.hSVPS.POI(obj.zOrien) = value;
  107. end % function Slider_Callback
  108. %-------------------------------------------------------------------------------
  109. function Edit_Callback(obj, src, evt)
  110. % check value, update Slider and Axis
  111. value = round(str2double(get(obj.hEdit, 'String')));
  112. if value >= get(obj.hSlider, 'Min') && value <= get(obj.hSlider, 'Max')
  113. set(obj.hSlider, 'Value', value);
  114. set(obj.hEdit, 'String', num2str(value));
  115. obj.hSVPS.POI(obj.zOrien) = value;
  116. else % invalid input, set back to slider value
  117. value = get(obj.hSlider, 'Value');
  118. set(obj.hEdit, 'String', num2str(value));
  119. end
  120. end % function Edit_Callback
  121. %-------------------------------------------------------------------------------
  122. function load_data(obj)
  123. set(obj.hSlider, 'Min', 1, 'Max', size(obj.hSVPS.Geometry.rhomw, obj.zOrien), 'Value', 1);
  124. set(obj.hSlider, 'SliderStep', [1 10] / size(obj.hSVPS.Geometry.rhomw, obj.zOrien));
  125. % set image coordinates, axis limits, DataAspectRatio
  126. switch obj.zOrien
  127. case 1
  128. set(obj.hImage, 'XData', obj.hSVPS.Geometry.z, 'YData', obj.hSVPS.Geometry.y);
  129. set(obj.hAxis, 'XLim', [min(obj.hSVPS.Geometry.z) max(obj.hSVPS.Geometry.z)]);
  130. set(obj.hAxis, 'YLim', [min(obj.hSVPS.Geometry.y) max(obj.hSVPS.Geometry.y)]);
  131. zoom(obj.hAxis, 'reset');
  132. daspect(obj.hAxis, [obj.hSVPS.Geometry.voxel_size(3) obj.hSVPS.Geometry.voxel_size(2) 1]);
  133. case 2
  134. set(obj.hImage, 'XData', obj.hSVPS.Geometry.z, 'YData', obj.hSVPS.Geometry.x);
  135. set(obj.hAxis, 'XLim', [min(obj.hSVPS.Geometry.z) max(obj.hSVPS.Geometry.z)]);
  136. set(obj.hAxis, 'YLim', [min(obj.hSVPS.Geometry.x) max(obj.hSVPS.Geometry.x)]);
  137. zoom(obj.hAxis, 'reset');
  138. daspect(obj.hAxis, [obj.hSVPS.Geometry.voxel_size(3) obj.hSVPS.Geometry.voxel_size(1) 1]);
  139. set(obj.hAxis, 'YDir', 'reverse');
  140. case 3
  141. set(obj.hImage, 'XData', obj.hSVPS.Geometry.x, 'YData', obj.hSVPS.Geometry.y);
  142. set(obj.hAxis, 'XLim', [min(obj.hSVPS.Geometry.x) max(obj.hSVPS.Geometry.x)]);
  143. set(obj.hAxis, 'YLim', [min(obj.hSVPS.Geometry.y) max(obj.hSVPS.Geometry.y)]);
  144. zoom(obj.hAxis, 'reset');
  145. daspect(obj.hAxis, [obj.hSVPS.Geometry.voxel_size(1) obj.hSVPS.Geometry.voxel_size(2) 1]);
  146. set(obj.hAxis, 'YDir', 'reverse');
  147. end
  148. % default to volume center
  149. obj.hSVPS.POI = round(size(obj.hSVPS.Geometry.rhomw)/2);
  150. % set slider and edit control when manually set focus point
  151. slice = obj.hSVPS.POI(obj.zOrien);
  152. set(obj.hSlider, 'Value', slice);
  153. set(obj.hEdit, 'String', slice);
  154. end % function load_data
  155. %-------------------------------------------------------------------------------
  156. function updateColorbar(obj)
  157. % only plot color on transvers axis
  158. if obj.zOrien ~= 3; return; end
  159. % delete old one
  160. delete(obj.hCbar); obj.hCbar = [];
  161. switch lower(obj.hSVPS.dosedisp.mode)
  162. case {'isodose' 'isodoseline'}
  163. % get a sorted, valid dose level and colors
  164. valid_indices = find(obj.hSVPS.dosedisp.level > 0);
  165. if isempty(valid_indices); return; end
  166. dose_levels = obj.hSVPS.dosedisp.level(valid_indices);
  167. dose_colors = obj.hSVPS.dosedisp.color(valid_indices,:);
  168. [dose_levels iX] = sort(dose_levels);
  169. dose_labels = arrayfun(@(d)num2str(d), dose_levels, 'UniformOutput', false)';
  170. cmap = dose_colors(iX, :);
  171. colormap(cmap);
  172. set(obj.hAxis, 'CLim', [0 1]);
  173. obj.hCbar = colorbar('Peer', obj.hAxis, 'Location', 'SouthOutside');
  174. set(obj.hCbar, 'TickLength', [0 0], ...
  175. 'XTick', (0.5:numel(dose_levels)-0.5)/numel(dose_levels), ...
  176. 'XTickLabel', dose_labels);
  177. case 'colorwash'
  178. colormap(jet(256));
  179. set(obj.hAxis, 'CLim', [0 max(obj.hSVPS.optResults.dose{end}(:))]);
  180. obj.hCbar = colorbar('Peer', obj.hAxis, 'Location', 'SouthOutside');
  181. end
  182. end % function updateColorbar
  183. %-------------------------------------------------------------------------------
  184. function updateAxis(obj)
  185. % save axis scaling
  186. % xlim = get(obj.hAxis, 'XLim');
  187. % ylim = get(obj.hAxis, 'YLim');
  188. % % redraw more if slice changed
  189. % if obj.hSVPS.POI(obj.zOrien) ~= obj.hSVPS.prev_POI(obj.zOrien)
  190. % obj.redraw_image();
  191. % obj.redraw_contour();
  192. % end
  193. % obj.redraw_lines();
  194. % restore axis scaling
  195. % set(obj.hAxis, 'XLim', xlim);
  196. % set(obj.hAxis, 'YLim', ylim);
  197. end
  198. %-------------------------------------------------------------------------------
  199. function redraw_lines(obj)
  200. % P1 & P2 are the extent of the grid
  201. P1 = [min(obj.hSVPS.Geometry.y) min(obj.hSVPS.Geometry.x) min(obj.hSVPS.Geometry.z)];
  202. P2 = [max(obj.hSVPS.Geometry.y) max(obj.hSVPS.Geometry.x) max(obj.hSVPS.Geometry.z)];
  203. % F is the coordinate of the intersection of TCS planes
  204. F = [obj.hSVPS.Geometry.y(obj.hSVPS.POI(1)) ...
  205. obj.hSVPS.Geometry.x(obj.hSVPS.POI(2)) ...
  206. obj.hSVPS.Geometry.z(obj.hSVPS.POI(3))];
  207. switch obj.zOrien
  208. case 1
  209. set(obj.hLineH, 'XData', [P1(3) P2(3)], 'YData', [F(2) F(2)]);
  210. set(obj.hLineV, 'XData', [F(3) F(3)], 'YData', [P1(2) P2(2)]);
  211. case 2
  212. set(obj.hLineH, 'XData', [P1(3) P2(3)], 'YData', [F(1) F(1)]);
  213. set(obj.hLineV, 'XData', [F(3) F(3)], 'YData', [P1(1) P2(1)]);
  214. case 3
  215. set(obj.hLineH, 'XData', [P1(2) P2(2)], 'YData', [F(1) F(1)]);
  216. set(obj.hLineV, 'XData', [F(2) F(2)], 'YData', [P1(1) P2(1)]);
  217. end
  218. % Set visibility
  219. if obj.hSVPS.TCSVisible == true
  220. set(obj.hLineH, 'Visible', 'on');
  221. set(obj.hLineV, 'Visible', 'on');
  222. else
  223. set(obj.hLineH, 'Visible', 'off');
  224. set(obj.hLineV, 'Visible', 'off');
  225. end
  226. end
  227. %-------------------------------------------------------------------------------
  228. function redraw_image(obj)
  229. slice = obj.hSVPS.POI(obj.zOrien);
  230. % get CT image
  231. switch obj.zOrien
  232. case 1
  233. ctImage = imagescX((obj.hSVPS.Geometry.data(slice,:,:)), gray(256), obj.hSVPS.ctClim);
  234. case 2
  235. ctImage = imagescX((obj.hSVPS.Geometry.data(:,slice,:)), gray(256), obj.hSVPS.ctClim);
  236. case 3
  237. ctImage = imagescX((obj.hSVPS.Geometry.data(:,:,slice)), gray(256), obj.hSVPS.ctClim);
  238. end
  239. % set image to CT. Will re-set if need to blend with dose later.
  240. set(obj.hImage, 'CData',ctImage);
  241. % redraw dose
  242. delete(obj.hDoseContours);
  243. obj.hDoseContours = [];
  244. if ~isempty(obj.hSVPS.optResults)
  245. switch obj.zOrien
  246. case 1
  247. doseSlice = squeeze(obj.hSVPS.optResults.dose{end}(slice,:,:));
  248. xaxis = obj.hSVPS.Geometry.z;
  249. yaxis = obj.hSVPS.Geometry.y;
  250. case 2
  251. doseSlice = squeeze(obj.hSVPS.optResults.dose{end}(:,slice,:));
  252. xaxis = obj.hSVPS.Geometry.z;
  253. yaxis = obj.hSVPS.Geometry.x;
  254. case 3
  255. doseSlice = squeeze(obj.hSVPS.optResults.dose{end}(:,:,slice));
  256. xaxis = obj.hSVPS.Geometry.x;
  257. yaxis = obj.hSVPS.Geometry.y;
  258. end
  259. switch lower(obj.hSVPS.dosedisp.mode)
  260. case {'isodoseline'}
  261. if ~isempty(nonzeros(obj.hSVPS.dosedisp.level))
  262. hold(obj.hAxis, 'on');
  263. % sort dose levels before contourf
  264. [tilde, sorted_indices]= sort(obj.hSVPS.dosedisp.level);
  265. for idx = sorted_indices(:)'
  266. % scalar of current dose level
  267. dose_level = obj.hSVPS.dosedisp.level(idx);
  268. if dose_level ~= 0
  269. % plot this contour level and append handles to list
  270. % [level level] is used to avoid single level ambiguity of contour
  271. [tilde, obj.hDoseContours(end+1)] = contour(obj.hAxis, ...
  272. xaxis, yaxis, ...
  273. doseSlice, [dose_level dose_level], ...
  274. '-', 'LineWidth', 2, ...
  275. 'LineColor', obj.hSVPS.dosedisp.color(idx, :), ...
  276. 'DisplayName', sprintf('%.1f', dose_level));
  277. end
  278. end
  279. hold(obj.hAxis, 'off');
  280. end
  281. case 'isodose'
  282. % Using transparency with contourf like this fails due to the overlay of patches:
  283. % hPatches = findobj(obj.hDoseContours(end), 'Type', 'patch', '-property', 'FaceAlpha');
  284. % set(hPatches, 'FaceAlpha', obj.hSVPS.dosedisp.alpha(idx));
  285. if ~isempty(nonzeros(obj.hSVPS.dosedisp.level))
  286. doseMap = ones(size(doseSlice));
  287. alphaMap = zeros(size(doseSlice));
  288. % sort dose levels
  289. [tilde, sorted_indices]= sort(obj.hSVPS.dosedisp.level);
  290. for idx = sorted_indices(:)'
  291. % scalar of current dose level
  292. dose_level = obj.hSVPS.dosedisp.level(idx);
  293. % pixels below cmin will have alpha = 0
  294. if dose_level ~= 0
  295. doseMap(doseSlice >= dose_level) = idx;
  296. alphaMap(doseSlice >= dose_level) = obj.hSVPS.dosedisp.alpha(idx);
  297. end
  298. end
  299. % get the color
  300. doseImage = zeros(size(doseSlice,1), size(doseSlice,2), 3);
  301. R = obj.hSVPS.dosedisp.color(:, 1);
  302. G = obj.hSVPS.dosedisp.color(:, 2);
  303. B = obj.hSVPS.dosedisp.color(:, 3);
  304. doseImage(:,:,1) = reshape(R(doseMap), size(doseSlice));
  305. doseImage(:,:,2) = reshape(G(doseMap), size(doseSlice));
  306. doseImage(:,:,3) = reshape(B(doseMap), size(doseSlice));
  307. %
  308. compImage = imblend(doseImage, alphaMap, ctImage, 1);
  309. set(obj.hImage, 'CData', compImage);
  310. end
  311. case 'colorwash'
  312. doseImage = imagescX(doseSlice, jet(256), [0 max(obj.hSVPS.optResults.dose{end}(:))]);
  313. alphaMap = interp1([0; 40], [0; 1], doseSlice, 'linear', 1);
  314. alphaMap = reshape(alphaMap, size(doseSlice));
  315. compImage = imblend(doseImage, alphaMap, ctImage, 1);
  316. set(obj.hImage, 'CData', compImage);
  317. end
  318. end
  319. end
  320. %-------------------------------------------------------------------------------
  321. function redraw_contour(obj)
  322. % This function is not called anymore. See redraw_overlay for
  323. % the actual drawing of the contours
  324. slice = obj.hSVPS.POI(obj.zOrien);
  325. disp('Contour!!')
  326. delete(obj.hROIs);
  327. obj.hROIs = [];
  328. hold(obj.hAxis,'on');
  329. for i = 1:numel(obj.hSVPS.Geometry.ROIS)
  330. % skip if display == OFF
  331. if obj.hSVPS.Geometry.ROIS{i}.visible == false
  332. continue;
  333. end
  334. switch obj.zOrien
  335. case 1
  336. curve_indices = find(obj.hSVPS.Geometry.ROIS{i}.Xcurves_slices == slice);
  337. if ~isempty(curve_indices)
  338. for curve_idx = curve_indices
  339. obj.hROIs(end+1) = plot(obj.hAxis, ...
  340. obj.hSVPS.Geometry.ROIS{i}.Xcurves{curve_idx}(:,3), ...
  341. obj.hSVPS.Geometry.ROIS{i}.Xcurves{curve_idx}(:,2), ...
  342. '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  343. end
  344. end
  345. case 2
  346. curve_indices = find(obj.hSVPS.Geometry.ROIS{i}.Ycurves_slices == slice);
  347. if ~isempty(curve_indices)
  348. for curve_idx = curve_indices
  349. obj.hROIs(end+1) = plot(obj.hAxis, ...
  350. obj.hSVPS.Geometry.ROIS{i}.Ycurves{curve_idx}(:,3), ...
  351. obj.hSVPS.Geometry.ROIS{i}.Ycurves{curve_idx}(:,1), ...
  352. '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  353. end
  354. end
  355. case 3
  356. % curve_indices = find(abs(obj.hSVPS.Geometry.ROIS{i}.curvesZ - obj.hSVPS.Geometry.z(slice)) < 1E-2);
  357. curve_indices = find(obj.hSVPS.Geometry.ROIS{i}.Zcurves_slices == slice);
  358. % skip if no curve found on current slice
  359. if ~isempty(curve_indices)
  360. for curve_idx = curve_indices
  361. obj.hROIs(end+1) = plot(obj.hAxis, ...
  362. obj.hSVPS.Geometry.ROIS{i}.curves{curve_idx}(:,1), ...
  363. obj.hSVPS.Geometry.ROIS{i}.curves{curve_idx}(:,2), ...
  364. '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  365. end
  366. end
  367. end
  368. end
  369. hold(obj.hAxis,'off');
  370. end
  371. %-------------------------------------------------------------------------------
  372. function redraw_overlay(obj)
  373. slice = obj.hSVPS.POI(obj.zOrien);
  374. delete(obj.hROIs);
  375. obj.hROIs = [];
  376. hold(obj.hAxis,'on');
  377. for i = 1:numel(obj.hSVPS.Geometry.ROIS)
  378. % skip if display == OFF
  379. % fprintf('ROI #%.0f', i)
  380. if obj.hSVPS.Geometry.ROIS{i}.visible == false
  381. % fprintf(' skipped!\n', i)
  382. continue;
  383. end
  384. % fprintf(' analyzed!\n', i)
  385. testIdxList=obj.hSVPS.Geometry.ROIS{i}.ind;
  386. matSize=size(obj.hSVPS.Geometry.data);
  387. [x,y,z] = ind2sub(matSize, testIdxList);
  388. % fprintf('ROI #%.0f \n', disp(obj.zOrien))
  389. switch obj.zOrien
  390. case 1
  391. curve_indices = find(x == slice);
  392. if ~isempty(curve_indices)
  393. for curve_idx = curve_indices
  394. canvas=zeros(matSize(2),matSize(3));
  395. idx=sub2ind([matSize(2),matSize(3)], y(curve_indices), z(curve_indices));
  396. canvas(idx)=1;
  397. % sum(canvas(:))
  398. B = bwboundaries(canvas);
  399. numContours=length(B);
  400. for contourI=1:numContours
  401. B_I = B{contourI};
  402. clear C
  403. % up-down (+ high)
  404. yshift= obj.hSVPS.Geometry.start(2) - 1.0*obj.hSVPS.Geometry.voxel_size(2);
  405. zshift= obj.hSVPS.Geometry.start(3) - 1.0*obj.hSVPS.Geometry.voxel_size(3);
  406. C(:,1)= yshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(2);
  407. C(:,2)= zshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(3);
  408. obj.hROIs(end+1) = plot(obj.hAxis, ...
  409. C(:,2), C(:,1), ...
  410. '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  411. end
  412. end
  413. end % end of IF
  414. case 2
  415. curve_indices = find(y == slice);
  416. if ~isempty(curve_indices)
  417. for curve_idx = curve_indices
  418. canvas=zeros(matSize(1),matSize(3));
  419. idx=sub2ind([matSize(1),matSize(3)], x(curve_indices), z(curve_indices));
  420. canvas(idx)=1;
  421. % sum(canvas(:))
  422. B = bwboundaries(canvas);
  423. numContours=length(B);
  424. for contourI=1:numContours
  425. B_I = B{contourI};
  426. clear C
  427. % up-down (+ high)
  428. xshift= obj.hSVPS.Geometry.start(1) - 1.0*obj.hSVPS.Geometry.voxel_size(1);
  429. zshift= obj.hSVPS.Geometry.start(3) - 1.0*obj.hSVPS.Geometry.voxel_size(3);
  430. C(:,1)= xshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(1);
  431. C(:,2)= zshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(3);
  432. obj.hROIs(end+1) = plot(obj.hAxis, ...
  433. C(:,2), C(:,1), ...
  434. '--', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  435. end
  436. end
  437. end % end of IF
  438. case 3
  439. curve_indices = find(z == slice);
  440. if ~isempty(curve_indices)
  441. for curve_idx = curve_indices
  442. canvas=zeros(matSize(1),matSize(2));
  443. idx=sub2ind([matSize(1),matSize(2)], x(curve_indices), y(curve_indices));
  444. canvas(idx)=1;
  445. % sum(canvas(:))
  446. B = bwboundaries(canvas);
  447. numContours=length(B);
  448. for contourI=1:numContours
  449. B_I = B{contourI};
  450. clear C
  451. % up-down (+ high)
  452. yshift= obj.hSVPS.Geometry.start(2) - 1.0*obj.hSVPS.Geometry.voxel_size(2);
  453. xshift= obj.hSVPS.Geometry.start(1) - 1.0*obj.hSVPS.Geometry.voxel_size(1);
  454. C(:,1)= yshift + (B_I(:,1))*obj.hSVPS.Geometry.voxel_size(1);
  455. C(:,2)= xshift + (B_I(:,2))*obj.hSVPS.Geometry.voxel_size(2);
  456. obj.hROIs(end+1) = plot(obj.hAxis, ...
  457. C(:,2), C(:,1), ...
  458. '-', 'LineWidth', 2, 'Color', obj.hSVPS.Geometry.ROIS{i}.color);
  459. end
  460. end
  461. end % end of IF
  462. end
  463. end
  464. hold(obj.hAxis,'off');
  465. end
  466. %-------------------------------------------------------------------------------
  467. end % methods
  468. %===============================================================================
  469. end