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

BUG: Fix integration with updated Slicer event delegation and VTK OpenVR API #131

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions VirtualReality/MRML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(${KIT}_SRCS
vtkMRML${MODULE_NAME}LayoutNode.h
vtk${MODULE_NAME}ViewInteractor.cxx
vtk${MODULE_NAME}ViewInteractor.h
vtk${MODULE_NAME}ViewInteractorObserver.cxx
vtk${MODULE_NAME}ViewInteractorObserver.h
vtk${MODULE_NAME}ViewInteractorStyle.cxx
vtk${MODULE_NAME}ViewInteractorStyle.h
)
Expand Down
58 changes: 38 additions & 20 deletions VirtualReality/MRML/vtkVirtualRealityViewInteractor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,21 @@ void vtkVirtualRealityViewInteractor::SetTriggerButtonFunction(std::string funct
return;
}

// The "eventId to state" mapping (see call to `MapInputToAction` below) applies to right and left
// controller buttons because they are bound to the same eventId:
// - `vtk_openvr_binding_*.json` files define the "button to action" mapping
// - `vtkOpenVRInteractorStyle()` contructor defines the "action to eventId" mapping

if (functionId.empty())
{
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkCommand::Select3DEvent, VTKIS_NONE);

this->GestureEnabledButtons.clear();
this->GestureEnabledButtons.push_back(static_cast<int>(vtkEventDataDeviceInput::Grip));
}
else if (!functionId.compare(vtkVirtualRealityViewInteractor::GetButtonFunctionIdForGrabObjectsAndWorld()))
{
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkCommand::Select3DEvent, VTKIS_POSITION_PROP);

this->GestureEnabledButtons.clear();
this->GestureEnabledButtons.push_back(static_cast<int>(vtkEventDataDeviceInput::Grip));
Expand All @@ -227,10 +230,14 @@ void vtkVirtualRealityViewInteractor::SetGestureButtonToTrigger()
vtkWarningMacro("SetGestureButtonToTrigger: Current interactor style is not a VR interactor style");
return;
}
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Grip, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Grip, VTKIS_NONE);

// The update "action to (eventId|function)" mapping (see call to `AddAction` below) applies to
// right and left controller buttons because they are bound to the same eventId:
// - "vtk_openvr_binding_*.json" defines the "button -> action" mapping
// - vtkOpenVRInteractorStyle defines the "action -> eventId" mapping
this->AddAction("/actions/vtk/in/TriggerAction", /*isAnalog=*/false,
[this](vtkEventData* ed) { this->HandleComplexGestureEvents(ed); });
this->AddAction("/actions/vtk/in/ComplexGestureAction", vtkCommand::Select3DEvent, /*isAnalog=*/false);

this->GestureEnabledButtons.clear();
this->GestureEnabledButtons.push_back(static_cast<int>(vtkEventDataDeviceInput::Trigger));
Expand All @@ -246,10 +253,13 @@ void vtkVirtualRealityViewInteractor::SetGestureButtonToGrip()
return;
}

vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Grip, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Grip, VTKIS_POSITION_PROP);
// The update "action to (eventId|function)" mapping (see call to `AddAction` below) applies to
// right and left controller buttons because they are bound to the same eventId:
// - "vtk_openvr_binding_*.json" defines the "button -> action" mapping
// - vtkOpenVRInteractorStyle defines the "action -> eventId" mapping
this->AddAction("/actions/vtk/in/TriggerAction", vtkCommand::Select3DEvent, /*isAnalog=*/false);
this->AddAction("/actions/vtk/in/ComplexGestureAction", /*isAnalog=*/false,
[this](vtkEventData* ed) { this->HandleComplexGestureEvents(ed); });

this->GestureEnabledButtons.clear();
this->GestureEnabledButtons.push_back(static_cast<int>(vtkEventDataDeviceInput::Grip));
Expand All @@ -265,10 +275,14 @@ void vtkVirtualRealityViewInteractor::SetGestureButtonToTriggerAndGrip()
return;
}

vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Grip, VTKIS_POSITION_PROP);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Grip, VTKIS_POSITION_PROP);
// The update "action to (eventId|function)" mapping (see call to `AddAction` below) applies to
// right and left controller buttons because they are bound to the same eventId:
// - "vtk_openvr_binding_*.json" defines the "button -> action" mapping
// - vtkOpenVRInteractorStyle defines the "action -> eventId" mapping
this->AddAction("/actions/vtk/in/TriggerAction", /*isAnalog=*/false,
[this](vtkEventData* ed) { this->HandleComplexGestureEvents(ed); });
this->AddAction("/actions/vtk/in/ComplexGestureAction", /*isAnalog=*/false,
[this](vtkEventData* ed) { this->HandleComplexGestureEvents(ed); });

this->GestureEnabledButtons.clear();
this->GestureEnabledButtons.push_back(static_cast<int>(vtkEventDataDeviceInput::Grip));
Expand All @@ -285,10 +299,14 @@ void vtkVirtualRealityViewInteractor::SetGestureButtonToNone()
return;
}

vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Trigger, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::RightController, vtkEventDataDeviceInput::Grip, VTKIS_NONE);
vrInteractorStyle->MapInputToAction(vtkEventDataDevice::LeftController, vtkEventDataDeviceInput::Grip, VTKIS_NONE);
// The update "action to (eventId|function)" mapping (see call to `AddAction` below) applies to
// right and left controller buttons because they are bound to the same eventId:
// - "vtk_openvr_binding_*.json" defines the "button -> action" mapping
// - vtkOpenVRInteractorStyle defines the "action -> eventId" mapping
this->AddAction("/actions/vtk/in/TriggerAction", /*isAnalog=*/false,
[](vtkEventData* vtkNotUsed(ed)) { });
this->AddAction("/actions/vtk/in/ComplexGestureAction", /*isAnalog=*/false,
[](vtkEventData* vtkNotUsed(ed)) { });

this->GestureEnabledButtons.clear();
}
Loading