Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lines in WGLMakie are not inspectable #3503

Closed
2 tasks done
kbarros opened this issue Dec 21, 2023 · 4 comments · Fixed by #3522
Closed
2 tasks done

Lines in WGLMakie are not inspectable #3503

kbarros opened this issue Dec 21, 2023 · 4 comments · Fixed by #3522
Labels
bug WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.

Comments

@kbarros
Copy link
Contributor

kbarros commented Dec 21, 2023

In the GLMakie backend, the objects produced by linesegments! can be inspectable. However, in WGLMakie, it seems they cannot.

Minimum working example:

using WGLMakie # works with GLMakie

fig = Figure()
ax = LScene(fig[1,1])
segments = [Point3f(1,0,0), Point3f(0,1,0)]
linesegments!(ax, segments; inspectable=true)
DataInspector(ax)
  • are you running newest version (version from docs) ?

Tested on WGLMakie v0.9.2.

  • What platform + GPU are you on?
Julia Version 1.10.0-rc3
Commit ed79752b939 (2023-12-18 09:57 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
@kbarros kbarros added the bug label Dec 21, 2023
@kbarros
Copy link
Contributor Author

kbarros commented Dec 25, 2023

A workaround might be to plot line segments as cylinders, but then I encounter other issues, cf. #3512 and #3513.

If those two are fixed before this issue, then here is an alternative to linesegments! that uses cylinders:

using WGLMakie, LinearAlgebra

function linesegmenttubes!(ax, pts; tubewidth, quality=32, kwargs...)
    marker = Makie._mantle(Makie.Point3f0(0, 0, -1/2), Makie.Point3f0(0, 0, 1/2), 1/2, 1/2, quality)
    @assert iseven(length(pts))
    x = pts[begin:2:end-1]
    y = pts[begin+1:2:end]
    pos = @. Makie.Point3f0((x + y) / 2)
    dirs = @. Makie.Vec3f0(y - x)
    markersize = [Makie.Vec3f0(tubewidth, tubewidth, norm(dir)) for dir in dirs]
    rotation = normalize.(dirs)
    Makie.meshscatter!(ax, pos; markersize, rotation, marker, kwargs...)
end

fig = Makie.Figure()
ax = Makie.LScene(fig[1, 1])
pts = [[0, 0, 0], [1, 0, 1], [2, 0, 1], [2, -1, 0]]
color = [:red, :blue]
linesegmenttubes!(ax, pts; tubewidth=0.1, quality=12, color)
Makie.DataInspector(ax; indicator_color=:gray)

@t-bltg t-bltg added the WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. label Dec 26, 2023
SimonDanisch added a commit that referenced this issue Dec 29, 2023
@SimonDanisch SimonDanisch linked a pull request Dec 29, 2023 that will close this issue
SimonDanisch added a commit that referenced this issue Dec 29, 2023
* cleanup three display and fix #3517

* fix delete

* fix #3503
@kbarros
Copy link
Contributor Author

kbarros commented Dec 30, 2023

Thanks a lot for looking into it. It's close, but there still seems to be a problem. Consider this slightly more complicated script:

begin
    fig = Figure()
    ax = LScene(fig[1,1])
    segments = [Point3f(1,0,0), Point3f(0,1,0), Point3f(0, 0, 1), Point3f(1, 0, 1)]
    color = [:red, :blue]
    inspector_label(_, i, _) = ["hello", "world", "nice", "day"][mod1(i, 4)]
    linesegments!(ax, segments; color, inspectable=true, inspector_label)
    DataInspector(ax)
    fig
end
  • GLMakie behavior: Inspecting the red line prints "world" and inspecting the blue line prints "day". Tooltip location follows mouse.
  • WGLMakie behavior: Inspecting the blue line almost works. Sometimes the tooltip follows the cursor and prints "day" like in GLMakie. Sometimes the tooltip snaps to the top-right and prints instead "nice" (see two images below). Inspecting the red line throws an error with the following stack trace:
┌ Warning: Error in window event callback
│   exception =
│    BoundsError: attempt to access 4-element Vector{Point{3, Float32}} at index [0:1]
│    Stacktrace:
│      [1] throw_boundserror(A::Vector{Point{3, Float32}}, I::Tuple{UnitRange{Int64}})
│        @ Base ./abstractarray.jl:734
│      [2] checkbounds
│        @ Base ./abstractarray.jl:699 [inlined]
│      [3] getindex(A::Vector{Point{3, Float32}}, I::UnitRange{Int64})
│        @ Base ./array.jl:973
│      [4] position_on_plot(plot::LineSegments{Tuple{Vector{Point{3, Float32}}}}, idx::Int64, ray::Makie.Ray; apply_transform::Bool)
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/ray_casting.jl:254
│      [5] position_on_plot
│        @ ~/.julia/packages/Makie/Qvk4f/src/interaction/ray_casting.jl:253 [inlined]
│      [6] position_on_plot(plot::LineSegments{Tuple{Vector{Point{3, Float32}}}}, idx::Int64; apply_transform::Bool)
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/ray_casting.jl:235
│      [7] position_on_plot
│        @ ~/.julia/packages/Makie/Qvk4f/src/interaction/ray_casting.jl:234 [inlined]
│      [8] show_data(inspector::DataInspector, plot::LineSegments{Tuple{Vector{Point{3, Float32}}}}, idx::Int64)
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/inspector.jl:518
│      [9] show_data_recursion(inspector::DataInspector, plot::LineSegments{Tuple{Vector{Point{3, Float32}}}}, idx::Int64)
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/inspector.jl:339
│     [10] on_hover(inspector::DataInspector)
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/inspector.jl:307
│     [11] (::Makie.var"#1236#1240"{DataInspector})(::Tuple{Float64, Float64})
│        @ Makie ~/.julia/packages/Makie/Qvk4f/src/interaction/inspector.jl:280
│     [12] #invokelatest#2
│        @ Base ./essentials.jl:887 [inlined]
│     [13] invokelatest
│        @ Base ./essentials.jl:884 [inlined]
│     [14] notify
│        @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
│     [15] setindex!(observable::Observable, val::Any)
│        @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
│     [16] (::WGLMakie.var"#58#60"{Dict{Any, Any}, Scene, Events})()
│        @ WGLMakie ~/.julia/packages/WGLMakie/t9g1u/src/events.jl:57
└ @ WGLMakie ~/.julia/packages/WGLMakie/t9g1u/src/events.jl:109

Two snapshots from WGLMakie backend shown below:

image image

@SimonDanisch
Copy link
Member

I think WGLMakie behaves correct now for this simpler example:

begin
    segments = Point2f[(0, 0), (0, 1), (1, 0), (1, 2)]
    color = [:red, :black, :blue, :black]
    inspector_label(_, i, _) = (@show Int(i); ["hello", "world", "nice", "day"][mod1(i, 4)])
    fig, ax, pl = linesegments(segments; color, inspector_label, linewidth=10)
    DataInspector(ax)
    display(fig; backend=WGLMakie)
end

It feels a bit buggy, that the index for the segment start only gets picked at the very beginning of the line, it should be more in the middle. Will need to look at the shader to see if we can fix that.

The out of bounds error you're getting sounds like you checked out the branch too early, I pushed a fix for that just before merging.

For GLMakie, it only gives indices for the ends of the line, not sure if we can change that right away.

@kbarros
Copy link
Contributor Author

kbarros commented Dec 30, 2023

Thanks, I can confirm the bounds error is gone! To elaborate on the remaining bug, it seems to either "detect" the line itself, correctly (index 2) or some other object marking the beginning of the line, at the wrong position (index 1). Please see attached movie in the context of your 2D example.

2D_example.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants