animation#

Animation([actors, length, loop, ...])

Keyframe animation class.

CameraAnimation([camera, length, loop, ...])

Camera keyframe animation class.

Timeline([animations, playback_panel, loop, ...])

Keyframe animation Timeline.

Module: animation.animation#

Actor

alias of vtkActor

Animation([actors, length, loop, ...])

Keyframe animation class.

Camera

alias of vtkCamera

CameraAnimation([camera, length, loop, ...])

Camera keyframe animation class.

Transform

alias of vtkTransform

defaultdict

defaultdict(default_factory=None, /, [...]) --> dict with default factory

line(lines[, colors, opacity, linewidth, ...])

Create an actor for one or more lines.

linear_interpolator(keyframes)

Linear interpolator for keyframes.

perf_counter()

Performance counter for benchmarking.

slerp(keyframes)

Spherical based rotation keyframes interpolator.

spline_interpolator(keyframes, degree)

N-th degree spline interpolator for keyframes.

step_interpolator(keyframes)

Step interpolator for keyframes.

warn(message[, category, stacklevel, source])

Issue a warning, or maybe ignore it or raise an exception.

Module: animation.helpers#

euclidean_distances(points)

Return a list of euclidean distances of a list of points or values.

get_next_timestamp(timestamps, current_time)

Return the minimum next timestamp of a given time.

get_previous_timestamp(timestamps, current_time)

Return the maximum previous timestamp of a given time.

get_time_tau(t, t0, t1)

Return a capped time tau between 0 and 1.

get_timestamps_from_keyframes(keyframes)

Return a sorted array of timestamps given dict of keyframes.

get_values_from_keyframes(keyframes)

Return an array of keyframes values sorted using timestamps.

lerp(v0, v1, t0, t1, t)

Return a linearly interpolated value.

Module: animation.interpolator#

color_interpolator(keyframes, rgb2space, ...)

Custom-space color interpolator.

cubic_bezier_interpolator(keyframes)

Cubic Bézier interpolator for keyframes.

cubic_spline_interpolator(keyframes)

Cubic spline interpolator for keyframes.

euclidean_distances(points)

Return a list of euclidean distances of a list of points or values.

get_next_timestamp(timestamps, current_time)

Return the minimum next timestamp of a given time.

get_previous_timestamp(timestamps, current_time)

Return the maximum previous timestamp of a given time.

get_time_tau(t, t0, t1)

Return a capped time tau between 0 and 1.

get_timestamps_from_keyframes(keyframes)

Return a sorted array of timestamps given dict of keyframes.

get_values_from_keyframes(keyframes)

Return an array of keyframes values sorted using timestamps.

hsv2rgb(hsv)

HSV to RGB color space conversion.

hsv_color_interpolator(keyframes)

HSV interpolator for color keyframes

lab2rgb(lab[, illuminant, observer])

Lab to RGB color space conversion.

lab_color_interpolator(keyframes)

LAB interpolator for color keyframes

lerp(v0, v1, t0, t1, t)

Return a linearly interpolated value.

linear_interpolator(keyframes)

Linear interpolator for keyframes.

rgb2hsv(rgb)

RGB to HSV color space conversion. :param rgb: The image in RGB format. By default, the final dimension denotes channels. :type rgb: (..., 3, ...) array_like.

rgb2lab(rgb[, illuminant, observer])

Conversion from the sRGB color space (IEC 61966-2-1:1999) to the CIE Lab colorspace under the given illuminant and observer.

rgb2xyz(rgb)

RGB to XYZ color space conversion.

slerp(keyframes)

Spherical based rotation keyframes interpolator.

splev(x, tck[, der, ext])

Evaluate a B-spline or its derivatives.

spline_interpolator(keyframes, degree)

N-th degree spline interpolator for keyframes.

splprep(x[, w, u, ub, ue, k, task, s, t, ...])

Find the B-spline representation of an N-D curve.

step_interpolator(keyframes)

Step interpolator for keyframes.

tan_cubic_spline_interpolator(keyframes)

Cubic spline interpolator for keyframes using tangents.

xyz2rgb(xyz)

XYZ to RGB color space conversion.

xyz_color_interpolator(keyframes)

XYZ interpolator for color keyframes

Module: animation.timeline#

Animation([actors, length, loop, ...])

Keyframe animation class.

PlaybackPanel([loop, position, width])

A playback controller that can do essential functionalities.

Timeline([animations, playback_panel, loop, ...])

Keyframe animation Timeline.

perf_counter()

Performance counter for benchmarking.

Animation#

