Giter Club home page Giter Club logo

Comments (4)

kbarros avatar kbarros commented on June 19, 2024

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)

from makie.jl.

kbarros avatar kbarros commented on June 19, 2024

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

from makie.jl.

SimonDanisch avatar SimonDanisch commented on June 19, 2024

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.

from makie.jl.

kbarros avatar kbarros commented on June 19, 2024

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

from makie.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.