Sphere Color Control using Radio Buttons

This example shows how to use the UI API. We will demonstrate how to create a Sphere and control its color using radio buttons.

First, some imports.

from fury import ui, window, actor, utils
import numpy as np
from fury.data import fetch_viz_icons

First we need to fetch some icons that are included in DIPY.


Data size is approximately 12KB
Dataset is already in place. If you want to fetch it again please first remove the folder /home/travis/.fury/icons

({'icomoon.tar.gz': ('https://digital.lib.washington.edu/researchworks/bitstream/handle/1773/38478/icomoon.tar.gz', 'BC1FEEA6F58BA3601D6A0B029EB8DFC5F352E21F2A16BA41099A96AA3F5A4735')}, '/home/travis/.fury/icons')

Sphere and Radio Buttons

Add a Sphere to the scene.

sphere = actor.sphere(centers=np.array([[50, 0, 0]]),
                      colors=np.array([[0, 0, 1]]),
                      radii=11.0, theta=360, phi=360)

# Creating a dict of possible options and mapping it with their values.
options = {'Blue': (0, 0, 255), 'Red': (255, 0, 0), 'Green': (0, 255, 0)}

color_toggler = ui.RadioButton(list(options), checked_labels=['Blue'],
                               padding=1, font_size=16,
                               font_family='Arial', position=(200, 200))

# A callback which will set the values for the box
def toggle_color(radio):
    vcolors = utils.colors_from_actor(sphere)
    color = options[radio.checked_labels[0]]
    vcolors[:] = np.array(color)

color_toggler.on_change = toggle_color

Show Manager

Now that all the elements have been initialised, we add them to the show manager.

Set camera for better visualization

viz radio buttons

Total running time of the script: ( 0 minutes 0.403 seconds)

Gallery generated by Sphinx-Gallery