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 =========================================================================*/
34 #ifndef vtkOpenXRRenderWindowInteractor_h
35 #define vtkOpenXRRenderWindowInteractor_h
36 
37 #include "vtkRenderingOpenXRModule.h" // For export macro
39 
40 #include "vtkEventData.h" // for ivar
41 #include "vtkOpenXRManager.h" //for types
42 
43 #include <functional> // for std::function
44 #include <map> // for std::map
45 
47 
48 class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
49 {
50 public:
53 
57  void Initialize() override;
58 
59  void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
60 
66  XrPosef* GetHandPose(const uint32_t hand);
67 
69 
73  void AddAction(const std::string& path, const vtkCommand::EventIds&);
74  void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
76  // add an event action
77 
78  void ConvertOpenXRPoseToWorldCoordinates(const XrPosef& xrPose,
79  double pos[3], // Output world position
80  double wxyz[4], // Output world orientation quaternion
81  double ppos[3], // Output physical position
82  double wdir[3]); // Output world view direction (-Z)
83 
89  bool ApplyVibration(const std::string& actionName, const int hand, const float amplitude = 0.5f,
90  const float duration = 25000000.0f, const float frequency = XR_FREQUENCY_UNSPECIFIED);
91 
92 protected:
95  void PrintSelf(ostream& os, vtkIndent indent) override;
96 
101 
107 
108  struct ActionData;
109 
111  bool LoadActions(const std::string& actionFilename);
112  bool LoadDefaultBinding(const std::string& bindingFilename);
114 
115  void HandleAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
116  void HandleBooleanAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
117  void HandlePoseAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
118  void HandleVector2fAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
119  void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
120 
121  struct ActionData
122  {
124 
126 
127  // This structure is defined in vtkOpenXRManager
128  // And hold OpenXR related data
129  Action_t ActionStruct{ XR_NULL_HANDLE };
130 
133  bool UseFunction = false;
134  };
135 
136  using MapAction = std::map<std::string, ActionData*>;
138 
139  vtkNew<vtkMatrix4x4> PoseToWorldMatrix; // used in calculations
140 
141 private:
143  void operator=(const vtkOpenXRRenderWindowInteractor&) = delete;
144 };
145 
146 #endif
147 // VTK-HeaderTest-Exclude: vtkOpenXRRenderWindowInteractor.h
a simple class to control print indentation
Definition: vtkIndent.h:49
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:82
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