コード例 #1
0
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=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
コード例 #2
0
button_right = ui.Button2D(icon_fnames=[
    ('square', read_viz_icons(fname='circle-right.png'))
],
                           position=(295, 295),
                           size=(30, 30))

textbox2 = ui.TextBox2D(50,
                        20,
                        position=(330, 270),
                        text="Element 2" + " " * 8)
button_down = ui.Button2D(icon_fnames=[
    ('square', read_viz_icons(fname='circle-down.png'))
],
                          position=(295, 265),
                          size=(30, 30))

content = ui.Panel2D(size=(170, 100), color=(1, 1, 1), align="left")
content.center = (330, 330)

textbox = ui.TextBox2D(50, 10, text="Hello World!!")
content.add_element(textbox, (20, 50))

elements = [textbox1, button_right, button_down, content, textbox2, textbox]

current_size = (800, 800)
show_manager = window.ShowManager(size=current_size,
                                  title="Accordion UI Example")
for element in elements:
    show_manager.scene.add(element)
show_manager.start()
コード例 #3
0
    spheres_actor = actor.billboard(xyz,
                                    colors,
                                    scales=cell_radii,
                                    fs_impl=fake_sphere)
    scene.add(spheres_actor)

    show_m = window.ShowManager(scene,
                                reset_camera=False,
                                order_transparent=True,
                                max_peels=0)
    show_m.initialize()

    global panel
    panel = ui.Panel2D((256, 144),
                       position=(40, 5),
                       color=(1, 1, 1),
                       opacity=.1,
                       align='right')

    thr_x1 = np.percentile(xyz[:, 0], 50)
    thr_x2 = max_xyz[0]
    global ind_x
    ind_x = argviz(thr_x1, thr_x2, xyz, 0)
    slider_clipping_plane_label_x = build_label('X Clipping Plane')
    slider_clipping_plane_thrs_x = ui.LineDoubleSlider2D(
        line_width=3,
        outer_radius=5,
        length=115,
        initial_values=(thr_x1, thr_x2),
        min_value=min_xyz[0],
        max_value=max_xyz[0],
コード例 #4
0
ファイル: fury_protocol.py プロジェクト: fury-gl/fury-web
    def create_visualization(self):
        ren_win = self.getView('-1')
        scene = ren_win.GetRenderers().GetFirstRenderer()
        showm = self.getSharedObject('SHOWM')

        self.panel = ui.Panel2D((480, 270),
                                position=(5, 5),
                                color=(1, 1, 1),
                                opacity=.1,
                                align='right')

        self.slider_frame_label = build_label('Frame')
        self.slider_frame_label.set_visibility(False)
        self.slider_frame_thr = ui.LineSlider2D(initial_value=0,
                                                min_value=0,
                                                max_value=1,
                                                length=260,
                                                line_width=3,
                                                outer_radius=8,
                                                font_size=16,
                                                text_template="{value:.0f}")
        self.slider_frame_thr.set_visibility(False)
        self.slider_frame_thr.on_change = self.change_frame
        self.slider_clipping_plane_label_x = build_label('X Clipping Plane')
        self.slider_clipping_plane_thrs_x = ui.LineDoubleSlider2D(
            line_width=3,
            outer_radius=8,
            length=260,
            initial_values=(self.low_ranges[0], self.high_ranges[0]),
            min_value=self.min_centers[0],
            max_value=self.max_centers[0],
            font_size=16,
            text_template="{value:.0f}")

        self.slider_clipping_plane_label_y = build_label('Y Clipping Plane')
        self.slider_clipping_plane_thrs_y = ui.LineDoubleSlider2D(
            line_width=3,
            outer_radius=8,
            length=260,
            initial_values=(self.low_ranges[1], self.high_ranges[1]),
            min_value=self.min_centers[1],
            max_value=self.max_centers[1],
            font_size=16,
            text_template="{value:.0f}")

        self.slider_clipping_plane_label_z = build_label('Z Clipping Plane')
        self.slider_clipping_plane_thrs_z = ui.LineDoubleSlider2D(
            line_width=3,
            outer_radius=8,
            length=260,
            initial_values=(self.low_ranges[2], self.high_ranges[2]),
            min_value=self.min_centers[2],
            max_value=self.max_centers[2],
            font_size=16,
            text_template="{value:.0f}")

        self.panel.add_element(self.slider_frame_label, (.04, .85))
        self.panel.add_element(self.slider_frame_thr, (.38, .85))
        self.panel.add_element(self.slider_clipping_plane_label_x, (.04, .55))
        self.panel.add_element(self.slider_clipping_plane_thrs_x, (.38, .55))
        self.panel.add_element(self.slider_clipping_plane_label_y, (.04, .35))
        self.panel.add_element(self.slider_clipping_plane_thrs_y, (.38, .35))
        self.panel.add_element(self.slider_clipping_plane_label_z, (.04, .15))
        self.panel.add_element(self.slider_clipping_plane_thrs_z, (.38, .15))

        scene.ResetCamera()
        scene.add(self.panel)
        self.size = scene.GetSize()
        # showm.add_window_callback(self.win_callback)
        showm.render()

        if self.load_default:
            print("load default")
            data = {
                "folder": os.path.abspath(os.path.dirname(__file__)),
                "filename": 'output00000246.xml'
            }
            self.add_frame(data)
コード例 #5
0
First, some imports.
"""

from fury import ui
from fury import window

from fury.layout import GridLayout

###############################################################################
# We create some panels and then we arrange them in a grid fashion
#
# First, we create some panels with different sizes/positions

panel_1 = ui.Panel2D(size=(200, 200),
                     color=(0.4, 0.6, 0.3),
                     position=(100, 100))

panel_2 = ui.Panel2D(size=(250, 250),
                     color=(0.8, 0.3, 0.5),
                     position=(150, 150))

###############################################################################
# Now we create two listboxes

listbox_1 = ui.ListBox2D(size=(150, 150), values=['First', 'Second', 'Third'])

listbox_2 = ui.ListBox2D(size=(250, 250), values=['First', 'Second', 'Third'])

###############################################################################
# Now we create two diffrent UI i.e. a slider and a listbox
コード例 #6
0
ファイル: test_ui.py プロジェクト: kakashihatakae/fury
def test_frame_rate_and_anti_aliasing():
    """Testing frame rate with/out anti-aliasing"""

    length_ = 200
    multi_samples = 32
    max_peels = 8

    st_x = np.arange(length_)
    st_y = np.sin(np.arange(length_))
    st_z = np.zeros(st_x.shape)
    st = np.zeros((length_, 3))
    st[:, 0] = st_x
    st[:, 1] = st_y
    st[:, 2] = st_z

    all_st = []
    all_st.append(st)
    for i in range(1000):
        all_st.append(st + i * np.array([0., .5, 0]))

    # st_actor = actor.line(all_st, linewidth=1)
    # TODO: textblock disappears when lod=True
    st_actor = actor.streamtube(all_st, linewidth=0.1, lod=False)

    scene = window.Scene()
    scene.background((1, 1., 1))

    # quick game style antialiasing
    scene.fxaa_on()
    scene.fxaa_off()

    # the good staff is later with multi-sampling

    tb = ui.TextBlock2D(font_size=40, color=(1, 0.5, 0))

    panel = ui.Panel2D(position=(400, 400), size=(400, 400))
    panel.add_element(tb, (0.2, 0.5))

    counter = itertools.count()
    showm = window.ShowManager(scene,
                               size=(1980, 1080), reset_camera=False,
                               order_transparent=True,
                               multi_samples=multi_samples,
                               max_peels=max_peels,
                               occlusion_ratio=0.0)

    showm.initialize()
    scene.add(panel)
    scene.add(st_actor)
    scene.reset_camera_tight()
    scene.zoom(5)

    class FrameRateHolder(object):
        fpss = []

    frh = FrameRateHolder()

    def timer_callback(_obj, _event):
        cnt = next(counter)
        if cnt % 1 == 0:
            fps = np.round(scene.frame_rate, 0)
            frh.fpss.append(fps)
            msg = "FPS " + str(fps) + ' ' + str(cnt)
            tb.message = msg
            showm.render()
        if cnt > 10:
            showm.exit()

    # Run every 200 milliseconds
    showm.add_timer_callback(True, 200, timer_callback)
    showm.start()

    arr = window.snapshot(scene, size=(1980, 1080),
                          offscreen=True,
                          order_transparent=True,
                          multi_samples=multi_samples,
                          max_peels=max_peels,
                          occlusion_ratio=0.0)
    assert_greater(np.sum(arr), 0)
    # TODO: check why in osx we have issues in Azure
    if not skip_osx:
        assert_greater(np.median(frh.fpss), 0)

    frh.fpss = []
    counter = itertools.count()
    multi_samples = 0
    showm = window.ShowManager(scene,
                               size=(1980, 1080), reset_camera=False,
                               order_transparent=True,
                               multi_samples=multi_samples,
                               max_peels=max_peels,
                               occlusion_ratio=0.0)

    showm.initialize()
    showm.add_timer_callback(True, 200, timer_callback)
    showm.start()

    arr2 = window.snapshot(scene, size=(1980, 1080),
                           offscreen=True,
                           order_transparent=True,
                           multi_samples=multi_samples,
                           max_peels=max_peels,
                           occlusion_ratio=0.0)
    assert_greater(np.sum(arr2), 0)
    if not skip_osx:
        assert_greater(np.median(frh.fpss), 0)
コード例 #7
0
ファイル: test_containers.py プロジェクト: m-agour/fury
def test_wrong_interactor_style():
    panel = ui.Panel2D(size=(300, 150))
    dummy_scene = window.Scene()
    _ = window.ShowManager(dummy_scene, interactor_style='trackball')
    npt.assert_raises(TypeError, panel.add_to_scene, dummy_scene)
コード例 #8
0
def test_wrong_interactor_style():
    panel = ui.Panel2D(size=(300, 150))
    dummy_renderer = window.Renderer()
    dummy_show_manager = window.ShowManager(dummy_renderer,
                                            interactor_style='trackball')
    npt.assert_raises(TypeError, panel.add_to_renderer, dummy_renderer)
コード例 #9
0
ファイル: newbie.py プロジェクト: ShreyasFadnavis/fury-tests
import os
from fury import ui, window, actor
import nibabel as nib
from dipy.data import fetch_bundles_2_subjects

panel = ui.Panel2D(size=(600, 400), color=(1, 1, 1), align="right")
panel.center = (500, 400)

icon_fnames = [('square', 'model_predictions.png'), ('square2', 'wmparc.png')]

button = ui.Button2D(icon_fnames, size=(500, 300))

panel.add_element(button, coords=(0., 0.))

scene = window.Scene()

showm = window.ShowManager(scene, size=(1000, 1000))

showm.initialize()

scene.add(actor.axes())

scene.add(panel)


def change_icon_callback(i_ren, _obj, _button):
    button.next_icon()
    showm.render()


button.on_left_mouse_button_clicked = change_icon_callback
コード例 #10
0
    def build_surface_demo(self, showm):
        xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 50], [200, 0, 0, 100]])

        colors = np.random.rand(*(xyzr.shape[0], 4))
        colors[:, 3] = 1

        # global text_block
        text_block = ui.TextBlock2D(text='',
                                    font_size=20,
                                    bold=True,
                                    color=(1, 1, 1))

        panel = ui.Panel2D(size=(350, 100),
                           position=(150, 90),
                           color=(.6, .6, .6))
        panel.add_element(text_block, (0.2, 0.3))

        sphere_actor = actor.sphere(centers=0.5 * xyzr[:, :3],
                                    colors=colors[:],
                                    radii=xyzr[:, 3])

        # sphere_actor.GetProperty().SetRepresentationToWireframe()
        # sphere_actor.GetProperty().SetWireFrame(1)
        axes_actor = actor.axes(scale=(10, 10, 10))

        picker = vtk.vtkCellPicker()
        # picker = window.vtk.vtkPointPicker()
        # print(picker.GetTolerance())
        picker.SetTolerance(0.01)

        dummy_sphere = actor.sphere(centers=np.array([[0, 0, 0]]),
                                    radii=.1,
                                    colors=np.array([[1, 1, 0, 1.]]))

        prev_translation = (0, 0, 0)

        def left_click_callback(obj, event):
            local_showm = left_click_callback.showm
            local_picker = left_click_callback.picker
            local_dummy_sphere = left_click_callback.dummy_sphere
            local_text_block = left_click_callback.text_block
            x, y, z = obj.GetCenter()
            event_pos = local_showm.iren.GetEventPosition()

            local_picker.Pick(event_pos[0], event_pos[1], 0, local_showm.scene)

            # cell_index = picker.GetCellId()
            point_index = local_picker.GetPointId()
            #text = 'Face ID ' + str(cell_index) + '\n' + 'Point ID ' + str(point_index)
            pos = np.round(local_picker.GetMapperPosition(), 3)
            text = str(point_index) + ' ' + str(pos)

            pi, pj, pk = prev_translation
            local_dummy_sphere.SetPosition(-pi, -pj, -pk)

            i, j, k = local_picker.GetMapperPosition()

            local_dummy_sphere.SetPosition(i, j, k)
            local_text_block.message = text
            # local_showm.render()

            local_showm.prev_translation = pos

        left_click_callback.showm = showm
        left_click_callback.picker = picker
        left_click_callback.prev_translation = prev_translation
        left_click_callback.text_block = text_block
        left_click_callback.dummy_sphere = dummy_sphere
        sphere_actor.AddObserver('LeftButtonPressEvent', left_click_callback,
                                 1)

        return ('Surface Demo',
                [panel, axes_actor, sphere_actor, dummy_sphere])
コード例 #11
0
    def build_slider_demo(self):
        panel = ui.Panel2D(size=(500, 150),
                           color=(1.0, 1.0, 1.0),
                           align="right",
                           opacity=0.1)
        panel.center = (500, 400)

        ring_slider = ui.RingSlider2D(center=(740, 400),
                                      initial_value=0,
                                      text_template="{angle:5.1f}")
        ring_slider.default_color = (1, 0.5, 0)
        ring_slider.track.color = (0.8, 0.3, 0)
        ring_slider.active_color = (0.9, 0.4, 0)
        ring_slider.handle.color = (1, 0.5, 0)

        line_slider = ui.LineSlider2D(center=(500, 250),
                                      initial_value=0,
                                      min_value=-10,
                                      max_value=10)
        line_slider.default_color = (1, 0.5, 0)
        line_slider.track.color = (0.8, 0.3, 0)
        line_slider.active_color = (0.9, 0.4, 0)
        line_slider.handle.color = (1, 0.5, 0)

        def cube_maker(color=(1, 1, 1), size=(0.2, 0.2, 0.2),
                       center=(0, 0, 0)):
            cube = vtk.vtkCubeSource()
            cube.SetXLength(size[0])
            cube.SetYLength(size[1])
            cube.SetZLength(size[2])
            if center is not None:
                cube.SetCenter(*center)
            cube_mapper = vtk.vtkPolyDataMapper()
            cube_mapper.SetInputConnection(cube.GetOutputPort())
            cube_actor = vtk.vtkActor()
            cube_actor.SetMapper(cube_mapper)
            if color is not None:
                cube_actor.GetProperty().SetColor(color)
            return cube_actor

        cube = cube_maker(color=(0, 0, 1),
                          size=(20, 20, 20),
                          center=(15, 0, 0))

        def rotate_cube(slider):
            angle = slider.value
            previous_angle = slider.previous_value
            rotation_angle = angle - previous_angle
            cube.RotateX(rotation_angle)

        ring_slider.on_change = rotate_cube

        def translate_cube(slider):
            value = slider.value
            cube.SetPosition(value, 0, 0)

        line_slider.on_change = translate_cube

        panel.add_element(ring_slider, (50, 20))
        panel.add_element(line_slider, (200, 70))

        return ('Slider Demo', [panel, cube])
コード例 #12
0
    def build_brain_demo(self, showm):
        # path = "/Users/koudoro/Software/temp/"
        path = "/pvw/data/"
        # lh_path = os.path.join(path, "100307_white_lh.vtk")
        # rh_path = os.path.join(path, "100307_white_rh.vtk")
        # lh_pd = load_polydata(lh_path)
        # rh_pd = load_polydata(rh_path)
        left_fname = os.path.join(path, 'pial_left.gii')
        right_fname = os.path.join(path, 'pial_right.gii')

        left_gii = nib.load(left_fname)
        right_gii = nib.load(right_fname)

        left_pointset = left_gii.darrays[
            0].data  # NIFTI_INTENT_POINTSET   1008
        left_triangles = left_gii.darrays[
            1].data  # NIFTI_INTENT_TRIANGLE   1009
        right_pointset = right_gii.darrays[0].data
        right_triangles = right_gii.darrays[1].data

        left_poly = vtk.vtkPolyData()
        right_poly = vtk.vtkPolyData()

        utils.set_polydata_vertices(left_poly, left_pointset)
        utils.set_polydata_triangles(left_poly, left_triangles)
        utils.set_polydata_vertices(right_poly, right_pointset)
        utils.set_polydata_triangles(right_poly, right_triangles)

        lh_actor = utils.get_actor_from_polydata(left_poly)
        rh_actor = utils.get_actor_from_polydata(right_poly)

        text_block = ui.TextBlock2D(text='',
                                    font_size=15,
                                    bold=True,
                                    color=(1, 1, 1))

        panel = ui.Panel2D(size=(250, 30),
                           position=(120, 30),
                           color=(.8, .8, .8),
                           opacity=0.1)
        panel.add_element(text_block, (0.1, 0.1))

        picker = vtk.vtkCellPicker()
        # picker = window.vtk.vtkPointPicker()
        # print(picker.GetTolerance())
        picker.SetTolerance(0.01)

        dummy_sphere = actor.sphere(centers=np.array([[0, 0, 0]]),
                                    radii=1,
                                    colors=np.array([[1, 1, 0, 1.]]))

        prev_translation = (0, 0, 0)

        def highlight(obj, event):
            if not hasattr(obj, 'selected'):
                obj.selected = False

            selected = obj.selected
            color = obj.default_color if selected else (1.0, 1.0, 1.0)
            if event == "RightButtonPressEvent":
                obj.GetProperty().SetColor(color)
                obj.selected = not obj.selected

        def left_click_callback(obj, event):
            local_showm = left_click_callback.showm
            local_picker = left_click_callback.picker
            local_dummy_sphere = left_click_callback.dummy_sphere
            local_prev_translation = left_click_callback.prev_translation
            local_text_block = left_click_callback.text_block
            x, y, z = obj.GetCenter()
            event_pos = local_showm.iren.GetEventPosition()

            local_picker.Pick(event_pos[0], event_pos[1], 0, local_showm.scene)

            # cell_index = picker.GetCellId()
            point_index = local_picker.GetPointId()
            #text = 'Face ID ' + str(cell_index) + '\n' + 'Point ID ' + str(point_index)
            pos = np.round(local_picker.GetMapperPosition(), 3)
            text = str(point_index) + ' ' + str(pos)

            pi, pj, pk = local_prev_translation
            local_dummy_sphere.SetPosition(-pi, -pj, -pk)

            i, j, k = local_picker.GetMapperPosition()

            local_dummy_sphere.SetPosition(i, j, k)
            local_text_block.message = text
            # local_showm.render()
            local_showm.prev_translation = pos

        left_click_callback.showm = showm
        left_click_callback.picker = picker
        left_click_callback.prev_translation = prev_translation
        left_click_callback.text_block = text_block
        left_click_callback.dummy_sphere = dummy_sphere

        lh_actor.AddObserver('LeftButtonPressEvent', left_click_callback, 1)
        rh_actor.AddObserver('LeftButtonPressEvent', left_click_callback, 1)

        rh_actor.selected = False
        lh_actor.selected = False
        rh_actor.default_color = (1.0, 0.5, 0.0)
        lh_actor.default_color = (1.0, 0.0, 0.5)
        rh_actor.AddObserver('RightButtonPressEvent', highlight, 1)
        rh_actor.AddObserver('RightButtonReleaseEvent', highlight, 1)
        lh_actor.AddObserver('RightButtonPressEvent', highlight, 1)
        lh_actor.AddObserver('RightButtonReleaseEvent', highlight, 1)

        return ('Brain Demo', [panel, lh_actor, rh_actor, dummy_sphere])
コード例 #13
0
def point_left_click_callback(obj, ev):
    """Get the value of the clicked voxel and show it in the panel."""
    event_pos = point_left_click_callback.show_m.iren.GetEventPosition()
    showm = point_left_click_callback.show_m
    scene = point_left_click_callback.show_m.scene
    picker = point_left_click_callback.picker
    nb_sphere_vertices = point_left_click_callback.nb_sphere_vertices

    panel = ui.Panel2D(size=(550, 300),
                       position=(20, 900),
                       color=(1, 1, 1),
                       opacity=0.1,
                       align="right")

    picker.Pick(event_pos[0],
                event_pos[1],
                0,
                scene)

    point_id = picker.GetPointId()
    if point_id < 0:
        print("invalid picking")
        return

    error=4
    inds = [(int(round(coord[0], 0)), int(round(coord[1], 0)), int(round(coord[2], 0))) for coord in get_neighborhood(picker.GetPickPosition(), error, zooms, dims)]

    point_candidates = []
    for point in inds:
        if point in coord_nodes_int:
            point_candidates.append(point)

    if len(point_candidates) > 1:
        coord_pick = closest(picker.GetPickPosition(), point_candidates)
    else:
        try:
            coord_pick = point_candidates[0]
        except:
            pass

    try:
        node_ix = coord_node_mappings[coord_node(x=coord_pick[0], y=coord_pick[1], z=coord_pick[2])]
        print(node_ix)
        met_list = get_mets_by_pointid(node_ix, G)
    except:
        pass

    try:
        print(stringify_met_list(met_list))
    except:
        pass

    try:
        comm_members = get_mets_by_pointid_comm(node_ix, G)
        sphere = get_sphere('symmetric362')
        comm_coords = []
        for comm_mem in comm_members:
            comm_coords.append(node_coord_mappings[comm_mem])
        point_actor = actor.sphere(list(set(comm_coords)), window.colors.royal_blue,
                                   radii=1.25, vertices=sphere.vertices, faces=sphere.faces)

        scene.add(point_actor)
        showm.render()
        def timer_callback(_obj, _event):
            scene.RemoveActor(point_actor)
            showm.render()

        showm.add_timer_callback(False, 100, timer_callback)
    except:
        pass

    return
コード例 #14
0
    ch2bet = os.path.join(DATA_DIR, 'ch2better.nii.gz')
    atlas = os.path.join(DATA_DIR, 'atlas_aal_8_t1w_mni.nii.gz')
    graph_properties = os.path.join(DATA_DIR, '127_net_metrics_csd_1.0_8mm_neat.csv')
    conn_matrix_path = os.path.join(DATA_DIR, '127_est_csd_unthresh_mat.npy')
    interactive = True

    # Instantiate scene
    scene = window.Scene()
    current_size = (1000, 1000)
    show_manager = window.ShowManager(scene=scene, size=current_size,
                                      title="Network Visualization")
    show_manager.initialize()

    panel = ui.Panel2D(size=(200, 200),
                       position=(750, 20),
                       color=(1, 1, 1),
                       opacity=0.1,
                       align="right")
    show_checkbox = ui.Checkbox(labels=["brain", "surfaces", "streamlines"])
    show_checkbox.on_change = visible_callback
    panel.add_element(show_checkbox, coords=(0.1, 0.333))
    scene.add(panel)

    win_callback.win_size = current_size
    win_callback.panel = panel

    # Load atlas rois
    atlas_img = nib.load(atlas)
    dims = atlas_img.shape
    zooms = atlas_img.get_header().get_zooms()
    atlas_img_data = atlas_img.get_data()
コード例 #15
0
ファイル: viz_slice.py プロジェクト: zoq/fury
show_m = window.ShowManager(scene, size=(1200, 900))
show_m.initialize()

###############################################################################
# We'll start by creating the panel and adding it to the ``ShowManager``

label_position = ui.TextBlock2D(text='Position:')
label_value = ui.TextBlock2D(text='Value:')

result_position = ui.TextBlock2D(text='')
result_value = ui.TextBlock2D(text='')

panel_picking = ui.Panel2D(size=(250, 125),
                           position=(20, 20),
                           color=(0, 0, 0),
                           opacity=0.75,
                           align="left")

panel_picking.add_element(label_position, (0.1, 0.55))
panel_picking.add_element(label_value, (0.1, 0.25))

panel_picking.add_element(result_position, (0.45, 0.55))
panel_picking.add_element(result_value, (0.45, 0.25))

show_m.scene.add(panel_picking)

##############################################################################
# Add a left-click callback to the slicer. Also disable interpolation so you
# can see what you are picking.
コード例 #16
0
                                    fs_impl=_FAKE_SPHERE)

    spheres_mapper = spheres_actor.GetMapper()
    spheres_mapper.AddObserver(vtk.vtkCommand.UpdateShaderEvent,
                               vtk_shader_callback)

    scene.add(spheres_actor)

    show_m = window.ShowManager(scene,
                                reset_camera=False,
                                order_transparent=True)
    show_m.initialize()

    panel = ui.Panel2D((480, 270),
                       position=(-185, 5),
                       color=(1, 1, 1),
                       opacity=.1,
                       align='right')

    slider_frame_label = build_label('Frame')
    slider_clipping_plane_label_x = build_label('X Clipping Plane')
    slider_clipping_plane_label_y = build_label('Y Clipping Plane')
    slider_clipping_plane_label_z = build_label('Z Clipping Plane')

    panel.add_element(slider_frame_label, (.04, .85))
    panel.add_element(slider_clipping_plane_label_x, (.04, .55))
    panel.add_element(slider_clipping_plane_label_y, (.04, .35))
    panel.add_element(slider_clipping_plane_label_z, (.04, .15))

    min_centers = np.min(centers, axis=0)
    max_centers = np.max(centers, axis=0)
コード例 #17
0
ファイル: viz_advanced.py プロジェクト: furious-atoms/fury
    label.background = (0, 0, 0)
    label.color = (1, 1, 1)

    return label


line_slider_label_z = build_label(text="Z Slice")
line_slider_label_x = build_label(text="X Slice")
line_slider_label_y = build_label(text="Y Slice")
opacity_slider_label = build_label(text="Opacity")

###############################################################################
# Now we will create a ``panel`` to contain the sliders and labels.

panel = ui.Panel2D(size=(300, 200),
                   color=(1, 1, 1),
                   opacity=0.1,
                   align="right")
panel.center = (1030, 120)

panel.add_element(line_slider_label_x, (0.1, 0.75))
panel.add_element(line_slider_x, (0.38, 0.75))
panel.add_element(line_slider_label_y, (0.1, 0.55))
panel.add_element(line_slider_y, (0.38, 0.55))
panel.add_element(line_slider_label_z, (0.1, 0.35))
panel.add_element(line_slider_z, (0.38, 0.35))
panel.add_element(opacity_slider_label, (0.1, 0.15))
panel.add_element(opacity_slider, (0.38, 0.15))

show_m.ren.add(panel)

###############################################################################
コード例 #18
0
ファイル: tumor_viz.py プロジェクト: rheiland/fury_tumor
    scene = window.Scene()

    global spheres_actor
    spheres_actor = actor.sphere(xyz, colors, radii=cell_radii, theta=8, phi=8)
    scene.add(spheres_actor)

    show_m = window.ShowManager(scene,
                                size=(1200, 900),
                                order_transparent=True,
                                reset_camera=False)
    show_m.initialize()

    global panel
    panel = ui.Panel2D((420, 240),
                       position=(760, 20),
                       color=(1, 1, 1),
                       opacity=.1,
                       align='right')

    thr_x1 = np.percentile(xyz[:, 0], 25)
    thr_x2 = max_xyz[0]
    global ind_x
    ind_x = argviz(thr_x1, thr_x2, xyz, 0)
    slider_clipping_plane_label_x = build_label('X Clipping Plane')
    slider_clipping_plane_thrs_x = ui.LineDoubleSlider2D(
        initial_values=(thr_x1, thr_x2),
        min_value=min_xyz[0],
        max_value=max_xyz[0],
        text_template="{value:.0f}")

    thr_y1 = np.percentile(xyz[:, 1], 25)
コード例 #19
0
ファイル: test_ui.py プロジェクト: kakashihatakae/fury
def test_ui_button_panel(recording=False):
    filename = "test_ui_button_panel"
    recording_filename = pjoin(DATA_DIR, filename + ".log.gz")
    expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json")

    # Rectangle
    rectangle_test = ui.Rectangle2D(size=(10, 10))
    another_rectangle_test = ui.Rectangle2D(size=(1, 1))

    # Button
    fetch_viz_icons()

    icon_files = []
    icon_files.append(('stop', read_viz_icons(fname='stop2.png')))
    icon_files.append(('play', read_viz_icons(fname='play3.png')))

    button_test = ui.Button2D(icon_fnames=icon_files)
    button_test.center = (20, 20)

    def make_invisible(i_ren, _obj, button):
        # i_ren: CustomInteractorStyle
        # obj: vtkActor picked
        # button: Button2D
        button.set_visibility(False)
        i_ren.force_render()
        i_ren.event.abort()

    def modify_button_callback(i_ren, _obj, button):
        # i_ren: CustomInteractorStyle
        # obj: vtkActor picked
        # button: Button2D
        button.next_icon()
        i_ren.force_render()

    button_test.on_right_mouse_button_pressed = make_invisible
    button_test.on_left_mouse_button_pressed = modify_button_callback

    button_test.scale((2, 2))
    button_color = button_test.color
    button_test.color = button_color

    # TextBlock
    text_block_test = ui.TextBlock2D()
    text_block_test.message = 'TextBlock'
    text_block_test.color = (0, 0, 0)

    # Panel
    panel = ui.Panel2D(size=(300, 150),
                       position=(290, 15),
                       color=(1, 1, 1), align="right")
    panel.add_element(rectangle_test, (290, 135))
    panel.add_element(button_test, (0.1, 0.1))
    panel.add_element(text_block_test, (0.7, 0.7))
    npt.assert_raises(ValueError, panel.add_element, another_rectangle_test,
                      (10., 0.5))
    npt.assert_raises(ValueError, panel.add_element, another_rectangle_test,
                      (-0.5, 0.5))

    # Assign the counter callback to every possible event.
    event_counter = EventCounter()
    event_counter.monitor(button_test)
    event_counter.monitor(panel.background)

    current_size = (600, 600)
    show_manager = window.ShowManager(size=current_size, title="FURY Button")

    show_manager.scene.add(panel)

    if recording:
        show_manager.record_events_to_file(recording_filename)
        print(list(event_counter.events_counts.items()))
        event_counter.save(expected_events_counts_filename)

    else:
        show_manager.play_events_from_file(recording_filename)
        expected = EventCounter.load(expected_events_counts_filename)
        event_counter.check_counts(expected)
コード例 #20
0
ファイル: viz_pbr_interactive.py プロジェクト: m-agour/fury
###############################################################################
# Let's setup now the window and the UI.

show_m = window.ShowManager(scene=scene,
                            size=(1920, 1080),
                            reset_camera=False,
                            order_transparent=True)
show_m.initialize()

###############################################################################
# We will create one single panel with all of our labels and sliders.

control_panel = ui.Panel2D((400, 500),
                           position=(5, 5),
                           color=(.25, .25, .25),
                           opacity=.75,
                           align='right')

###############################################################################
# By using our previously defined function, we can easily create all the labels
# we need for this demo. And then add them to the panel.

slider_label_metallic = ui.TextBlock2D(text='Metallic', font_size=16)
slider_label_roughness = ui.TextBlock2D(text='Roughness', font_size=16)
slider_label_anisotropy = ui.TextBlock2D(text='Anisotropy', font_size=16)
slider_label_anisotropy_rotation = ui.TextBlock2D(text='Anisotropy Rotation',
                                                  font_size=16)
slider_label_anisotropy_direction_x = ui.TextBlock2D(
    text='Anisotropy Direction X', font_size=16)
slider_label_anisotropy_direction_y = ui.TextBlock2D(
コード例 #21
0
fetch_viz_icons()

###############################################################################
# Now we can create an image container.

img = ui.ImageContainer2D(img_path=read_viz_icons(fname='home3.png'),
                          position=(450, 350))

###############################################################################
# Panel with buttons and text
# ===========================
#
# 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
コード例 #22
0
ファイル: file_dialog.py プロジェクト: Nibba2018/testing-fury
open_static = ui.TextBlock2D()
open_static.message = "Select template"

use_dir = ui.TextBlock2D()
use_dir.message = "Use directory"

out_dir = ui.TextBlock2D()
out_dir.message = "Output directory"

from pathlib import Path
home = str(Path.home())

file_menu = ui.FileMenu2D(home, size=(1200, 400))

panel = ui.Panel2D(size=(1800, 420))


class ProcessingObject(object):

    ftemplate = None
    dname = None
    out_dname = None


po = ProcessingObject()


def open_static_callback(obj, event):
    po.ftemplate = pjoin(file_menu.current_directory,
                         file_menu.listbox.selected[0])