primitive#

Module dedicated for basic primitives.

This module provides functions to create basic geometric primitives like spheres, boxes, cylinders, etc. that can be used for visualization.

faces_from_sphere_vertices(vertices)

Triangulate a set of vertices on the sphere.

repeat_primitive_function(func, centers, *)

Repeat vertices and triangles of a specific primitive function.

repeat_primitive(vertices, faces, centers, *)

Repeat vertices and triangles of a specific primitive shape.

prim_square()

Return vertices and triangles for a square geometry.

prim_box([detailed])

Return vertices and triangles for a box geometry.

prim_sphere(*[, name, gen_faces, phi, theta])

Provide vertices and triangles of the spheres.

prim_superquadric([roundness, sphere_name])

Provide vertices and triangles of a superquadric.

prim_tetrahedron()

Return vertices and triangles for a tetrahedron.

prim_icosahedron()

Return vertices and triangles for an icosahedron.

prim_rhombicuboctahedron()

Return vertices and triangles for a rhombicuboctahedron.

prim_star(*[, dim])

Return vertices and triangles for a 5-pointed star (2D or 3D).

prim_triangularprism()

Return vertices and triangle for a regular triangular prism.

prim_pentagonalprism()

Return vertices and triangles for a pentagonal prism.

prim_octagonalprism()

Return vertices and triangle for an octagonal prism.

prim_frustum()

Return vertices and triangles for a square frustum prism.

prim_cylinder(*[, radius, height, sectors, ...])

Return vertices and triangles for a cylinder.

prim_arrow(*[, height, resolution, ...])

Return vertices and triangles for arrow geometry.

prim_cone(*[, radius, height, sectors])

Return vertices and triangles of a cone.

prim_disk(*[, radius, sectors])

Return vertices and triangles for a disk.

prim_triangle()

Return vertices and triangles for a triangle geometry.

prim_ring(*[, inner_radius, outer_radius, ...])

Return vertices and triangles for a ring geometry.

faces_from_sphere_vertices#

fury.primitive.faces_from_sphere_vertices(vertices)[source]#

Triangulate a set of vertices on the sphere.

Parameters:

vertices (ndarray, shape (M, 3)) – XYZ coordinates of vertices on the sphere.

Returns:

Indices into vertices; forms triangular faces.

Return type:

ndarray, shape (N, 3)

repeat_primitive_function#

fury.primitive.repeat_primitive_function(func, centers, *, func_args=None, directions=(1, 0, 0), colors=(1, 0, 0), scales=1)[source]#

Repeat vertices and triangles of a specific primitive function.

It could be seen as a glyph. The primitive function should generate and return vertices and faces.

Parameters:
  • func (callable) – Primitive function.

  • centers (ndarray, shape (N, 3)) – Positions for repeated primitives.

  • func_args (list or None, optional) – Primitive function arguments/parameters.

  • directions (ndarray, shape (N, 3) or tuple (3,), optional) – Orientation vectors for the primitives.

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

  • scales (ndarray, shape (N,) or (N, 3) or float or int, optional) – Scaling factors for the primitives.

Returns:

  • big_vertices (ndarray) – Expanded vertices at the centers positions.

  • big_triangles (ndarray) – Expanded triangles that compose the repeated primitives.

  • big_colors (ndarray) – Expanded colors applied to all vertices/faces.

repeat_primitive#

fury.primitive.repeat_primitive(vertices, faces, centers, *, directions=None, colors=(1, 0, 0), scales=1, have_tiled_verts=False)[source]#

Repeat vertices and triangles of a specific primitive shape.

It could be seen as a glyph.

Parameters:
  • vertices (ndarray) – Vertices coordinates to duplicate at the centers positions.

  • faces (ndarray) – Triangles that compose the shape to duplicate.

  • centers (ndarray, shape (N, 3)) – Positions for repeated primitives.

  • directions (ndarray, shape (N, 3) or tuple (3,), optional) – Orientation vectors for the primitives.

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

  • scales (ndarray, shape (N,) or (N, 3) or float or int, optional) – Scaling factors for the primitives.

  • have_tiled_verts (bool, optional) – Option to control if vertices need to be duplicated or not.

