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

Documentation on Zoom! #1236

Closed
SimonCoste opened this issue Aug 19, 2021 · 4 comments · Fixed by #3113
Closed

Documentation on Zoom! #1236

SimonCoste opened this issue Aug 19, 2021 · 4 comments · Fixed by #3113

Comments

@SimonCoste
Copy link

SimonCoste commented Aug 19, 2021

Hello, I am trying to use the zoom! function, see here, but there is no usable doc and no examples.

More generally, the doc is extremely hard to use: there are many functions who use Vec3f0, but I found no reference for this. For instance, zoom(scene, Vec3f0(0,0,0), 2) outputs a

no method matching zoom!(::Scene, ::Vec{3, Float32}, ::Int64)

so that I have no clue on how to use these Vec3f0 objects.

I also have no clues on what are those 5f0 often found in examples, and I could not find something in the doc on them.

Related : https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 19, 2021

5f0 is a way to construct Float32, equivalent to Float32(5 * 10^0). Vec3f0 is just a (static) vector of 3 Float32's.

The function zoom!(scene, point, zoom_step, shift_lookat::Bool) applies to the old 3D camera, which is not used by default anymore. The arguments here are the scene it applies to (i.e. lscene.scene), the point which the zoom focuses, the amount of zooming that's done is zoom_step and shift_lookat = true adds translation when zooming to keep point at the same position.

The new camera has a method zoom!(scene, zoom_step) which does an fov based zoom where zoom_step again controls the amount of zooming. Depending on what kind of zoom you want. Here you need to call update_cam!(scene, cameracontrols(scene)) to apply the changes at the moment.

If you don't want an fov-based zoom you may want to try translating the camera instead. You can use translate_cam!(scene, Vec3f0(0, 0, +-zoom)) to translate in/out of the screen. (Again with a update_cam! afterwards) The Vec3f0 passed here is in camera space, so it's (left/right, up/down, in/out).

Another option is to adjust the camera position (eyeposition) and/or focal point (lookat) via update_cam!(scene, cameracontrols(scene), eyeposition, lookat).

This all only applies to 3D LScene's. If you're using a 2D Axis you should set xlims!(ax, low, high) and ylims!(ax, low, high) to zoom. Axis3 doesn't have a direct way to zoom available as far as I know.

@bvrb
Copy link

bvrb commented Aug 19, 2021

The new camera has a method zoom!(scene, zoom_step) which does an fov based zoom where zoom_step again controls the amount of zooming. Depending on what kind of zoom you want. Here you need to call update_cam!(scene, cameracontrols(scene)) to apply the changes at the moment.

I just tried this and can confirm it doesn't work for me either, in fact the plot disappears altogether after updating the camera as you described. However, zoom!(scene, cameracontrols(scene), zoom_step) followed by update_cam!(scene, cameracontrols(scene)) works correctly.

Is it possible that there is a typo on this line https://github.com/JuliaPlots/Makie.jl/blob/27fdbd6e5d1141e1e4456c9b008776825f3818c8/src/camera/camera3d.jl#L495 ? It seems that the zoom_step argument is never passed along to the zoom! method on the right hand side of the assignment, but instead gets set to false.

@SimonCoste
Copy link
Author

Thanks to both of you for your answers ! 
On my side, your proposals did not work. The code

using GLMakie
let
    U = LinRange(-pi, pi, 100) # 50
    V = LinRange(-pi, pi, 20)
    x1 = [cos(u) + .5 * cos(u) * cos(v)      for u in U, v in V]
    y1 = [sin(u) + .5 * sin(u) * cos(v)      for u in U, v in V]
    z1 = [.5 * sin(v)                        for u in U, v in V]
    x2 = [1 + cos(u) + .5 * cos(u) * cos(v)  for u in U, v in V]
    y2 = [.5 * sin(v)                        for u in U, v in V]
    z2 = [sin(u) + .5 * sin(u) * cos(v)      for u in U, v in V]
    fig = Figure(resolution =(900,600))
    ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true))
    wireframe!(ax.scene, x1,y1,z1, shading = false)
    zoom!(ax.scene, cameracontrols(ax.scene), 3)
    update_cam!(ax.scene, cameracontrols(ax.scene))
    fig[1,1] = ax
