Skip to content

Commit

Permalink
update volumeslices
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Jul 14, 2021
1 parent 5418e3a commit 2dccad4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
44 changes: 44 additions & 0 deletions docs/src/plotting_functions/volumeslices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# volumeslices

```@docs
volumeslices
```

### Examples

```@example
using GLMakie
GLMakie.activate!() # hide
Makie.inline!(true) # hide
fig = Figure()
ax = LScene(fig[1, 1], scenekw=(camera=cam3d!, show_axis=false))
x = LinRange(0, π, 50)
y = LinRange(0, 2π, 100)
z = LinRange(0, 3π, 150)
lsgrid = labelslidergrid!(
fig,
["yz plane - x axis", "xz plane - y axis", "xy plane - z axis"],
[1:length(x), 1:length(y), 1:length(z)]
)
fig[2, 1] = lsgrid.layout
vol = [cos(X)*sin(Y)*sin(Z) for X ∈ x, Y ∈ y, Z ∈ z]
plt = volumeslices!(ax, x, y, z, vol)
# connect sliders to `volumeslices` update methods
sl_yz, sl_xz, sl_xy = lsgrid.sliders
on(sl_yz.value) do v; plt[:update_yz][](v) end
on(sl_xz.value) do v; plt[:update_xz][](v) end
on(sl_xy.value) do v; plt[:update_xy][](v) end
set_close_to!(sl_yz, .5length(x))
set_close_to!(sl_xz, .5length(y))
set_close_to!(sl_xy, .5length(z))
cameracontrols(ax.scene).projectiontype[] = Makie.Orthographic
fig
```
53 changes: 30 additions & 23 deletions src/basic_recipes/volumeslices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,52 @@
"""
VolumeSlices
TODO add function signatures
TODO add descripton
volumeslices(x, y, z, v)
Draws heatmap slices of the volume v
## Attributes
$(ATTRIBUTES)
"""
@recipe(VolumeSlices, x, y, z, volume) do scene
Attributes(
colormap = theme(scene, :colormap),
colorrange = nothing,
alpha = 0.1,
contour = Attributes(),
heatmap = Attributes(),
)
end

convert_arguments(::Type{<: VolumeSlices}, x, y, z, volume) = convert_arguments(Contour, x, y, z, volume)
function plot!(vs::VolumeSlices)
@extract vs (x, y, z, volume)
replace_automatic!(vs, :colorrange) do
function plot!(plot::VolumeSlices)
@extract plot (x, y, z, volume)
replace_automatic!(plot, :colorrange) do
map(extrema, volume)
end
keys = (:colormap, :alpha, :colorrange)
contour!(vs, vs[:contour], x, y, z, volume)
planes = (:xy, :xz, :yz)
hattributes = vs[:heatmap]
sliders = map(zip(planes, (x, y, z))) do plane_r
plane, r = plane_r
idx = Node(1)
vs[plane] = idx
hmap = heatmap!(vs, hattributes, x, y, zeros(length(x[]), length(y[])))
on(idx) do i
transform!(hmap, (plane, r[][i]))
hattributes = plot[:heatmap]
mx, Mx = extrema(x[])
my, My = extrema(y[])
mz, Mz = extrema(z[])
v = ( # vertices
(mx, my, mz), (Mx, my, mz), (mx, My, mz), (mx, my, Mz),
(Mx, My, mz), (Mx, my, Mz), (mx, My, Mz), (Mx, My, Mz)
)
s = [ # segments
v[1], v[2], v[1], v[3], v[1], v[4], v[2], v[5],
v[2], v[6], v[3], v[5], v[3], v[7], v[5], v[8],
v[4], v[6], v[4], v[7], v[6], v[8], v[7], v[8],
]
# bounding box
col = RGBAf0(.5, .5, .5, .4)
linesegments!(plot, getindex.(s, 1), getindex.(s, 2), getindex.(s, 3), color=col)

axes = :x, :y, :z
for (ax, p, r, (X, Y)) zip(axes, (:yz, :xz, :xy), (x, y, z), ((y, z), (x, z), (x, y)))
hmap = heatmap!(plot, hattributes, X, Y, zeros(length(X[]), length(Y[])))
plot[Symbol(:update_, p)] = i -> begin
transform!(hmap, (p, r[][i]))
indices = ntuple(Val(3)) do j
planes[j] == plane ? i : (:)
axes[j] == ax ? i : (:)
end
hmap[3][] = view(volume[], indices...)
end
idx
end
plot!(scene, vs, rest)
plot
end

0 comments on commit 2dccad4

Please sign in to comment.