KomaMRI.jl icon indicating copy to clipboard operation
KomaMRI.jl copied to clipboard

[KomaUI Plotting] obj_ui[] does not draw on first time updated. Need to press :rho or other option.

Open curtcorum opened this issue 1 year ago • 9 comments

What happened?

obj_ui[] does not draw on first time updated: obj_ui_first_update

Need to press :rho or other button option: push_rho

Environment

OS x86_64-linux-gnu
Julia 1.10.4
KomaMRIPlots 0.8.3
KomaMRIFiles 0.8.2
KomaMRI 0.8.2
KomaMRICore 0.8.3
KomaMRIBase 0.8.4

curtcorum avatar Jun 13 '24 22:06 curtcorum

obj_ui[]=brain_phantom2D();

Has same behavior. No draw the first time.

curtcorum avatar Jun 13 '24 22:06 curtcorum

obj_ui[]=pelvis_phantom2D()

Also does the same thing, so consistent. Same code or same code called?

curtcorum avatar Jun 13 '24 22:06 curtcorum

I will need to look into this, in KomaUI.jl we define the callbacks as follows:

    on((obj) -> view_ui!(obj, w, seq_ui[], widgets_button_obj; key=:ρ, darkmode), obj_ui)

    for (widget_button, key) in zip(widgets_button_obj, fieldnames_obj)
        on((cnt) -> view_ui!(cnt, w, obj_ui[], seq_ui[], widgets_button_obj; key, darkmode), widget_button)
    end

So, for example, the first one means that each time obj_ui changes the view_ui! function is triggered. I believe the problem are the buttons, I am fixing this locally.

cncastillo avatar Jun 16 '24 00:06 cncastillo

After looking into it, that wasn't the problem. There are two things that I didn't realize:

  • plot_phantom_map was changed to use Plot instead of the backend-agnostic plot_koma, and that generates this problem.
  • If view_2D=true, the plot uses scatter instead of scattergl, which is very slow.

@pvillacorta could you fix this?

cncastillo avatar Jun 16 '24 20:06 cncastillo

@pvillacorta Also, it seems that plotting a phantom with too many spins shows fewer spins, with no warning telling the user that it is happening.

cncastillo avatar Jun 17 '24 14:06 cncastillo

@pvillacorta @cncastillo

It does seem to do the warning the first time only, which is probably related to the calling issues mentioned in: https://github.com/JuliaHealth/KomaMRI.jl/issues/407#issuecomment-2171855179

julia> obj_ui[]=brain_phantom3D(;ss=2)
┌ Warning: For performance reasons, the number of displayed spins was capped to `max_spins`=100000.
└ @ KomaMRIPlots ~/src/KomaMRI/KomaMRIPlots/src/ui/DisplayFunctions.jl:1080

curtcorum avatar Jun 17 '24 21:06 curtcorum

See maxlog=1 in line 1080 of https://github.com/JuliaHealth/KomaMRI.jl/pull/387/commits/592b85f345fa7e3701f436ef985b25a5d2043eaf. That is why the message only displays once

pvillacorta avatar Jun 17 '24 23:06 pvillacorta

  • plot_phantom_map was changed to use Plot instead of the backend-agnostic plot_koma, and that generates this problem.

The solution is not as easy as using plot_koma again, since PlotlyJS.plot (which is called by plot_koma when using the Plotly backend) does not support frames for animations. It looks like a bug from PlotlyJS. See:

  • https://discourse.julialang.org/t/plotlyjs-jl-animation/70058/9
  • https://community.plotly.com/t/adding-an-animation-button-to-a-julia-plot-with-slider/73404/2

  • If view_2D=true, the plot uses scatter instead of scattergl, which is very slow.

Solved in #413, as well as the maxlog issue

pvillacorta avatar Jun 18 '24 23:06 pvillacorta

https://github.com/JuliaHealth/KomaMRI.jl/pull/413#issuecomment-2189778867

pvillacorta avatar Jun 28 '24 07:06 pvillacorta