napari-animation icon indicating copy to clipboard operation
napari-animation copied to clipboard

Add example showing a simple 360 degree rotation

Open GenevieveBuckley opened this issue 1 year ago • 2 comments

I think it would be useful to add an example to the docs showing a simple 360 degree rotation. Ideally it should have a section at the beginning setting the camera zoom/angle/etc. (all the things people might want to adjust slightly for their own datasets).

Getting a nice even rotation speed is kind of hard to do manually, so I think this would be useful.

I wrote a script to do this pretty early on, I'll see if I can dig it out again. It wasn't hard to do, so it might be just as simple for someone to write another one.

GenevieveBuckley avatar Apr 19 '23 01:04 GenevieveBuckley

this would be useful for sure!

It shouldn't be too hard to bodge together with some programatically generated keyframes and a button in the GUI to add those would be nice

the camera now exposes view_direction and up_direction - rotating the view direction vector around the up vector would work

something like

import numpy as np
from scipy.spatial.transform import Rotation as R

camera: napari.Camera
animation: Animation

angles = np.linspace(0, 360, num=5).reshape(5, 1)
rotation = R.from_rotvec(np.array(camera.up_direction) * angles, degrees=True)
rotated_view_directions = rotation.apply(camera.view_direction)

for direction in rotated_view_directions:
    camera.set_view_direction(direction, up_direction=camera.up_direction)
    animation.capture_keyframe()

alisterburt avatar Apr 19 '23 11:04 alisterburt

It shouldn't be too hard to bodge together with some programatically generated keyframes and a button in the GUI to add those would be nice

Yes, absolutely!

GenevieveBuckley avatar Apr 20 '23 03:04 GenevieveBuckley