Skip to content

Commit

Permalink
ENH: Re-enable pick event to use it with the GUI widget
Browse files Browse the repository at this point in the history
At the start of the Pick event the interactor style invokes vtkCommand::PickEvent.
With this Python script it is possible to do the clicking with the right trigger.

  def onClick(caller, event):
    gw.onStartInteractionButtonClicked()

  vris = slicer.modules.virtualreality.viewWidget().interactor().GetInteractorStyle()
  vris.MapInputToAction(vtk.vtkEventDataDevice.RightController, vtk.vtkEventDataDeviceInput.Trigger, vtk.VTKIS_PICK)
  vris.AddObserver(vtk.vtkCommand.PickEvent, onClick)

Re KitwareMedical#43
  • Loading branch information
cpinter committed Aug 22, 2023
1 parent 856efa5 commit 84b633d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
22 changes: 11 additions & 11 deletions GUIWidgets/qSlicerGUIWidgetsModuleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@

#include "vtkSlicerQWidgetTexture.h"

// VirtualReality includes
#include "vtkMRMLVirtualRealityViewNode.h"
// VirtualReality Widgets includes
#include "qMRMLVirtualRealityHomeWidget.h"
#include "qMRMLVirtualRealityDataModuleWidget.h"
#include "qMRMLVirtualRealitySegmentEditorWidget.h"
#include "qMRMLVirtualRealityTransformWidget.h"

// VirtualReality Logic includes
#include "vtkSlicerVirtualRealityLogic.h"

// VirtualReality MRML includes
#include "vtkMRMLVirtualRealityViewNode.h"

// Slicer includes
#include "qSlicerApplication.h"
#include "qSlicerLayoutManager.h"
Expand All @@ -49,12 +57,6 @@
// Markups Logic includes
#include <vtkSlicerMarkupsLogic.h>

// Virtual Reality includes
#include "qMRMLVirtualRealityHomeWidget.h"
#include "qMRMLVirtualRealityDataModuleWidget.h"
#include "qMRMLVirtualRealitySegmentEditorWidget.h"
#include "qMRMLVirtualRealityTransformWidget.h"

// MRML includes
#include "vtkMRMLLinearTransformNode.h"
#include "vtkMRMLScene.h"
Expand Down Expand Up @@ -133,7 +135,7 @@ void qSlicerGUIWidgetsModuleWidget::setup()
QObject::connect(d->AddTransformWidgetButton, SIGNAL(clicked()), this, SLOT(onAddTransformWidgetButtonClicked()));

QObject::connect(d->SetUpInteractionButton, SIGNAL(clicked()), this, SLOT(onSetUpInteractionButtonClicked()));
QObject::connect(d->StartInteractionButton, SIGNAL(clicked()), this, SLOT(onStartInteractionButtonClicked()));
QObject::connect(d->StartInteractionButton, SIGNAL(clicked()), this, SLOT(onStartInteractionButtonClicked()));
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -253,8 +255,6 @@ void qSlicerGUIWidgetsModuleWidget::onSetUpInteractionButtonClicked()
//-----------------------------------------------------------------------------
void qSlicerGUIWidgetsModuleWidget::onStartInteractionButtonClicked()
{
//std::cout << "\n\nqSlicerGUIWidgetsModuleWidget::onStartInteractionButtonClicked() \n";

// Pointer transform
qSlicerApplication* app = qSlicerApplication::application();
vtkMRMLLinearTransformNode* transformNode = vtkMRMLLinearTransformNode::SafeDownCast(app->mrmlScene()->GetFirstNodeByName("PointerTransform"));
Expand Down
33 changes: 27 additions & 6 deletions VirtualReality/MRML/vtkVirtualRealityViewInteractorStyle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,27 @@ void vtkVirtualRealityViewInteractorStyle::EndDolly3D(vtkEventDataDevice3D* ed)
this->LastDolly3DEventTime->StopTimer();
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::StartPick(vtkEventDataDevice3D* ed)
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkEventDataDevice dev = ed->GetDevice();
this->Internal->InteractionState[static_cast<int>(dev)] = VTKIS_PICK;

// Let another class handle the pick event by connecting to this
this->InvokeEvent(vtkCommand::PickEvent);
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::EndPick(vtkEventDataDevice3D* ed)
{
vtkEventDataDevice dev = ed->GetDevice();
this->Internal->InteractionState[static_cast<int>(dev)] = VTKIS_NONE;
}

//----------------------------------------------------------------------------
// Multitouch interaction methods
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -931,9 +952,9 @@ void vtkVirtualRealityViewInteractorStyle::StartAction(int state, vtkEventDataDe
//case VTKIS_CLIP:
// this->StartClip(edata);
// break;
//case VTKIS_PICK:
// this->StartPick(edata);
// break;
case VTKIS_PICK:
this->StartPick(edata);
break;
//case VTKIS_LOAD_CAMERA_POSE:
// this->StartLoadCamPose(edata);
// break;
Expand All @@ -954,9 +975,9 @@ void vtkVirtualRealityViewInteractorStyle::EndAction(int state, vtkEventDataDevi
//case VTKIS_CLIP:
// this->EndClip(edata);
// break;
//case VTKIS_PICK:
// this->EndPick(edata);
// break;
case VTKIS_PICK:
this->EndPick(edata);
break;
//case VTKIS_MENU:
// this->Menu->SetInteractor(this->Interactor);
// this->Menu->Show(edata);
Expand Down
4 changes: 2 additions & 2 deletions VirtualReality/MRML/vtkVirtualRealityViewInteractorStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class VTK_SLICER_VIRTUALREALITY_MODULE_MRML_EXPORT vtkVirtualRealityViewInteract
/**
* Interaction mode entry points.
*/
//virtual void StartPick(vtkEventDataDevice3D *);
//virtual void EndPick(vtkEventDataDevice3D *);
//virtual void StartLoadCamPose(vtkEventDataDevice3D *);
//virtual void EndLoadCamPose(vtkEventDataDevice3D *);
virtual void StartPositionProp(vtkEventDataDevice3D *);
Expand All @@ -87,6 +85,8 @@ class VTK_SLICER_VIRTUALREALITY_MODULE_MRML_EXPORT vtkVirtualRealityViewInteract
//virtual void EndClip(vtkEventDataDevice3D *);
virtual void StartDolly3D(vtkEventDataDevice3D *);
virtual void EndDolly3D(vtkEventDataDevice3D *);
virtual void StartPick(vtkEventDataDevice3D *);
virtual void EndPick(vtkEventDataDevice3D *);
//@}

//@{
Expand Down

0 comments on commit 84b633d

Please sign in to comment.