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

Broken model transformations in GLMakie and WGLMakie but works in CairoMakie #2122

Open
mashu opened this issue Jul 9, 2022 · 8 comments
Open
Labels
Makie Backend independent issues (Makie core) maybe wontfix TODO: review planning For discussion and planning development transformation related to `Transformation` objects

Comments

@mashu
Copy link

mashu commented Jul 9, 2022

Hi,

Consider following example

using Makie.KernelDensity

x = randn(1000)
k = kde(x, npoints = 200)

f = Figure()
ax = Axis3(f[1, 1], limits = (-4, 4, -4, 4, 0, 1))
p = poly!(ax, Point2f.(k.x, k.density),
    model = Makie.Mat4f([   1 0 0 0
                            0 0 1 4
                            0 1 0 0
                            0 0 0 1
                        ])
    )
p = poly!(ax, Point2f.(k.x, k.density),
    model = Makie.Mat4f([   0 0 1 4
                            1 0 0 0
                            0 1 0 0
                            0 0 0 1
                        ])
    )
f

image
Picture shows up correctly in the CairoMakie backend, but is broken in GLMakie/WGLMakie showing distribution unaffected in the middle of the plot, shown in second picture
Screenshot from 2022-07-09 19-00-42

@jkrumbiegel
Copy link
Member

I assume the reason this happens is that the model transform of parent plots is not combined with the children transforms in GLMakie and WGLMakie.

@ffreyer
Copy link
Collaborator

ffreyer commented Jul 11, 2022

This happens because model isn't passed down in poly. CairoMakie uses poly directly, WGLMakie and GLMakie look at mesh (and lines).

julia> p.model[]
4×4 StaticArrays.SMatrix{4, 4, Float32, 16} with indices SOneTo(4)×SOneTo(4):
 0.0  0.0  1.0  4.0
 1.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0
 0.0  0.0  0.0  1.0

julia> p.plots[1].model[]
4×4 StaticArrays.SMatrix{4, 4, Float32, 16} with indices SOneTo(4)×SOneTo(4):
 1.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0
 0.0  0.0  1.0  0.0
 0.0  0.0  0.0  1.0

@jkrumbiegel
Copy link
Member

Hm yes but do you think all child plots should have completely separate model matrices? It seems reasonable to me that one might put a child element with a special model matrix into a parent object, and then wants to give the parent a different model matrix, which should leave the relative look of the child vs the parent intact.

@ffreyer
Copy link
Collaborator

ffreyer commented Jul 11, 2022

That's what happens with plot.transformation.model. plot.attributes.model acts as an overwrite atm, which I think is probably good. With transformation you can only affect translation, scale and rotation, while the model matrix could also apply shearing.

The better solution to the above is probably using rotate!(plot, axis, angle) + translate!(plot, pos) to keep this transformation inheritance stuff. That should also not have issues between different backends. (Though it does get annoying when different coordinate spaces get mixed)

@jkrumbiegel
Copy link
Member

Ok I probably just didn't understand the system well, then.

Can confirm that using this interface, I could make it work with GLMakie:

using Makie.KernelDensity

x = randn(1000)
k = kde(x, npoints = 200)

f = Figure()
ax = Axis3(f[1, 1], limits = (-4, 4, -4, 4, 0, 1))
p = poly!(ax, Point2f.(k.x, k.density))
translate!(p, Point3f(0, 4, 0))
rotate!(p, Point3f(1, 0, 0), pi/2)
p = poly!(ax, Point2f.(k.x, k.density))
rotate!(p, Point3f(0, 0, 1), pi/2)
rotate!(Accum, p, Point3f(1, 0, 0), pi/2)
translate!(p, Point3f(4, 0, 0))
f

image

@SimonDanisch
Copy link
Member

Can we actually close this?

@ffreyer
Copy link
Collaborator

ffreyer commented Dec 30, 2022

I think the question here is: Should the model attribute be passed to children?

If yes we may need to add model = :automatic as a default attribute so that it can be replaced with transformation.model if it's not set and so that we don't get this issue when model is set later.

If no, maybe we should stop advertising it in the plot example and instead advertise transformations.

@ffreyer
Copy link
Collaborator

ffreyer commented Dec 27, 2023

CairoMakie behaves like GLMakie and WGLMakie here now.

After #3246 the rescaling Axis3 does has also moved to transformation.model, which makes overwriting the model matrix through plot attributes more error-prone.

@ffreyer ffreyer added maybe wontfix TODO: review planning For discussion and planning development Makie Backend independent issues (Makie core) transformation related to `Transformation` objects labels Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Makie Backend independent issues (Makie core) maybe wontfix TODO: review planning For discussion and planning development transformation related to `Transformation` objects
Projects
None yet
Development

No branches or pull requests

4 participants