actors

Module: actors.odf_slicer

OdfSlicerActor(odfs, vertices, faces, …[, …])

VTK actor for visualizing slices of ODF field.

apply_affine(aff, pts)

Apply affine matrix aff to points pts.

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.

set_polydata_colors(polydata, colors[, …])

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

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

OdfSlicerActor

class fury.actors.odf_slicer.OdfSlicerActor(odfs, vertices, faces, indices, scale, norm, radial_scale, shape, global_cm, colormap, opacity, affine=None, B=None)[source]

Bases: vtkmodules.vtkRenderingCore.vtkActor

VTK actor for visualizing slices of ODF field.

Parameters
  • odfs (ndarray) – SF or SH coefficients 2-dimensional array.

  • vertices (ndarray) – The sphere vertices used for SH to SF projection.

  • faces (ndarray) – Indices of sphere vertices forming triangles. Should be ordered clockwise (see fury.utils.fix_winding_order).

  • indices (tuple) – Indices given in tuple(x_indices, y_indices, z_indices) format for mapping 2D ODF array to 3D voxel grid.

  • scale (float) – Multiplicative factor to apply to ODF amplitudes.

  • norm (bool) – Normalize SF amplitudes so that the maximum ODF amplitude per voxel along a direction is 1.

  • radial_scale (bool) – Scale sphere points by ODF values.

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

  • colormap (None or str) – The name of the colormap to use. Matplotlib colormaps are supported (e.g., ‘inferno’). If None then a RGB colormap is used.

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

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

  • B (ndarray (n_coeffs, n_vertices)) – Optional SH to SF matrix for projecting odfs given in SH coefficents on the sphere. If None, then the input is assumed to be expressed in SF coefficients.

__init__(odfs, vertices, faces, indices, scale, norm, radial_scale, shape, global_cm, colormap, opacity, affine=None, B=None)[source]

Initialize self. See help(type(self)) for accurate signature.

display(x=None, y=None, z=None)[source]

Display a slice along x, y, or z axis.

display_extent(x1, x2, y1, y2, z1, z2)[source]

Set visible volume from x1 (inclusive) to x2 (inclusive), y1 (inclusive) to y2 (inclusive), z1 (inclusive) to z2 (inclusive).

set_opacity(opacity)[source]

Set opacity value of ODFs to display.

slice_along_axis(slice_index, axis='zaxis')[source]

Slice ODF field at given slice_index along axis in [‘xaxis’, ‘yaxis’, zaxis’].

update_sphere(vertices, faces, B)[source]

Dynamically change the sphere used for SH to SF projection.

apply_affine

fury.actors.odf_slicer.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]]]...)

create_colormap

fury.actors.odf_slicer.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, 1] 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).

set_polydata_colors

fury.actors.odf_slicer.set_polydata_colors(polydata, colors, array_name='colors')[source]

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

Parameters
  • polydata (vtkPolyData) –

  • colors (colors, represented as 2D ndarrays (Nx3)) – colors are uint8 [0,255] RGB for each points

set_polydata_triangles

fury.actors.odf_slicer.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.actors.odf_slicer.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)) –