Key callback not working as expected (clear_geometries() or remove_geometry() not working)
- Dominant language
- C++
- Stars
- 14k
- Forks
- 2.6k
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 6
Description
In [#1961](https://github.com/isl-org/Open3D/issues/1961#issuecomment-644963130) Visualize Point Cloud Sequentially,
_____
**Describe the bug**
The " vis.register_key_callback(262, right_click)" doesn't work as expected.
**To Reproduce**
Run the script below:
```python
import open3d
import glob
def vis_dict(dict):
pcds = sorted(glob.glob('{}/*.pcd'.format(dict)))
print(pcds)
vis = open3d.visualization.VisualizerWithKeyCallback()
vis.create_window()
idx = 0
pcd = open3d.io.read_point_cloud(pcds[idx])
vis.add_geometry(pcd)
#vis.update_renderer()
def right_click(vis):
nonlocal idx
print('right_click')
idx = idx + 1
vis.clear_geometries() # or vis.remove_geometry()
pcd = open3d.io.read_point_cloud(pcds[idx])
vis.add_geometry(pcd)
def exit_key(vis):
vis.destroy_window()
vis.register_key_callback(262,right_click)
vis.register_key_callback(32,exit_key)
vis.poll_events()
vis.run()
#vis.destroy_window()
if __name__=='__main__':
vis_dict('/path/to/dict')
```
**Expected behavior**
I expect the following to happen when the above script runs:
1. Visualization window shows the first point cloud only
2. When I press the right click button, the visualization removes the first point cloud and then updates the visualization with the second point cloud.
3. However, it loads all the point clouds and displays them altogether as shown below.
**Screenshots**

**Environment (please complete the following information):**
- Operating system: (Ubuntu 18.04)
- Python version: (e.g. Python 3.6)
- Open3D version: open3d-0.13.0+dd076ba
- Is this remote workstation?: no
- How did you install Open3D?: (pip)
**Additional context**
The exit_key works as expected but
as soon as the script is run, all the point clouds (corresponding to three keyframes) are loaded at the beginning and displays in the visualizer(no choice to view them sequentially by pressing the right click button)
My goal is to:
1. Load a point cloud with certain viewpoint (defined in a json file)
2. capture the screen image (using vis.capture_screen_image("fname"))
3. Have an option to pause and resume
4. Repeat n times in a loop
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.