Skip to content

Commit

Permalink
STYLE: Simplify interactor style leveraging base class implementation
Browse files Browse the repository at this point in the history
Removes functions `OnSelect3D`, `OnMove3D`, `OnViewerMovement3D`, `StartAction`,
`EndAction`, `Movement3D` and `SetInteractor` functions that are available
in the base class.
  • Loading branch information
jcfr committed Dec 21, 2023
1 parent 938f019 commit 6a7f5ba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 343 deletions.
320 changes: 0 additions & 320 deletions VirtualReality/MRML/vtkVirtualRealityViewInteractorStyle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <vtkCallbackCommand.h>
#include <vtkInteractorStyle.h>
#include <vtkMath.h>
#include <vtkVRMenuWidget.h>
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkRenderer.h>
Expand Down Expand Up @@ -251,222 +250,12 @@ void vtkVirtualRealityViewInteractorStyle::PrintSelf(ostream& os, vtkIndent inde
this->Superclass::PrintSelf(os,indent);
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::SetInteractor(vtkRenderWindowInteractor *i)
{
if (i == this->Interactor)
{
return;
}

this->Superclass::SetInteractor(i);
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::SetDisplayableManagers(vtkMRMLDisplayableManagerGroup* displayableManagers)
{
this->DisplayableManagers = displayableManagers;
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::OnMove3D(vtkEventData* edata)
{
vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D();
if (!edd)
{
return;
}

// Retrieve device type
int idev = static_cast<int>(edd->GetDevice());

if (edd->GetDevice() == vtkEventDataDevice::HeadMountedDisplay)
{
edd->GetWorldDirection(this->HeadsetDir);
}

// Update current state
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];

// Set current state and interaction prop
this->InteractionProp = this->InteractionProps[idev];

auto interactionState = this->InteractionState[idev];
switch (interactionState)
{
case VTKIS_POSITION_PROP:
this->FindPokedRenderer(x, y);
this->PositionProp(edd);
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_DOLLY:
case VTKIS_GROUNDMOVEMENT:
case VTKIS_ELEVATION:
this->FindPokedRenderer(x, y);
this->Movement3D(interactionState, edd);
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_CLIP:
this->FindPokedRenderer(x, y);
this->Clip(edd);
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_USCALE:
this->FindPokedRenderer(x, y);
this->UniformScale();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
default:
vtkDebugMacro(<< "OnMove3D: unknown interaction state " << idev << ": "
<< this->InteractionState[idev]);
break;
}

// Update rays
this->UpdateRay(edd->GetDevice());
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::OnSelect3D(vtkEventData* edata)
{
vtkEventDataDevice3D* bd = edata->GetAsEventDataDevice3D();
if (!bd)
{
return;
}

int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);

decltype(this->InputMap)::key_type key(vtkCommand::Select3DEvent, bd->GetAction());
auto it = this->InputMap.find(key);
if (it == this->InputMap.end())
{
return;
}

int state = it->second;

// if grab mode then convert event data into where the ray is intersecting geometry
switch (bd->GetAction())
{
case vtkEventDataAction::Press:
case vtkEventDataAction::Touch:
this->StartAction(state, bd);
break;
case vtkEventDataAction::Release:
case vtkEventDataAction::Untouch:
this->EndAction(state, bd);
break;
default:
break;
}
}

//------------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::OnViewerMovement3D(vtkEventData* edata)
{
if (this->Style == vtkVRInteractorStyle::FLY_STYLE)
{
this->Movement3D(VTKIS_DOLLY, edata);
}
else if (this->Style == vtkVRInteractorStyle::GROUNDED_STYLE)
{
this->Movement3D(VTKIS_GROUNDMOVEMENT, edata);
}
}

//------------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::Movement3D(int interactionState, vtkEventData* edata)
{
vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D();
if (!edd)
{
return;
}

// Retrieve device type
int idev = static_cast<int>(edd->GetDevice());

// Update current state
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);

// Set current state and interaction prop
this->InteractionProp = this->InteractionProps[idev];

double const* pos = edd->GetTrackPadPosition();

if (edd->GetAction() == vtkEventDataAction::Press)
{
this->StartAction(interactionState, edd);
this->LastTrackPadPosition[0] = 0.0;
this->LastTrackPadPosition[1] = 0.0;
this->LastGroundMovementTrackPadPosition[0] = 0.0;
this->LastGroundMovementTrackPadPosition[1] = 0.0;
this->LastElevationTrackPadPosition[0] = 0.0;
this->LastElevationTrackPadPosition[1] = 0.0;
return;
}

if (edd->GetAction() == vtkEventDataAction::Release)
{
this->EndAction(interactionState, edd);
return;
}

// If the input event is from a joystick and is away from the center then
// call start. When the joystick returns to the center, call end.
if ((edd->GetInput() == vtkEventDataDeviceInput::Joystick ||
edd->GetInput() == vtkEventDataDeviceInput::TrackPad) &&
this->InteractionState[idev] != interactionState && fabs(pos[1]) > 0.1)
{
this->StartAction(interactionState, edd);
this->LastTrackPadPosition[0] = 0.0;
this->LastTrackPadPosition[1] = 0.0;
this->LastGroundMovementTrackPadPosition[0] = 0.0;
this->LastGroundMovementTrackPadPosition[1] = 0.0;
this->LastElevationTrackPadPosition[0] = 0.0;
this->LastElevationTrackPadPosition[1] = 0.0;
return;
}

if (this->InteractionState[idev] == interactionState)
{
// Stop when returning to the center on the joystick
if ((edd->GetInput() == vtkEventDataDeviceInput::Joystick ||
edd->GetInput() == vtkEventDataDeviceInput::TrackPad) &&
fabs(pos[1]) < 0.1)
{
this->EndAction(interactionState, edd);
return;
}

// Do the 3D movement corresponding to the interaction state
switch (interactionState)
{
case VTKIS_DOLLY:
this->Dolly3D(edd);
break;
case VTKIS_GROUNDMOVEMENT:
this->GroundMovement3D(edd);
break;
case VTKIS_ELEVATION:
this->Elevation3D(edd);
break;
default:
break;
}

this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
return;
}
}


//----------------------------------------------------------------------------
// Interaction methods
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -823,115 +612,6 @@ int vtkVirtualRealityViewInteractorStyle::GetMappedAction(vtkCommand::EventIds e
return VTKIS_NONE;
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::StartAction(int state, vtkEventDataDevice3D* edata)
{
switch (state)
{
case VTKIS_POSITION_PROP:
this->StartPositionProp(edata);
break;
case VTKIS_DOLLY:
this->StartMovement3D(state, edata);
this->LastDolly3DEventTime->StartTimer();
break;
case VTKIS_GROUNDMOVEMENT:
this->StartMovement3D(state, edata);
this->LastGroundMovement3DEventTime->StartTimer();
break;
case VTKIS_ELEVATION:
this->StartMovement3D(state, edata);
this->LastElevation3DEventTime->StartTimer();
break;
case VTKIS_CLIP:
this->StartClip(edata);
break;
case VTKIS_PICK:
this->StartPick(edata);
break;
case VTKIS_LOAD_CAMERA_POSE:
this->StartLoadCamPose(edata);
break;
case VTKIS_MENU:
// Menu is only displayed upon action end (e.g. button release)
break;
default:
vtkDebugMacro(<< "StartAction: unknown state " << state);
break;
}
}

//----------------------------------------------------------------------------
void vtkVirtualRealityViewInteractorStyle::EndAction(int state, vtkEventDataDevice3D* edata)
{
switch (state)
{
case VTKIS_POSITION_PROP:
this->EndPositionProp(edata);
break;
case VTKIS_DOLLY:
this->EndMovement3D(edata);
this->LastDolly3DEventTime->StopTimer();
break;
case VTKIS_GROUNDMOVEMENT:
this->EndMovement3D(edata);
this->LastGroundMovement3DEventTime->StopTimer();
break;
case VTKIS_ELEVATION:
this->EndMovement3D(edata);
this->LastElevation3DEventTime->StopTimer();
break;
case VTKIS_CLIP:
this->EndClip(edata);
break;
case VTKIS_PICK:
this->EndPick(edata);
break;
case VTKIS_MENU:
this->Menu->SetInteractor(this->Interactor);
this->Menu->Show(edata);
break;
case VTKIS_LOAD_CAMERA_POSE:
this->EndLoadCamPose(edata);
break;
case VTKIS_TOGGLE_DRAW_CONTROLS:
this->ToggleDrawControls();
break;
case VTKIS_EXIT:
if (this->Interactor)
{
this->Interactor->ExitCallback();
}
break;
case VTKIS_TELEPORTATION:
this->Teleportation3D(edata);
break;
case VTKIS_USCALE:
this->EndUniformScale();
break;
default:
vtkDebugMacro(<< "EndAction: unknown state " << state);
break;
}

// Reset complex gesture state because a button has been released
for (int d = 0; d < vtkEventDataNumberOfDevices; ++d)
{
switch (this->InteractionState[d])
{
case VTKIS_PAN:
case VTKIS_ZOOM:
case VTKIS_ROTATE:
this->InteractionState[d] = VTKIS_NONE;
break;
default:
vtkDebugMacro(<< "EndAction: unknown interaction state " << d << ": "
<< this->InteractionState[d]);
break;
}
}
}

//---------------------------------------------------------------------------
vtkMRMLScene* vtkVirtualRealityViewInteractorStyle::GetMRMLScene()
{
Expand Down
Loading

0 comments on commit 6a7f5ba

Please sign in to comment.