Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mouse Callback to VisualizerWithKeyCallback #6760

Merged
merged 4 commits into from May 15, 2024

Conversation

organic-nailer
Copy link
Contributor

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

Current Open3D Visualizer provides excellent 3D manipulation capabilities, but there are cases where developers may want to override its behavior. By introducing three additional callback functions for mouse events, developers will be able to handle mouse operations on their side only when necessary.
The addition of mouse operations has also been discussed in some issues: #2610 #4286

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

I added three callbacks related to mouse event to VisualizerWithKeyCallback.

  • MouseMoveCallback
  • MouseScrollCallback
  • MouseButtonCallback

Usage:

import open3d as o3d

bunny = o3d.data.BunnyMesh()
mesh = o3d.io.read_triangle_mesh(bunny.path)
mesh.compute_vertex_normals()

vis = o3d.visualization.VisualizerWithKeyCallback()

def on_key_action(vis, action, mods):
    print("on_key_action", action, mods)

vis.register_key_action_callback(ord("A"), on_key_action)

def on_mouse_move(vis, x, y):
    print("on_mouse_move", x, y)

def on_mouse_scroll(vis, x, y):
    print("on_mouse_scroll", x, y)

def on_mouse_button(vis, button, action, mods):
    print("on_mouse_button", button, action, mods)

vis.register_mouse_move_callback(on_mouse_move)
vis.register_mouse_scroll_callback(on_mouse_scroll)
vis.register_mouse_button_callback(on_mouse_button)

vis.create_window()
vis.add_geometry(mesh)
vis.run()

Result:

L7PsZ0r5Xotk2nt6.mp4

Copy link

update-docs bot commented Apr 20, 2024

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ssheorey ssheorey requested a review from errissa April 21, 2024 06:17
@ssheorey
Copy link
Member

Looks good in general. Needs testing. Thanks @organic-nailer

@organic-nailer
Copy link
Contributor Author

Thank you for checking. @ssheorey
How do I add tests? Is there something I can refer to?

@ssheorey ssheorey added this to the v0.19 milestone Apr 29, 2024
@ssheorey
Copy link
Member

By testing, I just meant someone other than the PR author trying out the example on a different computer. I've tried it out and it works fine.

I've added your excellent python example to the examples/python/visualization/customized_visualization_key_action.py file and also added C++ docs. Please add Python docs if you get a chance.

@ssheorey ssheorey merged commit a1fb32c into isl-org:main May 15, 2024
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants