MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.4k stars 308 forks source link

WGLMakie performance bug with Volume #1454

Open SimonDanisch opened 2 years ago

SimonDanisch commented 2 years ago

Somehow, this WGLMakie example makes everything stutter like crazy, even on a fast PC:

using WGLMakie, FileIO, NIfTI, ImageTransformations
WGLMakie.activate!()

brain = restrict(niread(Makie.assetpath("brain.nii.gz")).raw)
mini, maxi = extrema(brain)
cube_with_holes = Float32.((brain .- mini) ./ (maxi - mini))

function labeled_slider(r, name, start=first(r))
    s = JSServe.Slider(r)
    s.value[] = start
    return DOM.div(name, s, map(x-> string(round(x, digits=2)), s.value)), s
end

App() do session
    levelsd, levels = labeled_slider(2:10, "levels")
    absorptiond, absorption = labeled_slider(range(0, stop=5, step=0.5), "absorption", 3.0)
    isovalued, isovalue = labeled_slider(range(0, stop=1, step=0.1), "isovalue", 0.5)
    alphad, alpha = labeled_slider(range(0, stop=1, step=0.1), "alpha", 0.5)

    fig = Figure(resolution=(800, 800))
    # Make a colormap, with the first value being transparent
    colormap = RGBAf.(to_colormap(:plasma), 1.0)
    colormap[1] = RGBAf(0,0,0,0)

    volume!(LScene(fig[1, 2], show_axis=false), cube_with_holes, algorithm = :absorption, absorption=absorption, colormap=colormap)
    volume!(LScene(fig[1, 2], show_axis=false), cube_with_holes, algorithm = :mip, colormap=colormap)

    colgap!(fig.layout, 0)
    rowgap!(fig.layout, 0)

    return JSServe.record_states(session, DOM.div(absorptiond, isovalued, levelsd, alphad, fig))
end
ffreyer commented 1 month ago

@SimonDanisch Can this be closed?