Skip to content

Commit

Permalink
updated actor and uni tests for frustum
Browse files Browse the repository at this point in the history
  • Loading branch information
ManishReddyR committed Jan 25, 2025
1 parent a059abd commit efb3ccc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
66 changes: 65 additions & 1 deletion fury/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def square(
material="phong",
enable_picking=True,
):
"""Visualize one or many boxes with different features.
"""Visualize one or many squares with different features.
Parameters
----------
Expand Down Expand Up @@ -379,3 +379,67 @@ def square(
material=material,
enable_picking=enable_picking,
)


def frustum(
centers,
*,
directions=(0, 0, 0),
colors=(1, 1, 1),
scales=(1, 1, 1),
opacity=None,
material="phong",
enable_picking=True,
):
"""Visualize one or many frustums with different features.
Parameters
----------
centers : ndarray, shape (N, 3)
Box positions.
directions : ndarray, shape (N, 3), optional
The orientation vector of the box.
colors : ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,), optional
RGB or RGBA (for opacity) R, G, B and A should be at the range [0, 1].
scales : int or ndarray (N,3) or tuple (3,), optional
The size of the box in each dimension. If a single value is provided,
the same size will be used for all boxes.
opacity : float, optional
Takes values from 0 (fully transparent) to 1 (opaque).
If both `opacity` and RGBA are provided, the final alpha will be:
final_alpha = alpha_in_RGBA * opacity
material : str, optional
The material type for the boxes. Options are 'phong' and 'basic'.
enable_picking : bool, optional
Whether the boxes should be pickable in a 3D scene.
Returns
-------
mesh_actor : Actor
A mesh actor containing the generated boxes, with the specified
material and properties.
Examples
--------
>>> from fury import window, actor
>>> import numpy as np
>>> scene = window.Scene()
>>> centers = np.random.rand(5, 3) * 10
>>> colors = np.random.rand(5, 3)
>>> square_actor = actor.square(centers=centers, colors=colors)
>>> scene.add(square_actor)
>>> show_manager = window.ShowManager(scene=scene, size=(600, 600))
>>> show_manager.start()
"""
vertices, faces = fp.prim_frustum()
return actor_from_primitive(
vertices,
faces,
centers=centers,
colors=colors,
scales=scales,
directions=directions,
opacity=opacity,
material=material,
enable_picking=enable_picking,
)
17 changes: 17 additions & 0 deletions fury/tests/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ def test_square():

assert square_actor.prim_count == 1
scene.remove(square_actor)


def test_frustum():
scene = window.Scene()
centers = np.array([[0, 0, 0]])
colors = np.array([[1, 0, 0]])

frustum_actor = actor.frustum(centers=centers, colors=colors)
scene.add(frustum_actor)

npt.assert_array_equal(frustum_actor.local.position, centers[0])

mean_vertex = np.mean(frustum_actor.geometry.positions.view, axis=0)
npt.assert_array_almost_equal(mean_vertex, centers[0])

assert frustum_actor.prim_count == 1
scene.remove(frustum_actor)

0 comments on commit efb3ccc

Please sign in to comment.