Is your feature request related to a problem? Please describe.
Right now, you can create a visualizer and register an animation callback e.g.:
vis = open3d.Visualizer()
vis.register_animation_callback(callback)
But there is no such option for registering key event callbacks. I would like a function: Visualizer.register_key_callback(key, callback) so that I can register both key and animation callbacks in a Visualizer
There is an option for starting a Visualizer with a set of key callbacks, but in that case, you can't bind an animation callback (note that binding it in the key callback did not work as expected).
Describe the solution you'd like
A method in the visualizer class to bind a key callback on a visualizer. E.g. Visualizer.register_key_callback(key, callback)
Describe alternatives you've considered
To bind both key and animation callbacks, I've considered starting a Visualizer using open3d.draw_geometries_with_key_callbacks, then binding the animation callback inside the key callback using Visualizer.register_animation_callback. This however does not seem to work.
I have encountered the same problem.
I want to be able to use keyboard input to call my own functions while open3d visualizing.
@qianyizh: could you comment on this?
Can you try to use VisualizerWithKeyCallback instead of Visualizer? It should have both register_animation_callback and register_key_callback and both should work.
It seems strange to have a separate class for a visualizer which has a keyboard callback. I guess it's a workaround for now, but in the future I think it would be nice to be able to register_key_callback on a Viewer instance.
The libIGL viewer, for example, allows a user to specify a key callback which is called before the default key callback, and you can fully override the keyboard callback by returning a boolean value. Why not have something like this?
It was implemented piece by piece - hence there is a separate class. But as a retrospective, it is a bit weird. We may change it the next time we do a restructure of the code.
@fwilliams I think this issue can be closed. The keypress has been added to the visualizer. Please check,
from functools import partial
import open3d as o3d
import numpy as np
path = "file_name.png"
def save_image(vis):
vis.capture_screen_image(path)
print("Saved")
return False
pcd = o3d.io.read_point_cloud("assets/pointcloud.pcd")
vis = o3d.visualization.VisualizerWithKeyCallback()
vis.create_window()
vis.get_render_option().background_color = np.asarray([0, 0, 0])
view_ctl = vis.get_view_control()
vis.add_geometry(pcd)
vis.register_key_callback(ord("S"), partial(save_image))
vis.run()
vis.destroy_window()
Thanks! Looks like we can close this then :)
Most helpful comment
Can you try to use
VisualizerWithKeyCallbackinstead ofVisualizer? It should have bothregister_animation_callbackandregister_key_callbackand both should work.