How to use the fury.window.Scene 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 / fury / window.py View on Github external
start()
        add_window_callback()

        Examples
        --------
        >>> from fury import actor, window
        >>> scene = window.Scene()
        >>> scene.add(actor.axes())
        >>> showm = window.ShowManager(scene)
        >>> # showm.initialize()
        >>> # showm.render()
        >>> # showm.start()

        """
        if scene is None:
            scene = Scene()
        self.scene = scene
        self.title = title
        self.size = size
        self.png_magnify = png_magnify
        self.reset_camera = reset_camera
        self.order_transparent = order_transparent
        self.interactor_style = interactor_style
        self.stereo = stereo
        self.timers = []

        if self.reset_camera:
            self.scene.ResetCamera()

        self.window = vtk.vtkRenderWindow()

        if self.stereo.lower() != 'off':
github fury-gl / fury / docs / experimental / viz_shader_perlin_noise.py View on Github external
from fury import window
from scipy.spatial import Delaunay
from viz_shader_canvas import surface


import numpy as np
import vtk


scene = window.Scene()

size = 11
vertices = list()
for i in range(-size, size):
    for j in range(-size, size):
        fact1 = - np.sin(i) * np.cos(j)
        fact2 = - np.exp(abs(1 - np.sqrt(i ** 2 + j ** 2) / np.pi))
        z_coord = -abs(fact1 * fact2)
        vertices.append([i, j, z_coord])

c_arr = np.random.rand(len(vertices), 3)
np.random.shuffle(vertices)
vertices = np.array(vertices)
tri = Delaunay(vertices[:, [0, 1]])
faces = tri.simplices
github fury-gl / fury / docs / examples / viz_roi_contour.py View on Github external
# Next, we create a surface actor from the corpus callosum seed ROI. We
# provide the ROI data, the affine, the color in [R,G,B], and the opacity as
# a decimal between zero and one. Here, we set the color as blue/green with
# 50% opacity.

surface_opacity = 0.5
surface_color = [0, 1, 1]

seedroi_actor = actor.contour_from_roi(seed_mask, affine,
                                       surface_color, surface_opacity)

###############################################################################
# Next, we initialize a ''Scene'' object and add both actors
# to the rendering.

scene = window.Scene()
scene.add(streamlines_actor)
scene.add(seedroi_actor)

###############################################################################
# If you uncomment the following line, the rendering will pop up in an
# interactive window.

interactive = False
if interactive:
    window.show(scene)

# scene.zoom(1.5)
# scene.reset_clipping_range()

window.record(scene, out_path='contour_from_roi_tutorial.png',
              size=(600, 600))
github fury-gl / fury / docs / experimental / viz_shader_frag_fract.py View on Github external
[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
# we'll render as usual if the fragment is far from the camera
# but we'll render small circles instead if the fragment is too close

# we'll need the window size for our circle effect, so we'll inject it into
# the shader as a uniform. uniforms are set using a callback so that their
# values can be updated

# first create a callback which gets the window size
github fury-gl / fury / docs / experimental / viz_shader_texture.py View on Github external
from fury import window
from viz_shader_canvas import cube


import vtk


scene = window.Scene()

canvas_actor = cube()
canvas_actor.GetProperty().BackfaceCullingOff()
scene.add(canvas_actor)
mapper = canvas_actor.GetMapper()

texture = vtk.vtkTexture()
texture.CubeMapOn()
file = "sugar.jpg"

imgReader = vtk.vtkJPEGReader()
imgReader.SetFileName(file)

for i in range(6):
    flip = vtk.vtkImageFlip()
    flip.SetInputConnection(imgReader.GetOutputPort())
github fury-gl / fury / docs / experimental / viz_sdf.py View on Github external
from fury import actor, window, primitive, utils
import vtk
from vtk.util import numpy_support
import numpy as np


#Create  a Scene
scene = window.Scene()
scene.background((1.0, 0.8, 0.8))
#import a box primitive
vertices, faces = primitive.prim_box()
#create a actor
box_actor = utils.get_actor_from_primitive(vertices, faces)
center = ([5, 0, 0])

box_actor.SetPosition(center)

#create a Mapper
mapper = box_actor.GetMapper()
#set attribute for shader
vtk_center = numpy_support.numpy_to_vtk(center)
vtk_center.SetName("center")
box_actor.GetMapper().GetInput().GetPointData().AddArray(vtk_center)
github fury-gl / fury / docs / examples / viz_advanced.py View on Github external
###############################################################################
# If we want to see the objects in native space we need to make sure that all
# objects which are currently in world coordinates are transformed back to
# native space using the inverse of the affine.


if not world_coords:
    from dipy.tracking.streamline import transform_streamlines
    streamlines = transform_streamlines(streamlines, np.linalg.inv(affine))

###############################################################################
# Now we create, a ``Scene`` object and add the streamlines using the
# ``line`` function and an image plane using the ``slice`` function.

scene = window.Scene()
stream_actor = actor.line(streamlines)

if not world_coords:
    image_actor_z = actor.slicer(data, affine=np.eye(4))
else:
    image_actor_z = actor.slicer(data, affine)

###############################################################################
# We can also change also the opacity of the slicer.

slicer_opacity = 0.6
image_actor_z.opacity(slicer_opacity)

###############################################################################
# We can add additonal slicers by copying the original and adjusting the
# ``display_extent``.
github fury-gl / fury / docs / tutorials / 04_others / viz_surfaces.py View on Github external
cube_vertices = utils.get_polydata_vertices(cube_polydata)
colors = cube_vertices * 255
utils.set_polydata_colors(cube_polydata, colors)

print("new surface colors")
print(utils.get_polydata_colors(cube_polydata))

###############################################################################
# Visualize surfaces

# get vtkActor
cube_actor = utils.get_actor_from_polydata(cube_polydata)

# Create a scene
scene = window.Scene()
scene.add(cube_actor)
scene.set_camera(position=(10, 5, 7), focal_point=(0.5, 0.5, 0.5))
scene.zoom(3)

# display
# window.show(scene, size=(600, 600), reset_camera=False)
window.record(scene, out_path='cube.png', size=(600, 600))
github fury-gl / fury / docs / experimental / viz_shader_square.py View on Github external
from fury import actor, window
from viz_shader_canvas import cube, square


import numpy as np
import vtk


scene = window.Scene()
# scene.add(actor.axes())
# scene.background((1, 1, 1))
showm = window.ShowManager(scene, size=(1920, 1080),
                           order_transparent=True,
                           interactor_style='custom')

obj = 'cube'

if obj == 'square':

    canvas_actor = square(3)
    canvas_actor.GetProperty().BackfaceCullingOff()
    scene.add(canvas_actor)
    mapper = canvas_actor.GetMapper()

if obj == 'cube':