Skip to content

Commit a5468fc

Browse files
mwestphalcpinter
authored andcommitted
Rename VR interactor style callback functions
This commit initiates renaming of the interactor style event callback functions to support the action based input model introduced in Slicer/VTK@b7f02e6 This commit adds support for Select3DEvent and ViewerMovement3DEvent. - Select3DEvent: The action performed when this event is fired is defined by calling MapInputToAction (see [1]). - ViewerMovement3DEvent: Gives users the ability to fly by calling Dolly3D(). VTK's interactor style offers additional behavior to move around. [1] https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/VR/vtkVRInteractorStyle.cxx#L61 Future commits could focus on: - Completing synchronization of this class with vtkVRInteractorStyle: . Add support for Grounded movement style for ViewerMovement3DEvent . Add support for Elevation3DEvent, Pick3DEvent, Clip3DEvent NextPose3DEvent, Menu3DEvent - Confirm that multi gesture events (Pan, Rotate and Pinch) are functional if pressing the grip buttons, and propose new approach to customize the gesture button in VTK. Multi-gesture is handled by the interactor but only triggered by grip buttons (see [2]). This deprecates the vtkVirtualRealityViewInteractor::SetGestureButtonTo*** function. [2] https://github.com/Slicer/VTK/blob/slicer-v9.1.20220125-efbe2afc2/Rendering/VR/vtkVRRenderWindowInteractor.cxx#L366
1 parent c5c6d6f commit a5468fc

2 files changed

Lines changed: 97 additions & 2 deletions

File tree

VirtualReality/MRML/vtkVirtualRealityViewInteractorStyle.cxx

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ void vtkVirtualRealityViewInteractorStyle::OnMove3D(vtkEventData* edata)
394394
this->Dolly3D(edata);
395395
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
396396
break;
397+
// TODO: Add support for Pick3DEvent, Clip3DEvent, NextPose3DEvent, Menu3DEvent
398+
// added in VTK@b7f02e6
399+
//
397400
//case VTKIS_CLIP:
398401
// this->FindPokedRenderer(x, y);
399402
// this->Clip(edd);
@@ -409,7 +412,7 @@ void vtkVirtualRealityViewInteractorStyle::OnMove3D(vtkEventData* edata)
409412
}
410413

411414
//----------------------------------------------------------------------------
412-
void vtkVirtualRealityViewInteractorStyle::OnButton3D(vtkEventData* edata)
415+
void vtkVirtualRealityViewInteractorStyle::OnSelect3D(vtkEventData* edata)
413416
{
414417
if (this->DelegateInteractionEventToDisplayableManagers(edata))
415418
{
@@ -443,6 +446,92 @@ void vtkVirtualRealityViewInteractorStyle::OnButton3D(vtkEventData* edata)
443446
}
444447
}
445448

449+
//------------------------------------------------------------------------------
450+
void vtkVirtualRealityViewInteractorStyle::OnViewerMovement3D(vtkEventData* edata)
451+
{
452+
this->Movement3D(VTKIS_DOLLY, edata);
453+
// TODO: Add support for FLY_STYLE, GROUNDED_STYLE, and ElevationEvent that
454+
// were added in VTK@7a2c71e and VTK@ca4441c
455+
}
456+
457+
458+
//------------------------------------------------------------------------------
459+
void vtkVirtualRealityViewInteractorStyle::Movement3D(int interactionState, vtkEventData* edata)
460+
{
461+
vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D();
462+
if (!edd)
463+
{
464+
return;
465+
}
466+
467+
// Retrieve device type
468+
int idev = static_cast<int>(edd->GetDevice());
469+
470+
// Update current state
471+
int x = this->Interactor->GetEventPosition()[0];
472+
int y = this->Interactor->GetEventPosition()[1];
473+
this->FindPokedRenderer(x, y);
474+
475+
// Set current state and interaction prop
476+
//this->InteractionProp = this->InteractionProps[idev];
477+
478+
double const* pos = edd->GetTrackPadPosition();
479+
480+
if (edd->GetAction() == vtkEventDataAction::Press)
481+
{
482+
this->StartAction(interactionState, edd);
483+
this->LastTrackPadPosition[0] = 0.0;
484+
this->LastTrackPadPosition[1] = 0.0;
485+
return;
486+
}
487+
488+
if (edd->GetAction() == vtkEventDataAction::Release)
489+
{
490+
this->EndAction(interactionState, edd);
491+
return;
492+
}
493+
494+
// If the input event is from a joystick and is away from the center then
495+
// call start. When the joystick returns to the center, call end.
496+
if ((edd->GetInput() == vtkEventDataDeviceInput::Joystick ||
497+
edd->GetInput() == vtkEventDataDeviceInput::TrackPad) &&
498+
this->Internal->InteractionState[idev] != interactionState && fabs(pos[1]) > 0.1)
499+
{
500+
this->StartAction(interactionState, edd);
501+
this->LastTrackPadPosition[0] = 0.0;
502+
this->LastTrackPadPosition[1] = 0.0;
503+
return;
504+
}
505+
506+
if (this->Internal->InteractionState[idev] == interactionState)
507+
{
508+
// Stop when returning to the center on the joystick
509+
if ((edd->GetInput() == vtkEventDataDeviceInput::Joystick ||
510+
edd->GetInput() == vtkEventDataDeviceInput::TrackPad) &&
511+
fabs(pos[1]) < 0.1)
512+
{
513+
this->EndAction(interactionState, edd);
514+
return;
515+
}
516+
517+
// Do the 3D movement corresponding to the interaction state
518+
switch (interactionState)
519+
{
520+
case VTKIS_DOLLY:
521+
this->Dolly3D(edd);
522+
break;
523+
// TODO: Add support for FLY_STYLE, GROUNDED_STYLE, and ElevationEvent that
524+
// were added in VTK@7a2c71e and VTK@ca4441c
525+
default:
526+
break;
527+
}
528+
529+
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
530+
return;
531+
}
532+
}
533+
534+
446535
//----------------------------------------------------------------------------
447536
// Interaction methods
448537
//----------------------------------------------------------------------------

VirtualReality/MRML/vtkVirtualRealityViewInteractorStyle.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class VTK_SLICER_VIRTUALREALITY_MODULE_MRML_EXPORT vtkVirtualRealityViewInteract
6969

7070
//@{
7171
/// Override generic event bindings to call the corresponding action.
72-
void OnButton3D(vtkEventData *edata) override;
72+
void OnSelect3D(vtkEventData *edata) override;
7373
void OnMove3D(vtkEventData *edata) override;
74+
void OnViewerMovement3D(vtkEventData* edata) override;
7475
//@}
7576

7677
//@{
@@ -215,6 +216,11 @@ class VTK_SLICER_VIRTUALREALITY_MODULE_MRML_EXPORT vtkVirtualRealityViewInteract
215216
vtkVirtualRealityViewInteractorStyle();
216217
~vtkVirtualRealityViewInteractorStyle() override;
217218

219+
/**
220+
* Update the 3D movement according to the given interaction state.
221+
*/
222+
void Movement3D(int interactionState, vtkEventData* edata);
223+
218224
private:
219225
vtkVirtualRealityViewInteractorStyle(const vtkVirtualRealityViewInteractorStyle&); /// Not implemented.
220226
void operator=(const vtkVirtualRealityViewInteractorStyle&); /// Not implemented.

0 commit comments

Comments
 (0)