Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Last active April 6, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonDanisch/7f700728485a4742ad3c0767fb573828 to your computer and use it in GitHub Desktop.
Save SimonDanisch/7f700728485a4742ad3c0767fb573828 to your computer and use it in GitHub Desktop.
# Install development version of Plots and GLPlot
# Pkg.add("Plots"); Pkg.clone("GLPlot")
# for p in ["GLVisualize", "GeometryTypes", "GLPlot", "GLAbstraction", "GLWindow", "FixedSizeArrays"]
# Pkg.checkout(p)
# end
# checkout https://github.com/tbreloff/Plots.jl/pull/374
using GLPlot, GLVisualize, GLAbstraction, Colors, GeometryTypes, Plots, FileIO
using Reactive, GLWindow
GLPlot.init(); glvisualize()
# load a volume
vol = load(joinpath(homedir(), "Desktop", "brain.nii")).raw;
vol = vol ./ maximum(vol);
# plot it with blue colormap
p1 = plot(vol, fill=colormap("Blues", 7))
# prepare the slices
axes = ntuple(i-> linspace(0, 1, size(vol, i)), 3)
p2 = heatmap(axes[2], axes[3], vol[100, : , :], title="X Slice")
p3 = heatmap(axes[1], axes[3], vol[:, 100 , :], title="Y Slice")
p4 = heatmap(axes[1], axes[2], vol[:, : , 100], title="Z Slice")
plt = plot(p1, p2, p3, p4)
for i=1:3
# since plots updating mechanism still doesn't work perfectly with GLVisualize
# we need to get the raw visualization objects and gpu objects from the plots.
# This will be exposed by a more straightforward API in the future!
robj = plt[i+1].o.renderlist[1][end]
tex = robj[:intensity] # image slice residing on the GPU
range_s = play_control(1:size(vol, i))
preserve(map(range_s) do slice_idx
idx = ntuple(d-> d==i ? slice_idx : (:), 3)
# This conversion is necessary but will be automatic soon!
slice = permutedims(map(Intensity{1, Float32}, vol[idx...]), (2,1))
GLAbstraction.update!(tex, slice) # upload to memory
end)
end
@jgbos
Copy link

jgbos commented Apr 6, 2017

Is there an update to to this file? It no longer works:

ERROR: LoadError: type Void has no field renderlist
 in macro expansion; at /home/ju17693/projects/ASDF/glplot.jl:101 [inlined]
 in anonymous at ./<missing>:?
 in include_from_node1(::String) at ./loading.jl:488
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
while loading /home/ju17693/projects/ASDF/glplot.jl, in expression starting on line 97

Where the line is

 robj = plt[i+1].o.renderlist[1][end]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment