diff --git a/ci/setup_headless.sh b/ci/setup_headless.sh index ac47a69a9..6f22047d1 100755 --- a/ci/setup_headless.sh +++ b/ci/setup_headless.sh @@ -5,7 +5,8 @@ echo "DISPLAY=:99.0" >> $GITHUB_ENV if [ "$RUNNER_OS" == "Linux" ]; then echo "LIBGL_ALWAYS_SOFTWARE=1" >> $GITHUB_ENV echo "LIBGL_ALWAYS_INDIRECT=0" >> $GITHUB_ENV - sudo apt-get install -y libgl1-mesa-glx xvfb; + sudo apt-get update -y -qq; + sudo apt-get install --no-install-recommends -y libegl1-mesa-dev libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers; Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & sleep 3 elif [ "$RUNNER_OS" == "Windows" ]; then diff --git a/fury/tests/test_actor.py b/fury/tests/test_actor.py index a29b3631d..9528e03ad 100644 --- a/fury/tests/test_actor.py +++ b/fury/tests/test_actor.py @@ -1,3 +1,4 @@ +from PIL import Image import numpy as np import numpy.testing as npt @@ -13,17 +14,17 @@ def test_sphere(): sphere_actor = actor.sphere(centers=centers, colors=colors, radii=radii) scene.add(sphere_actor) - # window.record(scene=scene, fname="sphere_test_1.png") + window.snapshot(scene=scene, fname="sphere_test_1.png") - # img = Image.open("sphere_test_1.png") - # img_array = np.array(img) + img = Image.open("sphere_test_1.png") + img_array = np.array(img) - # mean_r, mean_g, mean_b, _ = np.mean( - # img_array.reshape(-1, img_array.shape[2]), axis=0 - # ) + mean_r, mean_g, mean_b, _ = np.mean( + img_array.reshape(-1, img_array.shape[2]), axis=0 + ) - # assert mean_r > mean_b and mean_r > mean_g - # assert 0 <= mean_r <= 255 and 0 <= mean_g <= 255 and 0 <= mean_b <= 255 + assert mean_r > mean_b and mean_r > mean_g + assert 0 <= mean_r <= 255 and 0 <= mean_g <= 255 and 0 <= mean_b <= 255 npt.assert_array_equal(sphere_actor.local.position, centers[0]) @@ -45,21 +46,20 @@ def test_sphere(): scene.remove(sphere_actor) scene.add(sphere_actor_2) - # TODO: Record does not exist in the v2, test needs to be update - # window.record(scene=scene, fname="sphere_test_2.png") + window.snapshot(scene=scene, fname="sphere_test_2.png") - # img = Image.open("sphere_test_2.png") - # img_array = np.array(img) + img = Image.open("sphere_test_2.png") + img_array = np.array(img) - # mean_r, mean_g, mean_b, mean_a = np.mean( - # img_array.reshape(-1, img_array.shape[2]), axis=0 - # ) + mean_r, mean_g, mean_b, mean_a = np.mean( + img_array.reshape(-1, img_array.shape[2]), axis=0 + ) - # assert mean_r > mean_b and mean_r > mean_g - # assert 0 <= mean_r <= 255 and 0 <= mean_g <= 255 and 0 <= mean_b <= 255 - # assert mean_a == 255.0 - # assert mean_b == 0.0 - # assert mean_g == 0.0 + assert mean_r > mean_b and mean_r > mean_g + assert 0 <= mean_r <= 255 and 0 <= mean_g <= 255 and 0 <= mean_b <= 255 + assert mean_a == 255.0 + assert mean_b == 0.0 + assert mean_g == 0.0 vertices = sphere_actor_2.geometry.positions.view faces = sphere_actor_2.geometry.indices.view @@ -112,50 +112,49 @@ def test_cylinder(): assert cylinder_actor.prim_count == 1 - # window.snapshot(scene=scene, fname="cylinder_test_1.png") + window.snapshot(scene=scene, fname="cylinder_test_1.png") - # img = Image.open("cylinder_test_1.png") - # img_array = np.array(img) + img = Image.open("cylinder_test_1.png") + img_array = np.array(img) - # mean_r, mean_g, mean_b, mean_a = np.mean( - # img_array.reshape(-1, img_array.shape[2]), axis=0 - # ) + mean_r, mean_g, mean_b, mean_a = np.mean( + img_array.reshape(-1, img_array.shape[2]), axis=0 + ) - # assert mean_r > mean_b and mean_r > mean_g - # assert 0 < mean_r < 255 and 0 < mean_g < 255 and 0 <= mean_b < 255 + assert mean_r > mean_b and mean_r > mean_g + assert 0 < mean_r < 255 and 0 < mean_g < 255 and 0 <= mean_b < 255 - # middle_pixel = img_array[img_array.shape[0] // 2, img_array.shape[1] // 2] - # r, g, b, a = middle_pixel - # assert r > g and r > b - # assert g == b - # assert r > 0 and g > 0 and b > 0 + middle_pixel = img_array[img_array.shape[0] // 2, img_array.shape[1] // 2] + r, g, b, a = middle_pixel + assert r > g and r > b + assert g == b + assert r > 0 and g > 0 and b > 0 scene.remove(cylinder_actor) - # cylinder_actor_2 = actor.cylinder( - # centers=centers, colors=colors, sectors=sectors, capped=capped, - # material="basic" - # ) - # scene.add(cylinder_actor_2) - # window.snapshot(scene=scene, fname="cylinder_test_2.png") - - # img = Image.open("cylinder_test_2.png") - # img_array = np.array(img) - - # mean_r, mean_g, mean_b, mean_a = np.mean( - # img_array.reshape(-1, img_array.shape[2]), axis=0 - # ) - - # assert mean_r > mean_b and mean_r > mean_g - # assert 0 < mean_r < 255 - # assert mean_g == 0 and mean_b == 0 - - # middle_pixel = img_array[img_array.shape[0] // 2, img_array.shape[1] // 2] - # r, g, b, a = middle_pixel - # assert r > g and r > b - # assert g == 0 and b == 0 - # assert r == 255 - # scene.remove(cylinder_actor_2) + cylinder_actor_2 = actor.cylinder( + centers=centers, colors=colors, sectors=sectors, capped=capped, material="basic" + ) + scene.add(cylinder_actor_2) + window.snapshot(scene=scene, fname="cylinder_test_2.png") + + img = Image.open("cylinder_test_2.png") + img_array = np.array(img) + + mean_r, mean_g, mean_b, mean_a = np.mean( + img_array.reshape(-1, img_array.shape[2]), axis=0 + ) + + assert mean_r > mean_b and mean_r > mean_g + assert 0 < mean_r < 255 + assert mean_g == 0 and mean_b == 0 + + middle_pixel = img_array[img_array.shape[0] // 2, img_array.shape[1] // 2] + r, g, b, a = middle_pixel + assert r > g and r > b + assert g == 0 and b == 0 + assert r == 255 + scene.remove(cylinder_actor_2) def test_square():