Skip to content

Commit

Permalink
plotSlice function changes
Browse files Browse the repository at this point in the history
Ct is the only required parameter. Dose cube is optional. Option for plotting the ct added.
  • Loading branch information
SimonaFa committed Feb 14, 2025
1 parent a590172 commit a1163e1
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions matRad/util/matRad_plotSlice.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [] = matRad_plotSlice(ct, dose, varargin)
function [] = matRad_plotSlice(ct, varargin)
% matRad tool function to directly plot a complete slice of a ct with dose
% optionally including contours and isolines
%
Expand Down Expand Up @@ -45,22 +45,25 @@
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

defaultDose = [];
defaultCst = [];
defaultSlice = floor(min(size(dose))./2);
defaultSlice = floor(min(ct.cubeDim)./2);
defaultAxesHandle = gca;
defaultCubeIdx = 1;
defaultPlane = 1;
defaultDoseWindow = [];
defaultThresh = [];
defaultAlpha = [];
defaultDoseColorMap = [];
defaultDoseColorMap = jet;
defaultDoseIsoLevels = [];
defaultVOIselection = [];
defaultContourColorMap = [];
defaultBoolPlotLegend = false;
defaultColorBarLabel = [];
defaultShowCt = true;

Check warning on line 63 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L48-L63

Added lines #L48 - L63 were not covered by tests

isSlice = @(x) x>=1 && x<=max(size(dose)) && floor(x)==x;
isDose = @(x) isnumeric(x) && all(size(x) == ct.cubeDim);
isSlice = @(x) x>=1 && x<=max(ct.cubeDim) && floor(x)==x;
isAxes = @(x) strcmp(get(gca, 'type'), 'axes');
isCubeIdx = @(x) isscalar(x);
isPlane = @(x) isscalar(x) && (sum(x==[1, 2, 3])==1);
Expand All @@ -73,12 +76,13 @@
isContourColorMap = @(x) isnumeric(x) && (size(x, 2)==3) && size(x, 1)>=2 && all(x(:) >= 0) && all(x(:) <= 1);
isBoolPlotLegend = @(x) x==0 || x ==1;
isColorBarLabel = @(x) isstring(x) || ischar(x);
isShowCt = @(x) isscalar(x) && (x==0) || (x==1);

Check warning on line 79 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L65-L79

Added lines #L65 - L79 were not covered by tests

p = inputParser;
p.KeepUnmatched = true;
addRequired(p, 'ct')

Check warning on line 83 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L81-L83

Added lines #L81 - L83 were not covered by tests
addRequired(p, 'dose')

addParameter(p, 'dose', defaultDose, isDose)
addParameter(p, 'cst', defaultCst)
addParameter(p, 'slice', defaultSlice, isSlice)
addParameter(p, 'axesHandle', defaultAxesHandle, isAxes)
Expand All @@ -93,8 +97,9 @@
addParameter(p, 'contourColorMap', defaultContourColorMap, isContourColorMap)
addParameter(p, 'boolPlotLegend', defaultBoolPlotLegend, isBoolPlotLegend)
addParameter(p, 'colorBarLabel', defaultColorBarLabel, isColorBarLabel)
addParameter(p, 'showCt', defaultShowCt, isShowCt)

Check warning on line 100 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L85-L100

Added lines #L85 - L100 were not covered by tests

parse(p, ct, dose, varargin{:});
parse(p, ct, varargin{:});

Check warning on line 102 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L102

Added line #L102 was not covered by tests

%% Unmatched properties
% General properties
Expand All @@ -118,24 +123,37 @@
% Flip axes direction
set(p.Results.axesHandle,'YDir','Reverse');

Check warning on line 124 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L124

Added line #L124 was not covered by tests
% plot ct slice
hCt = matRad_plotCtSlice(p.Results.axesHandle,p.Results.ct.cubeHU,p.Results.cubeIdx,p.Results.plane,p.Results.slice, [], []);
if p.Results.showCt
hCt = matRad_plotCtSlice(p.Results.axesHandle,p.Results.ct.cubeHU,p.Results.cubeIdx,p.Results.plane,p.Results.slice, [], []);

Check warning on line 127 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L126-L127

