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 ui, window
from fury.data import read_viz_icons
###############################################################################
# Let's create some buttons and text and put them in a panel.
# First we'll make the panel.
panel = ui.Panel2D(size=(300, 150), color=(1, 1, 1), align="right")
panel.center = (500, 400)
###############################################################################
# Then we'll make two text labels and place them on the panel.
# Note that we specifiy the position with integer numbers of pixels.
text = ui.TextBlock2D(text="Click me")
text2 = ui.TextBlock2D(text="Me too")
panel.add_element(text, (50, 100))
panel.add_element(text2, (180, 100))
###############################################################################
# Then we'll create two buttons and add them to the panel.
#
# Note that here we specify the positions with floats. In this case, these are
# percentages of the panel size.
button_example = ui.Button2D(
icon_fnames=[("square", read_viz_icons(fname="stop2.png"))]
)
icon_files = []
This example shows how to use the UI API. We will create a list
some geometric shapes from DIPY UI elements.
First, a bunch of imports.
"""
from fury import ui, window
###############################################################################
# Create some text blocks that will be showm when
# list elements will be selected
welcome_text = ui.TextBlock2D(text="Welcome", font_size=30,
position=(500, 400))
bye_text = ui.TextBlock2D(text="Bye", font_size=30, position=(500, 400))
fury_text = ui.TextBlock2D(text="Fury", font_size=30, position=(500, 400))
example = [welcome_text, bye_text, fury_text]
###############################################################################
# Hide these text blocks for now
def hide_all_examples():
for element in example:
element.set_visibility(False)
hide_all_examples()
###############################################################################
# Create ListBox with the values as parameter.
=========
ListBox
=========
This example shows how to use the UI API. We will create a list
some geometric shapes from DIPY UI elements.
First, a bunch of imports.
"""
from fury import ui, window
###############################################################################
# Create some text blocks that will be showm when
# list elements will be selected
welcome_text = ui.TextBlock2D(text="Welcome", font_size=30,
position=(500, 400))
bye_text = ui.TextBlock2D(text="Bye", font_size=30, position=(500, 400))
fury_text = ui.TextBlock2D(text="Fury", font_size=30, position=(500, 400))
example = [welcome_text, bye_text, fury_text]
###############################################################################
# Hide these text blocks for now
def hide_all_examples():
for element in example:
element.set_visibility(False)
hide_all_examples()
@window.vtk.calldata_type(window.vtk.VTK_OBJECT)
def vtk_shader_callback(caller, event, calldata=None):
program = calldata
global timer
if program is not None:
try:
program.SetUniformf("time", timer)
except ValueError:
pass
###############################################################################
# Let's add a textblock to the scene with a custom message
tb = ui.TextBlock2D()
tb.message = "Hello Shaders"
###############################################################################
# Change the property of the actor
utah.GetProperty().SetOpacity(0.5)
###############################################################################
# Invoke callbacks to any VTK object
mapper.AddObserver(window.vtk.vtkCommand.UpdateShaderEvent,
vtk_shader_callback)
###############################################################################
# Show Manager
from fury import ui, window
###############################################################################
# Let's draw some simple shapes. First, a rectangle.
rect = ui.Rectangle2D(size=(100, 100), position=(400, 400), color=(1, 0, 1))
###############################################################################
# Then we can draw a solid circle, or disk.
disk = ui.Disk2D(outer_radius=50, center=(400, 200), color=(1, 1, 0))
###############################################################################
# Add an inner radius to make a ring.
ring = ui.Disk2D(outer_radius=50, inner_radius=45,
center=(500, 600), color=(0, 1, 1))
###############################################################################
# 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 Shapes Example")
show_manager.scene.add(rect)
show_manager.scene.add(disk)
show_manager.scene.add(ring)
interactive = False
import numpy as np
from fury import actor, window, ui, utils, pick
centers = 0.5 * np.array([[0, 0, 0], [100, 0, 0], [200, 0, 0.]])
colors = np.array([[0.8, 0, 0], [0, 0.8, 0], [0, 0, 0.8]])
radii = 0.1 * np.array([50, 100, 150.])
selected = np.zeros(3, dtype=np.bool)
###############################################################################
# Let's create a panel to show what is picked
panel = ui.Panel2D(size=(400, 200), color=(1, .5, .0), align="right")
panel.center = (150, 200)
text_block = ui.TextBlock2D(text="Left click on object \n")
panel.add_element(text_block, (0.3, 0.3))
###############################################################################
# Build scene and add an actor with many objects.
scene = window.Scene()
label_actor = actor.label(text='Test')
###############################################################################
# This actor is made with 3 cubes of different orientation
directions = np.array([[np.sqrt(2)/2, 0, np.sqrt(2)/2],
[np.sqrt(2)/2, np.sqrt(2)/2, 0],
[0, np.sqrt(2)/2, np.sqrt(2)/2]])
fury_actor = actor.cube(centers, directions, colors, heights=radii)
When the objects will be picked they will change size and color.
"""
import numpy as np
from fury import actor, window, ui, utils, pick
centers = 0.5 * np.array([[0, 0, 0], [100, 0, 0], [200, 0, 0.]])
colors = np.array([[0.8, 0, 0], [0, 0.8, 0], [0, 0, 0.8]])
radii = 0.1 * np.array([50, 100, 150.])
selected = np.zeros(3, dtype=np.bool)
###############################################################################
# Let's create a panel to show what is picked
panel = ui.Panel2D(size=(400, 200), color=(1, .5, .0), align="right")
panel.center = (150, 200)
text_block = ui.TextBlock2D(text="Left click on object \n")
panel.add_element(text_block, (0.3, 0.3))
###############################################################################
# Build scene and add an actor with many objects.
scene = window.Scene()
label_actor = actor.label(text='Test')
###############################################################################
# This actor is made with 3 cubes of different orientation
directions = np.array([[np.sqrt(2)/2, 0, np.sqrt(2)/2],
global cube_x, cube_y
cube_y = slider.value
cube.SetPosition(cube_x, cube_y, 0)
line_slider_x.on_change = translate_cube_x
line_slider_y.on_change = translate_cube_y
###############################################################################
# Range Slider
# ============
#
# Finally, we can add a range slider. This element is composed of two sliders.
# The first slider has two handles which let you set the range of the second.
range_slider_x = ui.RangeSlider(
line_width=8, handle_side=25, range_slider_center=(450, 450),
value_slider_center=(450, 350), length=150, min_value=0,
max_value=10, font_size=18, range_precision=2, value_precision=4,
shape="square")
range_slider_y = ui.RangeSlider(
line_width=8, handle_side=25, range_slider_center=(750, 400),
value_slider_center=(650, 400), length=150, min_value=0,
max_value=10, font_size=18, range_precision=2, value_precision=4,
orientation="vertical", shape="square")
###############################################################################
# Select menu
# ============
#
# We just added many examples. If we showed them all at once, they would fill
# the screen. Let's make a simple menu to choose which example is shown.