Kitware / react-vtk-js

Declarative library exposing vtk.js visualization pipeline as React components
https://kitware.github.io/react-vtk-js/
77 stars 24 forks source link

Fix picking/hover to return closest object #47

Closed jadh4v closed 2 years ago

jadh4v commented 3 years ago

EDIT (outdated / previous commit):

Fix View.pick() function to return selection objects in a sorted order based on 'most number of pixels' under the queried footprint. Earlier, the function simply returned/handled the first object in the selection array, which was arbitrary.

EDIT (approach has been changed):

Add View.pickClosest(xp, yp, maxDistance) function to select / return a single object that is the closest to the mouse pointer position. Search region is restricted based on the pointerSize property. Earlier, the function simply returned/handled the first object in the selection array, which was unpredictable. This change affects the 'click' and 'hover' picking modes. The 'select' picking mode (which uses a shift + click-drag a rectangular region) continues to use the previous implementation, which returns all objects within that rectangular region (selection zone) in no particular order.

The algorithm for searching the closest object in the pixel buffer (mentioned here) is already present in vtk-js as vtkOpenGLHardwareSelector.getPixelInformation().

A corresponding fix was required in vtk-js described here: 2263.

jadh4v commented 3 years ago

@agirault @floryst Based on @FezVrasta 's suggestion, we could change the mouse picking to return the closes pixel to current mouse position. The case is trivial where there already is an object at the mouse position. Otherwise, we will return the object that has a foreground pixel closest to current mouse position.

jourdain commented 3 years ago

@martinken mentioned to me that on VTK/C++ we have a radius that enable the expected behavior. We should implement it on the JS side.

floryst commented 2 years ago

@martinken mentioned to me that on VTK/C++ we have a radius that enable the expected behavior. We should implement it on the JS side.

Do you have a link to where the C++ implementation is?

martinken commented 2 years ago

See https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Core/vtkHardwareSelector.cxx#L729

Basically it picks from the center, and if nothing is found starts workout out radially until it finds something or hits max distance.

jadh4v commented 2 years ago

Cool. This is great. But would this mean that the selector would now only return one result? Or would it be better to implement the new logic as a different function generateSelection(xp, yp, maxDistance) ?

jadh4v commented 2 years ago

Apologies for this going stale for so long. I will allocate some time soon to resurrect this.

jadh4v commented 2 years ago

@floryst @jourdain Ready for review.

jadh4v commented 2 years ago

@jourdain waiting for your green flag. Also I don't have write privileges, so someone will have to merge for me.

jourdain commented 2 years ago

:tada: This PR is included in version 1.10.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: