Skip to content

Commit 8ba638a

Browse files
committed
Adding uni test for cylinder_actor
1 parent f183974 commit 8ba638a

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

fury/actor.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ def cylinder(
196196
centers,
197197
colors,
198198
*,
199-
height= 1,
200-
sectors= 36,
201-
radii= 0.5,
199+
height=1,
200+
sectors=36,
201+
radii=0.5,
202202
scales=(1, 1, 1),
203203
directions=(0, 1, 0),
204-
capped= True,
205-
opacity= None,
206-
material= "phong",
207-
enable_picking= True,
204+
capped=True,
205+
opacity=None,
206+
material="phong",
207+
enable_picking=True,
208208
):
209209
"""Visualize one or many cylinders with different features.
210210
@@ -259,7 +259,8 @@ def cylinder(
259259
>>> show_manager.start()
260260
"""
261261

262-
vertices, faces = fp.prim_cylinder(radius= radii, height= height, sectors= sectors, capped= capped)
262+
vertices, faces = fp.prim_cylinder(
263+
radius=radii, height=height, sectors=sectors, capped=capped)
263264
res = fp.repeat_primitive(
264265
vertices,
265266
faces,
@@ -287,7 +288,8 @@ def cylinder(
287288
texcoords=big_vertices.astype("float32"),
288289
colors=big_colors.astype("float32"),
289290
)
290-
mat = _create_mesh_material(material=material, enable_picking=enable_picking)
291+
mat = _create_mesh_material(material=material,
292+
enable_picking=enable_picking)
291293
obj = create_mesh(geometry=geo, material=mat)
292294
obj.local.position = centers[0]
293295

fury/tests/test_actor.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
22
import numpy.testing as npt
33

4+
from PIL import Image
5+
46
from fury import actor, window
57

68

@@ -91,3 +93,66 @@ def test_box():
9193
assert box_actor.prim_count == 1
9294

9395
scene.remove(box_actor)
96+
97+
98+
def test_cylinder():
99+
scene = window.Scene()
100+
centers= np.array([[0,0,0]])
101+
colors= np.array([[1,0,0]])
102+
sectors= 36
103+
capped= True
104+
105+
cylinder_actor= actor.cylinder(
106+
centers=centers, colors=colors, sectors=sectors, capped=capped)
107+
scene.add(cylinder_actor)
108+
109+
npt.assert_array_equal(cylinder_actor.local.position, centers[0])
110+
mean_vertex= np.mean(cylinder_actor.geometry.positions.view, axis=0)
111+
112+
npt.assert_array_almost_equal(mean_vertex, centers[0], decimal=2)
113+
assert cylinder_actor.prim_count == 1
114+
115+
window.snapshot(scene=scene, fname="cylinder_test_1.png")
116+
117+
img = Image.open("cylinder_test_1.png")
118+
img_array = np.array(img)
119+
120+
mean_r, mean_g, mean_b, mean_a = np.mean(
121+
img_array.reshape(-1, img_array.shape[2]), axis=0
122+
)
123+
124+
assert mean_r > mean_b and mean_r > mean_g
125+
assert 0 < mean_r < 255 and 0 < mean_g < 255 and 0 <= mean_b < 255
126+
127+
middle_pixel = img_array[img_array.shape[0]//2, img_array.shape[1]//2]
128+
r, g, b, a = middle_pixel
129+
assert r > g and r > b
130+
assert g == b
131+
assert r > 0 and g > 0 and b > 0
132+
133+
scene.remove(cylinder_actor)
134+
135+
cylinder_actor_2 = actor.cylinder(
136+
centers=centers, colors=colors, sectors=sectors, capped=capped, material='basic')
137+
scene.add(cylinder_actor_2)
138+
window.snapshot(scene=scene, fname="cylinder_test_2.png")
139+
140+
img = Image.open("cylinder_test_2.png")
141+
img_array = np.array(img)
142+
143+
mean_r, mean_g, mean_b, mean_a = np.mean(
144+
img_array.reshape(-1, img_array.shape[2]), axis=0
145+
)
146+
147+
assert mean_r > mean_b and mean_r > mean_g
148+
assert 0 < mean_r < 255
149+
assert mean_g == 0 and mean_b == 0
150+
151+
middle_pixel = img_array[img_array.shape[0]//2,
152+
img_array.shape[1]//2]
153+
r, g, b, a = middle_pixel
154+
assert r > g and r > b
155+
assert g == 0 and b == 0
156+
assert r == 255
157+
158+
scene.remove(cylinder_actor_2)

0 commit comments

Comments
 (0)