Skip to content

Commit

Permalink
added tests and fixed some docstrings, also added to lib.py
Browse files Browse the repository at this point in the history
  • Loading branch information
robinroy03 committed Mar 12, 2024
1 parent 724ee56 commit 6a84176
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
24 changes: 16 additions & 8 deletions fury/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3978,26 +3978,34 @@ def __init__(self, negx, negy, negz, posx, posy, posz):
posz : ndarray
Input 2D RGB or RGBA array. Dtype should be uint8.
|----|
| +Y |
|----|----|----|----|
| -X | +Z | +X | -Z |
|----|----|----|----|
| -Y |
|----|
"""

self.planes = [PlaneSource() for _ in range(6)]

self.plane_centers = [
(0, 0.5, 0),
(-0.5, 0.5, 0.5),
(0, 0, 0.5),
(0, 1, 0.5),
(0, 0.5, 1),
(0, 0.5, 0),
(0.5, 0.5, 0.5),
(-0.5, 0.5, 0.5),
(0, 1, 0.5),
(0, 0.5, 1)
]

self.plane_normals = [
(0, 0, 1),
(0, 1, 0),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(1, 0, 0),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]

for plane, center, normal in zip(
Expand Down Expand Up @@ -4052,7 +4060,7 @@ def __init__(self, negx, negy, negz, posx, posy, posz):
def get_actor(self):
"""Returns
-------
assembled_actor : Actor
assembled_actor : Assembly
"""

Expand Down
2 changes: 2 additions & 0 deletions fury/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
WindowToImageFilter = rcvtk.vtkWindowToImageFilter
#: class for InteractorStyle
InteractorStyle = rcvtk.vtkInteractorStyle
#: class for PropCollection
PropCollection = rcvtk.vtkPropCollection
#: class for PropPicker
PropPicker = rcvtk.vtkPropPicker
#: class for PointPicker
Expand Down
51 changes: 51 additions & 0 deletions fury/tests/test_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from fury.actor import grid
from fury.decorators import skip_linux, skip_osx, skip_win
from fury.deprecator import ExpiredDeprecationError
from fury.lib import Assembly, PropCollection

# Allow import, but disable doctests if we don't have dipy
from fury.optpkg import optional_package
Expand Down Expand Up @@ -1881,3 +1882,53 @@ def test_actors_primitives_count():
primitives_count = test_case[2]
act = act_func(**args)
npt.assert_equal(primitives_count_from_actor(act), primitives_count)


def test_texturedcube(interactive=False):

arr_255 = np.full((720, 1280), 255, dtype=np.uint8)
arr_0 = np.full((720, 1280), 0, dtype=np.uint8)

arr_white = np.full((720, 1280, 3), 255, dtype=np.uint8)
arr_red = np.dstack((arr_255, arr_0, arr_0))
arr_green = np.dstack((arr_0, arr_255, arr_0))
arr_blue = np.dstack((arr_0, arr_0, arr_255))
arr_yellow = np.dstack((arr_255, arr_255, arr_0))
arr_aqua = np.dstack((arr_0, arr_255, arr_255))

cube = actor.TexturedCube(arr_white,
arr_red,
arr_green,
arr_blue,
arr_yellow,
arr_aqua)

cube_actor = cube.get_actor()

# testing whether the returned is an Assembled Actor Object
assert type(cube_actor) is type(Assembly())

# testing whether there are 6 different planes
plane_actors = PropCollection()
cube_actor.GetActors(plane_actors)

assert plane_actors.GetNumberOfItems() == 6

# testing whether the texture is getting updated
def timer_callback(_caller, _timer_event):
rgb_images = [arr_aqua,
arr_yellow,
arr_blue,
arr_green,
arr_red,
arr_white]
cube.texture_update(show_manager, *rgb_images)

assert cube.image_grids == rgb_images
show_manager.exit()

scene = window.Scene()
scene.add(cube_actor)
show_manager = window.ShowManager(scene, reset_camera=False)
show_manager.add_timer_callback(True, int(1/60), timer_callback)
show_manager.start()

0 comments on commit 6a84176

Please sign in to comment.