fury-gl / fury

FURY - Free Unified Rendering in pYthon.
https://fury.gl
Other
241 stars 181 forks source link

Allow selection and picking of surfaces with triangle strips #757

Open Garyfallidis opened 1 year ago

Garyfallidis commented 1 year ago

Currently the SelectionManager works as expected for selecting triangle representations of surfaces.

However when we have surfaces represented with triangle strips we need to be more careful and find the correct triangle indices from the strips.

To see the issue you can start by modifying the viz_selection.py tutorial and add actors that use strips such as streamtube and then try to select those and start debugging the issue.

Clarkszw commented 1 year ago

Hi @Garyfallidis, where is the viz_selection.py tutorial you mentioned..

update 10.3.2023 I think this is the tutorial you mentioned: Selecting multiple objects

Clarkszw commented 1 year ago

Hi @Garyfallidis , I need some help.. Here is the snippet I wrote for streamtube. But I don't know how to change the color for the selection. could you give me some hitns? Thanks in advance:)

import numpy as np
from fury import actor, window, pick, utils

scene = window.Scene()

lines = [np.random.rand(10, 3), 10 * np.random.rand(20, 3)]
colors = np.random.rand(2, 3)
streamtube_actor = actor.streamtube(lines, colors)

rgba = 255 * np.ones((100, 200, 4))
rgba[1:-1, 1:-1] = np.zeros((98, 198, 4))+100
texa = actor.texture_2d(rgba.astype(np.uint8))

scene.add(streamtube_actor)
scene.add(texa)
scene.reset_camera()
scene.zoom(3.)

showm = window.ShowManager(scene, size=(1024, 768),
                            order_transparent=True,
                            reset_camera=False)

selm = pick.SelectionManager(select='faces')
selm.selectable_off(texa)

vcolors = utils.colors_from_actor(streamtube_actor, 'colors')

def hover_callback(_obj, _event):
    event_pos = selm.event_position(showm.iren)
    # updates rectangular box around mouse
    texa.SetPosition(event_pos[0] - 200//2,
                     event_pos[1] - 100//2)

    # defines selection region and returns information from selected objects
    info = selm.select(event_pos, showm.scene, (200//2, 100//2))
    for node in info.keys():
        if info[node]['face'] is not None:
            if info[node]['actor'] is streamtube_actor:
                for face_index in info[node]['face']:
                    color_change = np.array([150, 0, 0], dtype='uint8')
                    vcolors[face_index] \
                        = color_change
                utils.update_actor(streamtube_actor)
    showm.render()

showm.add_iren_callback(hover_callback)

interactive = True

if interactive:
    showm.start()
Preetam-Das26 commented 8 months ago

Is this issue resolved? @Garyfallidis @Clarkszw