11import numpy as np
22import numpy .testing as npt
33
4+ from PIL import Image
5+
46from 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