napari / napari-animation

A napari plugin for making animations
https://napari.github.io/napari-animation/
Other
74 stars 27 forks source link

Add example showing a simple 360 degree rotation #164

Open GenevieveBuckley opened 1 year ago

GenevieveBuckley commented 1 year ago

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.

alisterburt commented 1 year ago

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()
GenevieveBuckley commented 1 year ago

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!