def test_vertices_from_actor(interactive=False): expected = np.array([[1.5, -0.5, 0.], [1.5, 0.5, 0], [2.5, 0.5, 0], [2.5, -0.5, 0], [-1, 1, 0], [-1, 3, 0], [1, 3, 0], [1, 1, 0], [-0.5, -0.5, 0], [-0.5, 0.5, 0], [0.5, 0.5, 0], [0.5, -0.5, 0]]) centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0]]) colors = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 255]]) scales = [1, 2, 1] verts, faces = fp.prim_square() res = fp.repeat_primitive(verts, faces, centers=centers, colors=colors, scales=scales) big_verts = res[0] big_faces = res[1] big_colors = res[2] actr = get_actor_from_primitive(big_verts, big_faces, big_colors) actr.GetProperty().BackfaceCullingOff() if interactive: scene = window.Scene() scene.add(actor.axes()) scene.add(actr) window.show(scene) res_vertices = vertices_from_actor(actr) npt.assert_array_almost_equal(expected, res_vertices)
def test_vertices_from_actor(interactive=False): expected = np.array([[1.5, -0.5, 0.], [1.5, 0.5, 0], [2.5, 0.5, 0], [2.5, -0.5, 0], [-1, 1, 0], [-1, 3, 0], [1, 3, 0], [1, 1, 0], [-0.5, -0.5, 0], [-0.5, 0.5, 0], [0.5, 0.5, 0], [0.5, -0.5, 0]]) centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0]]) colors = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 255]]) scales = [1, 2, 1] verts, faces = fp.prim_square() res = fp.repeat_primitive(verts, faces, centers=centers, colors=colors, scales=scales) big_verts = res[0] big_faces = res[1] big_colors = res[2] actr = get_actor_from_primitive(big_verts, big_faces, big_colors) actr.GetProperty().BackfaceCullingOff() if interactive: scene = window.Scene() scene.add(actor.axes()) scene.add(actr) window.show(scene) res_vertices = vertices_from_actor(actr) res_vertices_vtk = vertices_from_actor(actr, as_vtk=True) npt.assert_array_almost_equal(expected, res_vertices) npt.assert_equal(isinstance(res_vertices_vtk, vtk.vtkDoubleArray), True) # test colors_from_actor: l_colors = utils.colors_from_actor(actr) l_colors_vtk = utils.colors_from_actor(actr, as_vtk=True) l_colors_none = utils.colors_from_actor(actr, array_name='col') npt.assert_equal(l_colors_none, None) npt.assert_equal(isinstance(l_colors_vtk, vtk.vtkUnsignedCharArray), True) npt.assert_equal(np.unique(l_colors, axis=0).shape, colors.shape) l_array = utils.array_from_actor(actr, 'colors') l_array_vtk = utils.array_from_actor(actr, 'colors', as_vtk=True) l_array_none = utils.array_from_actor(actr, 'col') npt.assert_array_equal(l_array, l_colors) npt.assert_equal(l_array_none, None) npt.assert_equal(isinstance(l_array_vtk, vtk.vtkUnsignedCharArray), True)
def test_repeat_primitive(): # init variables verts, faces = fp.prim_square() centers = np.array([[0, 0, 0], [5, 0, 0], [10, 0, 0]]) dirs = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]]) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1.]]) big_verts, big_faces, big_colors = fp.repeat_primitive(vertices=verts, faces=faces, centers=centers, directions=dirs, colors=colors) npt.assert_equal(big_verts.shape[0], verts.shape[0] * centers.shape[0]) npt.assert_equal(big_faces.shape[0], faces.shape[0] * centers.shape[0]) npt.assert_equal(big_colors.shape[0], verts.shape[0] * centers.shape[0])
def test_square_actor(interactive=False): scene = window.Scene() centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0]]) colors = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 255]]) scale = [1, 2, 3] verts, faces = prim_square() res = repeat_primitive(verts, faces, centers=centers, colors=colors, scale=scale) big_verts, big_faces, big_colors, _ = res sq_actor = get_actor_from_primitive(big_verts, big_faces, big_colors) sq_actor.GetProperty().BackfaceCullingOff() scene.add(sq_actor) scene.add(actor.axes()) if interactive: window.show(scene)
def test_vertices_from_actor(): my_vertices = np.array([[2.5, -0.5, 0.], [1.5, -0.5, 0.], [1.5, 0.5, 0.], [2.5, 0.5, 0.], [1., 1., 0.], [-1., 1., 0.], [-1., 3., 0.], [1., 3., 0.], [0.5, -0.5, 0.], [-0.5, -0.5, 0.], [-0.5, 0.5, 0.], [0.5, 0.5, 0.]]) centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0]]) colors = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 255]]) scale = [1, 2, 1] verts, faces = fp.prim_square() res = fp.repeat_primitive(verts, faces, centers=centers, colors=colors, scale=scale) big_verts = res[0] big_faces = res[1] big_colors = res[2] actr = get_actor_from_primitive(big_verts, big_faces, big_colors) actr.GetProperty().BackfaceCullingOff() res_vertices = vertices_from_actor(actr) npt.assert_array_almost_equal(my_vertices, res_vertices)
def test_repeat_primitive(): # init variables verts, faces = fp.prim_square() centers = np.array([[0, 0, 0], [5, 0, 0], [10, 0, 0]]) dirs = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]]) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1.]]) res = fp.repeat_primitive(vertices=verts, faces=faces, centers=centers, directions=dirs, colors=colors) big_verts, big_faces, big_colors, big_centers = res npt.assert_equal(big_verts.shape[0], verts.shape[0] * centers.shape[0]) npt.assert_equal(big_faces.shape[0], faces.shape[0] * centers.shape[0]) npt.assert_equal(big_colors.shape[0], verts.shape[0] * centers.shape[0]) npt.assert_equal(big_centers.shape[0], verts.shape[0] * centers.shape[0]) npt.assert_equal(np.unique(np.concatenate(big_faces, axis=None)).tolist(), list(range(len(big_verts)))) # translate the squares primitives centers to be the origin big_vert_origin = big_verts - np.repeat(centers, 4, axis=0) # three repeated primitives sq1, sq2, sq3 = big_vert_origin.reshape([3, 12]) # primitives directed toward different directions must not be the same np.testing.assert_equal(np.any(np.not_equal(sq1, sq2)), True) np.testing.assert_equal(np.any(np.not_equal(sq1, sq3)), True) np.testing.assert_equal(np.any(np.not_equal(sq2, sq3)), True) np.testing.assert_equal(big_vert_origin.min(), -0.5) np.testing.assert_equal(big_vert_origin.max(), 0.5) np.testing.assert_equal(np.mean(big_vert_origin), 0)
from fury import actor, window import numpy as np import fury.primitive as fp import fury.shaders as fs from vtk.util import numpy_support from fury.utils import get_actor_from_primitive import vtk verts, faces = fp.prim_box() centers = np.array([[0, 0, 0], [8, 0, 0]]) repeated = fp.repeat_primitive(verts, faces, centers=centers, scales=5) rep_verts, rep_faces, rep_colors, rep_centers = repeated sdfactor = get_actor_from_primitive(rep_verts, rep_faces) vtk_center = numpy_support.numpy_to_vtk(rep_centers) vtk_center.SetNumberOfComponents(3) vtk_center.SetName("center") sdfactor.GetMapper().GetInput().GetPointData().AddArray(vtk_center) vs_dec_code = fs.load("sdf_dec.vert") vs_impl_code = fs.load("sdf_impl.vert") fs_dec_code = fs.load("sdfmulti_dec.frag") fs_impl_code = fs.load("sdfmulti_impl.frag") mapper = sdfactor.GetMapper() mapper.MapDataArrayToVertexAttribute( "center", "center", vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, -1) mapper.AddShaderReplacement(vtk.vtkShader.Vertex, "//VTK::ValuePass::Dec",