class fury.animation.Animation(actors=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: object

Keyframe animation class.

Animation is responsible for keyframe animations for a single or a group of actors. It’s used to handle multiple attributes and properties of Fury actors such as transformations, color, and scale. It also accepts custom data and interpolates them, such as temperature. Linear interpolation is used by default to interpolate data between the main keyframes.

actors#

Actor/s to be animated.

Type:

Actor or list[Actor], optional, default: None

length#

the fixed length of the animation. If set to None, the animation will get its duration from the keyframes being set.

Type:

float or int, default: None, optional

loop#

Whether to loop the animation (True) of play once (False).

Type:

bool, optional, default: True

motion_path_res#

the number of line segments used to visualizer the animation’s motion path (visualizing position).

Type:

int, default: None

__init__(actors=None, length=None, loop=True, motion_path_res=None)[source]#
property actors#

Return a list of actors.

Returns:

List of actors controlled by the Animation.

Return type:

list

add(item)[source]#

Add an item to the Animation. This item can be an Actor, Animation, list of Actors, or a list of Animations.

Parameters:

item (Animation, vtkActor, list[Animation], or list[vtkActor]) – Actor/s to be animated by the Animation.

add_actor(actor, static=False)[source]#

Add an actor or list of actors to the Animation.

Parameters:
  • actor (vtkActor or list(vtkActor)) – Actor/s to be animated by the Animation.

  • static (bool) – Indicated whether the actor should be animated and controlled by the animation or just a static actor that gets added to the scene along with the Animation.

add_child_animation(animation)[source]#

Add child Animation or list of Animations.

Parameters:

animation (Animation or list[Animation]) – Animation/s to be added.

add_static_actor(actor)[source]#

Add an actor or list of actors as static actor/s which will not be controlled nor animated by the Animation. All static actors will be added to the scene when the Animation is added to the scene.

Parameters:

actor (vtkActor or list(vtkActor)) – Static actor/s.

add_to_scene(scene)[source]#

Add this Animation, its actors and sub Animations to the scene

add_to_scene_at(timestamp)[source]#

Set timestamp for adding Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

add_update_callback(callback, prop=None)[source]#

Add a function to be called each time animation is updated This function must accept only one argument which is the current value of the named property.

Parameters:
  • callback (callable) – The function to be called whenever the animation is updated.

  • prop (str, optional, default: None) – The name of the property.

Notes

If no attribute name was provided, current time of the animation will be provided instead of current value for the callback.

property child_animations: list[fury.animation.animation.Animation]#

Return a list of child Animations.

Returns:

List of child Animations of this Animation.

Return type:

list

property current_timestamp#

Return the current time of the animation.

Returns:

The current time of the animation.

Return type:

float

property duration#

Return the duration of the animation.

Returns:

The duration of the animation.

Return type:

float

get_color(t)[source]#

Return the interpolated color.

Parameters:

t (float) – The time to interpolate color value at.

Returns:

The interpolated color.

Return type:

ndarray(1, 3)

get_current_value(attrib)[source]#

Return the value of an attribute at current time.

Parameters:

attrib (str) – The attribute name.

get_keyframes(attrib=None)[source]#

Get a keyframe for a specific or all attributes.

Parameters:

attrib (str, optional, default: None) – The name of the attribute. If None, all keyframes for all set attributes will be returned.

get_opacity(t)[source]#

Return the opacity value.

Parameters:

t (float) – The time to interpolate opacity at.

Returns:

The interpolated opacity.

Return type:

ndarray(1, 1)

get_position(t)[source]#

Return the interpolated position.

Parameters:

t (float) – The time to interpolate position at.

Returns:

The interpolated position.

Return type:

ndarray(1, 3)

get_rotation(t, as_quat=False)[source]#

Return the interpolated rotation.

Parameters:
  • t (float) – the time to interpolate rotation at.

  • as_quat (bool) – Returned rotation will be as quaternion if True.

Returns:

The interpolated rotation as Euler degrees by default.

Return type:

ndarray(1, 3)

get_scale(t)[source]#

Return the interpolated scale.

Parameters:

t (float) – The time to interpolate scale at.

Returns:

The interpolated scale.

Return type:

ndarray(1, 3)

get_value(attrib, timestamp)[source]#

Return the value of an attribute at any given timestamp.

Parameters:
  • attrib (str) – The attribute name.

  • timestamp (float) – The timestamp to interpolate at.

is_inside_scene_at(timestamp)[source]#

Check if the Animation is set to be inside the scene at a specific timestamp.

Returns:

True if the Animation is set to be inside the scene at the given timestamp.

Return type:

bool

Notes

If the parent Animation is set to be out of the scene at that time, all of their child animations will be out of the scene as well.

is_interpolatable(attrib)[source]#

Check whether a property is interpolatable.

Parameters:

attrib (str) – The name of the property.

Returns:

True if the property is interpolatable by the Animation.

Return type:

bool

Notes

True means that it’s safe to use Interpolator.interpolate(t) for the specified property. And False means the opposite.

property loop#

Get loop condition of the current animation.

Returns:

Whether the animation in loop mode (True) or play one mode (False).

Return type:

bool

property parent_animation#

Return the hierarchical parent Animation for current Animation.

Returns:

The parent Animation.

Return type:

Animation

remove_actor(actor)[source]#

Remove an actor from the Animation.

Parameters:

actor (vtkActor) – Actor to be removed from the Animation.

remove_actors()[source]#

Remove all actors from the Animation

remove_animations()[source]#

Remove all child Animations from the Animation

remove_from_scene(scene)[source]#

Remove Animation, its actors and sub Animations from the scene

remove_from_scene_at(timestamp)[source]#

Set timestamp for removing Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

set_color(timestamp, color, **kwargs)[source]#

Set color keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • color (ndarray, shape(1, 3)) – Color keyframe value associated with the timestamp.

set_color_interpolator(interpolator, is_evaluator=False)[source]#

Set the color interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the color keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_color_interpolator(lab_color_interpolator)
set_color_keyframes(keyframes)[source]#

Set a dict of color keyframes at once. Should be in the following form: {timestamp_1: color_1, timestamp_2: color_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and color as values.

Examples

>>> color_keyframes = {1, np.array([1, 0, 1]), 3, np.array([0, 0, 1])}
>>> Animation.set_color_keyframes(color_keyframes)
set_interpolator(attrib, interpolator, is_evaluator=False, **kwargs)[source]#

Set keyframes interpolator for a certain property

Parameters:
  • attrib (str) – The name of the property.

  • interpolator (callable) – The generator function of the interpolator to be used to interpolate/evaluate keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes such as: >>> def get_position(t): >>> return np.array([np.sin(t), np.cos(t) * 5, 5])

  • spline_degree (int, optional) – The degree of the spline in case of setting a spline interpolator.

Notes

If an evaluator is used to set the values of actor’s properties such as position, scale, color, rotation, or opacity, it has to return a value with the same shape as the evaluated property, i.e.: for scale, it has to return an array with shape 1x3, and for opacity, it has to return a 1x1, an int, or a float value.

Examples

>>> Animation.set_interpolator('position', linear_interpolator)
>>> pos_fun = lambda t: np.array([np.sin(t), np.cos(t), 0])
>>> Animation.set_interpolator('position', pos_fun)
set_keyframe(attrib, timestamp, value, update_interpolator=True, **kwargs)[source]#

Set a keyframe for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • timestamp (float) – Timestamp of the keyframe.

  • value (ndarray or float or bool) – Value of the keyframe at the given timestamp.

  • update_interpolator (bool, optional) – Interpolator will be reinitialized if Ture

  • in_cp (ndarray, shape (1, M), optional) – The in control point in case of using cubic Bézier interpolator.

  • out_cp (ndarray, shape (1, M), optional) – The out control point in case of using cubic Bézier interpolator.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

set_keyframes(attrib, keyframes)[source]#

Set multiple keyframes for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • keyframes (dict) – A dict object containing keyframes to be set.

Notes

Keyframes can be on any of the following forms: >>> key_frames_simple = {1: [1, 2, 1], 2: [3, 4, 5]} >>> key_frames_bezier = {1: {‘value’: [1, 2, 1]}, >>> 2: {‘value’: [3, 4, 5], ‘in_cp’: [1, 2, 3]}} >>> pos_keyframes = {1: np.array([1, 2, 3]), 3: np.array([5, 5, 5])} >>> Animation.set_keyframes(‘position’, pos_keyframes)

set_opacity(timestamp, opacity, **kwargs)[source]#

Set opacity keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • opacity (ndarray, shape(1, 3)) – Opacity keyframe value associated with the timestamp.

set_opacity_interpolator(interpolator, is_evaluator=False)[source]#

Set the opacity interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the opacity keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_opacity_interpolator(step_interpolator)
set_opacity_keyframes(keyframes)[source]#

Set a dict of opacity keyframes at once. Should be in the following form: {timestamp_1: opacity_1, timestamp_2: opacity_2}

Parameters:

keyframes (dict(float: ndarray, shape(1, 1) or float or int)) – A dict with timestamps as keys and opacities as values.

Notes

Opacity values should be between 0 and 1.

Examples

>>> opacity = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(opacity)
set_position(timestamp, position, **kwargs)[source]#

Set a position keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • position (ndarray, shape (1, 3)) – Position value

  • in_cp (float) – The control point in case of using cubic Bézier interpolator when time exceeds this timestamp.

  • out_cp (float) – The control point in case of using cubic Bézier interpolator when time precedes this timestamp.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

Notes

in_cp and out_cp only needed when using the cubic bezier interpolation method.

set_position_interpolator(interpolator, is_evaluator=False, **kwargs)[source]#

Set the position interpolator.

Parameters:
  • interpolator (callable) –

    The generator function of the interpolator that would handle the

    position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

  • degree (int) – The degree of the spline interpolation in case of setting the spline_interpolator.

Examples

>>> Animation.set_position_interpolator(spline_interpolator, degree=5)
set_position_keyframes(keyframes)[source]#

Set a dict of position keyframes at once. Should be in the following form: {timestamp_1: position_1, timestamp_2: position_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and positions as values.

Examples

>>> pos_keyframes = {1, np.array([0, 0, 0]), 3, np.array([50, 6, 6])}
>>> Animation.set_position_keyframes(pos_keyframes)
set_rotation(timestamp, rotation, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • rotation (ndarray, shape(1, 3) or shape(1, 4)) – Rotation data in euler degrees with shape(1, 3) or in quaternions with shape(1, 4).

Notes

Euler rotations are executed by rotating first around Z then around X, and finally around Y.

set_rotation_as_vector(timestamp, vector, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • vector (ndarray, shape(1, 3)) – Directional vector that describes the rotation.

set_rotation_interpolator(interpolator, is_evaluator=False)[source]#

Set the rotation interpolator .

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the rotation (orientation) keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_rotation_interpolator(slerp)
set_scale(timestamp, scalar, **kwargs)[source]#

Set a scale keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • scalar (ndarray, shape(1, 3)) – Scale keyframe value associated with the timestamp.

set_scale_interpolator(interpolator, is_evaluator=False)[source]#

Set the scale interpolator.

Parameters:
  • interpolator (callable) – TThe generator function of the interpolator that would handle the scale keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_scale_interpolator(step_interpolator)
set_scale_keyframes(keyframes)[source]#

Set a dict of scale keyframes at once. Should be in the following form: {timestamp_1: scale_1, timestamp_2: scale_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and scales as values.

Examples

>>> scale_keyframes = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(scale_keyframes)
property static_actors#

Return a list of static actors.

Returns:

List of static actors.

Return type:

list

property timeline#

Return the Timeline handling the current animation.

Returns:

The Timeline handling the current animation, None, if there is no associated Timeline.

Return type:

Timeline

update_animation(time=None)[source]#

Update the animation.

Update the animation at a certain time. This will make sure all attributes are calculated and set to the actors at that given time.

Parameters:

time (float or int, optional, default: None) – The time to update animation at. If None, the animation will play without adding it to a Timeline.

update_duration()[source]#

Update and return the duration of the Animation.

Returns:

The duration of the animation.

Return type:

float

update_motion_path()[source]#

Update motion path visualization actor

CameraAnimation#

class fury.animation.CameraAnimation(camera=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: Animation

Camera keyframe animation class.

This is used for animating a single camera using a set of keyframes.

camera#

Camera to be animated. If None, active camera will be animated.

Type:

Camera, optional, default: None

length#

the fixed length of the animation. If set to None, the animation will get its duration from the keyframes being set.

Type:

float or int, default: None, optional

loop#

Whether to loop the animation (True) of play once (False).

Type:

bool, optional, default: True

motion_path_res#

the number of line segments used to visualizer the animation’s motion path (visualizing position).

Type:

int, default: None

__init__(camera=None, length=None, loop=True, motion_path_res=None)[source]#
property camera: vtkCamera#

Return the camera assigned to this animation.

Returns:

The camera that is being animated by this CameraAnimation.

Return type:

Camera

get_focal(t)[source]#

Return the interpolated camera’s focal position.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera’s focal position.

Return type:

ndarray(1, 3)

Notes

The returned focal position does not necessarily reflect the current camera’s focal position, but the expected one.

get_view_up(t)[source]#

Return the interpolated camera’s view-up directional vector.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera view-up directional vector.

Return type:

ndarray(1, 3)

Notes

The returned focal position does not necessarily reflect the actual camera view up directional vector, but the expected one.

set_focal(timestamp, position, **kwargs)[source]#

Set camera’s focal position keyframe.

Parameters:
  • timestamp (float) – The time to interpolate opacity at.

  • position (ndarray, shape(1, 3)) – The camera position

set_focal_interpolator(interpolator, is_evaluator=False)[source]#

Set the camera focal position interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera focal position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_focal_keyframes(keyframes)[source]#

Set multiple camera focal position keyframes at once. Should be in the following form: {timestamp_1: focal_1, timestamp_2: focal_1, …}

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera focal positions as values.

Examples

>>> focal_pos = {0, np.array([1, 1, 1]), 3, np.array([20, 0, 0])}
>>> CameraAnimation.set_focal_keyframes(focal_pos)
set_view_up(timestamp, direction, **kwargs)[source]#

Set the camera view-up direction keyframe.

Parameters:
  • timestamp (float) – The time to interpolate at.

  • direction (ndarray, shape(1, 3)) – The camera view-up direction

set_view_up_interpolator(interpolator, is_evaluator=False)[source]#

Set the camera up-view vector animation interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera view-up keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_view_up_keyframes(keyframes)[source]#

Set multiple camera view up direction keyframes. Should be in the following form: {timestamp_1: view_up_1, timestamp_2: view_up_2, …}

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera view up vectors as values.

Examples

>>> view_ups = {0, np.array([1, 0, 0]), 3, np.array([0, 1, 0])}
>>> CameraAnimation.set_view_up_keyframes(view_ups)
update_animation(time=None)[source]#

Update the camera animation.

Parameters:

time (float or int, optional, default: None) – The time to update the camera animation at. If None, the animation will play.

Timeline#

class fury.animation.Timeline(animations=None, playback_panel=False, loop=True, length=None)[source]#

Bases: object

Keyframe animation Timeline.

Timeline is responsible for handling the playback of keyframes animations. It has multiple playback options which makes it easy to control the playback, speed, state of the animation with/without a GUI playback panel.

animations#

Actor/s to be animated directly by the Timeline (main Animation).

Type:

Animation or list[Animation], optional, default: None

playback_panel#

If True, the timeline will have a playback panel set, which can be used to control the playback of the timeline.

Type:

bool, optional

length#
the fixed length of the timeline. If set to None, the timeline will get

its length from the animations that it controls automatically.

Type:

float or int, default: None, optional

loop#

Whether loop playing the timeline or play once.

Type:

bool, optional

__init__(animations=None, playback_panel=False, loop=True, length=None)[source]#
add_animation(animation)[source]#

Add Animation or list of Animations.

Parameters:

animation (Animation or list[Animation] or tuple[Animation]) – Animation/s to be added.

add_to_scene(scene)[source]#

Add Timeline and all of its Animations to the scene

property animations: list[fury.animation.animation.Animation]#

Return a list of Animations.

Returns:

List of Animations controlled by the timeline.

Return type:

list

property current_timestamp#

Get current timestamp of the Timeline.

Returns:

The current time of the Timeline.

Return type:

float

property duration#

Return the duration of the Timeline.

Returns:

The duration of the Timeline.

Return type:

float

property has_playback_panel#

Return whether the Timeline has a playback panel.

Returns:

bool

Return type:

‘True’ if the Timeline has a playback panel. otherwise, ‘False’

property loop#

Get loop condition of the timeline.

Returns:

Whether the playback is in loop mode (True) or play one mode (False).

Return type:

bool

pause()[source]#

Pause the animation

property paused#

Return whether the Timeline is paused.

Returns:

True if the Timeline is paused.

Return type:

bool

play()[source]#

Play the animation

property playing#

Return whether the Timeline is playing.

Returns:

True if the Timeline is playing.

Return type:

bool

remove_from_scene(scene)[source]#

Remove Timeline and all of its Animations to the scene

restart()[source]#

Restart the animation

seek(timestamp)[source]#

Set the current timestamp of the Timeline.

Parameters:

timestamp (float) – The time to seek.

seek_percent(percent)[source]#

Seek a percentage of the Timeline’s final timestamp.

Parameters:

percent (float) – Value from 1 to 100.

property speed#

Return the speed of the timeline’s playback.

Returns:

The speed of the timeline’s playback.

Return type:

float

stop()[source]#

Stop the animation

property stopped#

Return whether the Timeline is stopped.

Returns:

True if Timeline is stopped.

Return type:

bool

update(force=False)[source]#

Update the timeline.

Update the Timeline and all the animations that it controls. As well as the playback of the Timeline (if exists).

Parameters:

force (bool, optional, default: False) – If True, the timeline will update even when the timeline is paused or stopped and hence, more resources will be used.

update_duration()[source]#

Update and return the duration of the Timeline.

Returns:

The duration of the Timeline.

Return type:

float

Actor#

fury.animation.animation.Actor#

alias of vtkActor

Animation#

class fury.animation.animation.Animation(actors=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: object

Keyframe animation class.

Animation is responsible for keyframe animations for a single or a group of actors. It’s used to handle multiple attributes and properties of Fury actors such as transformations, color, and scale. It also accepts custom data and interpolates them, such as temperature. Linear interpolation is used by default to interpolate data between the main keyframes.

actors#

Actor/s to be animated.

Type:

Actor or list[Actor], optional, default: None

length#

the fixed length of the animation. If set to None, the animation will get its duration from the keyframes being set.

Type:

float or int, default: None, optional

loop#

Whether to loop the animation (True) of play once (False).

Type:

bool, optional, default: True

motion_path_res#

the number of line segments used to visualizer the animation’s motion path (visualizing position).

Type:

int, default: None

__init__(actors=None, length=None, loop=True, motion_path_res=None)[source]#
property actors#

Return a list of actors.

Returns:

List of actors controlled by the Animation.

Return type:

list

add(item)[source]#

Add an item to the Animation. This item can be an Actor, Animation, list of Actors, or a list of Animations.

Parameters:

item (Animation, vtkActor, list[Animation], or list[vtkActor]) – Actor/s to be animated by the Animation.

add_actor(actor, static=False)[source]#

Add an actor or list of actors to the Animation.

Parameters:
  • actor (vtkActor or list(vtkActor)) – Actor/s to be animated by the Animation.

  • static (bool) – Indicated whether the actor should be animated and controlled by the animation or just a static actor that gets added to the scene along with the Animation.

add_child_animation(animation)[source]#

Add child Animation or list of Animations.

Parameters:

animation (Animation or list[Animation]) – Animation/s to be added.

add_static_actor(actor)[source]#

Add an actor or list of actors as static actor/s which will not be controlled nor animated by the Animation. All static actors will be added to the scene when the Animation is added to the scene.

Parameters:

actor (vtkActor or list(vtkActor)) – Static actor/s.

add_to_scene(scene)[source]#

Add this Animation, its actors and sub Animations to the scene

add_to_scene_at(timestamp)[source]#

Set timestamp for adding Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

add_update_callback(callback, prop=None)[source]#

Add a function to be called each time animation is updated This function must accept only one argument which is the current value of the named property.

Parameters:
  • callback (callable) – The function to be called whenever the animation is updated.

  • prop (str, optional, default: None) – The name of the property.

Notes

If no attribute name was provided, current time of the animation will be provided instead of current value for the callback.

property child_animations: list[fury.animation.animation.Animation]#

Return a list of child Animations.

Returns:

List of child Animations of this Animation.

Return type:

list

property current_timestamp#

Return the current time of the animation.

Returns:

The current time of the animation.

Return type:

float

property duration#

Return the duration of the animation.

Returns:

The duration of the animation.

Return type:

float

get_color(t)[source]#

Return the interpolated color.

Parameters:

t (float) – The time to interpolate color value at.

Returns:

The interpolated color.

Return type:

ndarray(1, 3)

get_current_value(attrib)[source]#

Return the value of an attribute at current time.

Parameters:

attrib (str) – The attribute name.

get_keyframes(attrib=None)[source]#

Get a keyframe for a specific or all attributes.

Parameters:

attrib (str, optional, default: None) – The name of the attribute. If None, all keyframes for all set attributes will be returned.

get_opacity(t)[source]#

Return the opacity value.

Parameters:

t (float) – The time to interpolate opacity at.

Returns:

The interpolated opacity.

Return type:

ndarray(1, 1)

get_position(t)[source]#

Return the interpolated position.

Parameters:

t (float) – The time to interpolate position at.

Returns:

The interpolated position.

Return type:

ndarray(1, 3)

get_rotation(t, as_quat=False)[source]#

Return the interpolated rotation.

Parameters:
  • t (float) – the time to interpolate rotation at.

  • as_quat (bool) – Returned rotation will be as quaternion if True.

Returns:

The interpolated rotation as Euler degrees by default.

Return type:

ndarray(1, 3)

get_scale(t)[source]#

Return the interpolated scale.

Parameters:

t (float) – The time to interpolate scale at.

Returns:

The interpolated scale.

Return type:

ndarray(1, 3)

get_value(attrib, timestamp)[source]#

Return the value of an attribute at any given timestamp.

Parameters:
  • attrib (str) – The attribute name.

  • timestamp (float) – The timestamp to interpolate at.

is_inside_scene_at(timestamp)[source]#

Check if the Animation is set to be inside the scene at a specific timestamp.

Returns:

True if the Animation is set to be inside the scene at the given timestamp.

Return type:

bool

Notes

If the parent Animation is set to be out of the scene at that time, all of their child animations will be out of the scene as well.

is_interpolatable(attrib)[source]#

Check whether a property is interpolatable.

Parameters:

attrib (str) – The name of the property.

Returns:

True if the property is interpolatable by the Animation.

Return type:

bool

Notes

True means that it’s safe to use Interpolator.interpolate(t) for the specified property. And False means the opposite.

property loop#

Get loop condition of the current animation.

Returns:

Whether the animation in loop mode (True) or play one mode (False).

Return type:

bool

property parent_animation#

Return the hierarchical parent Animation for current Animation.

Returns:

The parent Animation.

Return type:

Animation

remove_actor(actor)[source]#

Remove an actor from the Animation.

Parameters:

actor (vtkActor) – Actor to be removed from the Animation.

remove_actors()[source]#

Remove all actors from the Animation

remove_animations()[source]#

Remove all child Animations from the Animation

remove_from_scene(scene)[source]#

Remove Animation, its actors and sub Animations from the scene

remove_from_scene_at(timestamp)[source]#

Set timestamp for removing Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

set_color(timestamp, color, **kwargs)[source]#

Set color keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • color (ndarray, shape(1, 3)) – Color keyframe value associated with the timestamp.

set_color_interpolator(interpolator, is_evaluator=False)[source]#

Set the color interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the color keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_color_interpolator(lab_color_interpolator)
set_color_keyframes(keyframes)[source]#

Set a dict of color keyframes at once. Should be in the following form: {timestamp_1: color_1, timestamp_2: color_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and color as values.

Examples

>>> color_keyframes = {1, np.array([1, 0, 1]), 3, np.array([0, 0, 1])}
>>> Animation.set_color_keyframes(color_keyframes)
set_interpolator(attrib, interpolator, is_evaluator=False, **kwargs)[source]#

Set keyframes interpolator for a certain property

Parameters:
  • attrib (str) – The name of the property.

  • interpolator (callable) – The generator function of the interpolator to be used to interpolate/evaluate keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes such as: >>> def get_position(t): >>> return np.array([np.sin(t), np.cos(t) * 5, 5])

  • spline_degree (int, optional) – The degree of the spline in case of setting a spline interpolator.

Notes

If an evaluator is used to set the values of actor’s properties such as position, scale, color, rotation, or opacity, it has to return a value with the same shape as the evaluated property, i.e.: for scale, it has to return an array with shape 1x3, and for opacity, it has to return a 1x1, an int, or a float value.

Examples

>>> Animation.set_interpolator('position', linear_interpolator)
>>> pos_fun = lambda t: np.array([np.sin(t), np.cos(t), 0])
>>> Animation.set_interpolator('position', pos_fun)
set_keyframe(attrib, timestamp, value, update_interpolator=True, **kwargs)[source]#

Set a keyframe for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • timestamp (float) – Timestamp of the keyframe.

  • value (ndarray or float or bool) – Value of the keyframe at the given timestamp.

  • update_interpolator (bool, optional) – Interpolator will be reinitialized if Ture

  • in_cp (ndarray, shape (1, M), optional) – The in control point in case of using cubic Bézier interpolator.

  • out_cp (ndarray, shape (1, M), optional) – The out control point in case of using cubic Bézier interpolator.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

set_keyframes(attrib, keyframes)[source]#

Set multiple keyframes for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • keyframes (dict) – A dict object containing keyframes to be set.

Notes

Keyframes can be on any of the following forms: >>> key_frames_simple = {1: [1, 2, 1], 2: [3, 4, 5]} >>> key_frames_bezier = {1: {‘value’: [1, 2, 1]}, >>> 2: {‘value’: [3, 4, 5], ‘in_cp’: [1, 2, 3]}} >>> pos_keyframes = {1: np.array([1, 2, 3]), 3: np.array([5, 5, 5])} >>> Animation.set_keyframes(‘position’, pos_keyframes)

set_opacity(timestamp, opacity, **kwargs)[source]#

Set opacity keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • opacity (ndarray, shape(1, 3)) – Opacity keyframe value associated with the timestamp.

set_opacity_interpolator(interpolator, is_evaluator=False)[source]#

Set the opacity interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the opacity keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_opacity_interpolator(step_interpolator)
set_opacity_keyframes(keyframes)[source]#

Set a dict of opacity keyframes at once. Should be in the following form: {timestamp_1: opacity_1, timestamp_2: opacity_2}

Parameters:

keyframes (dict(float: ndarray, shape(1, 1) or float or int)) – A dict with timestamps as keys and opacities as values.

Notes

Opacity values should be between 0 and 1.

Examples

>>> opacity = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(opacity)
set_position(timestamp, position, **kwargs)[source]#

Set a position keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • position (ndarray, shape (1, 3)) – Position value

  • in_cp (float) – The control point in case of using cubic Bézier interpolator when time exceeds this timestamp.

  • out_cp (float) – The control point in case of using cubic Bézier interpolator when time precedes this timestamp.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

Notes

in_cp and out_cp only needed when using the cubic bezier interpolation method.

set_position_interpolator(interpolator, is_evaluator=False, **kwargs)[source]#

Set the position interpolator.

Parameters:
  • interpolator (callable) –

    The generator function of the interpolator that would handle the

    position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

  • degree (int) – The degree of the spline interpolation in case of setting the spline_interpolator.

Examples

>>> Animation.set_position_interpolator(spline_interpolator, degree=5)
set_position_keyframes(keyframes)[source]#

Set a dict of position keyframes at once. Should be in the following form: {timestamp_1: position_1, timestamp_2: position_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and positions as values.

Examples

>>> pos_keyframes = {1, np.array([0, 0, 0]), 3, np.array([50, 6, 6])}
>>> Animation.set_position_keyframes(pos_keyframes)
set_rotation(timestamp, rotation, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • rotation (ndarray, shape(1, 3) or shape(1, 4)) – Rotation data in euler degrees with shape(1, 3) or in quaternions with shape(1, 4).

Notes

Euler rotations are executed by rotating first around Z then around X, and finally around Y.

set_rotation_as_vector(timestamp, vector, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • vector (ndarray, shape(1, 3)) – Directional vector that describes the rotation.

set_rotation_interpolator(interpolator, is_evaluator=False)[source]#

Set the rotation interpolator .

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the rotation (orientation) keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_rotation_interpolator(slerp)
set_scale(timestamp, scalar, **kwargs)[source]#

Set a scale keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • scalar (ndarray, shape(1, 3)) – Scale keyframe value associated with the timestamp.

set_scale_interpolator(interpolator, is_evaluator=False)[source]#

Set the scale interpolator.

Parameters:
  • interpolator (callable) – TThe generator function of the interpolator that would handle the scale keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_scale_interpolator(step_interpolator)
set_scale_keyframes(keyframes)[source]#

Set a dict of scale keyframes at once. Should be in the following form: {timestamp_1: scale_1, timestamp_2: scale_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and scales as values.

Examples

>>> scale_keyframes = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(scale_keyframes)
property static_actors#

Return a list of static actors.

Returns:

List of static actors.

Return type:

list

property timeline#

Return the Timeline handling the current animation.

Returns:

The Timeline handling the current animation, None, if there is no associated Timeline.

Return type:

Timeline

update_animation(time=None)[source]#

Update the animation.

Update the animation at a certain time. This will make sure all attributes are calculated and set to the actors at that given time.

Parameters:

time (float or int, optional, default: None) – The time to update animation at. If None, the animation will play without adding it to a Timeline.

update_duration()[source]#

Update and return the duration of the Animation.

Returns:

The duration of the animation.

Return type:

float

update_motion_path()[source]#

Update motion path visualization actor

Camera#

fury.animation.animation.Camera#

alias of vtkCamera

CameraAnimation#

class fury.animation.animation.CameraAnimation(camera=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: Animation

Camera keyframe animation class.

This is used for animating a single camera using a set of keyframes.

camera#

Camera to be animated. If None, active camera will be animated.

Type:

Camera, optional, default: None

length#

the fixed length of the animation. If set to None, the animation will get its duration from the keyframes being set.

Type:

float or int, default: None, optional

loop#

Whether to loop the animation (True) of play once (False).

Type:

bool, optional, default: True

motion_path_res#

the number of line segments used to visualizer the animation’s motion path (visualizing position).

Type:

int, default: None

__init__(camera=None, length=None, loop=True, motion_path_res=None)[source]#
property camera: vtkCamera#

Return the camera assigned to this animation.

Returns:

The camera that is being animated by this CameraAnimation.

Return type:

Camera

get_focal(t)[source]#

Return the interpolated camera’s focal position.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera’s focal position.

Return type:

ndarray(1, 3)

Notes

The returned focal position does not necessarily reflect the current camera’s focal position, but the expected one.

get_view_up(t)[source]#

Return the interpolated camera’s view-up directional vector.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera view-up directional vector.

Return type:

ndarray(1, 3)

Notes

The returned focal position does not necessarily reflect the actual camera view up directional vector, but the expected one.

set_focal(timestamp, position, **kwargs)[source]#

Set camera’s focal position keyframe.

Parameters:
  • timestamp (float) – The time to interpolate opacity at.

  • position (ndarray, shape(1, 3)) – The camera position

set_focal_interpolator(interpolator, is_evaluator=False)[source]#

Set the camera focal position interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera focal position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_focal_keyframes(keyframes)[source]#

Set multiple camera focal position keyframes at once. Should be in the following form: {timestamp_1: focal_1, timestamp_2: focal_1, …}

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera focal positions as values.

Examples

>>> focal_pos = {0, np.array([1, 1, 1]), 3, np.array([20, 0, 0])}
>>> CameraAnimation.set_focal_keyframes(focal_pos)
set_view_up(timestamp, direction, **kwargs)[source]#

Set the camera view-up direction keyframe.

Parameters:
  • timestamp (float) – The time to interpolate at.

  • direction (ndarray, shape(1, 3)) – The camera view-up direction

set_view_up_interpolator(interpolator, is_evaluator=False)[source]#

Set the camera up-view vector animation interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera view-up keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_view_up_keyframes(keyframes)[source]#

Set multiple camera view up direction keyframes. Should be in the following form: {timestamp_1: view_up_1, timestamp_2: view_up_2, …}

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera view up vectors as values.

Examples

>>> view_ups = {0, np.array([1, 0, 0]), 3, np.array([0, 1, 0])}
>>> CameraAnimation.set_view_up_keyframes(view_ups)
update_animation(time=None)[source]#

Update the camera animation.

Parameters:

time (float or int, optional, default: None) – The time to update the camera animation at. If None, the animation will play.

Transform#

fury.animation.animation.Transform#

alias of vtkTransform

defaultdict#

class fury.animation.animation.defaultdict#

Bases: dict

defaultdict(default_factory=None, /, […]) –> dict with default factory

The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.

__init__(*args, **kwargs)#
copy() a shallow copy of D.#
default_factory#

Factory for default value called by __missing__().

line#

fury.animation.animation.line(lines, colors=None, opacity=1, linewidth=1, spline_subdiv=None, lod=True, lod_points=10000, lod_points_size=3, lookup_colormap=None, depth_cue=False, fake_tube=False)[source]#

Create an actor for one or more lines.

Parameters:
  • lines (list of arrays) –

  • colors (array (N, 3), list of arrays, tuple (3,), array (K,)) – If None or False, a standard orientation colormap is used for every line. If one tuple of color is used. Then all streamlines will have the same colour. If an array (N, 3) is given, where N is equal to the number of lines. Then every line is coloured with a different RGB color. If a list of RGB arrays is given then every point of every line takes a different color. If an array (K, 3) is given, where K is the number of points of all lines then every point is colored with a different RGB color. If an array (K,) is given, where K is the number of points of all lines then these are considered as the values to be used by the colormap. If an array (L,) is given, where L is the number of streamlines then these are considered as the values to be used by the colormap per streamline. If an array (X, Y, Z) or (X, Y, Z, 3) is given then the values for the colormap are interpolated automatically using trilinear interpolation.

  • opacity (float, optional) – Takes values from 0 (fully transparent) to 1 (opaque). Default is 1.

  • linewidth (float, optional) – Line thickness. Default is 1.

  • spline_subdiv (int, optional) – Number of splines subdivision to smooth streamtubes. Default is None which means no subdivision.

  • lod (bool, optional) – Use LODActor(level of detail) rather than Actor. Default is True. Level of detail actors do not render the full geometry when the frame rate is low.

  • lod_points (int, optional) – Number of points to be used when LOD is in effect. Default is 10000.

  • lod_points_size (int) – Size of points when lod is in effect. Default is 3.

  • lookup_colormap (vtkLookupTable, optional) – Add a default lookup table to the colormap. Default is None which calls fury.actor.colormap_lookup_table().

  • depth_cue (boolean, optional) – Add a size depth cue so that lines shrink with distance to the camera. Works best with linewidth <= 1.

  • fake_tube (boolean, optional) – Add shading to lines to approximate the look of tubes.

Returns:

v – Line.

Return type:

Actor or LODActor object

Examples

>>> from fury import actor, window
>>> scene = window.Scene()
>>> lines = [np.random.rand(10, 3), np.random.rand(20, 3)]
>>> colors = np.random.rand(2, 3)
>>> c = actor.line(lines, colors)
>>> scene.add(c)
>>> #window.show(scene)

linear_interpolator#

fury.animation.animation.linear_interpolator(keyframes)[source]#

Linear interpolator for keyframes.

This is a general linear interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data to be linearly interpolated.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

perf_counter#

fury.animation.animation.perf_counter() float#

Performance counter for benchmarking.

slerp#

fury.animation.animation.slerp(keyframes)[source]#

Spherical based rotation keyframes interpolator.

A rotation interpolator to be used for rotation keyframes.

Parameters:

keyframes (dict) – Rotation keyframes to be interpolated at any time.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Notes

Rotation keyframes must be in the form of quaternions.

spline_interpolator#

fury.animation.animation.spline_interpolator(keyframes, degree)[source]#

N-th degree spline interpolator for keyframes.

This is a general n-th degree spline interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the spline curve. Data should be on the following format: >>> {1: {‘value’: np.array([…])}, 2: {‘value’: np.array([…])}}

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

step_interpolator#

fury.animation.animation.step_interpolator(keyframes)[source]#

Step interpolator for keyframes.

This is a simple step interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the spline

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

warn#

fury.animation.animation.warn(message, category=None, stacklevel=1, source=None)#

Issue a warning, or maybe ignore it or raise an exception.

euclidean_distances#

fury.animation.helpers.euclidean_distances(points)[source]#

Return a list of euclidean distances of a list of points or values.

Parameters:

points (ndarray) – Array of points or valued to calculate euclidean distances between.

Returns:

A List of euclidean distance between each consecutive points or values.

Return type:

list

get_next_timestamp#

fury.animation.helpers.get_next_timestamp(timestamps, current_time, include_first=False)[source]#

Return the minimum next timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_first (bool, optional, default: False) – If True, even the first timestamp will be considered a valid next timestamp.

Returns:

The next timestamp

Return type:

float or int

get_previous_timestamp#

fury.animation.helpers.get_previous_timestamp(timestamps, current_time, include_last=False)[source]#

Return the maximum previous timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_last (bool, optional, default: False) – If True, even the last timestamp will be considered a valid previous timestamp.

Returns:

The previous timestamp

Return type:

float or int

get_time_tau#

fury.animation.helpers.get_time_tau(t, t0, t1)[source]#

Return a capped time tau between 0 and 1.

Parameters:
  • t (float or int) – Current time to calculate tau for.

  • t0 (float or int) – Lower timestamp of the time period.

  • t1 (float or int) – Higher timestamp of the time period.

Returns:

The time tau

Return type:

float

get_timestamps_from_keyframes#

fury.animation.helpers.get_timestamps_from_keyframes(keyframes)[source]#

Return a sorted array of timestamps given dict of keyframes.

Parameters:

keyframes (dict) – keyframes dict that contains timestamps as keys.

Returns:

Array of sorted timestamps extracted from the keyframes.

Return type:

ndarray

get_values_from_keyframes#

fury.animation.helpers.get_values_from_keyframes(keyframes)[source]#

Return an array of keyframes values sorted using timestamps.

Parameters:

keyframes (dict) – keyframes dict that contains timestamps as keys and data as values.

Returns:

Array of sorted values extracted from the keyframes.

Return type:

ndarray

lerp#

fury.animation.helpers.lerp(v0, v1, t0, t1, t)[source]#

Return a linearly interpolated value.

Parameters:
  • v0 (ndarray or float or int.) – The first value

  • v1 (ndarray or float or int.) – The second value

  • t (float or int) – Current time to interpolate at.

  • t0 (float or int) – Timestamp associated with v0.

  • t1 (float or int) – Timestamp associated with v1.

Returns:

The interpolated value

Return type:

ndarray or float

color_interpolator#

fury.animation.interpolator.color_interpolator(keyframes, rgb2space, space2rgb)[source]#

Custom-space color interpolator.

Interpolate values linearly inside a custom color space.

Parameters:
  • keyframes (dict) – Rotation keyframes to be interpolated at any time.

  • rgb2space (function) –

    A functions that take color value in rgb and return that color

    converted to the targeted space.

  • space2rgb (function) – A functions that take color value in the targeted space and returns that color in rgb space.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

cubic_bezier_interpolator#

fury.animation.interpolator.cubic_bezier_interpolator(keyframes)[source]#

Cubic Bézier interpolator for keyframes.

This is a general cubic Bézier interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframes to be interpolated at any time.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Notes

If no control points are set in the keyframes, The cubic Bézier interpolator will almost behave as a linear interpolator.

cubic_spline_interpolator#

fury.animation.interpolator.cubic_spline_interpolator(keyframes)[source]#

Cubic spline interpolator for keyframes.

This is a general cubic spline interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the cubic spline curve.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

euclidean_distances#

fury.animation.interpolator.euclidean_distances(points)[source]#

Return a list of euclidean distances of a list of points or values.

Parameters:

points (ndarray) – Array of points or valued to calculate euclidean distances between.

Returns:

A List of euclidean distance between each consecutive points or values.

Return type:

list

get_next_timestamp#

fury.animation.interpolator.get_next_timestamp(timestamps, current_time, include_first=False)[source]#

Return the minimum next timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_first (bool, optional, default: False) – If True, even the first timestamp will be considered a valid next timestamp.

Returns:

The next timestamp

Return type:

float or int

get_previous_timestamp#

fury.animation.interpolator.get_previous_timestamp(timestamps, current_time, include_last=False)[source]#

Return the maximum previous timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_last (bool, optional, default: False) – If True, even the last timestamp will be considered a valid previous timestamp.

Returns:

The previous timestamp

Return type:

float or int

get_time_tau#

fury.animation.interpolator.get_time_tau(t, t0, t1)[source]#

Return a capped time tau between 0 and 1.

Parameters:
  • t (float or int) – Current time to calculate tau for.

  • t0 (float or int) – Lower timestamp of the time period.

  • t1 (float or int) – Higher timestamp of the time period.

Returns:

The time tau

Return type:

float

get_timestamps_from_keyframes#

fury.animation.interpolator.get_timestamps_from_keyframes(keyframes)[source]#

Return a sorted array of timestamps given dict of keyframes.

Parameters:

keyframes (dict) – keyframes dict that contains timestamps as keys.

Returns:

Array of sorted timestamps extracted from the keyframes.

Return type:

ndarray

get_values_from_keyframes#

fury.animation.interpolator.get_values_from_keyframes(keyframes)[source]#

Return an array of keyframes values sorted using timestamps.

Parameters:

keyframes (dict) – keyframes dict that contains timestamps as keys and data as values.

Returns:

Array of sorted values extracted from the keyframes.

Return type:

ndarray

hsv2rgb#

fury.animation.interpolator.hsv2rgb(hsv)[source]#

HSV to RGB color space conversion.

Parameters:

hsv ((..., 3, ...) array_like) – The image in HSV format. By default, the final dimension denotes channels.

Returns:

out – The image in RGB format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

hsv_color_interpolator#

fury.animation.interpolator.hsv_color_interpolator(keyframes)[source]#

HSV interpolator for color keyframes

lab2rgb#

fury.animation.interpolator.lab2rgb(lab, illuminant='D65', observer='2')[source]#

Lab to RGB color space conversion.

Parameters:
  • lab ((..., 3, ...) array_like) – The image in Lab format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case sensitive).

  • observer ({"2", "10", "R"}, optional) – The aperture angle of the observer.

Returns:

out – The image in RGB format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

lab_color_interpolator#

fury.animation.interpolator.lab_color_interpolator(keyframes)[source]#

LAB interpolator for color keyframes

lerp#

fury.animation.interpolator.lerp(v0, v1, t0, t1, t)[source]#

Return a linearly interpolated value.

Parameters:
  • v0 (ndarray or float or int.) – The first value

  • v1 (ndarray or float or int.) – The second value

  • t (float or int) – Current time to interpolate at.

  • t0 (float or int) – Timestamp associated with v0.

  • t1 (float or int) – Timestamp associated with v1.

Returns:

The interpolated value

Return type:

ndarray or float

linear_interpolator#

fury.animation.interpolator.linear_interpolator(keyframes)[source]#

Linear interpolator for keyframes.

This is a general linear interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data to be linearly interpolated.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

rgb2hsv#

fury.animation.interpolator.rgb2hsv(rgb)[source]#

RGB to HSV color space conversion. :param rgb: The image in RGB format. By default, the final dimension denotes

channels.

Returns:

out – The image in HSV format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

rgb2lab#

fury.animation.interpolator.rgb2lab(rgb, illuminant='D65', observer='2')[source]#

Conversion from the sRGB color space (IEC 61966-2-1:1999) to the CIE Lab colorspace under the given illuminant and observer.

Parameters:
  • rgb ((..., 3, ...) array_like) – The image in RGB format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case sensitive).

  • observer ({"2", "10", "R"}, optional) – The aperture angle of the observer.

Returns:

out – The image in Lab format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

rgb2xyz#

fury.animation.interpolator.rgb2xyz(rgb)[source]#

RGB to XYZ color space conversion.

Parameters:

rgb ((..., 3, ...) array_like) – The image in RGB format. By default, the final dimension denotes channels.

Returns:

out – The image in XYZ format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

slerp#

fury.animation.interpolator.slerp(keyframes)[source]#

Spherical based rotation keyframes interpolator.

A rotation interpolator to be used for rotation keyframes.

Parameters:

keyframes (dict) – Rotation keyframes to be interpolated at any time.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Notes

Rotation keyframes must be in the form of quaternions.

splev#

fury.animation.interpolator.splev(x, tck, der=0, ext=0)[source]#

Evaluate a B-spline or its derivatives.

Given the knots and coefficients of a B-spline representation, evaluate the value of the smoothing polynomial and its derivatives. This is a wrapper around the FORTRAN routines splev and splder of FITPACK.

Parameters:
  • x (array_like) – An array of points at which to return the value of the smoothed spline or its derivatives. If tck was returned from splprep, then the parameter values, u should be given.

  • tck (3-tuple or a BSpline object) – If a tuple, then it should be a sequence of length 3 returned by splrep or splprep containing the knots, coefficients, and degree of the spline. (Also see Notes.)

  • der (int, optional) – The order of derivative of the spline to compute (must be less than or equal to k, the degree of the spline).

  • ext (int, optional) –

    Controls the value returned for elements of x not in the interval defined by the knot sequence.

    • if ext=0, return the extrapolated value.

    • if ext=1, return 0

    • if ext=2, raise a ValueError

    • if ext=3, return the boundary value.

    The default value is 0.

Returns:

y – An array of values representing the spline function evaluated at the points in x. If tck was returned from splprep, then this is a list of arrays representing the curve in an N-D space.

Return type:

ndarray or list of ndarrays

Notes

Manipulating the tck-tuples directly is not recommended. In new code, prefer using BSpline objects.

See also

splprep, splrep, sproot, spalde, splint, bisplrep, bisplev, BSpline

References

Examples

Examples are given in the tutorial.

spline_interpolator#

fury.animation.interpolator.spline_interpolator(keyframes, degree)[source]#

N-th degree spline interpolator for keyframes.

This is a general n-th degree spline interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the spline curve. Data should be on the following format: >>> {1: {‘value’: np.array([…])}, 2: {‘value’: np.array([…])}}

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

splprep#

fury.animation.interpolator.splprep(x, w=None, u=None, ub=None, ue=None, k=3, task=0, s=None, t=None, full_output=0, nest=None, per=0, quiet=1)[source]#

Find the B-spline representation of an N-D curve.

Given a list of N rank-1 arrays, x, which represent a curve in N-D space parametrized by u, find a smooth approximating spline curve g(u). Uses the FORTRAN routine parcur from FITPACK.

Parameters:
  • x (array_like) – A list of sample vector arrays representing the curve.

  • w (array_like, optional) – Strictly positive rank-1 array of weights the same length as x[0]. The weights are used in computing the weighted least-squares spline fit. If the errors in the x values have standard-deviation given by the vector d, then w should be 1/d. Default is ones(len(x[0])).

  • u (array_like, optional) –

    An array of parameter values. If not given, these values are calculated automatically as M = len(x[0]), where

    v[0] = 0

    v[i] = v[i-1] + distance(x[i], x[i-1])

    u[i] = v[i] / v[M-1]

  • ub (int, optional) – The end-points of the parameters interval. Defaults to u[0] and u[-1].

  • ue (int, optional) – The end-points of the parameters interval. Defaults to u[0] and u[-1].

  • k (int, optional) – Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. 1 <= k <= 5, default is 3.

  • task (int, optional) – If task==0 (default), find t and c for a given smoothing factor, s. If task==1, find t and c for another value of the smoothing factor, s. There must have been a previous call with task=0 or task=1 for the same set of data. If task=-1 find the weighted least square spline for a given set of knots, t.

  • s (float, optional) – A smoothing condition. The amount of smoothness is determined by satisfying the conditions: sum((w * (y - g))**2,axis=0) <= s, where g(x) is the smoothed interpolation of (x,y). The user can use s to control the trade-off between closeness and smoothness of fit. Larger s means more smoothing while smaller values of s indicate less smoothing. Recommended values of s depend on the weights, w. If the weights represent the inverse of the standard-deviation of y, then a good s value should be found in the range (m-sqrt(2*m),m+sqrt(2*m)), where m is the number of data points in x, y, and w.

  • t (int, optional) – The knots needed for task=-1.

  • full_output (int, optional) – If non-zero, then return optional outputs.

  • nest (int, optional) – An over-estimate of the total number of knots of the spline to help in determining the storage space. By default nest=m/2. Always large enough is nest=m+k+1.

  • per (int, optional) – If non-zero, data points are considered periodic with period x[m-1] - x[0] and a smooth periodic spline approximation is returned. Values of y[m-1] and w[m-1] are not used.

  • quiet (int, optional) – Non-zero to suppress messages.

Returns:

  • tck (tuple) – (t,c,k) a tuple containing the vector of knots, the B-spline coefficients, and the degree of the spline.

  • u (array) – An array of the values of the parameter.

  • fp (float) – The weighted sum of squared residuals of the spline approximation.

  • ier (int) – An integer flag about splrep success. Success is indicated if ier<=0. If ier in [1,2,3] an error occurred but was not raised. Otherwise an error is raised.

  • msg (str) – A message corresponding to the integer flag, ier.

See also

splrep, splev, sproot, spalde, splint, bisplrep, bisplev, UnivariateSpline, BivariateSpline, BSpline, make_interp_spline

Notes

See splev for evaluation of the spline and its derivatives. The number of dimensions N must be smaller than 11.

The number of coefficients in the c array is k+1 less than the number of knots, len(t). This is in contrast with splrep, which zero-pads the array of coefficients to have the same length as the array of knots. These additional coefficients are ignored by evaluation routines, splev and BSpline.

References

Examples

Generate a discretization of a limacon curve in the polar coordinates:

>>> import numpy as np
>>> phi = np.linspace(0, 2.*np.pi, 40)
>>> r = 0.5 + np.cos(phi)         # polar coords
>>> x, y = r * np.cos(phi), r * np.sin(phi)    # convert to cartesian

And interpolate:

>>> from scipy.interpolate import splprep, splev
>>> tck, u = splprep([x, y], s=0)
>>> new_points = splev(u, tck)

Notice that (i) we force interpolation by using s=0, (ii) the parameterization, u, is generated automatically. Now plot the result:

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot(x, y, 'ro')
>>> ax.plot(new_points[0], new_points[1], 'r-')
>>> plt.show()

step_interpolator#

fury.animation.interpolator.step_interpolator(keyframes)[source]#

Step interpolator for keyframes.

This is a simple step interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the spline

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

tan_cubic_spline_interpolator#

fury.animation.interpolator.tan_cubic_spline_interpolator(keyframes)[source]#

Cubic spline interpolator for keyframes using tangents. glTF contains additional tangent information for the cubic spline interpolator.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the cubic spline curve.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

xyz2rgb#

fury.animation.interpolator.xyz2rgb(xyz)[source]#

XYZ to RGB color space conversion.

Parameters:

xyz ((..., 3, ...) array_like) – The image in XYZ format. By default, the final dimension denotes channels.

Returns:

out – The image in RGB format. Same dimensions as input.

Return type:

(…, 3, …) ndarray

Notes

Original Implementation from scikit-image package. it can be found at: scikit-image/scikit-image This implementation might have been modified.

xyz_color_interpolator#

fury.animation.interpolator.xyz_color_interpolator(keyframes)[source]#

XYZ interpolator for color keyframes

Animation#

class fury.animation.timeline.Animation(actors=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: object

Keyframe animation class.

Animation is responsible for keyframe animations for a single or a group of actors. It’s used to handle multiple attributes and properties of Fury actors such as transformations, color, and scale. It also accepts custom data and interpolates them, such as temperature. Linear interpolation is used by default to interpolate data between the main keyframes.

actors#

Actor/s to be animated.

Type:

Actor or list[Actor], optional, default: None

length#

the fixed length of the animation. If set to None, the animation will get its duration from the keyframes being set.

Type:

float or int, default: None, optional

loop#

Whether to loop the animation (True) of play once (False).

Type:

bool, optional, default: True

motion_path_res#

the number of line segments used to visualizer the animation’s motion path (visualizing position).

Type:

int, default: None

__init__(actors=None, length=None, loop=True, motion_path_res=None)[source]#
property actors#

Return a list of actors.

Returns:

List of actors controlled by the Animation.

Return type:

list

add(item)[source]#

Add an item to the Animation. This item can be an Actor, Animation, list of Actors, or a list of Animations.

Parameters:

item (Animation, vtkActor, list[Animation], or list[vtkActor]) – Actor/s to be animated by the Animation.

add_actor(actor, static=False)[source]#

Add an actor or list of actors to the Animation.

Parameters:
  • actor (vtkActor or list(vtkActor)) – Actor/s to be animated by the Animation.

  • static (bool) – Indicated whether the actor should be animated and controlled by the animation or just a static actor that gets added to the scene along with the Animation.

add_child_animation(animation)[source]#

Add child Animation or list of Animations.

Parameters:

animation (Animation or list[Animation]) – Animation/s to be added.

add_static_actor(actor)[source]#

Add an actor or list of actors as static actor/s which will not be controlled nor animated by the Animation. All static actors will be added to the scene when the Animation is added to the scene.

Parameters:

actor (vtkActor or list(vtkActor)) – Static actor/s.

add_to_scene(scene)[source]#

Add this Animation, its actors and sub Animations to the scene

add_to_scene_at(timestamp)[source]#

Set timestamp for adding Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

add_update_callback(callback, prop=None)[source]#

Add a function to be called each time animation is updated This function must accept only one argument which is the current value of the named property.

Parameters:
  • callback (callable) – The function to be called whenever the animation is updated.

  • prop (str, optional, default: None) – The name of the property.

Notes

If no attribute name was provided, current time of the animation will be provided instead of current value for the callback.

property child_animations: list[fury.animation.animation.Animation]#

Return a list of child Animations.

Returns:

List of child Animations of this Animation.

Return type:

list

property current_timestamp#

Return the current time of the animation.

Returns:

The current time of the animation.

Return type:

float

property duration#

Return the duration of the animation.

Returns:

The duration of the animation.

Return type:

float

get_color(t)[source]#

Return the interpolated color.

Parameters:

t (float) – The time to interpolate color value at.

Returns:

The interpolated color.

Return type:

ndarray(1, 3)

get_current_value(attrib)[source]#

Return the value of an attribute at current time.

Parameters:

attrib (str) – The attribute name.

get_keyframes(attrib=None)[source]#

Get a keyframe for a specific or all attributes.

Parameters:

attrib (str, optional, default: None) – The name of the attribute. If None, all keyframes for all set attributes will be returned.

get_opacity(t)[source]#

Return the opacity value.

Parameters:

t (float) – The time to interpolate opacity at.

Returns:

The interpolated opacity.

Return type:

ndarray(1, 1)

get_position(t)[source]#

Return the interpolated position.

Parameters:

t (float) – The time to interpolate position at.

Returns:

The interpolated position.

Return type:

ndarray(1, 3)

get_rotation(t, as_quat=False)[source]#

Return the interpolated rotation.

Parameters:
  • t (float) – the time to interpolate rotation at.

  • as_quat (bool) – Returned rotation will be as quaternion if True.

Returns:

The interpolated rotation as Euler degrees by default.

Return type:

ndarray(1, 3)

get_scale(t)[source]#

Return the interpolated scale.

Parameters:

t (float) – The time to interpolate scale at.

Returns:

The interpolated scale.

Return type:

ndarray(1, 3)

get_value(attrib, timestamp)[source]#

Return the value of an attribute at any given timestamp.

Parameters:
  • attrib (str) – The attribute name.

  • timestamp (float) – The timestamp to interpolate at.

is_inside_scene_at(timestamp)[source]#

Check if the Animation is set to be inside the scene at a specific timestamp.

Returns:

True if the Animation is set to be inside the scene at the given timestamp.

Return type:

bool

Notes

If the parent Animation is set to be out of the scene at that time, all of their child animations will be out of the scene as well.

is_interpolatable(attrib)[source]#

Check whether a property is interpolatable.

Parameters:

attrib (str) – The name of the property.

Returns:

True if the property is interpolatable by the Animation.

Return type:

bool

Notes

True means that it’s safe to use Interpolator.interpolate(t) for the specified property. And False means the opposite.

property loop#

Get loop condition of the current animation.

Returns:

Whether the animation in loop mode (True) or play one mode (False).

Return type:

bool

property parent_animation#

Return the hierarchical parent Animation for current Animation.

Returns:

The parent Animation.

Return type:

Animation

remove_actor(actor)[source]#

Remove an actor from the Animation.

Parameters:

actor (vtkActor) – Actor to be removed from the Animation.

remove_actors()[source]#

Remove all actors from the Animation

remove_animations()[source]#

Remove all child Animations from the Animation

remove_from_scene(scene)[source]#

Remove Animation, its actors and sub Animations from the scene

remove_from_scene_at(timestamp)[source]#

Set timestamp for removing Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event.

set_color(timestamp, color, **kwargs)[source]#

Set color keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • color (ndarray, shape(1, 3)) – Color keyframe value associated with the timestamp.

set_color_interpolator(interpolator, is_evaluator=False)[source]#

Set the color interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the color keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_color_interpolator(lab_color_interpolator)
set_color_keyframes(keyframes)[source]#

Set a dict of color keyframes at once. Should be in the following form: {timestamp_1: color_1, timestamp_2: color_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and color as values.

Examples

>>> color_keyframes = {1, np.array([1, 0, 1]), 3, np.array([0, 0, 1])}
>>> Animation.set_color_keyframes(color_keyframes)
set_interpolator(attrib, interpolator, is_evaluator=False, **kwargs)[source]#

Set keyframes interpolator for a certain property

Parameters:
  • attrib (str) – The name of the property.

  • interpolator (callable) – The generator function of the interpolator to be used to interpolate/evaluate keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes such as: >>> def get_position(t): >>> return np.array([np.sin(t), np.cos(t) * 5, 5])

  • spline_degree (int, optional) – The degree of the spline in case of setting a spline interpolator.

Notes

If an evaluator is used to set the values of actor’s properties such as position, scale, color, rotation, or opacity, it has to return a value with the same shape as the evaluated property, i.e.: for scale, it has to return an array with shape 1x3, and for opacity, it has to return a 1x1, an int, or a float value.

Examples

>>> Animation.set_interpolator('position', linear_interpolator)
>>> pos_fun = lambda t: np.array([np.sin(t), np.cos(t), 0])
>>> Animation.set_interpolator('position', pos_fun)
set_keyframe(attrib, timestamp, value, update_interpolator=True, **kwargs)[source]#

Set a keyframe for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • timestamp (float) – Timestamp of the keyframe.

  • value (ndarray or float or bool) – Value of the keyframe at the given timestamp.

  • update_interpolator (bool, optional) – Interpolator will be reinitialized if Ture

  • in_cp (ndarray, shape (1, M), optional) – The in control point in case of using cubic Bézier interpolator.

  • out_cp (ndarray, shape (1, M), optional) – The out control point in case of using cubic Bézier interpolator.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

set_keyframes(attrib, keyframes)[source]#

Set multiple keyframes for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • keyframes (dict) – A dict object containing keyframes to be set.

Notes

Keyframes can be on any of the following forms: >>> key_frames_simple = {1: [1, 2, 1], 2: [3, 4, 5]} >>> key_frames_bezier = {1: {‘value’: [1, 2, 1]}, >>> 2: {‘value’: [3, 4, 5], ‘in_cp’: [1, 2, 3]}} >>> pos_keyframes = {1: np.array([1, 2, 3]), 3: np.array([5, 5, 5])} >>> Animation.set_keyframes(‘position’, pos_keyframes)

set_opacity(timestamp, opacity, **kwargs)[source]#

Set opacity keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • opacity (ndarray, shape(1, 3)) – Opacity keyframe value associated with the timestamp.

set_opacity_interpolator(interpolator, is_evaluator=False)[source]#

Set the opacity interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the opacity keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_opacity_interpolator(step_interpolator)
set_opacity_keyframes(keyframes)[source]#

Set a dict of opacity keyframes at once. Should be in the following form: {timestamp_1: opacity_1, timestamp_2: opacity_2}

Parameters:

keyframes (dict(float: ndarray, shape(1, 1) or float or int)) – A dict with timestamps as keys and opacities as values.

Notes

Opacity values should be between 0 and 1.

Examples

>>> opacity = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(opacity)
set_position(timestamp, position, **kwargs)[source]#

Set a position keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • position (ndarray, shape (1, 3)) – Position value

  • in_cp (float) – The control point in case of using cubic Bézier interpolator when time exceeds this timestamp.

  • out_cp (float) – The control point in case of using cubic Bézier interpolator when time precedes this timestamp.

  • in_tangent (ndarray, shape (1, M), optional) – The in tangent at that position for the cubic spline curve.

  • out_tangent (ndarray, shape (1, M), optional) – The out tangent at that position for the cubic spline curve.

Notes

in_cp and out_cp only needed when using the cubic bezier interpolation method.

set_position_interpolator(interpolator, is_evaluator=False, **kwargs)[source]#

Set the position interpolator.

Parameters:
  • interpolator (callable) –

    The generator function of the interpolator that would handle the

    position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

  • degree (int) – The degree of the spline interpolation in case of setting the spline_interpolator.

Examples

>>> Animation.set_position_interpolator(spline_interpolator, degree=5)
set_position_keyframes(keyframes)[source]#

Set a dict of position keyframes at once. Should be in the following form: {timestamp_1: position_1, timestamp_2: position_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and positions as values.

Examples

>>> pos_keyframes = {1, np.array([0, 0, 0]), 3, np.array([50, 6, 6])}
>>> Animation.set_position_keyframes(pos_keyframes)
set_rotation(timestamp, rotation, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • rotation (ndarray, shape(1, 3) or shape(1, 4)) – Rotation data in euler degrees with shape(1, 3) or in quaternions with shape(1, 4).

Notes

Euler rotations are executed by rotating first around Z then around X, and finally around Y.

set_rotation_as_vector(timestamp, vector, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • vector (ndarray, shape(1, 3)) – Directional vector that describes the rotation.

set_rotation_interpolator(interpolator, is_evaluator=False)[source]#

Set the rotation interpolator .

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the rotation (orientation) keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_rotation_interpolator(slerp)
set_scale(timestamp, scalar, **kwargs)[source]#

Set a scale keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe

  • scalar (ndarray, shape(1, 3)) – Scale keyframe value associated with the timestamp.

set_scale_interpolator(interpolator, is_evaluator=False)[source]#

Set the scale interpolator.

Parameters:
  • interpolator (callable) – TThe generator function of the interpolator that would handle the scale keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_scale_interpolator(step_interpolator)
set_scale_keyframes(keyframes)[source]#

Set a dict of scale keyframes at once. Should be in the following form: {timestamp_1: scale_1, timestamp_2: scale_2}

Parameters:

keyframes (dict) – A dict with timestamps as keys and scales as values.

Examples

>>> scale_keyframes = {1, np.array([1, 1, 1]), 3, np.array([2, 2, 3])}
>>> Animation.set_scale_keyframes(scale_keyframes)
property static_actors#

Return a list of static actors.

Returns:

List of static actors.

Return type:

list

property timeline#

Return the Timeline handling the current animation.

Returns:

The Timeline handling the current animation, None, if there is no associated Timeline.

Return type:

Timeline

update_animation(time=None)[source]#

Update the animation.

Update the animation at a certain time. This will make sure all attributes are calculated and set to the actors at that given time.

Parameters:

time (float or int, optional, default: None) – The time to update animation at. If None, the animation will play without adding it to a Timeline.

update_duration()[source]#

Update and return the duration of the Animation.

Returns:

The duration of the animation.

Return type:

float

update_motion_path()[source]#

Update motion path visualization actor

PlaybackPanel#

class fury.animation.timeline.PlaybackPanel(loop=False, position=(0, 0), width=None)[source]#

Bases: UI

A playback controller that can do essential functionalities. such as play, pause, stop, and seek.

__init__(loop=False, position=(0, 0), width=None)[source]#

Init scene.

Parameters:

position ((float, float)) – Absolute coordinates (x, y) of the lower-left corner of this UI component.

property current_time#

Get current time of the progress slider.

Returns:

Progress slider current value.

Return type:

float

property current_time_str#

Returns current time as a string.

Returns:

Current time formatted as a string in the form:HH:MM:SS.

Return type:

str

property final_time#

Set final progress slider time value.

Returns:

Final time for the progress slider.

Return type:

float

loop()[source]#

Set repeating mode to loop.

pause()[source]#

Pause the playback

play()[source]#

Play the playback

play_once()[source]#

Set repeating mode to repeat once.

property speed#

Returns current speed.

Returns:

Current time formatted as a string in the form:HH:MM:SS.

Return type:

str

stop()[source]#

Stop the playback

property width#

Return the width of the PlaybackPanel

Returns:

The width of the PlaybackPanel.

Return type:

float

Timeline#

class fury.animation.timeline.Timeline(animations=None, playback_panel=False, loop=True, length=None)[source]#

Bases: object

Keyframe animation Timeline.

Timeline is responsible for handling the playback of keyframes animations. It has multiple playback options which makes it easy to control the playback, speed, state of the animation with/without a GUI playback panel.

animations#

Actor/s to be animated directly by the Timeline (main Animation).

Type:

Animation or list[Animation], optional, default: None

playback_panel#

If True, the timeline will have a playback panel set, which can be used to control the playback of the timeline.

Type:

bool, optional

length#
the fixed length of the timeline. If set to None, the timeline will get

its length from the animations that it controls automatically.

Type:

float or int, default: None, optional

loop#

Whether loop playing the timeline or play once.

Type:

bool, optional

__init__(animations=None, playback_panel=False, loop=True, length=None)[source]#
add_animation(animation)[source]#

Add Animation or list of Animations.

Parameters:

animation (Animation or list[Animation] or tuple[Animation]) – Animation/s to be added.

add_to_scene(scene)[source]#

Add Timeline and all of its Animations to the scene

property animations: list[fury.animation.animation.Animation]#

Return a list of Animations.

Returns:

List of Animations controlled by the timeline.

Return type:

list

property current_timestamp#

Get current timestamp of the Timeline.

Returns:

The current time of the Timeline.

Return type:

float

property duration#

Return the duration of the Timeline.

Returns:

The duration of the Timeline.

Return type:

float

property has_playback_panel#

Return whether the Timeline has a playback panel.

Returns:

bool

Return type:

‘True’ if the Timeline has a playback panel. otherwise, ‘False’

property loop#

Get loop condition of the timeline.

Returns:

Whether the playback is in loop mode (True) or play one mode (False).

Return type:

bool

pause()[source]#

Pause the animation

property paused#

Return whether the Timeline is paused.

Returns:

True if the Timeline is paused.

Return type:

bool

play()[source]#

Play the animation

property playing#

Return whether the Timeline is playing.

Returns:

True if the Timeline is playing.

Return type:

bool

remove_from_scene(scene)[source]#

Remove Timeline and all of its Animations to the scene

restart()[source]#

Restart the animation

seek(timestamp)[source]#

Set the current timestamp of the Timeline.

Parameters:

timestamp (float) – The time to seek.

seek_percent(percent)[source]#

Seek a percentage of the Timeline’s final timestamp.

Parameters:

percent (float) – Value from 1 to 100.

property speed#

Return the speed of the timeline’s playback.

Returns:

The speed of the timeline’s playback.

Return type:

float

stop()[source]#

Stop the animation

property stopped#

Return whether the Timeline is stopped.

Returns:

True if Timeline is stopped.

Return type:

bool

update(force=False)[source]#

Update the timeline.

Update the Timeline and all the animations that it controls. As well as the playback of the Timeline (if exists).

Parameters:

force (bool, optional, default: False) – If True, the timeline will update even when the timeline is paused or stopped and hence, more resources will be used.

update_duration()[source]#

Update and return the duration of the Timeline.

Returns:

The duration of the Timeline.

Return type:

float

perf_counter#

fury.animation.timeline.perf_counter() float#

Performance counter for benchmarking.