From efb3cccc5d3db19ab05dd62bf1fb6c3330663afe Mon Sep 17 00:00:00 2001 From: Manish Reddy Rakasi Date: Sat, 25 Jan 2025 16:43:23 -0500 Subject: [PATCH] updated actor and uni tests for frustum --- fury/actor.py | 66 +++++++++++++++++++++++++++++++++++++++- fury/tests/test_actor.py | 17 +++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/fury/actor.py b/fury/actor.py index e1f314b14..67bc1e4d3 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -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 ---------- @@ -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, + ) diff --git a/fury/tests/test_actor.py b/fury/tests/test_actor.py index 9528e03ad..1248cf2b4 100644 --- a/fury/tests/test_actor.py +++ b/fury/tests/test_actor.py @@ -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)