actor

Module that provide actors to render.

Container([layout])

Provides functionalities for grouping multiple actors using a given layout.

apply_affine(aff, pts)

Apply affine matrix aff to points pts.

arrow(centers, directions, colors[, …])

Visualize one or many arrow with differents features.

axes([scale, colorx, colory, colorz, opacity])

Create an actor with the coordinate’s system axes where red = x, green = y, blue = z.

billboard(centers[, colors, scale, vs_dec, …])

Create a billboard actor.

box(centers, directions, colors[, size, …])

Visualize one or many Box with different features.

colormap_lookup_table([scale_range, …])

Lookup table for the colormap.

cone(centers, directions, colors[, heights, …])

Visualize one or many cones with different features.

contour_from_label(data[, affine, color])

Generate surface actor from a labeled Array.

contour_from_roi(data[, affine, color, opacity])

Generate surface actor from a binary ROI.

create_colormap(v[, name, auto])

Create colors from a specific colormap and return it as an array of shape (N,3) where every row gives the corresponding r,g,b value.

cube(centers, directions, colors[, heights, …])

Visualize one or many cube with different features.

cylinder(centers, directions, colors[, …])

Visualize one or many cylinder with different features.

dots(points[, color, opacity, dot_size])

Create one or more 3d points.

figure(pic[, interpolation])

Return a figure as an image actor

get_actor_from_primitive(vertices, triangles)

Get actor from a vtkPolyData.

grid(actors[, captions, caption_offset, …])

Creates a grid of actors that lies in the xy-plane.

label([text, pos, scale, color])

Create a label actor.

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

Create an actor for one or more lines.

lines_to_vtk_polydata(lines[, colors])

Create a vtkPolyData with lines and colors.

load_image(filename[, as_vtktype, use_pillow])

Load an image.

numpy_to_vtk_matrix(array)

Convert a numpy array to a VTK matrix.

odf_slicer(odfs[, affine, mask, sphere, …])

Slice spherical fields in native or world coordinates

orient2rgb(v)

Get Standard orientation 2 rgb colormap.

peak_slicer(peaks_dirs[, peaks_values, …])

Visualize peak directions as given from peaks_from_model.

point(points, colors[, _opacity, …])

Visualize points as sphere glyphs

repeat_sources(centers, colors[, …])

Transform a vtksource to glyph.

rgb_to_vtk(data)

RGB or RGBA images to VTK arrays.

scalar_bar([lookup_table, title])

Default scalar bar actor for a given colormap (colorbar)

set_input(vtk_object, inp)

Set Generic input function which takes into account VTK 5 or 6.

set_polydata_triangles(polydata, triangles)

Set polydata triangles with a numpy array (ndarrays Nx3 int).

set_polydata_vertices(polydata, vertices)

Set polydata vertices with a numpy array (ndarrays Nx3 int).

shallow_copy(vtk_object)

Create a shallow copy of a given vtkObject object.

slicer(data[, affine, value_range, opacity, …])

Cut 3D scalar or rgb volumes into 2D images.

sphere(centers, colors[, radii, theta, phi, …])

Visualize one or many spheres with different colors and radii

streamtube(lines[, colors, opacity, …])

Use streamtubes to visualize polylines

superquadric(centers[, roundness, …])

Visualize one or many superquadrics with different features.

surface(vertices[, faces, colors, smooth, …])

Generates a surface actor from an array of vertices The color and smoothness of the surface can be customized by specifying the type of subdivision algorithm and the number of subdivisions.

tensor_slicer(evals, evecs[, affine, mask, …])

Slice many tensors as ellipsoids in native or world coordinates.

text_3d(text[, position, color, font_size, …])

Generate 2D text that lives in the 3D world

texture(rgb[, interp])

Map an RGB or RGBA texture on a plane

texture_on_sphere(rgb[, theta, phi, interpolate])

Container

class fury.actor.Container(layout=<fury.layout.Layout object>)[source]

Bases: object

Provides functionalities for grouping multiple actors using a given layout.

anchor

Anchor of this container used when laying out items in a container. The anchor point is relative to the center of the container. Default: (0, 0, 0).

Type

3-tuple of float

padding

Padding around this container bounding box. The 6-tuple represents (pad_x_neg, pad_x_pos, pad_y_neg, pad_y_pos, pad_z_neg, pad_z_pos). Default: (0, 0, 0, 0, 0, 0)

