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

Datashader #2883

Merged
merged 48 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
71e7981
copy ShadeYourData.jl and make a recipe
jkrumbiegel Apr 21, 2023
4933f31
use points and threads
jkrumbiegel Apr 21, 2023
569afc2
improve performance + add examples
SimonDanisch May 2, 2023
260e67c
avoid aggregation matrix reallocation on every update
jkrumbiegel May 3, 2023
b63a5c6
use on_latest
SimonDanisch May 3, 2023
9cf6566
fix points
SimonDanisch May 3, 2023
757c300
remove unused destructured args
SimonDanisch May 3, 2023
f0dd80b
rearrange thread array and avoid clamp
jkrumbiegel May 4, 2023
653ce7f
remove `@time`
jkrumbiegel May 4, 2023
7a82854
Merge branch 'master' into jk/datashader
SimonDanisch May 9, 2023
57382f5
Merge branch 'jk/datashader' of https://github.com/MakieOrg/Makie.jl …
SimonDanisch May 9, 2023
bb6705f
clean up and documentation
SimonDanisch May 10, 2023
0a15b9b
categorical prototype
SimonDanisch Jun 2, 2023
47aee0d
Merge branch 'master' into jk/datashader
SimonDanisch Aug 17, 2023
be26d65
improve wording
SimonDanisch Aug 17, 2023
e76bf09
clean up + legend for categorical
SimonDanisch Aug 18, 2023
c3176b0
dont use async for output
SimonDanisch Aug 21, 2023
2463441
Merge branch 'master' into jk/datashader
SimonDanisch Aug 21, 2023
901477c
update link to script
SimonDanisch Aug 21, 2023
80eb008
Merge branch 'jk/datashader' of https://github.com/JuliaPlots/Makie.j…
SimonDanisch Aug 21, 2023
0011239
start adding docstrings
SimonDanisch Aug 22, 2023
ae5b366
improve docs and names
SimonDanisch Aug 23, 2023
9a148f8
cleanup
SimonDanisch Aug 23, 2023
a9042ed
fix imports
SimonDanisch Aug 23, 2023
9ad504a
fix docs
SimonDanisch Aug 23, 2023
205f946
address code review by @jkrumbiegel
SimonDanisch Aug 23, 2023
c1f5cc6
make videos autoplay
SimonDanisch Aug 28, 2023
d570a02
fix missing var
SimonDanisch Aug 28, 2023
2ba020e
Merge branch 'master' into jk/datashader
SimonDanisch Aug 29, 2023
63e6861
fix import
SimonDanisch Aug 29, 2023
4e17504
merge master
SimonDanisch Sep 13, 2023
500541c
update docs + support Colorbar
SimonDanisch Sep 13, 2023
eccc033
add test
SimonDanisch Sep 14, 2023
e22e2b0
Merge branch 'master' into jk/datashader
SimonDanisch Sep 18, 2023
ba40f64
clean up
SimonDanisch Sep 18, 2023
ce76931
Merge branch 'jk/datashader' of https://github.com/MakieOrg/Makie.jl …
SimonDanisch Sep 18, 2023
8fd0bb0
remove unused + better stacktrace
SimonDanisch Sep 19, 2023
790ccb7
implement texture resizing for WGLMakie
SimonDanisch Sep 19, 2023
83d1ea1
forgot new
SimonDanisch Sep 19, 2023
d0b483c
don't make legend elements half transparent
SimonDanisch Sep 19, 2023
1c74e41
Hack into JS to get some logs in Julia
SimonDanisch Sep 19, 2023
4d82c31
stringify doesnt work on any object
SimonDanisch Sep 19, 2023
a13e262
try catch!?
SimonDanisch Sep 19, 2023
f8de0d0
did this time out simply because its slow?!
SimonDanisch Sep 19, 2023
fdc363c
bring beck fewer airports
SimonDanisch Sep 19, 2023
5fe4cc2
fix test
SimonDanisch Sep 19, 2023
8e5243f
Merge branch 'master' into jk/datashader
SimonDanisch Sep 19, 2023
969cb0d
add comment
SimonDanisch Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GLMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Makie = "=0.19.9"
MeshIO = "0.4"
ModernGL = "1"
Observables = "0.5.1"
ShaderAbstractions = "0.3"
ShaderAbstractions = "0.4"
PrecompileTools = "1.0"
StaticArrays = "0.12, 1.0"
julia = "1"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ PolygonOps = "0.1.1"
PrecompileTools = "1.0"
RelocatableFolders = "0.1, 0.2, 0.3, 1.0"
Setfield = "1"
ShaderAbstractions = "0.3"
ShaderAbstractions = "0.4"
Showoff = "0.3, 1.0.2"
SignedDistanceFields = "0.4"
StableHashTraits = "1"
Expand Down
52 changes: 52 additions & 0 deletions RPRMakie/examples/datashader-rpr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using DelimitedFiles, GLMakie
GLMakie.activate!() # hide
# For saving/showing/inlining into documentation we need to disable async calculation.
Makie.set_theme!(DataShader=(; async_latest=false))
airports = Point2f.(eachrow(readdlm(assetpath("airportlocations.csv"))))
(xmin, ymin), (xmax, ymax) = extrema(xx)

xx = Rect2f(points)
all(x-> x in xx, points)


canvas = Canvas(Rect2f(points))
aggregate!(canvas, points);

m = collect(Makie.get_aggregation(canvas))

(xmin, ymin), (xmax, ymax) = map(x-> x./widths(canvas.bounds), extrema(canvas.bounds))

xw, yw = 1 ./ size(m)
maxi = maximum(mscaled)
GLMakie.activate!()
radiance = 50
lights = [EnvironmentLight(0.5, load(RPR.assetpath("studio026.exr"))),
PointLight(Vec3f(0, 0, 2), RGBf(radiance, radiance, radiance))]
mscaled = m ./ widths(canvas.bounds)[1]
recmesh = GeometryBasics.normal_mesh(Rect3f(Vec3f(-0.5), Vec3f(1)))
RPRMakie.activate!(plugin=RPR.Northstar, iterations=1, resource=RPR.RPR_CREATION_FLAGS_ENABLE_GPU1)
f, ax, pl = meshscatter(
xmin .. xmax, ymin .. ymax, mscaled;
axis=(; type=LScene, show_axis=false, scenekw=(; lights=lights)),
marker=recmesh,
color=mscaled,
colorrange=Vec2f(0.000001, maxi),
lowclip=(:blue, 0.1),
colormap=[:white, :red],
material=(; type=:Microfacet, color=:gray, roughness=0.2, ior=1.390),
markersize=Vec3f.(xw, yw, vec(mscaled))
)
ax.scene |> display
display(f; backend=GLMakie)
using RPRMakie, FileIO

RPRMakie.activate!(plugin=RPR.Tahoe, iterations=1, resource=RPR.RPR_CREATION_FLAGS_ENABLE_GPU1)
RPRMakie.replace_scene_rpr!(ax.scene)


l = lights[2]

l.position[] = Vec3f(xmin + xmax/2, ymin + ymax / 2, widths(canvas.bounds)[1])
l.radiance[] = RGBf(500, 500, 500)

pl.colorrange[] = Vec2f(0.000001, maxi)
13 changes: 12 additions & 1 deletion RPRMakie/src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,25 @@ function to_rpr_object(context, matsys, scene, plot::Makie.MeshScatter)
cmap = to_colormap(plot.colormap[])
crange = plot.colorrange[]
color_from_num = Makie.interpolated_getindex.((cmap,), color, (crange,))

object_id = RPR.InputLookupMaterial(matsys)
object_id.value = RPR.RPR_MATERIAL_NODE_LOOKUP_OBJECT_ID

uv = object_id * Vec3f(0, 1/n_instances, 0)

