Skip to content

Commit

Permalink
Solve plot_phantom_map bug for 2D and 1D phantoms
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Oct 24, 2024
1 parent 82e0f08 commit 14c7b08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion KomaMRIBase/src/datatypes/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function get_dims(obj::Phantom)
push!(dims, any(x -> x != 0, obj.x))
push!(dims, any(x -> x != 0, obj.y))
push!(dims, any(x -> x != 0, obj.z))
return dims
return sum(dims) > 0 ? dims : Bool[1, 0, 0]
end

"""
Expand Down
20 changes: 16 additions & 4 deletions KomaMRIPlots/src/ui/DisplayFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,21 @@ function plot_phantom_map(
l = Layout(;title=obj.name*": "*string(key))

if view_2d # 2D
function get_displayed_dims(v)
if sum(v) == 1
idx = argmax(v)[1]
return [idx in [1, 3], idx in [1, 2], idx in [2,3]]
else
return v
end
end

# Layout config
dims = get_displayed_dims(KomaMRIBase.get_dims(obj))
axis = ["x", "y", "z"][dims]

l[:xaxis] = attr(
title="x",
title=axis[1],
range=[x0, xf],
ticksuffix=" cm",
backgroundcolor=plot_bgcolor,
Expand All @@ -1147,7 +1159,7 @@ function plot_phantom_map(
scaleanchor="y"
)
l[:yaxis] = attr(
title="y",
title=axis[2],
range=[x0, xf],
ticksuffix=" cm",
backgroundcolor=plot_bgcolor,
Expand All @@ -1159,8 +1171,8 @@ function plot_phantom_map(
# Add traces
for i in 1:length(t)
push!(traces, scattergl(
x=(x[:,i])*1e2,
y=(y[:,i])*1e2,
x=dims[1] ? (x[:,i])*1e2 : (y[:,i])*1e2,
y=dims[1] & dims[2] ? (y[:,i])*1e2 : (z[:,i])*1e2,
mode="markers",
marker=attr(color=getproperty(obj,key)*factor,
showscale=colorbar,
Expand Down

0 comments on commit 14c7b08

Please sign in to comment.