Type

6-tuple of float

__init__(layout=<fury.layout.Layout object>)[source]
Parameters

layout (fury.layout.Layout object) – Items of this container will be arranged according to layout.

AddPosition(position)[source]
GetBounds()[source]

Get the bounds of the container.

GetCenter()[source]

Get the center of the bounding box.

GetLength()[source]

Get the length of bounding box diagonal.

GetPosition()[source]
GetVisibility()[source]
NewInstance()[source]
SetPosition(position)[source]
SetVisibility(visibility)[source]
ShallowCopy(other)[source]
add(*items, **kwargs)[source]

Adds some items to this container.

Parameters
  • items (vtkProp3D objects) – Items to add to this container.

  • borrow (bool) – If True the items are added as-is, otherwise a shallow copy is made first. If you intend to reuse the items elsewhere you should set borrow=False. Default: True.

add_to_scene(ren)[source]

Adds the items of this container to a given renderer.

clear()[source]

Clears all items of this container.

property items
update()[source]

Updates the position of the items of this container.

apply_affine

fury.actor.apply_affine(aff, pts)[source]

Apply affine matrix aff to points pts.

Returns result of application of aff to the right of pts. The coordinate dimension of pts should be the last. For the 3D case, aff will be shape (4,4) and pts will have final axis length 3 - maybe it will just be N by 3. The return value is the transformed points, in this case:: res = np.dot(aff[:3,:3], pts.T) + aff[:3,3:4] transformed_pts = res.T This routine is more general than 3D, in that aff can have any shape (N,N), and pts can have any shape, as long as the last dimension is for the coordinates, and is therefore length N-1.

Parameters
  • aff ((N, N) array-like) – Homogenous affine, for 3D points, will be 4 by 4. Contrary to first appearance, the affine will be applied on the left of pts.

  • pts ((.., N-1) array-like) – Points, where the last dimension contains the coordinates of each point. For 3D, the last dimension will be length 3.

Returns

transformed_pts – transformed points

Return type

(.., N-1) array

Notes

Copied from nibabel to remove dependency.

Examples

>>> aff = np.array([[0,2,0,10],[3,0,0,11],[0,0,4,12],[0,0,0,1]])
>>> pts = np.array([[1,2,3],[2,3,4],[4,5,6],[6,7,8]])
>>> apply_affine(aff, pts) 
array([[14, 14, 24],
       [16, 17, 28],
       [20, 23, 36],
       [24, 29, 44]]...)
Just to show that in the simple 3D case, it is equivalent to:
>>> (np.dot(aff[:3,:3], pts.T) + aff[:3,3:4]).T 
array([[14, 14, 24],
       [16, 17, 28],
       [20, 23, 36],
       [24, 29, 44]]...)
But `pts` can be a more complicated shape:
>>> pts = pts.reshape((2,2,3))
>>> apply_affine(aff, pts) 
array([[[14, 14, 24],
        [16, 17, 28]],

       [[20, 23, 36],
        [24, 29, 44]]]...)

arrow

fury.actor.arrow(centers, directions, colors, heights=1.0, resolution=10, tip_length=0.35, tip_radius=0.1, shaft_radius=0.03, vertices=None, faces=None)[source]

Visualize one or many arrow with differents features.

Parameters
  • centers (ndarray, shape (N, 3)) – Arrow positions

  • directions (ndarray, shape (N, 3)) – The orientation vector of the arrow.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • heights (ndarray, shape (N)) – The height of the arrow.

  • resolution (int) – The resolution of the arrow.

  • tip_length (float) – The tip size of the arrow (default: 0.35)

  • tip_radius (float) – the tip radius of the arrow (default: 0.1)

  • shaft_radius (float) – The shaft radius of the arrow (default: 0.03)

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the arrow.

  • faces (ndarray, shape (M, 3)) – If faces is None then a arrow is created based on directions, heights and resolution. If not then a arrow is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> directions = np.random.rand(5, 3)
>>> heights = np.random.rand(5)
>>> arrow_actor = actor.arrow(centers, directions, (1, 1, 1), heights)
>>> scene.add(arrow_actor)
>>> # window.show(scene)

axes

