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

Wass contributions #882

Closed
wants to merge 9 commits into from
47 changes: 34 additions & 13 deletions fury/animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@

"""

def __init__(self, actors=None, length=None, loop=True, motion_path_res=None):
def __init__(self, actors=None,
length=None,
loop=True,
motion_path_res=None):

super().__init__()
self._data = defaultdict(dict)
Expand Down Expand Up @@ -81,7 +84,8 @@
else:
self._duration = max(
self._max_timestamp,
max([0] + [anim.update_duration() for anim in self.child_animations]),
max([0] + [anim.update_duration()
for anim in self.child_animations]),
)

return self.duration
Expand Down Expand Up @@ -184,7 +188,8 @@
data[attrib] = {
'keyframes': defaultdict(dict),
'interpolator': {
'base': linear_interpolator if attrib != 'rotation' else slerp,
'base': (linear_interpolator
if attrib != 'rotation' else slerp),
'func': None,
'args': defaultdict(),
},
Expand All @@ -206,7 +211,8 @@
if attrib is None:
attribs = data.keys()
return {
attrib: data.get(attrib, {}).get('keyframes', {}) for attrib in attribs
attrib: data.get(attrib,
{}).get('keyframes', {}) for attrib in attribs
}
return data.get(attrib, {}).get('keyframes', {})

Expand Down Expand Up @@ -315,7 +321,8 @@
parent_in_scene = parent._added_to_scene

if self.is_interpolatable('in_scene'):
in_scene = parent_in_scene and self.get_value('in_scene', timestamp)
in_scene = parent_in_scene and self.get_value('in_scene',

Check warning on line 324 in fury/animation/animation.py

View check run for this annotation

Codecov / codecov/patch

fury/animation/animation.py#L324

Added line #L324 was not covered by tests
timestamp)
else:
in_scene = parent_in_scene
return in_scene
Expand Down Expand Up @@ -360,7 +367,8 @@
self._scene.rm(*self._actors)
self._added_to_scene = False

def set_interpolator(self, attrib, interpolator, is_evaluator=False, **kwargs):
def set_interpolator(self, attrib, interpolator,
is_evaluator=False, **kwargs):
"""Set keyframes interpolator for a certain property

Parameters
Expand Down Expand Up @@ -438,7 +446,8 @@
data = self._data
return bool(data.get(attrib, {}).get('interpolator', {}).get('func'))

def set_position_interpolator(self, interpolator, is_evaluator=False, **kwargs):
def set_position_interpolator(self, interpolator,
is_evaluator=False, **kwargs):
"""Set the position interpolator.

Parameters
Expand Down Expand Up @@ -501,7 +510,8 @@
>>> Animation.set_rotation_interpolator(slerp)

"""
self.set_interpolator('rotation', interpolator, is_evaluator=is_evaluator)
self.set_interpolator('rotation', interpolator,
is_evaluator=is_evaluator)

def set_color_interpolator(self, interpolator, is_evaluator=False):
"""Set the color interpolator.
Expand Down Expand Up @@ -539,7 +549,9 @@
>>> Animation.set_opacity_interpolator(step_interpolator)

"""
self.set_interpolator('opacity', interpolator, is_evaluator=is_evaluator)
self.set_interpolator('opacity',
interpolator,
is_evaluator=is_evaluator)

def get_value(self, attrib, timestamp):
"""Return the value of an attribute at any given timestamp.
Expand All @@ -553,7 +565,8 @@

"""
value = (
self._data.get(attrib, {}).get('interpolator', {}).get('func')(timestamp)
self._data.get(attrib,
{}).get('interpolator', {}).get('func')(timestamp)
)
return value

Expand Down Expand Up @@ -1217,7 +1230,11 @@

"""

def __init__(self, camera=None, length=None, loop=True, motion_path_res=None):
def __init__(self,
camera=None,
length=None,
loop=True,
motion_path_res=None):
super(CameraAnimation, self).__init__(
length=length, loop=loop, motion_path_res=motion_path_res
)
Expand Down Expand Up @@ -1381,7 +1398,8 @@
function that does not depend on keyframes.

"""
self.set_interpolator('view_up', interpolator, is_evaluator=is_evaluator)
self.set_interpolator('view_up', interpolator,

Check warning on line 1401 in fury/animation/animation.py

View check run for this annotation

Codecov / codecov/patch

fury/animation/animation.py#L1401

Added line #L1401 was not covered by tests
is_evaluator=is_evaluator)

def update_animation(self, time=None):
"""Update the camera animation.
Expand All @@ -1406,7 +1424,10 @@
# camera axis is reverted
rot = -self.get_rotation(time, as_quat=True)
rot = transform.Rotation.from_quat(rot).as_matrix()
rot = np.array([[*rot[0], 0], [*rot[1], 0], [*rot[2], 0], [0, 0, 0, 1]])
rot = np.array([[*rot[0], 0],
[*rot[1], 0],
[*rot[2], 0],
[0, 0, 0, 1]])
rot = translation @ rot @ np.linalg.inv(translation)
self._camera.SetModelTransformMatrix(rot.flatten())

Expand Down
3 changes: 2 additions & 1 deletion fury/animation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def get_values_from_keyframes(keyframes):

"""
return np.asarray(
[keyframes.get(t, {}).get('value', None) for t in sorted(keyframes.keys())]
[keyframes.get(t, {}).get('value', None)
for t in sorted(keyframes.keys())]
)


Expand Down
6 changes: 3 additions & 3 deletions fury/animation/tests/fares
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class myclass():
myclass.usren+=1
def __str__(self):
return f'collage name is {self.pname} , dof = {self.ccname}'

def print(self):
if self.pname in myclass.notallow:
print('not allowed')
else:
print(f'{self.pname} , {self.ccname}')

def allinfo():
print(f'the end of the class')
@classmethod
Expand All @@ -37,7 +37,7 @@ class student(myclass):
def __init__(self,name,cname,age):
super().__init__(name,cname)
self.age=age

def __str__(self):
return f'your name is {self.pname} ,course name = {self.ccname}, your age is {self.age}'

Expand Down
4 changes: 2 additions & 2 deletions fury/animation/tests/test_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import numpy.testing as npt

from fury.animation import Animation, Timeline
import fury.testing as ft
from fury.animation import Animation, Timeline
from fury.ui import PlaybackPanel
from fury.window import Scene, ShowManager
from fury.window import ShowManager, Scene


def assert_not_equal(x, y):
Expand Down
12 changes: 9 additions & 3 deletions fury/animation/timeline.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from time import perf_counter

from PIL import Image
import numpy as np
from PIL import Image

from fury import window
from fury.animation.animation import Animation
Expand Down Expand Up @@ -33,7 +33,9 @@

"""

def __init__(self, animations=None, playback_panel=False, loop=True, length=None):
def __init__(self, animations=None,
playback_panel=False,
loop=True, length=None):

self._scene = None
self.playback_panel = None
Expand Down Expand Up @@ -365,7 +367,11 @@
render_window.SetSize(*size)

if order_transparent:
window.antialiasing(scene, render_window, multi_samples, max_peels, 0)
window.antialiasing(scene,

Check warning on line 370 in fury/animation/timeline.py

View check run for this annotation

Codecov / codecov/patch

fury/animation/timeline.py#L370

Added line #L370 was not covered by tests
render_window,
multi_samples,
max_peels,
0)

window_to_image_filter = WindowToImageFilter()

Expand Down
Loading