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

Improve Event Delegation in qMRMLThreeDView and qMRMLSliceView #7311

Conversation

jcfr
Copy link
Member

@jcfr jcfr commented Oct 30, 2023

This pull request is aimed at streamlining the review process and testing by consolidating several independent changes, each of which will be contributed separately.

The primary focus for review in this pull request is the last commit, titled ENH: Improve Event Delegation in qMRMLThreeDView and qMRMLSliceView.

In this commit, we've refactored vtkMRMLThreeDViewInteractorStyle and vtkMRMLSliceViewInteractorStyle to inherit from vtkObject and have implemented event delegation to MRML displayable managers and their associated widgets by observing the interactor style.

This enhancement allows for the association of specialized interactor styles, such as vtkOpenXRInteractorStyle or vtkOpenVRInteractorStyle, with the render window while still maintaining MRML-specific event delegation.

Dependent Changes

The introduction of the commit ENH: Allow virtual func to be called during MRML(ThreeD|Slice)View pimpl init necessitates an update to CTK, which can be found in the following pull request:

Update: CTK pull request commontk/CTK#1153 has been integrated upstream and corresponding External_CTK.cmake update has been added to this pull request by integrating the commits being contributed in the following pull request:

Associated independent changes are being contributed in these pull requests:

@jcfr jcfr linked an issue Oct 30, 2023 that may be closed by this pull request
@jcfr jcfr force-pushed the refactor-qMRMLThreeDView-and-qMRMLSliceView-event-delegation branch 5 times, most recently from 6b58b0e to d7492b3 Compare November 6, 2023 15:23
@jcfr jcfr force-pushed the refactor-qMRMLThreeDView-and-qMRMLSliceView-event-delegation branch from d7492b3 to 2f7a6cc Compare November 14, 2023 16:15
@jcfr jcfr added this to the Slicer 5.5 milestone Nov 16, 2023
Refactor vtkMRMLThreeDViewInteractorStyle and vtkMRMLSliceViewInteractorStyle
to derive from vtkObject and implement event delegation to MRML displayable
managers and associated widgets by observing the interactor style.

This will allows to associate specialized interactor styles like
vtkOpenXRInteractorStyle or vtkOpenVRInteractorStyle with render window
while maintaining the MRML specific event delegation.

Co-authored-by: Lucas Gandel <lucas.gandel@kitware.com>
@jcfr jcfr force-pushed the refactor-qMRMLThreeDView-and-qMRMLSliceView-event-delegation branch from 2f7a6cc to 80fba35 Compare November 17, 2023 06:45
@jcfr jcfr self-assigned this Nov 21, 2023
Copy link
Contributor

@lassoan lassoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t like going back to using interactor style, as it is just an unnecessary additional layer that adds complexity and not sufficient to actually handle all interactions in complex applications. Interactor styles should be rather removed from VTK, too (and let VTK widgets handle camera movement).

However, I cannot pinpoint any functional errors with the changes and I see that you worked a lot on this and would not want to hold up things that depend on these changes, so I'm OK if the changes are merged.

return;
}
this->Superclass::OnKeyPress();
this->GetInteractorStyle()->OnKeyPress();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all we do is calling the Superclass implementation then it is better to remove the method completely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended to keep the same behavior as we had before, I will create a follow-up pull request and/or issue to move forward with simplification

@@ -37,43 +40,44 @@ class vtkTimerLog;
/// Some additional high-level events (such as click and double-click)
/// are generated here.
class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLViewInteractorStyle :
public vtkInteractorStyle3D
public vtkObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is not based on an interactor style?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because our vtkMRMLViewInteractorStyle are technically observer and not interactor style anymore. For more details, see section Refactor Interactor Styles in #7310

For sake of reducing the amount of changes and allowing easy review, I didn't rename our classes. For more details, see section Renaming Interactor Styles in #7310.

@@ -110,7 +111,8 @@ bool vtkMRMLThreeDViewInteractorStyle::DelegateInteractionEventToDisplayableMana
// Get display and world position
int* displayPositionInt = this->GetInteractor()->GetEventPosition();
vtkRenderer* pokedRenderer = this->GetInteractor()->FindPokedRenderer(displayPositionInt[0], displayPositionInt[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindPokedRenderer is error-prone. If somebody adds any content to the render window in a new renderer then it may break picking and or interaction with other widgets. It would be safer to pass the main 3D content renderer, not whatever renderer happened to be found at that position.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this can be improved and I will create a dedicated issue to improve and address this. In prefer to keep the existing behavior and focus this pull request on only revisiting the observation of the interactor style events.

@jcfr
Copy link
Member Author

jcfr commented Nov 22, 2023

I don’t like going back to using interactor style, as it is just an unnecessary additional layer that adds complexity and not sufficient to actually handle all interactions in complex applications.

After discussion with @LucasGandel, we indeed acknowledge that the VTK interactor style currently implemented in the vtkRenderingVR (and OpenVR and OpenXR specialization) could be revisited to avoid having some much "logic" associated with it.

I cannot pinpoint any functional errors with the changes and I see that you worked a lot on this and would not want to hold up things that depend on these changes, so I'm OK if the changes are merged.

Thanks for reviewing and provided detailed feedback. As you indicated, while this is not the "best" path forward, it allows to move forward 🙏

Now that I commented inline, let me know if you have other questions before approving ✔️

@jcfr jcfr requested a review from lassoan November 22, 2023 21:12
@jcfr
Copy link
Member Author

jcfr commented Nov 22, 2023

going back to using interactor style, as it is just an unnecessary additional layer that adds complexity

As a point of clarification, this pull-request does not add any functional changes.
Instead of having:

  • vtkMRMLViewInteractorStyle derives from vtkInteractorStyle3D, it now derives from vtkObject
  • vtkMRMLViewInteractorStyle override callback, it calls corresponding functions by observing the interactor style associated with the render window
  • the qMRMLThreeDView class set vtkMRMLThreeDViewInteractorStyle as interactor style, it sets an instance of vtkInteractorStyle3D
  • the qMRMLSliceView class set vtkMRMLSliceViewInteractorStyle as interactor style, it sets an instance of vtkInteractorStyleUser

Doing so allows to associate the OpenVR or OpenXR rendering windows with their corresponding interactor style while maintaining the delegation of event to our displayable manager working as expected.

Copy link
Contributor

@lassoan lassoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the responses, I have no further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Improve Event Delegation in qMRMLThreeDView and qMRMLSliceView
2 participants