From 73a260b11928161a0d98e7de5a441c8a3d1dba9c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sun, 25 Aug 2024 22:01:38 -0700 Subject: [PATCH 1/5] Allow GLMakie to display surfaces transformed by a 3d transform func --- GLMakie/src/drawing_primitives.jl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/GLMakie/src/drawing_primitives.jl b/GLMakie/src/drawing_primitives.jl index 65550461d71..d0020ac6180 100644 --- a/GLMakie/src/drawing_primitives.jl +++ b/GLMakie/src/drawing_primitives.jl @@ -820,33 +820,34 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Surface) if all(T -> T <: Union{AbstractMatrix, AbstractVector}, types) t = Makie.transform_func_obs(plot) mat = plot[3] - xypos = lift(plot, pop!(gl_attributes, :f32c), plot.model, t, plot[1], plot[2], space) do f32c, model, t, x, y, space + xyzpos = lift(plot, pop!(gl_attributes, :f32c), plot.model, t, plot[1], plot[2], mat, space) do f32c, model, t, x, y, z, space # Only if transform doesn't do anything, we can stay linear in 1/2D if Makie.is_identity_transform(t) && isnothing(f32c) - return (x, y) + return (x, y, z) elseif Makie.is_translation_scale_matrix(model) matrix = if x isa AbstractMatrix && y isa AbstractMatrix - Makie.f32_convert(f32c, apply_transform.((t,), Point.(x, y), space), space) + [Makie.f32_convert(f32c, apply_transform(t, Point3(x, y, z[ix, iy]), space), space) for (ix, x) in pairs(x), (iy, y) in pairs(y)] else # If we do any transformation, we have to assume things aren't on the grid anymore # so x + y need to become matrices. - [Makie.f32_convert(f32c, apply_transform(t, Point(x, y), space), space) for x in x, y in y] + [Makie.f32_convert(f32c, apply_transform(t, Point3(x, y, z[ix, iy]), space), space) for (ix, x) in pairs(x), (iy, y) in pairs(y)] end - return (first.(matrix), last.(matrix)) + return (getindex.(matrix, 1), getindex.(matrix, 2), getindex.(matrix, 3)) else matrix = if x isa AbstractMatrix && y isa AbstractMatrix - Makie.f32_convert(f32c, apply_transform_and_model.((model,), (t,), Point.(x, y), space, Point2d), space) + [Makie.f32_convert(f32c, apply_transform_and_model(model, t, Point3.(x, y, z[ix, iy]), space, Point3d), space) for (ix, x) in pairs(x), (iy, y) in pairs(y)] else # If we do any transformation, we have to assume things aren't on the grid anymore # so x + y need to become matrices. - [Makie.f32_convert(f32c, apply_transform_and_model(model, t, Point(x, y), space, Point2d), space) for x in x, y in y] + [Makie.f32_convert(f32c, apply_transform_and_model(model, t, Point3(x, y, z[ix, iy]), space, Point3d), space) for (ix, x) in pairs(x), (iy, y) in pairs(y)] end - return (first.(matrix), last.(matrix)) + return (getindex.(matrix, 1), getindex.(matrix, 2), getindex.(matrix, 3)) end end - xpos = lift(first, plot, xypos) - ypos = lift(last, plot, xypos) - args = map((xpos, ypos, mat)) do arg + xpos = lift(Base.Fix2(getindex, 1), plot, xyzpos) + ypos = lift(Base.Fix2(getindex, 2), plot, xyzpos) + zpos = lift(Base.Fix2(getindex, 3), plot, xyzpos) + args = map((xpos, ypos, zpos)) do arg Texture(lift(x-> convert(Array, el32convert(x)), plot, arg); minfilter=:linear) end if isnothing(img) From c191cfaaf3f8d94d56dbf743ed7cf1b94b4c7267 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 2 Sep 2024 20:30:31 -0700 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 114cbb95560..619cbf4d31b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Bring back `poly` convert arguments for matrix with points as row [#4266](https://github.com/MakieOrg/Makie.jl/pull/4258). - Fix gl_ClipDistance related segfault on WSL with GLMakie [#4270](https://github.com/MakieOrg/Makie.jl/pull/4270) - Added option `label_position = :center` to place labels centered over each bar [#4274](https://github.com/MakieOrg/Makie.jl/pull/4274). +- Fix GLMakie `surface` implementation for 3D `transform_func` [#4243](https://github.com/MakieOrg/Makie.jl/pull/4243) ## [0.21.9] - 2024-08-27 From 6ca1e2ca8815ba9879fe4921105a94ba58c2bbae Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 2 Sep 2024 20:40:15 -0700 Subject: [PATCH 3/5] Add reference image test --- ReferenceTests/src/tests/examples3d.jl | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ReferenceTests/src/tests/examples3d.jl b/ReferenceTests/src/tests/examples3d.jl index 494f2fe95f5..f4882744955 100644 --- a/ReferenceTests/src/tests/examples3d.jl +++ b/ReferenceTests/src/tests/examples3d.jl @@ -734,3 +734,32 @@ end ls2, pl = surface(f[1, 2], Makie.peaks(20); interpolate=false, axis=(; show_axis=false)) f end + +@reference_test "Surface with 3D transform_func" begin + + SPHERICAL_TRANSFORM = Makie.PointTrans{3}() do geographic_point + # Longitude is directly translatable to a spherical coordinate + # θ (azimuth) + θ = deg2rad(geographic_point[1]) + # The polar angle is 90 degrees minus the latitude + # ϕ (polar angle) + ϕ = deg2rad(90 - geographic_point[2]) + # Finally, we define the base radius as 1, + # and all z values are offset by 1. + r = 1 + geographic_point[3] + # and we don't need to multiply by it. + return Point3( + r * sin(ϕ) * cos(θ), + r * sin(ϕ) * sin(θ), + r * cos(ϕ) + ) + end + + xs = -180:180 + ys = -90:90 + field = [exp(cosd(x)) + 3(y/90) for x in xs, y in ys] ./ 10 + + f, a, p = surface(xs, ys, field; axis = (; type = LScene,), shading = NoShading) + p.transformation.transform_func[] = SPHERICAL_TRANSFORM + f +end From a737e8df930fa8cb789f1ae56756c118f36d582c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 2 Sep 2024 20:50:39 -0700 Subject: [PATCH 4/5] Make shape more evident --- ReferenceTests/src/tests/examples3d.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReferenceTests/src/tests/examples3d.jl b/ReferenceTests/src/tests/examples3d.jl index f4882744955..bb567af3a06 100644 --- a/ReferenceTests/src/tests/examples3d.jl +++ b/ReferenceTests/src/tests/examples3d.jl @@ -757,7 +757,7 @@ end xs = -180:180 ys = -90:90 - field = [exp(cosd(x)) + 3(y/90) for x in xs, y in ys] ./ 10 + field = [exp(cosd(x)) + 3(y/90) for x in xs, y in ys] ./ 5 f, a, p = surface(xs, ys, field; axis = (; type = LScene,), shading = NoShading) p.transformation.transform_func[] = SPHERICAL_TRANSFORM From f26468ad8e079c9843aca3f250eb885b704033df Mon Sep 17 00:00:00 2001 From: Frederic Freyer Date: Fri, 18 Oct 2024 14:15:10 +0200 Subject: [PATCH 5/5] fix double end --- ReferenceTests/src/tests/examples3d.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReferenceTests/src/tests/examples3d.jl b/ReferenceTests/src/tests/examples3d.jl index bb6e5c908d5..ff29a3fc8bc 100644 --- a/ReferenceTests/src/tests/examples3d.jl +++ b/ReferenceTests/src/tests/examples3d.jl @@ -734,7 +734,7 @@ end f, a, p = surface(xs, ys, field; axis = (; type = LScene,), shading = NoShading) p.transformation.transform_func[] = SPHERICAL_TRANSFORM f -end end +end @reference_test "volumeslices" begin r = range(-1, 1, length = 10) @@ -748,4 +748,4 @@ end p.update_yz[](4) p.update_xy[](10) fig -end \ No newline at end of file +end