fury.actor.axes(scale=(1, 1, 1), colorx=(1, 0, 0), colory=(0, 1, 0), colorz=(0, 0, 1), opacity=1)[source]

Create an actor with the coordinate’s system axes where red = x, green = y, blue = z.

Parameters
  • scale (tuple (3,)) – Axes size e.g. (100, 100, 100). Default is (1, 1, 1).

  • colorx (tuple (3,)) – x-axis color. Default red (1, 0, 0).

  • colory (tuple (3,)) – y-axis color. Default green (0, 1, 0).

  • colorz (tuple (3,)) – z-axis color. Default blue (0, 0, 1).

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

Returns

Return type

vtkActor

billboard

fury.actor.billboard(centers, colors=(0, 255, 0), scale=1, vs_dec=None, vs_impl=None, fs_dec=None, fs_impl=None, gs_dec=None, gs_impl=None)[source]

Create a billboard actor.

Billboards are 2D elements incrusted in a 3D world. It offers you the possibility to draw differents shapes/elements at the shader level.

Parameters
  • centers (ndarray, shape (N, 3)) – Superquadrics positions

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • scale (ndarray, shape (N) or (N,3) or float or int, optional) – The height of the cone.

  • vs_dec (str or list of str, optional) – vertex shaders code that contains all variable/function delarations

  • vs_impl (str or list of str, optional) – vertex shaders code that contains all variable/function implementation

  • fs_dec (str or list of str, optional) – Fragment shaders code that contains all variable/function delarations

  • fs_impl (str or list of str, optional) – Fragment shaders code that contains all variable/function implementation

  • gs_dec (str or list of str, optional) – Geometry shaders code that contains all variable/function delarations

  • gs_impl (str or list of str, optional) – Geometry shaders code that contains all variable/function mplementation

Returns

Return type

vtkActor

box

fury.actor.box(centers, directions, colors, size=(1, 2, 3), heights=1, vertices=None, faces=None)[source]

Visualize one or many Box with different features.

Parameters
  • centers (ndarray, shape (N, 3)) – Box positions

  • directions (ndarray, shape (N, 3)) – The orientation vector of the box.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • size (tuple (3,)) – Box lengths on each direction (x, y, z), default(1, 2, 3)

  • heights (ndarray, shape (N)) – The height of the arrow.

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the sphere.

  • faces (ndarray, shape (M, 3)) – If faces is None then a sphere is created based on theta and phi angles If not then a sphere is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> dirs = np.random.rand(5, 3)
>>> heights = np.random.rand(5)
>>> box_actor = actor.box(centers, dirs, (1, 1, 1), heights=heights)
>>> scene.add(box_actor)
>>> # window.show(scene)

colormap_lookup_table

fury.actor.colormap_lookup_table(scale_range=(0, 1), hue_range=(0.8, 0), saturation_range=(1, 1), value_range=(0.8, 0.8))[source]

Lookup table for the colormap.

Parameters
  • scale_range (tuple) – It can be anything e.g. (0, 1) or (0, 255). Usually it is the mininum and maximum value of your data. Default is (0, 1).

  • hue_range (tuple of floats) – HSV values (min 0 and max 1). Default is (0.8, 0).

  • saturation_range (tuple of floats) – HSV values (min 0 and max 1). Default is (1, 1).

  • value_range (tuple of floats) – HSV value (min 0 and max 1). Default is (0.8, 0.8).

Returns

lookup_table

Return type

vtkLookupTable

cone

fury.actor.cone(centers, directions, colors, heights=1.0, resolution=10, vertices=None, faces=None)[source]

Visualize one or many cones with different features.

Parameters
  • centers (ndarray, shape (N, 3)) – Cone positions

  • directions (ndarray, shape (N, 3)) – The orientation vector of the cone.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • heights (ndarray, shape (N)) – The height of the cone.

  • resolution (int) – The resolution of the cone.

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the cone.

  • faces (ndarray, shape (M, 3)) – If faces is None then a cone is created based on directions, heights and resolution. If not then a cone is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> directions = np.random.rand(5, 3)
>>> heights = np.random.rand(5)
>>> cone_actor = actor.cone(centers, directions, (1, 1, 1), heights)
>>> scene.add(cone_actor)
>>> # window.show(scene)

contour_from_label

fury.actor.contour_from_label(data, affine=None, color=None)[source]