Added lines #L126 - L127 were not covered by tests
else
%figure()
end
hold on;

Check warning on line 131 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L131

Added line #L131 was not covered by tests

%% Plot dose
if ~isempty(p.Results.doseWindow) && p.Results.doseWindow(2) - p.Results.doseWindow(1) <= 0
p.Results.doseWindow = [0 2];
end
if ~isempty(p.Results.dose)
if ~isempty(p.Results.doseWindow) && p.Results.doseWindow(2) - p.Results.doseWindow(1) <= 0
p.Results.doseWindow = [0 2];

Check warning on line 136 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L134-L136

Added lines #L134 - L136 were not covered by tests
end

[hDose,doseColorMap,doseWindow] = matRad_plotDoseSlice(p.Results.axesHandle, p.Results.dose, p.Results.plane, p.Results.slice, p.Results.thresh, p.Results.alpha, p.Results.doseColorMap, p.Results.doseWindow);
[hDose,doseColorMap,doseWindow] = matRad_plotDoseSlice(p.Results.axesHandle, p.Results.dose, p.Results.plane, p.Results.slice, p.Results.thresh, p.Results.alpha, p.Results.doseColorMap, p.Results.doseWindow);

Check warning on line 139 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L139

Added line #L139 was not covered by tests

%% Plot iso dose lines
if ~isempty(p.Results.doseIsoLevels)
hIsoDose = matRad_plotIsoDoseLines(p.Results.axesHandle,p.Results.dose,[],p.Results.doseIsoLevels,false,p.Results.plane,p.Results.slice,p.Results.doseColorMap,p.Results.doseWindow, lineVarargin{:});
hold on;
else
hIsoDose = [];
end
%% Plot iso dose lines
if ~isempty(p.Results.doseIsoLevels)
hIsoDose = matRad_plotIsoDoseLines(p.Results.axesHandle,p.Results.dose,[],p.Results.doseIsoLevels,false,p.Results.plane,p.Results.slice,p.Results.doseColorMap,p.Results.doseWindow, lineVarargin{:});
hold on;

Check warning on line 144 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L142-L144

Added lines #L142 - L144 were not covered by tests
else
hIsoDose = [];

Check warning on line 146 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L146

Added line #L146 was not covered by tests
end

%% Set Colorbar
hCMap = matRad_plotColorbar(p.Results.axesHandle,doseColorMap,doseWindow,'Location','EastOutside');
set(hCMap,'Color',matRad_cfg.gui.textColor);
if ~isempty(p.Results.colorBarLabel)
set(get(hCMap,'YLabel'),'String', p.Results.colorBarLabel,'FontSize',matRad_cfg.gui.fontSize);

Check warning on line 153 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L150-L153

Added lines #L150 - L153 were not covered by tests
end
set(get(hCMap,'YLabel'),'String', p.Results.colorBarLabel, textVarargin{:});

Check warning on line 155 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L155

Added line #L155 was not covered by tests
end
%% Plot VOI contours & Legend

if ~isempty(p.Results.cst)
Expand Down Expand Up @@ -188,18 +206,10 @@
set(p.Results.axesHandle,'DataAspectRatio',[res 1])

Check warning on line 206 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L205-L206

Added lines #L205 - L206 were not covered by tests
end

%% Set Colorbar
hCMap = matRad_plotColorbar(p.Results.axesHandle,doseColorMap,doseWindow,'Location','EastOutside');
set(hCMap,'Color',matRad_cfg.gui.textColor);
if ~isempty(p.Results.colorBarLabel)
set(get(hCMap,'YLabel'),'String', p.Results.colorBarLabel,'FontSize',matRad_cfg.gui.fontSize);
end

%% Set text properties
if ~isempty(textVarargin)
set(p.Results.axesHandle, textVarargin{:})
set(p.Results.axesHandle.Title, textVarargin{:})

Check warning on line 212 in matRad/util/matRad_plotSlice.m

View check run for this annotation

Codecov / codecov/patch

matRad/util/matRad_plotSlice.m#L210-L212

Added lines #L210 - L212 were not covered by tests
set(get(hCMap,'YLabel'),'String', p.Results.colorBarLabel, textVarargin{:});
end

end

0 comments on commit a1163e1

Please sign in to comment.