Returns:

  • big_vertices (ndarray) – Expanded vertices at the centers positions.

  • big_triangles (ndarray) – Expanded triangles that compose the repeated primitives.

  • big_colors (ndarray) – Expanded colors applied to all vertices/faces.

  • big_centers (ndarray) – Expanded centers for all vertices/faces.

prim_square#

fury.primitive.prim_square()[source]#

Return vertices and triangles for a square geometry.

Returns:

  • vertices (ndarray, shape (4, 3)) – Coordinates of the 4 vertices that compose the square.

  • triangles (ndarray, shape (2, 3)) – Indices of the 2 triangles that compose the square.

prim_box#

fury.primitive.prim_box(detailed=True)[source]#

Return vertices and triangles for a box geometry.

Parameters:

detailed (bool, optional) – If True, returns 24 vertices (no shared vertices between orthogonal faces). If False, returns 8 unique vertices.

Returns:

  • vertices (ndarray) – Array of vertex coordinates.

  • triangles (ndarray) – Array of triangle indices.

prim_sphere#

fury.primitive.prim_sphere(*, name='symmetric362', gen_faces=False, phi=None, theta=None)[source]#

Provide vertices and triangles of the spheres.

Parameters:
  • name (str, optional) – Which sphere to use, one of: * ‘symmetric362’ * ‘symmetric642’ * ‘symmetric724’ * ‘repulsion724’ * ‘repulsion100’ * ‘repulsion200’

  • gen_faces (bool, optional) – If True, triangulate a set of vertices on the sphere to get the faces. Otherwise, load the saved faces from a file.

  • phi (int, optional) – Number of points in the latitude direction.

  • theta (int, optional) – Number of points in the longitude direction.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the sphere.

  • triangles (ndarray) – Triangles that compose the sphere.

Examples

>>> import numpy as np
>>> from fury.primitive import prim_sphere
>>> verts, faces = prim_sphere(name='symmetric362')
>>> verts.shape == (362, 3)
True
>>> faces.shape == (720, 3)
True

prim_superquadric#

fury.primitive.prim_superquadric(roundness=(1, 1), sphere_name='symmetric362')[source]#

Provide vertices and triangles of a superquadric.

Parameters:
  • roundness (tuple of float, optional) – Parameters (Phi and Theta) that control the shape of the superquadric.

  • sphere_name (str, optional) – Which sphere to use as a base, one of: * ‘symmetric362’ * ‘symmetric642’ * ‘symmetric724’ * ‘repulsion724’ * ‘repulsion100’ * ‘repulsion200’

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the superquadric.

  • triangles (ndarray) – Triangles that compose the superquadric.

Examples

>>> import numpy as np
>>> from fury.primitive import prim_superquadric
>>> verts, faces = prim_superquadric(roundness=(1, 1))
>>> verts.shape == (362, 3)
True
>>> faces.shape == (720, 3)
True

prim_tetrahedron#

fury.primitive.prim_tetrahedron()[source]#

Return vertices and triangles for a tetrahedron.

This shape has a side length of two units.

Returns:

  • vertices (ndarray, shape (4, 3)) – Coordinates of the 4 vertices.

  • triangles (ndarray, shape (4, 3)) – Indices of the 4 triangles representing the tetrahedron.

prim_icosahedron#

fury.primitive.prim_icosahedron()[source]#

Return vertices and triangles for an icosahedron.

Returns:

  • vertices (ndarray, shape (12, 3)) – Coordinates of the 12 vertices of the icosahedron.

  • triangles (ndarray, shape (20, 3)) – Indices of the 20 triangles representing the icosahedron.

prim_rhombicuboctahedron#

fury.primitive.prim_rhombicuboctahedron()[source]#

Return vertices and triangles for a rhombicuboctahedron.

Returns:

  • vertices (ndarray, shape (24, 3)) – Coordinates of the 24 vertices of the rhombicuboctahedron.

  • triangles (ndarray, shape (44, 3)) – Indices of the 44 triangles representing the rhombicuboctahedron.

prim_star#

fury.primitive.prim_star(*, dim=2)[source]#

Return vertices and triangles for a 5-pointed star (2D or 3D).

Parameters:

dim (int, optional) – Dimension of the star, either 2 or 3.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the star.

  • triangles (ndarray) – Triangles that compose the star.

prim_triangularprism#

fury.primitive.prim_triangularprism()[source]#

Return vertices and triangle for a regular triangular prism.