Generate surface actor from a labeled Array.

The color and opacity of individual surfaces can be customized.

Parameters
  • data (array, shape (X, Y, Z)) – A labeled array file that will be binarized and displayed.

  • affine (array, shape (4, 4)) – Grid to space (usually RAS 1mm) transformation matrix. Default is None. If None then the identity matrix is used.

  • color ((N, 3) or (N, 4) ndarray) – RGB/RGBA values in [0,1]. Default is None. If None then random colors are used. Alpha channel is set to 1 by default.

Returns

contour_assembly – Array surface object displayed in space coordinates as calculated by the affine parameter in the order of their roi ids.

Return type

vtkAssembly

contour_from_roi

fury.actor.contour_from_roi(data, affine=None, color=array([1, 0, 0]), opacity=1)[source]

Generate surface actor from a binary ROI.

The color and opacity of the surface can be customized.

Parameters
  • data (array, shape (X, Y, Z)) – An ROI file that will be binarized and displayed.

  • affine (array, shape (4, 4)) – Grid to space (usually RAS 1mm) transformation matrix. Default is None. If None then the identity matrix is used.

  • color ((1, 3) ndarray) – RGB values in [0,1].

  • opacity (float) – Opacity of surface between 0 and 1.

Returns

contour_assembly – ROI surface object displayed in space coordinates as calculated by the affine parameter.

Return type

vtkAssembly

create_colormap

fury.actor.create_colormap(v, name='plasma', auto=True)[source]

Create colors from a specific colormap and return it as an array of shape (N,3) where every row gives the corresponding r,g,b value. The colormaps we use are similar with those of matplotlib.

Parameters
  • v ((N,) array) – vector of values to be mapped in RGB colors according to colormap

  • name (str.) – Name of the colormap. Currently implemented: ‘jet’, ‘blues’, ‘accent’, ‘bone’ and matplotlib colormaps if you have matplotlib installed. For example, we suggest using ‘plasma’, ‘viridis’ or ‘inferno’. ‘jet’ is popular but can be often misleading and we will deprecate it the future.

  • auto (bool,) – if auto is True then v is interpolated to [0, 10] from v.min() to v.max()

Notes

FURY supports a few colormaps for those who do not use Matplotlib, for more colormaps consider downloading Matplotlib (see matplotlib.org).

cube

fury.actor.cube(centers, directions, colors, heights=1, vertices=None, faces=None)[source]

Visualize one or many cube with different features.

Parameters
  • centers (ndarray, shape (N, 3)) – Cube positions

  • directions (ndarray, shape (N, 3)) – The orientation vector of the cube.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • heights (ndarray, shape (N)) – The height of the arrow.

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the sphere.

  • faces (ndarray, shape (M, 3)) – If faces is None then a sphere is created based on theta and phi angles If not then a sphere is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> dirs = np.random.rand(5, 3)
>>> heights = np.random.rand(5)
>>> cube_actor = actor.cube(centers, dirs, (1, 1, 1), heights=heights)
>>> scene.add(cube_actor)
>>> # window.show(scene)

cylinder

fury.actor.cylinder(centers, directions, colors, radius=0.05, heights=1, capped=False, resolution=6, vertices=None, faces=None)[source]

Visualize one or many cylinder with different features.

Parameters
  • centers (ndarray, shape (N, 3)) – Cylinder positions

  • directions (ndarray, shape (N, 3)) – The orientation vector of the cylinder.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • radius (float) – cylinder radius, default: 1

  • heights (ndarray, shape (N)) – The height of the arrow.

  • capped (bool) – Turn on/off whether to cap cylinder with polygons. Default (False)

  • resolution (int) – Number of facets used to define cylinder.

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the sphere.

  • faces (ndarray, shape (M, 3)) – If faces is None then a sphere is created based on theta and phi angles If not then a sphere is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> dirs = np.random.rand(5, 3)
>>> heights = np.random.rand(5)
>>> actor = actor.cylinder(centers, dirs, (1, 1, 1), heights=heights)
>>> scene.add(actor)
>>> # window.show(scene)

dots

fury.actor.dots(points, color=(1, 0, 0), opacity=1, dot_size=5)[source]

Create one or more 3d points.

Parameters
  • points (ndarray, (N, 3)) –

  • color (tuple (3,)) –

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

  • dot_size (int) –

