utils
#
|
Remove the observer with the given id from the actor. |
|
Set Generic input function which takes into account VTK 5 or 6. |
|
Convert Numpy points array to a vtk points array. |
|
Convert Numpy color array to a vtk color array. |
|
Convert numpy array to a vtk cell array. |
|
Convert numpy array to a vtk image data. |
|
Evaluate input_array at the given indices using trilinear interpolation. |
|
Create a vtkPolyData with lines and colors. |
|
Convert vtk polydata to a list of lines ndarrays. |
|
Get triangles (ndarrays Nx3 int) from a vtk polydata. |
|
Get vertices (ndarrays Nx3 int) from a vtk polydata. |
|
Get texture coordinates (ndarrays Nx2 float) from a vtk polydata. |
|
Get vertices normal (ndarrays Nx3 int) from a vtk polydata. |
|
Get vertices tangent (ndarrays Nx3 int) from a vtk polydata. |
|
Get points color (ndarrays Nx3 int) from a vtk polydata. |
|
Get a field from a vtk polydata. |
|
Add a field to a vtk polydata. |
|
Add primitives count to polydata. |
|
Get primitives count from actor's polydata. |
|
Add primitives count to actor's polydata. |
|
Get primitives count from actor's polydata. |
|
Set polydata triangles with a numpy array (ndarrays Nx3 int). |
|
Set polydata vertices with a numpy array (ndarrays Nx3 int). |
|
Set polydata normals with a numpy array (ndarrays Nx3 int). |
|
Set polydata tangents with a numpy array (ndarrays Nx3 int). |
|
Set polydata colors with a numpy array (ndarrays Nx3 int). |
|
Set polydata texture coordinates with a numpy array (ndarrays Nx2 float). |
|
Generate and update polydata normals. |
|
Get vtkPolyDataMapper from a vtkPolyData. |
|
Get actor from a vtkPolyDataMapper. |
|
Get actor from a vtkPolyData. |
|
Get actor from a vtkPolyData. |
|
Transform a vtksource to glyph. |
|
Apply affine matrix affine to the actor act. |
|
Apply affine matrix aff to points pts. |
|
|
|
Convert VTK matrix to numpy array. |
|
Convert a numpy array to a VTK matrix. |
|
Get the bounding box sizes of an actor. |
|
Construct a XY-grid based on the cells content shape. |
|
Create a shallow copy of a given vtkObject object. |
|
Rotate actor around axis by angle. |
|
RGB or RGBA images to VTK arrays. |
|
Normalize a numpy array of 3 component vectors shape=(N, 3). |
|
Calculate normals from vertices and faces. |
Calculate tangents from normals and a 3D vector representing the |
|
|
Determine the winding order of a given set of vertices and a triangle. |
|
Change the vertices order of a given triangle. |
|
Return corrected triangles. |
|
Access to vertices from actor. |
|
Access colors from actor which uses polydata. |
|
Access normals from actor which uses polydata. |
|
Access tangents from actor which uses polydata. |
|
Access array from actor which uses polydata. |
|
Set normals to actor which uses polydata. |
|
Set tangents to actor which uses polydata. |
|
Compute Bounds of actor. |
|
Update actor. |
|
Return Bounds of actor. |
|
Returns the actor wireframe. |
|
Update colors of a surface actor. |
|
Returns a VTK scalar array containing colors information for each one of the points according to the policy defined by the parameter colors. |
|
Method to check if the passed actor is UI or vtkProp3D |
|
Change the origin of an actor to a custom position. |
remove_observer_from_actor#
set_input#
- fury.utils.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) –
- Return type:
vtk_object
Notes
- This can be used in the following way::
from fury.utils import set_input poly_mapper = set_input(PolyDataMapper(), poly_data)
numpy_to_vtk_points#
numpy_to_vtk_colors#
- fury.utils.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_cells#
- fury.utils.numpy_to_vtk_cells(data, *, is_coords=True)[source]#
Convert numpy array to a vtk cell array.
- Parameters:
data (ndarray) – points coordinate or connectivity array (e.g triangles).
is_coords (ndarray) – Select the type of array. default: True.
- Returns:
vtk_cell – connectivity + offset information
- Return type:
vtkCellArray
numpy_to_vtk_image_data#
- fury.utils.numpy_to_vtk_image_data(array, *, spacing=(1.0, 1.0, 1.0), origin=(0.0, 0.0, 0.0), deep=True)[source]#
Convert numpy array to a vtk image data.
- Parameters:
array (ndarray) – pixel coordinate and colors values.
spacing ((float, float, float) (optional)) – sets the size of voxel (unit of space in each direction x,y,z)
origin ((float, float, float) (optional)) – sets the origin at the given point
deep (bool (optional)) – decides the type of copy(ie. deep or shallow)
- Returns:
vtk_image
- Return type:
vtkImageData
map_coordinates_3d_4d#
lines_to_vtk_polydata#
- fury.utils.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
get_polydata_lines#
get_polydata_triangles#
get_polydata_vertices#
get_polydata_tcoord#
get_polydata_normals#
get_polydata_tangents#
get_polydata_colors#
get_polydata_field#
- fury.utils.get_polydata_field(polydata, field_name, *, as_vtk=False)[source]#
Get a field from a vtk polydata.
- Parameters:
polydata (vtkPolyData) –
field_name (str) –
as_vtk (optional) – By default, ndarray is returned.
- Returns:
output – Field data. The return type depends on the value of the as_vtk parameter. None if the field is not found.
- Return type:
ndarray or vtkDataArray
add_polydata_numeric_field#
set_polydata_primitives_count#
get_polydata_primitives_count#
primitives_count_to_actor#
primitives_count_from_actor#
set_polydata_triangles#
set_polydata_vertices#
set_polydata_normals#
set_polydata_tangents#
set_polydata_colors#
set_polydata_tcoords#
update_polydata_normals#
get_polymapper_from_polydata#
get_actor_from_polymapper#
get_actor_from_polydata#
get_actor_from_primitive#
- fury.utils.get_actor_from_primitive(vertices, triangles, *, colors=None, normals=None, backface_culling=True, prim_count=1)[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) or (Nx4) ndarray) – RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1] N is equal to the number of vertices.
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
prim_count (int, optional) – primitives count to be associated with the actor
- Returns:
actor
- Return type:
actor
repeat_sources#
apply_affine_to_actor#
apply_affine#
- fury.utils.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) – Homogeneous 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]]]...)
asbytes#
vtk_matrix_to_numpy#
numpy_to_vtk_matrix#
get_bounding_box_sizes#
get_grid_cells_position#
- fury.utils.get_grid_cells_position(shapes, *, aspect_ratio=1.7777777777777777, dim=None)[source]#
Construct a XY-grid based on the cells content shape.
This function generates the coordinates of every grid cell. The width and height of every cell correspond to the largest width and the largest height respectively. The grid dimensions will automatically be adjusted to respect the given aspect ratio unless they are explicitly specified.
The grid follows a row-major order with the top left corner being at coordinates (0,0,0) and the bottom right corner being at coordinates (nb_cols*cell_width, -nb_rows*cell_height, 0). Note that the X increases while the Y decreases.
- Parameters:
- Returns:
3D coordinates of every grid cell.
- Return type:
ndarray
shallow_copy#
rotate#
rgb_to_vtk#
normalize_v3#
normals_from_v_f#
tangents_from_direction_of_anisotropy#
- fury.utils.tangents_from_direction_of_anisotropy(normals, direction)[source]#
- Calculate tangents from normals and a 3D vector representing the
direction of anisotropy.
- Parameters:
normals (normals, represented as 2D ndarrays (Nx3) (one per vertex)) –
direction (tuple (3,) or array (3,)) –
- Returns:
output – Tangents, represented as 2D ndarrays (Nx3).
- Return type:
array (N, 3)
triangle_order#
- fury.utils.triangle_order(vertices, faces)[source]#
Determine the winding order of a given set of vertices and a triangle.
- Parameters:
vertices (ndarray) – array of vertices making up a shape
faces (ndarray) – array of triangles
- Returns:
order – If the order is counter clockwise (CCW), returns True. Otherwise, returns False.
- Return type:
change_vertices_order#
- fury.utils.change_vertices_order(triangle)[source]#
Change the vertices order of a given triangle.
- Parameters:
triangle (ndarray, shape(1, 3)) – array of 3 vertices making up a triangle
- Returns:
new_triangle – new array of vertices making up a triangle in the opposite winding order of the given parameter
- Return type:
ndarray, shape(1, 3)
fix_winding_order#
- fury.utils.fix_winding_order(vertices, triangles, *, clockwise=False)[source]#
Return corrected triangles.
Given an ordering of the triangle’s three vertices, a triangle can appear to have a clockwise winding or counter-clockwise winding. Clockwise means that the three vertices, in order, rotate clockwise around the triangle’s center.
- Parameters:
vertices (ndarray) – array of vertices corresponding to a shape
triangles (ndarray) – array of triangles corresponding to a shape
clockwise (bool) – triangle order type: clockwise (default) or counter-clockwise.
- Returns:
corrected_triangles – The corrected order of the vert parameter
- Return type:
ndarray
vertices_from_actor#
colors_from_actor#
normals_from_actor#
tangents_from_actor#
array_from_actor#
normals_to_actor#
tangents_to_actor#
compute_bounds#
update_actor#
get_bounds#
represent_actor_as_wireframe#
update_surface_actor_colors#
color_check#
- fury.utils.color_check(pts_len, *, colors=None)[source]#
Returns a VTK scalar array containing colors information for each one of the points according to the policy defined by the parameter colors.
- Parameters:
pts_len (int) – length of points ndarray
colors (None or tuple (3D or 4D) or array/ndarray (N, 3 or 4)) – If None a predefined color is used for each point. If a tuple of color is used. Then all points 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.
- Returns:
color_array (vtkDataArray) – vtk scalar array with name ‘colors’.
global_opacity (float) – returns 1 if the colors array doesn’t contain opacity otherwise -1. If colors array has 4 dimensions, it checks values of the fourth dimension. If the value is the same, then assign it to global_opacity.
is_ui#
set_actor_origin#
- fury.utils.set_actor_origin(actor, *, center=None)[source]#
Change the origin of an actor to a custom position.
- Parameters:
actor (Actor) – The actor object to change origin for.
center (ndarray, optional, default: None) – The new center position. If None, the origin will be set to the mean of the actor’s vertices.