VTK  9.2.6
vtkOpenXRRenderWindowInteractor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenXRRenderWindowInteractor.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 vtkOpenXRRenderWindowInteractor_h
26 #define vtkOpenXRRenderWindowInteractor_h
27 
28 #include "vtkRenderingOpenXRModule.h" // For export macro
30 
31 #include "vtkEventData.h" // for ivar
32 #include "vtkOpenXRManager.h" //for types
33 
34 #include <functional> // for std::function
35 #include <map> // for std::map
36 
38 
39 class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
40 {
41 public:
44 
48  void Initialize() override;
49 
50  void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
51 
57  XrPosef* GetHandPose(const uint32_t hand);
58 
60 
64  void AddAction(const std::string& path, const vtkCommand::EventIds&);
65  void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
67  // add an event action
68 
69  void ConvertOpenXRPoseToWorldCoordinates(const XrPosef& xrPose,
70  double pos[3], // Output world position
71  double wxyz[4], // Output world orientation quaternion
72  double ppos[3], // Output physical position
73  double wdir[3]); // Output world view direction (-Z)
74 
80  bool ApplyVibration(const std::string& actionName, const int hand, const float amplitude = 0.5f,
81  const float duration = 25000000.0f, const float frequency = XR_FREQUENCY_UNSPECIFIED);
82 
83 protected:
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
92 
97  void PollXrActions();
98 
99  struct ActionData;
100 
102  bool LoadActions(const std::string& actionFilename);
103  bool LoadDefaultBinding(const std::string& bindingFilename);
105 
106  void HandleAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
107  void HandleBooleanAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
108  void HandlePoseAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
109  void HandleVector2fAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
110  void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
111 
112  struct ActionData
113  {
115 
117 
118  // This structure is defined in vtkOpenXRManager
119  // And hold OpenXR related data
120  Action_t ActionStruct{ XR_NULL_HANDLE };
121 
124  bool UseFunction = false;
125  };
126 
127  using MapAction = std::map<std::string, ActionData*>;
129 
130  vtkNew<vtkMatrix4x4> PoseToWorldMatrix; // used in calculations
131 
132 private:
134  void operator=(const vtkOpenXRRenderWindowInteractor&) = delete;
135 };
136 
137 #endif
138 // VTK-HeaderTest-Exclude: vtkOpenXRRenderWindowInteractor.h
a simple class to control print indentation
Definition: vtkIndent.h:119
implements OpenXR specific functions required by vtkRenderWindowInteractor.
void HandleBooleanAction(const ActionData &actionData, const int hand, vtkEventDataDevice3D *ed)
void ProcessXrEvents()
Process OpenXR specific events.
void DoOneEvent(vtkVRRenderWindow *renWin, vtkRenderer *ren) override
Implements the event loop.
void HandleAction(const ActionData &actionData, const int hand, vtkEventDataDevice3D *ed)
void AddAction(const std::string &path, const std::function< void(vtkEventData *)> &)
bool ApplyVibration(const std::string &actionName, const int hand, const float amplitude=0.5f, const float duration=25000000.0f, const float frequency=XR_FREQUENCY_UNSPECIFIED)
Apply haptic vibration using the provided action action to emit vibration on hand to emit on amplitud...
static vtkOpenXRRenderWindowInteractor * New()
void AddAction(const std::string &path, const vtkCommand::EventIds &)
Assign an event or std::function to an event path.
bool LoadDefaultBinding(const std::string &bindingFilename)
XrActionType GetActionTypeFromString(const std::string &type)
void ApplyAction(const ActionData &actionData, vtkEventDataDevice3D *ed)
void PollXrActions()
Update tha action states using the OpenXRManager and handle all actions.
std::map< std::string, ActionData * > MapAction
void HandlePoseAction(const ActionData &actionData, const int hand, vtkEventDataDevice3D *ed)
ActionData * GetActionDataFromName(const std::string &actionName)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ConvertOpenXRPoseToWorldCoordinates(const XrPosef &xrPose, double pos[3], double wxyz[4], double ppos[3], double wdir[3])
XrPosef * GetHandPose(const uint32_t hand)
Return the XrPosef for the action named "handpose" and the hand hand or return nullptr if "handpose" ...
void HandleVector2fAction(const ActionData &actionData, const int hand, vtkEventDataDevice3D *ed)
void Initialize() override
Initialize the event handler.
bool LoadActions(const std::string &actionFilename)
abstract specification for renderers
Definition: vtkRenderer.h:182
Implements VR specific functions required by vtkRenderWindowInteractor.
VR rendering window.
@ function
Definition: vtkX3D.h:255
@ frequency
Definition: vtkX3D.h:365
@ type
Definition: vtkX3D.h:522
@ string
Definition: vtkX3D.h:496
vtkEventDataDeviceInput
Definition: vtkEventData.h:40
vtkOpenXRManager::Action_t Action_t