Returns

Return type

vtkActor

figure

fury.actor.figure(pic, interpolation='nearest')[source]

Return a figure as an image actor

Parameters
  • pic (filename or numpy RGBA array) –

  • interpolation (str) – Options are nearest, linear or cubic. Default is nearest.

Returns

image_actor

Return type

vtkImageActor

get_actor_from_primitive

fury.actor.get_actor_from_primitive(vertices, triangles, colors=None, normals=None, backface_culling=True)[source]

Get actor from a vtkPolyData.

Parameters
  • vertices ((Mx3) ndarray) – XYZ coordinates of the object

  • triangles ((Nx3) ndarray) – Indices into vertices; forms triangular faces.

  • colors ((Nx3) ndarray) – N is equal to the number of lines. Every line is coloured with a different RGB color.

  • normals ((Nx3) ndarray) – normals, represented as 2D ndarrays (Nx3) (one per vertex)

  • backface_culling (bool) – culling of polygons based on orientation of normal with respect to camera. If backface culling is True, polygons facing away from camera are not drawn. Default: True

Returns

actor

Return type

actor

grid

fury.actor.grid(actors, captions=None, caption_offset=(0, -100, 0), cell_padding=0, cell_shape='rect', aspect_ratio=1.7777777777777777, dim=None)[source]

Creates a grid of actors that lies in the xy-plane.

Parameters
  • actors (list of vtkProp3D objects) – Actors to be layout in a grid manner.

  • captions (list of vtkProp3D objects or list of str) – Objects serving as captions (can be any vtkProp3D object, not necessarily text). There should be one caption per actor. By default, there are no captions.

  • caption_offset (tuple of float (optional)) – Tells where to position the caption w.r.t. the center of its associated actor. Default: (0, -100, 0).

  • cell_padding (tuple of 2 floats or float) – Each grid cell will be padded according to (pad_x, pad_y) i.e. horizontally and vertically. Padding is evenly distributed on each side of the cell. If a single float is provided then both pad_x and pad_y will have the same value.

  • cell_shape (str) – Specifies the desired shape of every grid cell. ‘rect’ ensures the cells are the tightest. ‘square’ ensures the cells are as wide as high. ‘diagonal’ ensures the content of the cells can be rotated without colliding with content of the neighboring cells.

  • aspect_ratio (float) – Aspect ratio of the grid (width/height). Default: 16:9.

  • dim (tuple of int) – Dimension (nb_rows, nb_cols) of the grid. If provided, aspect_ratio will be ignored.

Returns

Object that represents the grid containing all the actors and captions, if any.

Return type

fury.actor.Container object

label

fury.actor.label(text='Origin', pos=(0, 0, 0), scale=(0.2, 0.2, 0.2), color=(1, 1, 1))[source]

Create a label actor.

This actor will always face the camera

Parameters
  • text (str) – Text for the label.

  • pos ((3,) array_like, optional) – Left down position of the label.

  • scale ((3,) array_like) – Changes the size of the label.

  • color ((3,) array_like) – Label color as (r,g,b) tuple.

Returns

l – Label.

Return type

vtkActor object

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> l = actor.label(text='Hello')
>>> scene.add(l)
>>> #window.show(scene)

line

fury.actor.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 vtkLODActor(level of detail) rather than vtkActor. 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

vtkActor or vtkLODActor 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)

lines_to_vtk_polydata

fury.actor.lines_to_vtk_polydata(lines, colors=None)[source]

Create a vtkPolyData with lines and colors.

Parameters
  • lines (list) – list of N curves represented as 2D ndarrays

  • 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.

Returns

  • poly_data (vtkPolyData)

  • color_is_scalar (bool, true if the color array is a single scalar) – Scalar array could be used with a colormap lut None if no color was used

load_image

fury.actor.load_image(filename, as_vtktype=False, use_pillow=True)[source]

Load an image.

Parameters
  • filename (str) – should be png, bmp, jpeg or jpg files

  • as_vtktype (bool, optional) – if True, return vtk output otherwise an ndarray. Default False.

  • use_pillow (bool, optional) – Use pillow python library to load the files. Default True

Returns

image – desired image array

Return type

ndarray or vtk output

numpy_to_vtk_matrix

fury.actor.numpy_to_vtk_matrix(array)[source]

