matRad function that generates the plot for the CT in the GUI 3D view The function can also be used in personal matlab figures by passing the corresponding axes handle call [ctHandle,cMap,window] = matRad_plotCtSlice3D(axesHandle,ct,cubeIdx,plane,ctSlice,cMap,window) input axesHandle handle to 3D axes the slice should be displayed in ct the ct struct used in matRad cubeIdx Index of the desired cube in the ct struct plane plane view (coronal=1,sagittal=2,axial=3) ctSlice slice in the selected plane of the 3D cube cMap optional argument defining the colormap, default is bone if you want to use the default map with the window argument you can use an empty array [] window optional argument defining the displayed range. default is [min(ctCube(:)) max(ctCube(:))] output ctHandle handle of the plotted CT axes cMap used colormap (same as input if set) window used window (same as input if set) 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. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [ctHandle,cMap,window] = matRad_plotCtSlice3D(axesHandle,ct,cubeIdx,plane,ctSlice,cMap,window) 0002 % matRad function that generates the plot for the CT in the GUI 3D view 0003 % The function can also be used in personal matlab figures by passing the 0004 % corresponding axes handle 0005 % 0006 % call 0007 % [ctHandle,cMap,window] = matRad_plotCtSlice3D(axesHandle,ct,cubeIdx,plane,ctSlice,cMap,window) 0008 % 0009 % input 0010 % axesHandle handle to 3D axes the slice should be displayed in 0011 % ct the ct struct used in matRad 0012 % cubeIdx Index of the desired cube in the ct struct 0013 % plane plane view (coronal=1,sagittal=2,axial=3) 0014 % ctSlice slice in the selected plane of the 3D cube 0015 % cMap optional argument defining the colormap, default is bone 0016 % if you want to use the default map with the window argument 0017 % you can use an empty array [] 0018 % window optional argument defining the displayed range. default is 0019 % [min(ctCube(:)) max(ctCube(:))] 0020 % 0021 % output 0022 % ctHandle handle of the plotted CT axes 0023 % cMap used colormap (same as input if set) 0024 % window used window (same as input if set) 0025 % 0026 % References 0027 % - 0028 % 0029 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0030 % 0031 % Copyright 2015 the matRad development team. 0032 % 0033 % This file is part of the matRad project. It is subject to the license 0034 % terms in the LICENSE file found in the top-level directory of this 0035 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0036 % of the matRad project, including this file, may be copied, modified, 0037 % propagated, or distributed except according to the terms contained in the 0038 % LICENSE file. 0039 % 0040 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0041 0042 matRad_cfg = MatRad_Config.instance(); 0043 0044 %Use default colormap? 0045 if nargin < 6 || isempty(cMap) 0046 cMap = bone(64); 0047 end 0048 0049 if nargin < 7 || isempty(window) 0050 window = [min(ct.cubeHU{cubeIdx}(:)) max(ct.cubeHU{cubeIdx}(:))]; 0051 end 0052 0053 cMapScale = size(cMap,1) - 1; 0054 0055 %Create the coordinates 0056 coords{1} = ct.resolution.x * (1:ct.cubeDim(2)); 0057 coords{2} = ct.resolution.y * (1:ct.cubeDim(1)); 0058 coords{3} = ct.resolution.z * (1:ct.cubeDim(3)); 0059 0060 % slice plot with surface(...), colormapping can be done by texture 0061 % mapping, this is why we use surface instead of slice 0062 if plane == 1 % Coronal plane 0063 [xMesh,zMesh] = meshgrid(coords{2},coords{3}); 0064 yMesh = ctSlice*ct.resolution.x*ones(size(xMesh)); 0065 ctIndexed = uint8(cMapScale*(squeeze((ct.cubeHU{cubeIdx}(ctSlice,:,:)-window(1))/(window(2) - window(1))))); 0066 % ct_rgb = permute(ct_rgb,[2 1 3]); 0067 elseif plane == 2 % sagittal plane 0068 [yMesh,zMesh] = meshgrid(coords{1},coords{3}); 0069 xMesh = ctSlice*ct.resolution.y*ones(size(yMesh)); 0070 ctIndexed = uint8(cMapScale*(squeeze((ct.cubeHU{cubeIdx}(:,ctSlice,:)-window(1))/(window(2) - window(1))))); 0071 % ct_rgb = permute(ct_rgb,[2 1 3]); 0072 elseif plane == 3 % Axial plane 0073 [xMesh,yMesh] = meshgrid(coords{2},coords{1}); 0074 zMesh = ctSlice*ct.resolution.z*ones(size(xMesh)); 0075 ctIndexed = uint8(cMapScale*(squeeze((ct.cubeHU{cubeIdx}(:,:,ctSlice)-window(1))/(window(2) - window(1))))); 0076 else 0077 matRad_cfg.dispError('Invalid plane ''%d'' selected for visualization!',plane); 0078 end 0079 0080 %This circumenvents a bug in Octave when the index in the image hase the maximum value of uint8 0081 if matRad_cfg.isOctave 0082 ctIndexed(ctIndexed == 255) = 254; 0083 end 0084 0085 ct_rgb = ind2rgb(ctIndexed,cMap); 0086 0087 ctHandle = surface('XData',xMesh, 'YData',yMesh, 'ZData',zMesh, ... 0088 'CData',ct_rgb, 'CDataMapping','direct', ... 0089 'EdgeColor','none', 'FaceColor','texturemap', 'BackFaceLighting','unlit','FaceLighting','flat','Parent',axesHandle); 0090 0091 %{ 0092 % slice plot with slice(...) 0093 % seems technically more reasonable, however manual colormapping not straightforward 0094 [xMesh,yMesh,zMesh] = meshgrid(coords{:}); 0095 slicePlane{1} = []; 0096 slicePlane{2} = []; 0097 slicePlane{3} = []; 0098 0099 slicePlane{plane} = coords{plane}(ctSlice); 0100 0101 ct_rgb = ind2rgb(uint8(cMapScale*((ct.cubeHU{cubeIdx}-window(1))/(window(2) - window(1)))),cMap); 0102 0103 ctHandle = slice(axesHandle,xMesh,yMesh,zMesh,ct.cubeHU{cubeIdx},slicePlane{:}); 0104 0105 set(ctHandle,'EdgeColor','none'); 0106 %} 0107 0108 0109 0110 end 0111 0112 0113