Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from fury import window
from viz_shader_canvas import cube
import vtk
scene = window.Scene()
showm = window.ShowManager(scene, order_transparent=True)
canvas_actor = cube()
canvas_actor.GetProperty().BackfaceCullingOff()
scene.add(canvas_actor)
scene.background((1, 1, 1))
mapper = canvas_actor.GetMapper()
# Modify the vertex shader to pass the position of the vertex
mapper.AddShaderReplacement(
vtk.vtkShader.Vertex,
"//VTK::Normal::Dec", # replace the normal block
True, # before the standard replacements
"""
//VTK::Normal::Dec // we still want the default
out vec4 myVertexMC;
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.
showm = window.ShowManager(scene,
size=(900, 768), reset_camera=False,
order_transparent=True)
##############################################################################
# We want to make a small animation for fun!
# We can determine the duration of animation with using the ``counter``.
# Use itertools to avoid global variables.
counter = itertools.count()
##############################################################################
# The timer will call this user defined callback every 200 milliseconds. The
# application will exit after the callback has been called 20 times.
def timer_callback(_obj, _event):
element.set_visibility(True)
if values.index(listbox.selected[0]) == 4:
cube.SetVisibility(True)
listbox.on_change = display_element
###############################################################################
# Show Manager
# ==================================
#
# Now that all the elements have been initialised, we add them to the show
# manager.
current_size = (800, 800)
show_manager = window.ShowManager(size=current_size, title="DIPY UI Example")
show_manager.scene.add(listbox)
for example in examples:
for element in example:
show_manager.scene.add(element)
show_manager.scene.add(cube)
show_manager.scene.reset_camera()
show_manager.scene.set_camera(position=(0, 0, 200))
show_manager.scene.reset_clipping_range()
show_manager.scene.azimuth(30)
# To interact with the UI, set interactive = True
interactive = False
if interactive:
show_manager.start()
def cube_maker(color=(1, 1, 1), size=(0.2, 0.2, 0.2), center=(0, 0, 0)):
cube = window.vtk.vtkCubeSource()
cube.SetXLength(size[0])
cube.SetYLength(size[1])
cube.SetZLength(size[2])
if center is not None:
cube.SetCenter(*center)
cube_mapper = window.vtk.vtkPolyDataMapper()
cube_mapper.SetInputConnection(cube.GetOutputPort())
cube_actor = window.vtk.vtkActor()
cube_actor.SetMapper(cube_mapper)
if color is not None:
cube_actor.GetProperty().SetColor(color)
return cube_actor