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

How can I easily reproduce a special perspective state? #279

Closed
JintaoLee-Roger opened this issue Sep 5, 2024 · 2 comments
Closed

How can I easily reproduce a special perspective state? #279

JintaoLee-Roger opened this issue Sep 5, 2024 · 2 comments

Comments

@JintaoLee-Roger
Copy link

Hi! I’m encountering some issues while adjusting the initial view state.

  • How can I adjust the initial view size, or is there a function similar to auto_range that scales the entire figure to fit within the visible area? Currently, if my images are large, only a small portion is displayed, making the initial view too zoomed in. I know there are parameters like scale, render_width, and render_height that can be adjusted, but if there are too many images or meshes, adjusting each one individually becomes tedious. Additionally, it’s hard to know the exact values to achieve the desired result.

  • Is there a way to set the coordinate center on the screen? In many cases, the range we’re interested in is greater than zero. For example, I may use three images to represent slices of a 3D medical CT scan or different directions of a 3D geological model, and typically, the coordinates I set are greater than zero. In this case, the generated figure appears shifted towards the top-right corner of the screen instead of being centered, requiring extra dragging to reach the center.

  • A more general/ultimate question: After adjusting a view (rotating, zooming, panning), how can I easily reproduce this exact state? As you know, when preparing publications or slides for presentations, we often need to display different datasets or results from the same perspective/view to facilitate comparison. This requires capturing the current visualization state after adjusting it to the optimal view, and then applying that state when visualizing other data.

I’d be grateful for your help. Thank you!

@brentyi
Copy link
Collaborator

brentyi commented Sep 7, 2024

Hi @JintaoLee-Roger!

I think the best we have for all of these is the camera handle API, which lets you read/write the camera state.

For your three questions:

  • There's no auto_range, but you can do some math to set the camera position, orientation, look at, FOV, etc programatically.
  • You can set camera.look_at to a length-3 tuple or numpy array to look at a specific point in the scene.
  • For saving/restoring the camera state, you can read these properties and then write them back later. This would also require code on your end, however.

For accessing the camera handle, one option is to do so when the client connects:

server = viser.ViserServer()

@server.on_client_connect
def _(client: viser.ClientHandle) -> None:
    client.camera.position = (1., 1., 1.)

If you have any event object (for example, from a GUI callback), you can also access event.client.camera.

Does that help?

@JintaoLee-Roger
Copy link
Author

Yes! I have achived my goal by your advises. Thank you very much.

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

2 participants