def test_hover_selection_vertices(recording=False): # simply hover through blue, green, red cubes # close to any vertices of each of the cubes recording_filename = join(DATA_DIR, 'selector_vertices.log.gz') centers, colors, radii = _get_three_cubes() scene = window.Scene() cube_actor = actor.cube(centers, directions=(1, 0, 0), colors=colors, scales=radii) scene.add(cube_actor) selm = pick.SelectionManager(select='vertices') showm = window.ShowManager(scene, size=(900, 768), reset_camera=False, order_transparent=True) showm.initialize() global track_objects2 track_objects2 = [] def hover_callback(_obj, _event): global track_objects2 event_pos = selm.event_position(showm.iren) info = selm.select(event_pos, showm.scene, (100, 100)) selected_triangles = info[0]['vertex'] if selected_triangles is not None: track_objects2.append(selected_triangles[0] // 8) showm.render() showm.add_iren_callback(hover_callback) if recording: showm.record_events_to_file(recording_filename) else: showm.play_events_from_file(recording_filename) track_obj = set(track_objects2) npt.assert_(track_obj.issubset({0, 1, 2})) del track_objects2
def test_hover_selection_actors_only(recording=False): # simply hover going through blue, green, red cubes recording_filename = join(DATA_DIR, 'selector_actors.log.gz') centers, colors, radii = _get_three_cubes() scene = window.Scene() cube_actor = actor.cube(centers, directions=(1, 0, 0), colors=colors, scales=radii) scene.add(cube_actor) selm = pick.SelectionManager(select='actors') showm = window.ShowManager(scene, size=(900, 768), reset_camera=False, order_transparent=True) showm.initialize() def hover_callback(_obj, _event): event_pos = selm.event_position(showm.iren) info = selm.pick(event_pos, showm.scene) selected_actor = info['actor'] # print(id(selected_actor), id(cube_actor)) if selected_actor is not None: npt.assert_equal(id(cube_actor), id(selected_actor)) showm.render() showm.add_iren_callback(hover_callback) if recording: showm.record_events_to_file(recording_filename) else: showm.play_events_from_file(recording_filename)
def test_selector_manager(): centers, colors, radii = _get_three_cubes() scene = window.Scene() cube_actor = actor.cube(centers, directions=(1, 0, 2), colors=colors, scales=radii) pts = 100 * (np.random.rand(100, 3) - 0.5) + np.array([20, 0, 0.]) pts_actor = actor.dots(pts, dot_size=10) rgb = 255 * np.ones((400, 400, 3), dtype=np.uint8) tex_actor = actor.texture(rgb) scene.add(cube_actor) scene.add(pts_actor) scene.add(tex_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() selm = pick.SelectionManager(select='faces') selm.selectable_off([tex_actor]) selm.selectable_on([tex_actor]) selm.selectable_off([tex_actor]) def timer_callback(_obj, _event): cnt = next(counter) tb.message = "Let's count up to 15 and exit :" + str(cnt) if cnt % 10 == 0: # select large area info_plus = selm.select((900 // 2, 768 // 2), scene, (30, 30)) for info in info_plus.keys(): if info_plus[info]['actor'] in [cube_actor, pts_actor]: npt.assert_(True) else: npt.assert_(False) # select single pixel info_ = selm.pick((900 // 2, 768 // 2), scene) if info_['actor'] in [cube_actor, pts_actor]: npt.assert_(True) else: npt.assert_(False) showm.render() if cnt == 15: showm.exit() pass scene.add(tb) # Run every 200 milliseconds showm.add_timer_callback(True, 200, timer_callback) showm.start()
############################################################################### # Create a rectangular 2d box as a texture 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(cube_actor) scene.add(texa) scene.reset_camera() scene.zoom(3.) ############################################################################### # Create the Selection Manager selm = pick.SelectionManager(select='faces') ############################################################################### # Tell Selection Manager to avoid selecting specific actors selm.selectable_off(texa) ############################################################################### # Let's make the callback which will be called # when we hover the mouse 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)