Convert a numpy array to a VTK matrix.

odf_slicer

fury.actor.odf_slicer(odfs, affine=None, mask=None, sphere=None, scale=2.2, norm=True, radial_scale=True, opacity=1.0, colormap='blues', global_cm=False)[source]

Slice spherical fields in native or world coordinates

Parameters
  • odfs (ndarray) – 4D array of spherical functions

  • affine (array) – 4x4 transformation array from native coordinates to world coordinates

  • mask (ndarray) – 3D mask

  • sphere (Sphere) – a sphere

  • scale (float) – Distance between spheres.

  • norm (bool) – Normalize sphere_values.

  • radial_scale (bool) – Scale sphere points according to odf values.

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

  • colormap (None or str) – If None then white color is used. Otherwise the name of colormap is given. Matplotlib colormaps are supported (e.g., ‘inferno’).

  • global_cm (bool) – If True the colormap will be applied in all ODFs. If False it will be applied individually at each voxel (default False).

Returns

actor – Spheres

Return type

vtkActor

orient2rgb

fury.actor.orient2rgb(v)[source]

Get Standard orientation 2 rgb colormap.

v : array, shape (N, 3) of vectors not necessarily normalized

Returns

c – given in V.

Return type

array, shape (N, 3) matrix of rgb colors corresponding to the vectors

Examples

>>> from fury import colormap
>>> v = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
>>> c = colormap.orient2rgb(v)

peak_slicer

fury.actor.peak_slicer(peaks_dirs, peaks_values=None, mask=None, affine=None, colors=(1, 0, 0), opacity=1.0, linewidth=1, lod=False, lod_points=10000, lod_points_size=3)[source]

Visualize peak directions as given from peaks_from_model.

Parameters
  • peaks_dirs (ndarray) – Peak directions. The shape of the array can be (M, 3) or (X, M, 3) or (X, Y, M, 3) or (X, Y, Z, M, 3)

  • peaks_values (ndarray) – Peak values. The shape of the array can be (M, ) or (X, M) or (X, Y, M) or (X, Y, Z, M)

  • affine (array) – 4x4 transformation array from native coordinates to world coordinates

  • mask (ndarray) – 3D mask

  • colors (tuple or None) – Default red color. If None then every peak gets an orientation color in similarity to a DEC map.

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

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

  • lod (bool) – Use vtkLODActor(level of detail) rather than vtkActor. Default is False. Level of detail actors do not render the full geometry when the frame rate is low.

  • lod_points (int) – 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.

Returns

Return type

vtkActor

point

fury.actor.point(points, colors, _opacity=1.0, point_radius=0.1, theta=8, phi=8)[source]

Visualize points as sphere glyphs

Parameters
  • points (ndarray, shape (N, 3)) –

  • colors (ndarray (N,3) or tuple (3,)) –

  • point_radius (float) –

  • theta (int) –

  • phi (int) –

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

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> pts = np.random.rand(5, 3)
>>> point_actor = actor.point(pts, window.colors.coral)
>>> scene.add(point_actor)
>>> # window.show(scene)

repeat_sources

fury.actor.repeat_sources(centers, colors, active_scalars=1.0, directions=None, source=None, vertices=None, faces=None)[source]

Transform a vtksource to glyph.

rgb_to_vtk

fury.actor.rgb_to_vtk(data)[source]

RGB or RGBA images to VTK arrays.

Parameters

data (ndarray) – Shape can be (X, Y, 3) or (X, Y, 4)

Returns

Return type

vtkImageData

scalar_bar

fury.actor.scalar_bar(lookup_table=None, title=' ')[source]

Default scalar bar actor for a given colormap (colorbar)

Parameters
  • lookup_table (vtkLookupTable or None) – If None then colormap_lookup_table is called with default options.

  • title (str) –

Returns

scalar_bar

Return type

vtkScalarBarActor

set_input

fury.actor.set_input(vtk_object, inp)[source]

Set Generic input function which takes into account VTK 5 or 6.

Parameters
  • vtk_object (vtk object) –

  • inp (vtkPolyData or vtkImageData or vtkAlgorithmOutput) –

Returns

Return type

vtk_object

Notes

This can be used in the following way::

from fury.utils import set_input poly_mapper = set_input(vtk.vtkPolyDataMapper(), poly_data)