Returns:

  • vertices (ndarray) – Vertices coords that compose our prism.

  • triangles (ndarray) – Triangles that compose our prism.

prim_pentagonalprism#

fury.primitive.prim_pentagonalprism()[source]#

Return vertices and triangles for a pentagonal prism.

Returns:

  • vertices (ndarray) – Vertices coords that compose our pentagonal prism.

  • triangles (ndarray) – Triangles that compose our pentagonal prism.

prim_octagonalprism#

fury.primitive.prim_octagonalprism()[source]#

Return vertices and triangle for an octagonal prism.

Returns:

  • vertices (ndarray) – Vertices coords that compose our octagonal prism.

  • triangles (ndarray) – Triangles that compose our octagonal prism.

prim_frustum#

fury.primitive.prim_frustum()[source]#

Return vertices and triangles for a square frustum prism.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the frustum prism.

  • triangles (ndarray) – Triangles that compose the frustum prism.

prim_cylinder#

fury.primitive.prim_cylinder(*, radius=0.5, height=1, sectors=36, capped=True)[source]#

Return vertices and triangles for a cylinder.

Parameters:
  • radius (float, optional) – Radius of the cylinder.

  • height (float, optional) – Height of the cylinder.

  • sectors (int, optional) – Number of sectors in the cylinder. Must be greater than 7.

  • capped (bool, optional) – Whether the cylinder is capped at both ends or open.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the cylinder.

  • triangles (ndarray) – Triangles that compose the cylinder.

Raises:

prim_arrow#

fury.primitive.prim_arrow(*, height=1.0, resolution=10, tip_length=0.35, tip_radius=0.1, shaft_radius=0.03)[source]#

Return vertices and triangles for arrow geometry.

Parameters:
  • height (float, optional) – Height of the arrow.

  • resolution (int, optional) – Resolution of the arrow.

  • tip_length (float, optional) – Length of the arrow tip.

  • tip_radius (float, optional) – Radius of the arrow tip.

  • shaft_radius (float, optional) – Radius of the arrow shaft.

Returns:

  • vertices (ndarray) – Vertices coordinates of the arrow.

  • triangles (ndarray) – Triangles that compose the arrow.

prim_cone#

fury.primitive.prim_cone(*, radius=0.5, height=1, sectors=10)[source]#

Return vertices and triangles of a cone.

Parameters:
  • radius (float, optional) – Radius of the cone.

  • height (float, optional) – Height of the cone.

  • sectors (int, optional) – Number of sectors in the cone. Must be greater than 2.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the cone.

  • triangles (ndarray) – Triangles that compose the cone.

Raises:

ValueError – If sectors is less than 3.

prim_disk#

fury.primitive.prim_disk(*, radius=0.5, sectors=36)[source]#

Return vertices and triangles for a disk.

Parameters:
  • radius (float, optional) – Radius of the disk.

  • sectors (int, optional) – Number of triangle sectors forming the disk.

Returns:

  • vertices (ndarray) – Vertices coordinates that compose the disk.

  • triangles (ndarray) – Triangles that compose the disk.

Raises:

prim_triangle#

fury.primitive.prim_triangle()[source]#

Return vertices and triangles for a triangle geometry.

Returns:

  • vertices (ndarray, shape (3, 3)) – Coordinates of the 3 vertices that compose the triangle.

  • triangles (ndarray, shape (1, 3)) – Indices of the 1 triangle that composes the geometry.

prim_ring#

fury.primitive.prim_ring(*, inner_radius=0.5, outer_radius=1, radial_segments=1, circumferential_segments=32)[source]#

Return vertices and triangles for a ring geometry.

Parameters:
  • inner_radius (float, optional) – The inner radius of the ring (radius of the hole).

  • outer_radius (float, optional) – The outer radius of the ring.

  • radial_segments (int, optional) – Number of segments along the radial direction.

  • circumferential_segments (int, optional) – Number of segments around the circumference.

Returns:

  • vertices (ndarray, shape (3, 3)) – Coordinates of the 3 vertices that compose the triangle.

  • triangles (ndarray, shape (1, 3)) – Indices of the 1 triangle that composes the geometry.

Raises:

ValueError – If radial_segments is less than 1. If circumferential_segments is less than 3. If inner_radius is not between 0 and outer_radius.