tex = RPR.Texture(matsys, collect(color_from_num'); uv = uv)

material.color = tex
elseif color isa AbstractMatrix{<:Number}
cmap = to_colormap(plot.colormap[])
crange = plot.colorrange[]
color_from_num = Makie.interpolated_getindex.((cmap,), color, (crange,))
object_id = RPR.InputLookupMaterial(matsys)
object_id.value = RPR.RPR_MATERIAL_NODE_LOOKUP_OBJECT_ID

uv = object_id * Vec3f(0, 1/n_instances, 0)

tex = RPR.Texture(matsys, color_from_num; uv=uv)

material.color = tex
elseif color isa Colorant
material.color = color
Expand Down
18 changes: 18 additions & 0 deletions ReferenceTests/src/tests/figures_and_makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,21 @@ end

fig
end

@reference_test "datashader" begin
airports = Point2f.(eachrow(readdlm(assetpath("airportlocations.csv"))))
# Dont use the full dataset, since WGLMakie seems to time out if it's too big
fewer = airports[RNG.rand(1:length(airports), 1000)]
fig, ax, ds = datashader(fewer; async=false)
Colorbar(fig[1, 2], ds; width=100)
hidedecorations!(ax)
hidespines!(ax)

normaldist = RNG.randn(Point2f, 100000)
ds1 = normaldist .+ (Point2f(-1, 0),)
ds2 = normaldist .+ (Point2f(1, 0),)
ax, pl = datashader(fig[2, :], Dict("a" => ds1, "b" => ds2); async=false)
hidedecorations!(ax)
axislegend(ax)
fig
end
2 changes: 1 addition & 1 deletion WGLMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ JSServe = "2.2"
Makie = "=0.19.9"
Observables = "0.5.1"
RelocatableFolders = "0.1, 0.2, 0.3, 1.0"
ShaderAbstractions = "0.3"
ShaderAbstractions = "0.4"
PrecompileTools = "1.0"
StaticArrays = "0.12, 1.0"
PNGFiles = "0.3, 0.4"
Expand Down
17 changes: 14 additions & 3 deletions WGLMakie/src/Serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,31 @@ function create_texture(data) {
}

function re_create_texture(old_texture, buffer, size) {
let tex;
if (size.length == 3) {
const tex = new THREE.DataTexture3D(buffer, size[0], size[1], size[2]);
tex = new THREE.DataTexture3D(buffer, size[0], size[1], size[2]);
tex.format = old_texture.format;
tex.type = old_texture.type;
return tex;
} else {
return new THREE.DataTexture(
tex = new THREE.DataTexture(
buffer,
size[0],
size[1] ? size[1] : 1,
old_texture.format,
old_texture.type
);
}
tex.minFilter = old_texture.minFilter
tex.magFilter = old_texture.magFilter
tex.anisotropy = old_texture.anisotropy
tex.wrapS = old_texture.wrapS
if (size.length > 1) {
tex.wrapT = old_texture.wrapT
}
if (size.length > 2) {
tex.wrapR = old_texture.wrapR
}
return tex
}
function BufferAttribute(buffer) {
const jsbuff = new THREE.BufferAttribute(buffer.flat, buffer.type_length);
Expand Down
2 changes: 0 additions & 2 deletions WGLMakie/src/imagelike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ function create_shader(mscene::Scene, plot::Surface)
normals = Buffer(lift(surface_normals, px, py, pz))
per_vertex = Dict(:positions => positions, :faces => faces, :uv => uv, :normals => normals)

plot_attributes = copy(plot.attributes)

uniforms = Dict(:uniform_color => color, :color => false)
return draw_mesh(mscene, per_vertex, plot, uniforms)
end
Expand Down
1 change: 0 additions & 1 deletion WGLMakie/src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ end

function draw_mesh(mscene::Scene, per_vertex, plot, uniforms; permute_tex=true)
filter!(kv -> !(kv[2] isa Function), uniforms)
color = plot.calculated_colors
handle_color!(plot, uniforms, per_vertex; permute_tex=permute_tex)

get!(uniforms, :pattern, false)
Expand Down
6 changes: 3 additions & 3 deletions WGLMakie/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function register_geometry_updates(update_buffer::Observable, named_buffers)
if buffer isa Buffer
on(ShaderAbstractions.updater(buffer).update) do (f, args)
# update to replace the whole buffer!
if f === (setindex!) && args[1] isa AbstractArray && args[2] isa Colon
if f === ShaderAbstractions.update!
new_array = args[1]
flat = flatten_buffer(new_array)
update_buffer[] = [name, serialize_three(flat), length(new_array)]
Expand All @@ -222,7 +222,7 @@ function uniform_updater(uniforms::Dict)
for (name, value) in uniforms
if value isa Sampler
on(ShaderAbstractions.updater(value).update) do (f, args)
if f == setindex! && args[2] isa Colon
if f === ShaderAbstractions.update!
updater[] = [name, [Int32[size(value.data)...], serialize_three(args[1])]]
end
return
Expand Down Expand Up @@ -250,7 +250,7 @@ reinterpret_faces(faces::AbstractVector) = collect(reinterpret(UInt32, decompose
function reinterpret_faces(faces::Buffer)
result = Observable(reinterpret_faces(ShaderAbstractions.data(faces)))
on(ShaderAbstractions.updater(faces).update) do (f, args)
if f === (setindex!) && args[1] isa AbstractArray && args[2] isa Colon
if f === ShaderAbstractions.update!
result[] = reinterpret_faces(args[1])
end
end
Expand Down
10 changes: 8 additions & 2 deletions WGLMakie/src/three_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ function three_display(session::Session, scene::Scene; screen_config...)
ta = JSServe.Retain(TEXTURE_ATLAS)
evaljs(session, js"""
$(WGL).then(WGL => {
WGL.create_scene($wrapper, $canvas, $canvas_width, $scene_serialized, $comm, $width, $height, $(ta), $(config.framerate), $(config.resize_to_body))
$(done_init).notify(true)
try {
WGL.create_scene($wrapper, $canvas, $canvas_width, $scene_serialized, $comm, $width, $height, $(ta), $(config.framerate), $(config.resize_to_body))
$(done_init).notify(true)
} catch (e) {
JSServe.Connection.send_error("error initializing scene", e)
$(done_init).notify(false)
return
}
})
""")
on(session, done_init) do val
Expand Down
17 changes: 14 additions & 3 deletions WGLMakie/src/wglmakie.bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -20004,14 +20004,25 @@ function create_texture(data) {
}
}
function re_create_texture(old_texture, buffer, size) {
let tex;
if (size.length == 3) {
const tex = new mod.DataTexture3D(buffer, size[0], size[1], size[2]);
tex = new mod.DataTexture3D(buffer, size[0], size[1], size[2]);
tex.format = old_texture.format;
tex.type = old_texture.type;
return tex;
} else {
return new mod.DataTexture(buffer, size[0], size[1] ? size[1] : 1, old_texture.format, old_texture.type);
tex = new mod.DataTexture(buffer, size[0], size[1] ? size[1] : 1, old_texture.format, old_texture.type);
}
tex.minFilter = old_texture.minFilter;
tex.magFilter = old_texture.magFilter;
tex.anisotropy = old_texture.anisotropy;
tex.wrapS = old_texture.wrapS;
if (size.length > 1) {
tex.wrapT = old_texture.wrapT;
}
if (size.length > 2) {
tex.wrapR = old_texture.wrapR;
}
return tex;
}
function BufferAttribute(buffer) {
const jsbuff = new mod.BufferAttribute(buffer.flat, buffer.type_length);
Expand Down
2 changes: 2 additions & 0 deletions WGLMakie/src/wglmakie.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ export function register_popup(popup, scene, plots_to_pick, callback) {
});
}



window.WGL = {
deserialize_scene,
threejs_module,
Expand Down
Binary file added docs/_assets/datashader-14million.mp4
Binary file not shown.
Binary file added docs/_assets/datashader_2-7_billion.mp4
Binary file not shown.
Binary file added docs/_assets/nyc-per-vendor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/explanations/backends/rprmakie.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ end
~~~

~~~
<video autoplay controls src="/assets/opengl_interop.mp4">
<video mute autoplay controls src="/assets/opengl_interop.mp4">
</video>
~~~

Expand Down Expand Up @@ -429,7 +429,7 @@ end
~~~

~~~
<video autoplay controls src="/assets/lego_walk.mp4">
<video mute autoplay controls src="/assets/lego_walk.mp4">
</video>
~~~

Expand Down
Loading
Loading