예제 #1
0
def _sphere(scale=1):

    vertices, faces = prim_sphere('symmetric362')

    from fury.utils import set_polydata_vertices, set_polydata_triangles, vtk
    polydata = vtk.vtkPolyData()

    set_polydata_vertices(polydata, scale * vertices)
    set_polydata_triangles(polydata, faces)
    from fury.utils import set_polydata_normals, normals_from_v_f

    normals = normals_from_v_f(scale * vertices, faces)
    set_polydata_normals(polydata, normals)
    return polydata, scale * vertices, normals
예제 #2
0
def custom_glyph(centers, directions=None, colors=(1, 0, 0),
                 normals=(1, 0, 0), sq_params=None,
                 geom='square', scale=1, **kwargs):
    """Return a custom glyph actor
    """
    if geom.lower() == 'square':
        unit_verts, unit_triangles = square()
        origin_z = 0
    elif geom.lower() == 'box':
        unit_verts, unit_triangles = box()
        origin_z = 0.5
    elif geom.lower() == 'octahedron':
        unit_verts, unit_triangles = octahedron()
        origin_z = 0.5
    elif geom.lower() == 'icosahedron':
        unit_verts, unit_triangles = icosahedron()
        origin_z = 0.5
    elif geom.lower() == 'superquadric':
        unit_verts, unit_triangles = superquadric(sq_params)
        origin_z = 0.5
    else:
        unit_verts, unit_triangles = None
        origin_z = 0

    # update vertices
    big_vertices = np.tile(unit_verts, (centers.shape[0], 1))
    big_centers = np.repeat(centers, unit_verts.shape[0], axis=0)
    # center it
    big_vertices -= np.array([0.5, 0.5, origin_z])
    # apply centers position
    big_vertices += big_centers
    # scale them
    if isinstance(scale, (list, tuple, np.ndarray)):
        scale = np.repeat(scale, unit_verts.shape[0], axis=0)
        scale = scale.reshape((big_vertices.shape[0], 1))
    big_vertices *= scale

    # update triangles
    big_triangles = np.tile(unit_triangles, (centers.shape[0], 1))
    z = np.repeat(np.arange(0, centers.shape[0] *
                            unit_verts.shape[0], step=unit_verts.shape[0]),
                            unit_triangles.shape[0],
                            axis=0).reshape((big_triangles.shape[0], 1))
    big_triangles = np.add(z, big_triangles, casting="unsafe")

    # update colors
    if isinstance(colors, (tuple, list)):
        colors = np.array([colors] * centers.shape[0])
    big_colors = np.repeat(colors*255, unit_verts.shape[0], axis=0)

    # update normals
    if isinstance(normals, (tuple, list)):
        normals = np.array([normals] * centers.shape[0])
    big_normals = np.repeat(normals, unit_verts.shape[0], axis=0)

    # if isinstance(normals, (tuple, list)):
    #     directions = np.array([directions] * centers.shape[0])
    # big_dirs = np.repeat(normals, unit_verts.shape[0], axis=0)
    r, p, t = cart2sphere(0, 0, 1)
    m = euler_matrix(r, p, t, 'rxzy')
    print(big_vertices)
    big_vertices -= big_centers
    big_vertices = np.dot(m[:3, :3], big_vertices.T).T + big_centers

    # Create a Polydata
    pd = vtk.vtkPolyData()
    set_polydata_vertices(pd, big_vertices)
    set_polydata_triangles(pd, big_triangles)
    set_polydata_colors(pd, big_colors)
    set_polydata_normals(pd, big_normals)
    update_polydata_normals(pd)

    current_actor = get_actor_from_polydata(pd)
    if geom.lower() == 'square':
        current_actor.GetProperty().BackfaceCullingOff()
    return current_actor