set_polydata_triangles

fury.actor.set_polydata_triangles(polydata, triangles)[source]

Set polydata triangles with a numpy array (ndarrays Nx3 int).

Parameters
  • polydata (vtkPolyData) –

  • triangles (array (N, 3)) – triangles, represented as 2D ndarrays (Nx3)

set_polydata_vertices

fury.actor.set_polydata_vertices(polydata, vertices)[source]

Set polydata vertices with a numpy array (ndarrays Nx3 int).

Parameters
  • polydata (vtkPolyData) –

  • vertices (vertices, represented as 2D ndarrays (Nx3)) –

shallow_copy

fury.actor.shallow_copy(vtk_object)[source]

Create a shallow copy of a given vtkObject object.

slicer

fury.actor.slicer(data, affine=None, value_range=None, opacity=1.0, lookup_colormap=None, interpolation='linear', picking_tol=0.025)[source]

Cut 3D scalar or rgb volumes into 2D images.

Parameters
  • data (array, shape (X, Y, Z) or (X, Y, Z, 3)) – A grayscale or rgb 4D volume as a numpy array. If rgb then values expected on the range [0, 255].

  • affine (array, shape (4, 4)) – Grid to space (usually RAS 1mm) transformation matrix. Default is None. If None then the identity matrix is used.

  • value_range (None or tuple (2,)) – If None then the values will be interpolated from (data.min(), data.max()) to (0, 255). Otherwise from (value_range[0], value_range[1]) to (0, 255).

  • opacity (float, optional) – Opacity of 0 means completely transparent and 1 completely visible.

  • lookup_colormap (vtkLookupTable, optional) – If None (default) then a grayscale map is created.

  • interpolation (string, optional) – If ‘linear’ (default) then linear interpolation is used on the final texture mapping. If ‘nearest’ then nearest neighbor interpolation is used on the final texture mapping.

  • picking_tol (float, optional) – The tolerance for the vtkCellPicker, specified as a fraction of rendering window size.

Returns

image_actor – An object that is capable of displaying different parts of the volume as slices. The key method of this object is display_extent where one can input grid coordinates and display the slice in space (or grid) coordinates as calculated by the affine parameter.

Return type

ImageActor

sphere

fury.actor.sphere(centers, colors, radii=1.0, theta=16, phi=16, vertices=None, faces=None)[source]

Visualize one or many spheres with different colors and radii

Parameters
  • centers (ndarray, shape (N, 3)) – Spheres positions

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • radii (float or ndarray, shape (N,)) – Sphere radius

  • theta (int) –

  • phi (int) –

  • vertices (ndarray, shape (N, 3)) – The point cloud defining the sphere.

  • faces (ndarray, shape (M, 3)) – If faces is None then a sphere is created based on theta and phi angles If not then a sphere is created with the provided vertices and faces.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3)
>>> sphere_actor = actor.sphere(centers, window.colors.coral)
>>> scene.add(sphere_actor)
>>> # window.show(scene)

streamtube

fury.actor.streamtube(lines, colors=None, opacity=1, linewidth=0.1, tube_sides=9, lod=True, lod_points=10000, lod_points_size=3, spline_subdiv=None, lookup_colormap=None)[source]

Use streamtubes to visualize polylines

Parameters
  • lines (list) – list of N curves represented as 2D ndarrays

  • 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) – Default is 0.01.

  • tube_sides (int, optional) – Default is 9.

  • lod (bool, optional) – Use vtkLODActor(level of detail) rather than vtkActor. 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, optional) – Size of points when lod is in effect. Default is 3.

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

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

Examples

>>> import numpy as np
>>> 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.streamtube(lines, colors)
>>> scene.add(c)
>>> #window.show(scene)

Notes

Streamtubes can be heavy on GPU when loading many streamlines and therefore, you may experience slow rendering time depending on system GPU. A solution to this problem is to reduce the number of points in each streamline. In Dipy we provide an algorithm that will reduce the number of points on the straighter parts of the streamline but keep more points on the curvier parts. This can be used in the following way:

from dipy.tracking.distances import approx_polygon_track
lines = [approx_polygon_track(line, 0.2) for line in lines]

Alternatively we suggest using the line actor which is much more efficient.

superquadric

