VTK  9.2.20230201
vtkVRInteractorStyle.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkVRInteractorStyle.h
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
25 #ifndef vtkVRInteractorStyle_h
26 #define vtkVRInteractorStyle_h
27 
28 #include "vtkEventData.h" // for enums
29 #include "vtkInteractorStyle3D.h"
30 #include "vtkNew.h" // for vtkNew
31 #include "vtkRenderingVRModule.h" // For export macro
32 #include "vtkSmartPointer.h" // for vtkSmartPointer
33 
34 #include <map> // for std::map
35 #include <vector> // for std::vector
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkCallbackCommand;
39 class vtkCell;
40 class vtkPlane;
42 class vtkSelection;
43 class vtkSphereSource;
44 class vtkTextActor3D;
48 class vtkVRMenuWidget;
49 
50 class VTKRENDERINGVR_EXPORT vtkVRInteractorStyle : public vtkInteractorStyle3D
51 {
52 public:
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
57 
60  void OnSelect3D(vtkEventData* edata) override;
61  void OnNextPose3D(vtkEventData* edata) override;
62  void OnViewerMovement3D(vtkEventData* edata) override;
63  void OnMove3D(vtkEventData* edata) override;
64  void OnMenu3D(vtkEventData* edata) override;
65  void OnElevation3D(vtkEventData* edata) override;
67 
69 
80  void StartMovement3D(int interactionState, vtkEventDataDevice3D*);
83 
85 
88  void OnPan() override;
89  void OnPinch() override;
90  void OnRotate() override;
92 
94 
97  void ProbeData(vtkEventDataDevice controller);
98  void PositionProp(vtkEventData*, double* lwpos = nullptr, double* lwori = nullptr) override;
100  virtual void LoadNextCameraPose() = 0;
102 
108 
114 
116 
124 
129  vtkEventDataDevice device, vtkEventDataDeviceInput input, const std::string& text = {});
130 
135 
137 
142  vtkSetMacro(HoverPick, bool);
143  vtkGetMacro(HoverPick, bool);
144  vtkBooleanMacro(HoverPick, bool);
146 
148 
152  vtkSetMacro(GrabWithRay, bool);
153  vtkGetMacro(GrabWithRay, bool);
154  vtkBooleanMacro(GrabWithRay, bool);
156 
158  {
160  GROUNDED_STYLE
161  };
162 
164 
168  vtkSetMacro(Style, MovementStyle);
169  vtkGetMacro(Style, MovementStyle);
171 
176  {
177  return this->InteractionState[static_cast<int>(device)];
178  }
179 
181 
184  void ShowRay(vtkEventDataDevice controller);
185  void HideRay(vtkEventDataDevice controller);
187 
189 
192  void ShowBillboard(const std::string& text);
195 
200  void ShowPickSphere(double* pos, double radius, vtkProp3D*);
201 
208 
213 
215 
219  void SetDrawControls(bool);
221 
226 
230  virtual void SetupActions(vtkRenderWindowInteractor* iren) = 0;
231 
235  vtkVRMenuWidget* GetMenu() { return this->Menu.Get(); }
236 
237 protected:
240 
244  void UpdateRay(vtkEventDataDevice controller);
245 
247  static void MenuCallback(
248  vtkObject* object, unsigned long event, void* clientdata, void* calldata);
249 
253  void StartAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);
254  void EndAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);
255 
259  bool HardwareSelect(vtkEventDataDevice controller, bool actorPassOnly);
260 
264  void Movement3D(int interactionState, vtkEventData* edata);
265 
266  bool HoverPick = false;
267  bool GrabWithRay = true;
268 
272 
277 
278  // Device input to interaction state mapping
279  std::map<std::tuple<vtkCommand::EventIds, vtkEventDataAction>, int> InputMap;
281 
282  // Store required controllers information when performing action
283  int InteractionState[vtkEventDataNumberOfDevices];
284  std::vector<vtkSmartPointer<vtkProp3D>> InteractionProps;
285  std::vector<vtkSmartPointer<vtkPlane>> ClippingPlanes;
286 
287  // Store headset world orientation
288  double HeadsetDir[3] = { 0, 0, 0 };
289 
290  // Store movement style
292 
293 private:
295  void operator=(const vtkVRInteractorStyle&) = delete;
296 };
297 
298 VTK_ABI_NAMESPACE_END
299 #endif
supports function callbacks
abstract class to specify cell behavior
Definition: vtkCell.h:151
a simple class to control print indentation
Definition: vtkIndent.h:120
extends interaction to support 3D input
abstract base class for most VTK objects
Definition: vtkObject.h:83
perform various plane computations
Definition: vtkPlane.h:147
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:100
platform-independent render window interaction including picking and frame rate control.
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:171
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.
vtkVRMenuWidget * GetMenu()
Return the menu to allow the user to add options to it.
virtual void SetupActions(vtkRenderWindowInteractor *iren)=0
Setup default actions defined with an action path and a corresponding command.
void StartMovement3D(int interactionState, vtkEventDataDevice3D *)
Interaction mode entry points.
std::vector< vtkSmartPointer< vtkPlane > > ClippingPlanes
vtkNew< vtkTextActor3D > TextActor3D
void Clip(vtkEventDataDevice3D *)
Methods for interaction.
void ShowBillboard(const std::string &text)
Show/hide billboard with given text string.
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.
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).
int GetInteractionState(vtkEventDataDevice device)
Return interaction state for the specified device (dolly, pick, none, etc...).
void StartPick(vtkEventDataDevice3D *)
Interaction mode entry points.
void OnMenu3D(vtkEventData *edata) override
Override generic event bindings to call the corresponding action.
void OnPinch() override
Multitouch events binding.
void StartAction(int VTKIS_STATE, vtkEventDataDevice3D *edata)
Utility routines.
void EndPick(vtkEventDataDevice3D *)
Interaction mode entry points.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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.
void StartClip(vtkEventDataDevice3D *)
Interaction mode entry points.
void EndPickCallback(vtkSelection *sel)
void MapInputToAction(vtkCommand::EventIds eid, vtkEventDataAction action, int state)
Map controller inputs to actions.
void EndClip(vtkEventDataDevice3D *)
Interaction mode entry points.
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
void EndMovement3D(vtkEventDataDevice3D *)
Interaction mode entry points.
static void MenuCallback(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
vtkNew< vtkVRMenuWidget > Menu
void EndPositionProp(vtkEventDataDevice3D *)
Interaction mode entry points.
void StartLoadCamPose(vtkEventDataDevice3D *)
Interaction mode entry points.
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.
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
Multitouch events binding.
void OnPan() override
Multitouch events binding.
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...
void UpdateRay(vtkEventDataDevice controller)
Update and draw the ray.
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 vtkVRControlsHelper * MakeControlsHelper()=0
Creates a new ControlsHelper suitable for use with the child class.
void EndLoadCamPose(vtkEventDataDevice3D *)
Interaction mode entry points.
void StartPositionProp(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
@ radius
Definition: vtkX3D.h:264
@ string
Definition: vtkX3D.h:502
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:27
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:37
vtkEventDataAction
Definition: vtkEventData.h:56
vtkEventDataDeviceInput
Definition: vtkEventData.h:41
const int vtkEventDataNumberOfInputs
Definition: vtkEventData.h:52