VTK  9.5.2
vtkVRInteractorStyle.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
9
10#ifndef vtkVRInteractorStyle_h
11#define vtkVRInteractorStyle_h
12
13#include "vtkEventData.h" // for enums
15#include "vtkNew.h" // for vtkNew
16#include "vtkRenderingVRModule.h" // For export macro
17#include "vtkSmartPointer.h" // for vtkSmartPointer
18
19#include <map> // for std::map
20#include <vector> // for std::vector
21
22VTK_ABI_NAMESPACE_BEGIN
24class vtkCell;
25class vtkPlane;
27class vtkSelection;
28class vtkSphereSource;
29class vtkTextActor3D;
33class vtkVRMenuWidget;
34
35class VTKRENDERINGVR_EXPORT vtkVRInteractorStyle : public vtkInteractorStyle3D
36{
37public:
39 void PrintSelf(ostream& os, vtkIndent indent) override;
40
42
45 void OnSelect3D(vtkEventData* edata) override;
46 void OnNextPose3D(vtkEventData* edata) override;
47 void OnViewerMovement3D(vtkEventData* edata) override;
48 void OnMove3D(vtkEventData* edata) override;
49 void OnMenu3D(vtkEventData* edata) override;
50 void OnElevation3D(vtkEventData* edata) override;
52
54
65 virtual void StartMovement3D(int interactionState, vtkEventDataDevice3D*);
68
70
73 void OnPan() override;
74 void OnPinch() override;
75 void OnRotate() override;
77
79
82 void ProbeData(vtkEventDataDevice controller);
83 void PositionProp(vtkEventData*, double* lwpos = nullptr, double* lwori = nullptr) override;
85 virtual void LoadNextCameraPose() = 0;
87
93
99
104
106
116
121 vtkEventDataDevice device, vtkEventDataDeviceInput input, const std::string& text = {});
122
127
129
134 vtkSetMacro(HoverPick, bool);
135 vtkGetMacro(HoverPick, bool);
136 vtkBooleanMacro(HoverPick, bool);
138
140
144 vtkSetMacro(GrabWithRay, bool);
145 vtkGetMacro(GrabWithRay, bool);
146 vtkBooleanMacro(GrabWithRay, bool);
148
154
156
160 vtkSetMacro(Style, MovementStyle);
161 vtkGetMacro(Style, MovementStyle);
163
170 {
171 int deviceIndex = static_cast<int>(device);
172 if (deviceIndex < 0 || deviceIndex >= vtkEventDataNumberOfDevices)
173 {
174 // Since VTKIS_*STATE* are expected to be >= VTKIS_NONE with VTKIS_NONE == 0,
175 // return -1 if device is invalid.
176 return -1;
177 }
178 return this->InteractionState[static_cast<int>(device)];
179 }
180
189
191
194 void ShowRay(vtkEventDataDevice controller);
195 void HideRay(vtkEventDataDevice controller);
197
199
202 void ShowBillboard(const std::string& text);
205
210 void ShowPickSphere(double* pos, double radius, vtkProp3D*);
211
216
218
223
225
229 void SetDrawControls(bool);
231
236
241
245 vtkVRMenuWidget* GetMenu() { return this->Menu.Get(); }
246
247protected:
250
254 virtual void UpdateRay(vtkEventDataDevice controller);
255
257 static void MenuCallback(
258 vtkObject* object, unsigned long event, void* clientdata, void* calldata);
259
263 void StartAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);
264 void EndAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);
265
269 bool HardwareSelect(vtkEventDataDevice controller, bool actorPassOnly);
270
274 void Movement3D(int interactionState, vtkEventData* edata);
275
276 bool HoverPick = false;
277 bool GrabWithRay = true;
278
282
287
288 // Device input to interaction state mapping
289 std::map<std::tuple<vtkCommand::EventIds, vtkEventDataAction>, int> InputMap;
291
292 // Store required controllers information when performing action
294 std::vector<vtkSmartPointer<vtkProp3D>> InteractionProps;
295 std::vector<vtkSmartPointer<vtkPlane>> ClippingPlanes;
296
297 // Store headset world orientation
298 double HeadsetDir[3] = { 0, 0, 0 };
299
300 // Store movement style
302
303 // Interaction timers
306
307 // Interaction trackpad position
309 double LastElevationTrackPadPosition[2] = { 0, 0 };
310
311private:
313 void operator=(const vtkVRInteractorStyle&) = delete;
314};
315
316VTK_ABI_NAMESPACE_END
317#endif
supports function callbacks
abstract class to specify cell behavior
Definition vtkCell.h:51
a simple class to control print indentation
Definition vtkIndent.h:29
vtkInteractorStyle3D()
Get/Set the interaction picker.
Allocate and hold a VTK object.
Definition vtkNew.h:58
abstract base class for most VTK objects
Definition vtkObject.h:50
perform various plane computations
Definition vtkPlane.h:32
represents an 3D object for placement in a rendered scene
Definition vtkProp3D.h:40
platform-independent render window interaction including picking and frame rate control.
data object that represents a "selection" in VTK.
create a polygonal sphere centered at the origin
An actor that displays text.
Tooltip helper explaining controls Helper class to draw one tooltip per button around the controller.
pick an actor/prop given a controller position and orientation
Extended from vtkInteractorStyle3D to override command methods.
void ShowPickSphere(double *pos, double radius, vtkProp3D *)
Make the pick actor a sphere of given radius centered at given position, and show it.
void PositionProp(vtkEventData *, double *lwpos=nullptr, double *lwori=nullptr) override
Methods for interaction.
void ProbeData(vtkEventDataDevice controller)
Methods for interaction.
virtual void SetupActions(vtkRenderWindowInteractor *iren)=0
Setup default actions defined with an action path and a corresponding command.
vtkVRMenuWidget * GetMenu()
Return the menu to allow the user to add options to it.
std::vector< vtkSmartPointer< vtkPlane > > ClippingPlanes
vtkNew< vtkTextActor3D > TextActor3D
void Clip(vtkEventDataDevice3D *)
Methods for interaction.
virtual void EndMovement3D(vtkEventDataDevice3D *)
Interaction mode entry points.
virtual void StartPick(vtkEventDataDevice3D *)
Interaction mode entry points.
void ShowBillboard(const std::string &text)
Show/hide billboard with given text string.
double LastGroundMovementTrackPadPosition[2]
void SetDrawControls(bool)
Control visibility of descriptive tooltips for controller/HMD models.
void OnNextPose3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
void EndAction(int VTKIS_STATE, vtkEventDataDevice3D *edata)
void OnSelect3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
virtual vtkVRControlsHelper * MakeControlsHelper()=0
Creates a new ControlsHelper suitable for use with the child class.
vtkNew< vtkCallbackCommand > MenuCommand
void Movement3D(int interactionState, vtkEventData *edata)
Update the 3D movement according to the given interaction state.
bool HardwareSelect(vtkEventDataDevice controller, bool actorPassOnly)
Pick using hardware selector.
void HidePickActor()
Hide the pick actor (sphere or polydata).
virtual void StartMovement3D(int interactionState, vtkEventDataDevice3D *)
Interaction mode entry points.
int GetInteractionState(vtkEventDataDevice device)
Return interaction state for the specified device (dolly, pick, none, etc...).
virtual void StartLoadCamPose(vtkEventDataDevice3D *)
Interaction mode entry points.
void OnMenu3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
void OnPinch() override
Complex gesture events binding.
void StartAction(int VTKIS_STATE, vtkEventDataDevice3D *edata)
Utility routines.
vtkNew< vtkTimerLog > LastGroundMovement3DEventTime
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVRControlsHelper * ControlsHelpers[vtkEventDataNumberOfDevices][vtkEventDataNumberOfInputs]
void AddTooltipForInput(vtkEventDataDevice device, vtkEventDataDeviceInput input, const std::string &text={})
Define the helper text that goes with an input.
void OnElevation3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
vtkNew< vtkTimerLog > LastElevation3DEventTime
void Teleportation3D(vtkEventDataDevice3D *edd)
Instant movement to the picked point.
int InteractionState[vtkEventDataNumberOfDevices]
void EndPickCallback(vtkSelection *sel)
void MapInputToAction(vtkCommand::EventIds eid, vtkEventDataAction action, int state)
Map controller inputs to actions.
vtkNew< vtkVRMenuRepresentation > MenuRepresentation
void SetInteractor(vtkRenderWindowInteractor *iren) override
Set the Interactor wrapper being controlled by this object.
vtkNew< vtkVRHardwarePicker > HardwarePicker
void HideBillboard()
Show/hide billboard with given text string.
void ShowRay(vtkEventDataDevice controller)
Show/hide the ray for the specified controller.
~vtkVRInteractorStyle() override
virtual void EndPositionProp(vtkEventDataDevice3D *)
Interaction mode entry points.
static void MenuCallback(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
virtual void EndLoadCamPose(vtkEventDataDevice3D *)
Interaction mode entry points.
int GetMappedAction(vtkCommand::EventIds eid, vtkEventDataAction action=vtkEventDataAction::Press)
Map controller inputs to actions.
vtkNew< vtkVRMenuWidget > Menu
virtual void UpdateRay(vtkEventDataDevice controller)
Update and draw the ray.
void OnViewerMovement3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
void HideRay(vtkEventDataDevice controller)
Show/hide the ray for the specified controller.
virtual void EndPick(vtkEventDataDevice3D *)
Interaction mode entry points.
std::map< std::tuple< vtkCommand::EventIds, vtkEventDataAction >, int > InputMap
void ShowPickCell(vtkCell *cell, vtkProp3D *)
Make the pick actor a polydata built from the points and edges of the given cell, and show it.
void OnRotate() override
Complex gesture events binding.
void OnPan() override
Complex gesture events binding.
void SetInteractionState(vtkEventDataDevice device, int state)
Set interaction state for the specified device (dolly, pick, none, etc...).
void OnMove3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
vtkNew< vtkActor > PickActor
std::vector< vtkSmartPointer< vtkProp3D > > InteractionProps
virtual void LoadNextCameraPose()=0
Methods for interaction.
void ToggleDrawControls()
Control visibility of descriptive tooltips for controller/HMD models.
void GroundMovement3D(vtkEventDataDevice3D *)
Move the camera on the "XY" plan (ground) using the thumbstick/trackpad position (up/down and left/ri...
virtual void StartPositionProp(vtkEventDataDevice3D *)
Interaction mode entry points.
void MapInputToAction(vtkCommand::EventIds eid, int state)
Map controller inputs to actions.
void Elevation3D(vtkEventDataDevice3D *)
Move the camera following the "Z" axis (elevation) using the thumbstick/trackpad position (up/down).
virtual void EndClip(vtkEventDataDevice3D *)
Interaction mode entry points.
virtual void StartClip(vtkEventDataDevice3D *)
Interaction mode entry points.
vtkNew< vtkSphereSource > Sphere
Widget representation for vtkVRMenuWidget Implementation of the popup panel representation for the vt...
3D widget to display a menu in VR
vtkEventDataDevice
platform-independent event data structures
const int vtkEventDataNumberOfDevices
vtkEventDataAction
vtkEventDataDeviceInput
const int vtkEventDataNumberOfInputs