Last active
April 6, 2017 14:54
-
-
Save SimonDanisch/7f700728485a4742ad3c0767fb573828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an update to to this file? It no longer works:
Where the line is