actors
#
Module: actors.odf_slicer
#
alias of |
|
|
VTK actor for visualizing slices of ODF field. |
alias of |
|
alias of |
|
|
Apply affine matrix aff to points pts. |
|
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 with a numpy array (ndarrays Nx3 int). |
|
Set polydata triangles with a numpy array (ndarrays Nx3 int). |
|
Set polydata vertices with a numpy array (ndarrays Nx3 int). |
Module: actors.peak
#
alias of |
|
alias of |
|
alias of |
|
|
VTK actor for visualizing slices of ODF field. |
alias of |
|
alias of |
|
|
Apply affine matrix aff to points pts. |
|
Link a numpy array with vertex attribute. |
|
boys 2 rgb cool colormap |
|
set_call_data_type(type) -- convenience decorator to easily set the CallDataType attribute for python function used as observer callback. |
|
Lookup table for the colormap. |
|
Import a Fury shader. |
|
Convert Numpy color array to a vtk color array. |
|
Convert Numpy points array to a vtk points array. |
|
Get Standard orientation 2 rgb colormap. |
|
Apply your own substitutions to the shader creation process. |
Actor
#
- fury.actors.odf_slicer.Actor#
alias of
vtkActor
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:
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]#
- 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).
PolyData
#
- fury.actors.odf_slicer.PolyData#
alias of
vtkPolyData
PolyDataMapper
#
- fury.actors.odf_slicer.PolyDataMapper#
alias of
vtkPolyDataMapper
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#
set_polydata_triangles#
set_polydata_vertices#
Actor
#
- fury.actors.peak.Actor#
alias of
vtkActor
CellArray
#
- fury.actors.peak.CellArray#
alias of
vtkCellArray
Command
#
- fury.actors.peak.Command#
alias of
vtkCommand
PeakActor
#
- class fury.actors.peak.PeakActor(directions, indices, values=None, affine=None, colors=None, lookup_colormap=None, linewidth=1, symmetric=True)[source]#
Bases:
vtkActor
VTK actor for visualizing slices of ODF field.
- Parameters:
directions (ndarray) – Peak directions. The shape of the array should be (X, Y, Z, D, 3).
indices (tuple) – Indices given in tuple(x_indices, y_indices, z_indices) format for mapping 2D ODF array to 3D voxel grid.
values (ndarray, optional) – Peak values. The shape of the array should be (X, Y, Z, D).
affine (array, optional) – 4x4 transformation array from native coordinates to world coordinates.
colors (None or string ('rgb_standard') or tuple (3D or 4D) or) –
- array/ndarray (N, 3 or 4) or array/ndarray (K, 3 or 4) or
array/ndarray(N, ) or array/ndarray (K, )
If None a standard orientation colormap is used for every line. If one tuple of color is used. Then all streamlines will have the same color. If an array (N, 3 or 4) is given, where N is equal to the number of points. Then every point is colored with a different RGB(A) color. If an array (K, 3 or 4) is given, where K is equal to the number of lines. Then every line is colored with a different RGB(A) color. If an array (N, ) is given, where N is the number of points then these are considered as the values to be used by the colormap. If an array (K,) is given, where K is the number of lines then these are considered as the values to be used by the colormap.
lookup_colormap (vtkLookupTable, optional) – Add a default lookup table to the colormap. Default is None which calls
fury.actor.colormap_lookup_table()
.linewidth (float, optional) – Line thickness. Default is 1.
symmetric (bool, optional) – If True, peaks are drawn for both peaks_dirs and -peaks_dirs. Else, peaks are only drawn for directions given by peaks_dirs. Default is True.
- __init__(directions, indices, values=None, affine=None, colors=None, lookup_colormap=None, linewidth=1, symmetric=True)[source]#
- property cross_section#
- property global_opacity#
- property high_ranges#
- property is_range#
- property linewidth#
- property low_ranges#
- property max_centers#
- property min_centers#
PolyData
#
- fury.actors.peak.PolyData#
alias of
vtkPolyData
PolyDataMapper
#
- fury.actors.peak.PolyDataMapper#
alias of
vtkPolyDataMapper
apply_affine#
- fury.actors.peak.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]]]...)
attribute_to_actor#
- fury.actors.peak.attribute_to_actor(actor, arr, attr_name, deep=True)[source]#
Link a numpy array with vertex attribute.
- Parameters:
actor (vtkActor) – Fury actor you want to add the vertex attribute to.
arr (ndarray) – Array to link to vertices.
attr_name (str) – Vertex attribute name. The vtk array will take the same name as the attribute.
deep (bool, optional) – If True a deep copy is applied, otherwise a shallow copy is applied. Default True.
boys2rgb#
- fury.actors.peak.boys2rgb(v)[source]#
boys 2 rgb cool colormap
Maps a given field of undirected lines (line field) to rgb colors using Boy’s Surface immersion of the real projective plane. Boy’s Surface is one of the three possible surfaces obtained by gluing a Mobius strip to the edge of a disk. The other two are the crosscap and Roman surface, Steiner surfaces that are homeomorphic to the real projective plane (Pinkall 1986). The Boy’s surface is the only 3D immersion of the projective plane without singularities. Visit http://www.cs.brown.edu/~cad/rp2coloring for further details. Cagatay Demiralp, 9/7/2008.
Code was initially in matlab and was rewritten in Python for fury by the FURY Team. Thank you Cagatay for putting this online.
- Parameters:
v (array, shape (N, 3) of unit vectors (e.g., principal eigenvectors of) – tensor data) representing one of the two directions of the undirected lines in a line field.
- 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.boys2rgb(v)
calldata_type#
- fury.actors.peak.calldata_type(type)[source]#
set_call_data_type(type) – convenience decorator to easily set the CallDataType attribute for python function used as observer callback. For example:
import vtkmodules.util.calldata_type import vtkmodules.util.vtkConstants import vtkmodules.vtkCommonCore import vtkCommand, vtkLookupTable
@calldata_type(vtkConstants.VTK_STRING) def onError(caller, event, calldata):
print(“caller: %s - event: %s - msg: %s” % (caller.GetClassName(), event, calldata))
lt = vtkLookupTable() lt.AddObserver(vtkCommand.ErrorEvent, onError) lt.SetTableRange(2,1)
colormap_lookup_table#
- fury.actors.peak.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:
LookupTable
import_fury_shader#
- fury.actors.peak.import_fury_shader(shader_file)[source]#
Import a Fury shader.
- Parameters:
shader_file (str) – Filename of shader. The file must be in the fury/shaders directory and must have the one of the supported extensions specified by the Khronos Group (KhronosGroup/glslang).
- Returns:
code – GLSL shader code.
- Return type:
numpy_to_vtk_colors#
- fury.actors.peak.numpy_to_vtk_colors(colors)[source]#
Convert Numpy color array to a vtk color array.
- Parameters:
colors (ndarray) –
- Returns:
vtk_colors
- Return type:
vtkDataArray
Notes
If colors are not already in UNSIGNED_CHAR you may need to multiply by 255.
Examples
>>> import numpy as np >>> from fury.utils import numpy_to_vtk_colors >>> rgb_array = np.random.rand(100, 3) >>> vtk_colors = numpy_to_vtk_colors(255 * rgb_array)
numpy_to_vtk_points#
orient2rgb#
- fury.actors.peak.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)
shader_to_actor#
- fury.actors.peak.shader_to_actor(actor, shader_type, impl_code='', decl_code='', block='valuepass', keep_default=True, replace_first=True, replace_all=False, debug=False)[source]#
Apply your own substitutions to the shader creation process.
A set of string replacements is applied to a shader template. This function let’s apply custom string replacements.
- Parameters:
actor (vtkActor) – Fury actor you want to set the shader code to.
shader_type (str) – Shader type: vertex, fragment
impl_code (str, optional) – Shader implementation code, should be a string or filename. Default None.
decl_code (str, optional) – Shader declaration code, should be a string or filename. Default None.
block (str, optional) – Section name to be replaced. VTK use of heavy string replacements to insert shader and make it flexible. Each section of the shader template have a specific name. For more information: https://vtk.org/Wiki/Shaders_In_VTK. The possible values are: position, normal, light, tcoord, color, clip, camera, prim_id, valuepass. by default valuepass
keep_default (bool, optional) – Keep the default block tag to let VTK replace it with its default behavior. Default True.
replace_first (bool, optional) – If True, apply this change before the standard VTK replacements. Default True.
replace_all (bool, optional) – [description], by default False
debug (bool, optional) – Introduce a small error to debug shader code. Default False.