isl-org / isl-org/Open3D

visualizer register_key_callback does not work as expected

Open
#6,309 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### Describe the issue

I have been trying to use open3d VisualizerWithKeyCallback to visualize a list of preloaded things (e.g. point clouds and cooresponding box). The key callback worked, but it seems the keyboard event callback is invoked twice each time i press the key. I have tried 0.17.0 (which i believe is the latest version), and also 0.16.0

### Steps to reproduce the bug

```python
vis = o3d.visualization.VisualizerWithKeyCallback()
# load things
track_id_list = xxx
show_index = 0
def key_forward_callback(vis):
nonlocal show_index
show_index = min(show_index + 1, len(track_id_list) - 1)
show(vis)
return True

def key_backward_callback(vis):
nonlocal show_index
show_index = max(show_index - 1, 0)
show(vis)
return True

def show(vis):
nonlocal show_index
show_track_id = track_id_list[show_index]
print("Showing track id: {}".format(show_track_id))
pcd = pcd_list[show_track_id]
vis.clear_geometries()
vis.add_geometry(pcd)
vis.update_renderer()
vis.poll_events()

vis.create_window()
vis.get_render_option().point_size = 1.0
vis.get_render_option().background_color = np.zeros(3)
vis.register_key_callback(ord('Z'), key_backward_callback)
vis.register_key_callback(32, key_forward_callback)
vis.run()
```

### Error message

basically when i press 'space' key it prints two lines of showing track id. The same thing happens when i press 'Z' going backward.
----------------------------------
Showing track id: 1335
Showing track id: 0
Showing track id: 25
Showing track id: 0
Showing track id: 1335
......
-----------------------------------

### Expected behavior

_No response_

### Open3D, Python and System information

```markdown
- Operating system: Ubuntu 18.04
- Python version: Python 3.7.12
- Open3D version: 0.16.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip
```

### Additional information

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.