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_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)
directions=normals, colors=(1, 0, 0), heights=0.2, resolution=10, vertices=None, faces=None) ############################################################################## # To be able to visualize the surface of the primitive sphere, we use # ``get_actor_from_primitive``. primitive_colors = np.zeros(vertices.shape) primitive_colors[:, 2] = 180 primitive_actor = utils.get_actor_from_primitive(vertices=vertices, triangles=triangles, colors=primitive_colors, normals=normals, backface_culling=True) ############################################################################## # We add all actors (visual objects) defined above to the scene. scene.add(point_actor) scene.add(arrow_actor) scene.add(primitive_actor) scene.add(actor.axes()) ############################################################################## # The ShowManager class is the interface between the scene, the window and the # interactor.
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",
import numpy as np from fury import window, utils, actor, primitive import itertools vertices, triangles = primitive.prim_star() colors = 255 * np.random.rand(*vertices.shape) point_actor = actor.point(vertices, point_radius=0.01, colors=colors / 255.) # this does not work #colors = np.array([255, 0. , 0.]) # this does work colors = np.array([[255, 0., 0.], [255, 0., 0.], [255, 0., 0.], [255, 0., 0.], [255, 0., 0.], [255, 0., 0.], [255, 0., 0.], [255, 0., 0.]]) frustum_actor = utils.get_actor_from_primitive(vertices=vertices, triangles=triangles, colors=colors, backface_culling=False) scene = window.Scene() scene.add(point_actor) scene.add(actor.axes()) scene.add(frustum_actor) # frustum_actor.GetProperty().SetOpacity(0.3) scene.set_camera(position=(10, 5, 7), focal_point=(0, 0, 0)) window.show(scene, size=(600, 600), reset_camera=False)