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

Bounding Boxes #1653

Closed
ffreyer opened this issue Feb 8, 2022 · 8 comments
Closed

Bounding Boxes #1653

ffreyer opened this issue Feb 8, 2022 · 8 comments

Comments

@ffreyer
Copy link
Collaborator

ffreyer commented Feb 8, 2022

I wanted to collect some issues/thoughts on bounding boxes. I'll work on them after #1596 gets merged.

Bounding Boxes ignore marker sizes

They probably shouldn't...

fig, ax, p = meshscatter(Point2f[(0,0), (1,1)], marker = Rect2f(-0.5, -0.5, 1, 1))
bb = boundingbox(p)
# GeometryBasics.HyperRectangle{3, Float32}(Float32[0.0, 0.0, 0.0], Float32[1.0, 1.0, 0.0])
lines!(ax, Rect2f(bb), color = :red)

Screenshot from 2022-02-08 15-53-52

User facing text plots have no bounding box

fig, ax, p = text("Test")
bb = boundingbox(p)
# GeometryBasics.HyperRectangle{3, Float32}(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 0.0])

Internal text bounding boxes always have pixel units widths and data space origins

They should be in whatever space the primary plot is in

fig, ax, p = text("Test", position = Point2f(7.3, -0.3))
bb = boundingbox(p.plots[1])
# GeometryBasics.HyperRectangle{3, Float32}(Float32[7.3, -0.3, 0.0], Float32[42.36328, 23.28125, 0.0])

Bounding boxes in different spaces

Sometimes it may be useful to get a bounding box in a different space than the plot is in. For example, if you want to annotate a point in 3D with a white background pane it would be useful to plot the text at a 3D data space position and the pane using its screen/pixel space bounding box.

Per-marker bounding boxes

Getting bounding boxes per marker or whatever makes sense for a given plot might also be useful. I think it would be necessary for a ray based point picking system and probably for a collision system. It can also be useful to highlight hovered objects with pick.

@koehlerson
Copy link
Contributor

Let me know if I should open a separate issue for it, but it seems that the space=:pixel option doesn't work in recipes

t = Makie.text!(Ele,"$id", position=position, textsize=Ele[:textsize])
bb = Makie.boundingbox(t)
Makie.wireframe!(Ele,bb,space=:pixel)

produces
grafik

@ffreyer
Copy link
Collaborator Author

ffreyer commented Oct 17, 2022

That's a separate issue. What's happening in your case is that bounding boxes are calculated with the limits from just after text!(...). At that point they should be correct. Once you add the wireframe plot however the limits get updated and thus the bounding boxes are no longer correct. The fix (in Makie) is to ignore anything but space = :data from triggering limit updates like it's done for Axis3 and Axis.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Oct 17, 2022

I can't reproduce this with

fig = Figure()
ax = LScene(fig[1, 1])
t = text!(ax, ["test 1", "test 2"], position = [Point3f(0), Point3f(1)])
bb = boundingbox(t)
wireframe!(ax, bb, space = :pixel)
fig

and the limit updates seem to all go through center! which already excludes space = :pixel. Maybe your version is too old?

@koehlerson
Copy link
Contributor

koehlerson commented Oct 17, 2022

It works outside of recipes for me as well! I observe this behavior only within a recipe (within same environment, i.e. same Makie version)

@jkrumbiegel
Copy link
Member

I think Makie still has to clean up some logic with the limits of nested plots. There's also a related problem if you want to use vlines! inside a plot recipe, its yautolimits = false attribute doesn't work anymore.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Oct 17, 2022

Ah, right, that's because

function data_limits(scenelike, exclude=(p)-> false)
bb_ref = Base.RefValue(Rect3f())
foreach_plot(scenelike) do plot
if !exclude(plot)
update_boundingbox!(bb_ref, data_limits(plot))
end
end
return bb_ref[]
end

only considers exclude for the top level plot. That should be happening with Axis3 and Axis too...

@jkrumbiegel
Copy link
Member

At least for xautolimits etc. a simple exclude doesn't work anyway because for vlines! as the example, you want to include where the lines are in x, but not in y (because that's scene-projection-dependent). I currently run that logic on the Axis level but that's problematic when using recipes.

@t-bltg t-bltg mentioned this issue Dec 14, 2022
8 tasks
@ffreyer
Copy link
Collaborator Author

ffreyer commented Jul 27, 2023

I'm closing this in favor of #2881

@ffreyer ffreyer closed this as completed Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants