How to use the fury.utils.set_polydata_triangles function in fury

To help you get started, we’ve selected a few fury examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fury-gl / fury / docs / experimental / viz_canvas.py View on Github external
# print(big_tris)

    big_cols = np.repeat(colors, verts.shape[0], axis=0)

    # print(big_cols)

    big_centers = np.repeat(centers, verts.shape[0], axis=0)

    # print(big_centers)

    big_centers *= big_scales[:, np.newaxis]

    # print(big_centers)

    set_polydata_vertices(polydata, big_verts)
    set_polydata_triangles(polydata, big_tris)
    set_polydata_colors(polydata, big_cols)

    vtk_centers = numpy_support.numpy_to_vtk(big_centers, deep=True)
    vtk_centers.SetNumberOfComponents(3)
    vtk_centers.SetName("center")
    polydata.GetPointData().AddArray(vtk_centers)

    canvas_actor = get_actor_from_polydata(polydata)
    canvas_actor.GetProperty().BackfaceCullingOff()

    scene.add(canvas_actor)

    mapper = canvas_actor.GetMapper()

    mapper.MapDataArrayToVertexAttribute(
        "center", "center", vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, -1)
github fury-gl / fury / fury / actor.py View on Github external
all_faces = np.concatenate(all_faces)

    cols = np.ascontiguousarray(
        np.reshape(cols, (cols.shape[0] * cols.shape[1],
                   cols.shape[2])), dtype='f4')

    vtk_colors = numpy_support.numpy_to_vtk(
        cols,
        deep=True,
        array_type=vtk.VTK_UNSIGNED_CHAR)

    vtk_colors.SetName("Colors")

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)
    set_polydata_triangles(polydata, all_faces)
    polydata.GetPointData().SetScalars(vtk_colors)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polydata)

    return mapper
github fury-gl / fury / fury / actor.py View on Github external
cols[k] = tmp.copy()

        cols = np.ascontiguousarray(
            np.reshape(cols, (cols.shape[0] * cols.shape[1],
                       cols.shape[2])), dtype='f4')

    vtk_colors = numpy_support.numpy_to_vtk(
        np.asarray(255 * cols),
        deep=True,
        array_type=vtk.VTK_UNSIGNED_CHAR)

    vtk_colors.SetName("Colors")

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)
    set_polydata_triangles(polydata, all_faces)

    polydata.GetPointData().SetScalars(vtk_colors)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polydata)

    return mapper
github fury-gl / fury / docs / experimental / viz_shader_frag_fract.py View on Github external
[0,  3,  2],
                         [0,  1,  3],
                         [2,  7,  6],
                         [2,  3,  7],
                         [4,  6,  7],
                         [4,  7,  5],
                         [0,  4,  5],
                         [0,  5,  1],
                         [1,  5,  7],
                         [1, 7, 3]], dtype='i8')

my_colors = my_vertices * 255  # transform from [0, 1] to [0, 255]

# use a FURY util to apply the above values to the polydata
utils.set_polydata_vertices(my_polydata, my_vertices)
utils.set_polydata_triangles(my_polydata, my_triangles)
utils.set_polydata_colors(my_polydata, my_colors)

# in VTK, shaders are applied at the mapper level
# get mapper from polydata
cube_actor = utils.get_actor_from_polydata(my_polydata)
mapper = cube_actor.GetMapper()

# add the cube to a scene and show it
scene = window.Scene()
scene.add(cube_actor)

scene.background((1, 1, 1))

window.show(scene, size=(500, 500))

# let's use a frag shader to change how the cube is rendered
github fury-gl / fury / docs / experimental / viz_canvas.py View on Github external
tris = np.array([[0, 1, 2], [2, 3, 0]], dtype='i8')

    big_tris = np.tile(tris, (centers.shape[0], 1))
    shifts = np.repeat(np.arange(0, centers.shape[0] * verts.shape[0],
                                 verts.shape[0]), tris.shape[0])

    big_tris += shifts[:, np.newaxis]

    big_cols = np.repeat(colors, verts.shape[0], axis=0)

    big_centers = np.repeat(centers, verts.shape[0], axis=0)

    big_centers *= big_scales[:, np.newaxis]

    set_polydata_vertices(polydata, big_verts)
    set_polydata_triangles(polydata, big_tris)
    set_polydata_colors(polydata, big_cols)

    vtk_centers = numpy_support.numpy_to_vtk(big_centers, deep=True)
    vtk_centers.SetNumberOfComponents(3)
    vtk_centers.SetName("center")
    polydata.GetPointData().AddArray(vtk_centers)

    canvas_actor = get_actor_from_polydata(polydata)
    canvas_actor.GetProperty().BackfaceCullingOff()

    scene.add(canvas_actor)

    mapper = canvas_actor.GetMapper()

    mapper.MapDataArrayToVertexAttribute(
        "center", "center", vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, -1)
github fury-gl / fury / docs / tutorials / 04_others / viz_surfaces.py View on Github external
[0, 1, 3],
                         [2, 7, 6],
                         [2, 3, 7],
                         [4, 6, 7],
                         [4, 7, 5],
                         [0, 4, 5],
                         [0, 5, 1],
                         [1, 5, 7],
                         [1, 7, 3]], dtype='i8')


###############################################################################
# Set vertices and triangles in the ``vtkPolyData``

utils.set_polydata_vertices(my_polydata, my_vertices)
utils.set_polydata_triangles(my_polydata, my_triangles)

###############################################################################
# Save the ``vtkPolyData``

file_name = "my_cube.vtk"
save_polydata(my_polydata, file_name)
print("Surface saved in " + file_name)

###############################################################################
# Load the ``vtkPolyData``

cube_polydata = load_polydata(file_name)

###############################################################################
# add color based on vertices position
github fury-gl / fury / docs / experimental / viz_shader_canvas.py View on Github external
my_triangles = np.array([[0, 6, 4],
                            [0, 2, 6],
                            [0, 3, 2],
                            [0, 1, 3],
                            [2, 7, 6],
                            [2, 3, 7],
                            [4, 6, 7],
                            [4, 7, 5],
                            [0, 4, 5],
                            [0, 5, 1],
                            [1, 5, 7],
                            [1, 7, 3]], dtype='i8')

    set_polydata_vertices(my_polydata, my_vertices)
    set_polydata_triangles(my_polydata, my_triangles)
    return get_actor_from_polydata(my_polydata)