vcolors = utils.colors_from_actor(fury_actor, 'colors') ############################################################################### # Adding an actor showing the axes of the world coordinates ax = actor.axes(scale=(10, 10, 10)) scene.add(fury_actor) scene.add(label_actor) scene.add(ax) scene.reset_camera() ############################################################################### # Create the Picking manager pickm = pick.PickingManager() ############################################################################### # Time to make the callback which will be called when we pick an object def left_click_callback(obj, event): # Get the event position on display and pick event_pos = pickm.event_position(showm.iren) picked_info = pickm.pick(event_pos, showm.scene) vertex_index = picked_info['vertex'] # Calculate the objects index
def test_picking_manager(): xyz = 10 * np.random.rand(100, 3) colors = np.random.rand(100, 4) radii = np.random.rand(100) + 0.5 scene = window.Scene() sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=radii) scene.add(sphere_actor) showm = window.ShowManager(scene, size=(900, 768), reset_camera=False, order_transparent=True) showm.initialize() tb = ui.TextBlock2D(bold=True) # use itertools to avoid global variables counter = itertools.count() pickm = pick.PickingManager() record_indices = { 'vertex_indices': [], 'face_indices': [], 'xyz': [], 'actor': [] } def timer_callback(_obj, _event): cnt = next(counter) tb.message = "Let's count up to 15 and exit :" + str(cnt) showm.scene.azimuth(0.05 * cnt) # sphere_actor.GetProperty().SetOpacity(cnt/100.) if cnt % 10 == 0: # pick at position info = pickm.pick((900 / 2, 768 / 2), scene) record_indices['vertex_indices'].append(info['vertex']) record_indices['face_indices'].append(info['face']) record_indices['xyz'].append(info['xyz']) record_indices['actor'].append(info['actor']) showm.render() if cnt == 15: showm.exit() scene.add(tb) # Run every 200 milliseconds showm.add_timer_callback(True, 200, timer_callback) showm.start() assert_greater(np.sum(np.array(record_indices['vertex_indices'])), 1) assert_greater(np.sum(np.array(record_indices['face_indices'])), 1) for ac in record_indices['actor']: if ac is not None: npt.assert_equal(ac is sphere_actor, True) assert_greater( np.sum(np.abs(np.diff(np.array(record_indices['xyz']), axis=0))), 0)