Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 145 additions & 2 deletions fury/actor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import numpy as np

from fury.geometry import buffer_to_geometry, create_mesh
from fury.material import _create_mesh_material
from fury.geometry import buffer_to_geometry, create_mesh, create_point
from fury.material import (
_create_mesh_material,
_create_points_material,
)
import fury.primitive as fp


Expand Down Expand Up @@ -1127,3 +1130,143 @@ def star(
material=material,
enable_picking=enable_picking,
)


def point(
centers,
*,
size=4.0,
colors=(1.0, 0.0, 0.0),
material="basic",
map=None,
aa=True,
opacity=1.0,
enable_picking=True,
):
"""Visualize one or many points with different features.

Parameters
----------
centers : ndarray, shape (N, 3).
The positions of the points.
size : float
The size (diameter) of the points in logical pixels.
colors : ndarray (N,3) or (N,4) or tuple (3,) or tuple (4,), optional
RGB or RGBA values in the range [0, 1].
material : str, optional
The material type for the points.
Options are 'basic', 'gaussian'.
map : TextureMap | Texture
The texture map specifying the color for each texture coordinate.
aa : bool, optional
Whether or not the points are anti-aliased in the shader.
opacity : float, optional
Takes values from 0 (fully transparent) to 1 (opaque).
enable_picking : bool, optional
Whether the points should be pickable in a 3D scene.

Returns
-------
point_actor : Actor
An point actor containing the generated points with the specified material
and properties.

Examples
--------
>>> from fury import window, actor
>>> import numpy as np
>>> scene = window.Scene()
>>> centers = np.random.rand(1000, 3) * 10
>>> colors = np.random.rand(1000, 3)
>>> point_actor = actor.point(centers=centers, colors=colors)
>>> scene.add(point_actor)
>>> show_manager = window.ShowManager(scene=scene, size=(600, 600))
>>> show_manager.start()
"""
geo = buffer_to_geometry(
Comment thread
ManishReddyR marked this conversation as resolved.
positions=centers.astype("float32"),
colors=colors.astype("float32"),
)

mat = _create_points_material(
size=size,
material=material,
map=map,
aa=aa,
opacity=opacity,
enable_picking=enable_picking,
)

obj = create_point(geo, mat)
return obj


def marker(
centers,
*,
size=15,
colors=(1.0, 0.0, 0.0),
marker="circle",
edge_color="black",
edge_width=1.0,
opacity=1.0,
enable_picking=True,
):
"""Visualize one or many marker with different features.

Parameters
----------
centers : ndarray, shape (N, 3).
The positions of the markers.
size : float
The size (diameter) of the points in logical pixels.
colors : ndarray (N,3) or (N,4) or tuple (3,) or tuple (4,), optional
RGB or RGBA values in the range [0, 1].
marker : str | MarkerShape
Comment thread
ManishReddyR marked this conversation as resolved.
The shape of the marker.
Options are "●": "circle", "+": "plus", "x": "cross", "♥": "heart",
"✳": "asterix".
edge_color : str | tuple | Color
The color of line marking the edge of the markers.
edge_width : float, optional
The width of the edge of the markers.
opacity : float, optional
Takes values from 0 (fully transparent) to 1 (opaque).
enable_picking : bool, optional
Whether the points should be pickable in a 3D scene.

Returns
-------
marker_actor : Actor
An marker actor containing the generated points with the specified material
and properties.

Examples
--------
>>> from fury import window, actor
>>> import numpy as np
>>> scene = window.Scene()
>>> centers = np.random.rand(1000, 3) * 10
>>> colors = np.random.rand(1000, 3)
>>> marker_actor = actor.marker(centers=centers, colors=colors)
>>> scene.add(marker_actor)
>>> show_manager = window.ShowManager(scene=scene, size=(600, 600))
>>> show_manager.start()
"""
geo = buffer_to_geometry(
Comment thread
ManishReddyR marked this conversation as resolved.
positions=centers.astype("float32"),
colors=colors.astype("float32"),
)

mat = _create_points_material(
material="marker",
size=size,
marker=marker,
edge_color=edge_color,
edge_width=edge_width,
opacity=opacity,
enable_picking=enable_picking,
)

obj = create_point(geo, mat)
return obj
53 changes: 52 additions & 1 deletion fury/geometry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from pygfx import Geometry, Mesh
from fury.lib import (
Geometry,
Mesh,
MeshBasicMaterial,
MeshPhongMaterial,
Points,
PointsGaussianBlobMaterial,
PointsMarkerMaterial,
PointsMaterial,
)


def buffer_to_geometry(positions, **kwargs):
Expand All @@ -19,6 +28,9 @@ def buffer_to_geometry(positions, **kwargs):
geo : Geometry
The geometry object.
"""
if positions is None or positions.size == 0:
raise ValueError("positions array cannot be empty or None.")

geo = Geometry(positions=positions, **kwargs)
return geo

Expand All @@ -39,5 +51,44 @@ def create_mesh(geometry, material):
mesh : Mesh
The mesh object.
"""
if not isinstance(geometry, Geometry):
raise TypeError("geometry must be an instance of Geometry.")

if not isinstance(material, (MeshPhongMaterial, MeshBasicMaterial)):
raise TypeError(
"material must be an instance of MeshPhongMaterial or MeshBasicMaterial."
)

mesh = Mesh(geometry=geometry, material=material)
return mesh


def create_point(geometry, material):
"""
Create a point object.

Parameters
----------
geometry : Geometry
The geometry object.
material : Material
The material object.

Returns
-------
points : Points
The point object.
"""
if not isinstance(geometry, Geometry):
raise TypeError("geometry must be an instance of Geometry.")

if not isinstance(
material, (PointsMaterial, PointsGaussianBlobMaterial, PointsMarkerMaterial)
):
raise TypeError(
"material must be an instance of PointsMaterial, "
"PointsGaussianBlobMaterial or PointsMarkerMaterial."
)

point = Points(geometry=geometry, material=material)
Comment thread
ManishReddyR marked this conversation as resolved.
return point
10 changes: 10 additions & 0 deletions fury/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
Scene: TypeAlias = gfx.Scene
Viewport: TypeAlias = gfx.Viewport

Geometry = gfx.Geometry
Mesh = gfx.Mesh
Points = gfx.Points

MeshBasicMaterial = gfx.MeshBasicMaterial
MeshPhongMaterial = gfx.MeshPhongMaterial
PointsMaterial = gfx.PointsMaterial
PointsGaussianBlobMaterial = gfx.PointsGaussianBlobMaterial
PointsMarkerMaterial = gfx.PointsMarkerMaterial

DirectionalLight = gfx.DirectionalLight
OrbitController = gfx.OrbitController
PerspectiveCamera = gfx.PerspectiveCamera
Expand Down
Loading