fury.actor.superquadric(centers, roundness=(1, 1), directions=(1, 0, 0), colors=(255, 0, 0), scale=1)[source]

Visualize one or many superquadrics with different features.

Parameters
  • centers (ndarray, shape (N, 3)) – Superquadrics positions

  • roundness (ndarray, shape (N, 2) or tuple/list (2,), optional) – parameters (Phi and Theta) that control the shape of the superquadric

  • directions (ndarray, shape (N, 3) or tuple (3,), optional) – The orientation vector of the cone.

  • colors (ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,)) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1]

  • scale (ndarray, shape (N) or (N,3) or float or int, optional) – The height of the cone.

Returns

Return type

vtkActor

Examples

>>> from fury import window, actor
>>> scene = window.Scene()
>>> centers = np.random.rand(3, 3) * 10
>>> directions = np.random.rand(3, 3)
>>> scale = np.random.rand(5)
>>> roundness = np.array([[1, 1], [1, 2], [2, 1]])
>>> sq_actor = actor.superquadric(centers, roundness=roundness,
...                               directions=directions,
...                               colors=colors, scale=scale)
>>> scene.add(sq_actor)
>>> # window.show(scene)

surface

fury.actor.surface(vertices, faces=None, colors=None, smooth=None, subdivision=3)[source]

Generates a surface actor from an array of vertices The color and smoothness of the surface can be customized by specifying the type of subdivision algorithm and the number of subdivisions.

Parameters
  • vertices (array, shape (X, Y, Z)) – The point cloud defining the surface.

  • faces (array) – An array of precomputed triangulation for the point cloud. It is an optional parameter, it is computed locally if None

  • colors ((N, 3) array) – Specifies the colors associated with each vertex in the vertices array. Optional parameter, if not passed, all vertices are colored white

  • smooth (string - "loop" or "butterfly") – Defines the type of subdivision to be used for smoothing the surface

  • subdivision (integer, default = 3) – Defines the number of subdivisions to do for each triangulation of the point cloud. The higher the value, smoother the surface but at the cost of higher computation

Returns

surface_actor – A vtkActor visualizing the final surface computed from the point cloud is returned.

Return type

vtkActor

tensor_slicer

fury.actor.tensor_slicer(evals, evecs, affine=None, mask=None, sphere=None, scale=2.2, norm=True, opacity=1.0, scalar_colors=None)[source]

Slice many tensors as ellipsoids in native or world coordinates.

Parameters
  • evals ((3,) or (X, 3) or (X, Y, 3) or (X, Y, Z, 3) ndarray) – eigenvalues

  • evecs ((3, 3) or (X, 3, 3) or (X, Y, 3, 3) or (X, Y, Z, 3, 3) ndarray) – eigenvectors

  • affine (array) – 4x4 transformation array from native coordinates to world coordinates*

  • mask (ndarray) – 3D mask

  • sphere (Sphere) – a sphere

  • scale (float) – Distance between spheres.

  • norm (bool) – Normalize sphere_values.

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

  • scalar_colors ((3,) or (X, 3) or (X, Y, 3) or (X, Y, Z, 3) ndarray) – RGB colors used to show the tensors Default None, color the ellipsoids using color_fa

Returns

actor – Ellipsoid

Return type

vtkActor

text_3d

fury.actor.text_3d(text, position=(0, 0, 0), color=(1, 1, 1), font_size=12, font_family='Arial', justification='left', vertical_justification='bottom', bold=False, italic=False, shadow=False)[source]

Generate 2D text that lives in the 3D world

Parameters
  • text (str) –

  • position (tuple) –

  • color (tuple) –

  • font_size (int) –

  • font_family (str) –

  • justification (str) – Left, center or right (default left)

  • vertical_justification (str) – Bottom, middle or top (default bottom)

  • bold (bool) –

  • italic (bool) –

  • shadow (bool) –

Returns

Return type

textActor3D

texture

fury.actor.texture(rgb, interp=True)[source]

Map an RGB or RGBA texture on a plane

Parameters
  • rgb (ndarray) – Input 2D RGB or RGBA array. Dtype should be uint8.

  • interp (bool) – Interpolate between grid centers. Default True.

Returns

Return type

vtkActor

texture_on_sphere

fury.actor.texture_on_sphere(rgb, theta=60, phi=60, interpolate=True)[source]