end

does not result in a zoomed picture, with or without the cameracontrols(ax.scene).

Replacing the zoom! line with translate_cam!(scene, Vec3f0(0, 0, 3)) does not yield any difference either.

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 20, 2021

It seems that the zoom_step argument is never passed along to the zoom! method on the right hand side of the assignment, but instead gets set to false.

Oh yea, that's a typo.

On my side, your proposals did not work. The code ... does not result in a zoomed picture, with or without the cameracontrols(ax.scene).

I think Makie enters things everything when the plot is first displayed. You can try reordering some things and displaying first

fig = Figure(resolution =(900,600))
ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true))
wireframe!(ax.scene, x1,y1,z1, shading = false)
fig[1,1] = ax
display(fig)
zoom!(ax.scene, cameracontrols(ax.scene), 3)
update_cam!(ax.scene, cameracontrols(ax.scene))

or manually centering

ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true, center = false))
wireframe!(ax.scene, x1,y1,z1, shading = false)
center!(ax.scene)
zoom!(ax.scene, cameracontrols(ax.scene), 3)
update_cam!(ax.scene, cameracontrols(ax.scene))

@ffreyer ffreyer mentioned this issue Mar 13, 2023
4 tasks
SimonDanisch added a commit that referenced this issue Nov 17, 2023
Continues #2831 !
Still needs to check, if I rebased correctly and didn't incorrectly
apply some of the changes!

## Merged PRs
- #2598
- #2746
- #2346
- #2544
- #3082
- #2868
- #3062
- #3106
- #3281
- #3246

## TODOS

- [x] fix flaky test `@test GLMakie.window_size(screen.glscreen) ==
scaled(screen, (W, H))`
- [x] Merge axis type inferences from #2220 
- [x] Test on different resolution screens, IJulia, Pluto, VSCode,
Windowed
- [x] rebase to only have merge commits from the PRs 
- [x] investigate unexpected speed ups
- [x] reset camera settings from tests
- [ ] check doc image generation
- [x] rethink default near/far in Camera3D (compatability with OIT)
- [x] merge #3246
- [x] fix WGLMakie issues/tests:
- [x] fix line depth issues (see tests: ~~hexbin colorrange~~ (not new),
LaTeXStrings in Axis3, Axis3 axis reversal)
  - [x] fix lighting of surface with nan points (fixed in #3246)
- ~~volume/3D contour artifacts (see 3D Contour with 2D contour
slices)~~ not new
  - ~~artifacting in "colorscale (lines)"~~ not new
- [x] GLMakie:
  - [x] slight outline in "scatter image markers" test
  - ~~clipping/z-fighting in "volume translated"~~ not new
- [x] CairoMakie:
  -  ~~Artfiacting in `colorscale (lines)"~~ not new
  - ~~markersize in "scatter rotations" changed?~~ not new
  - ~~color change in "colorscale (poly)"~~ not new
  - ~~transparency/render order of "OldAxis + Surface"~~ not new
  - ~~render order in "Merged color mesh"~~ not new
  - ~~render order of "Surface + wireframe + contour"~~ not new
- [x] Check "SpecApi in convert_arguments" (colors swapped?)


## Fixes the following errors

- fixes #2721 via #2746
- fixes #1600 via #2746
- fixes #1236 via #2746
- fixes MakieOrg/GeoMakie.jl#133 via #2598
- closes #2522
- closes #3239 via #3246
- fixes #3238 via #3246
- fixes #2985 via #3246
- fixes #3307 via #3281
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

Successfully merging a pull request may close this issue.

3 participants