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 
91  void ProcessXrEvents();
92 
97  void PollXrActions();
98 
99  struct ActionData;
100 
101  XrActionType GetActionTypeFromString(const std::string& type);
102  bool LoadActions(const std::string& actionFilename);
103  bool LoadDefaultBinding(const std::string& bindingFilename);
104  ActionData* GetActionDataFromName(const std::string& actionName);
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 
123  std::function<void(vtkEventData*)> Function;
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
implements OpenXR specific functions required by vtkRenderWindowInteractor.
virtual void DoOneEvent(vtkVRRenderWindow *renWin, vtkRenderer *ren)=0
Implements the event loop.
vtkEventDataDeviceInput
Definition: vtkEventData.h:39
Implements VR specific functions required by vtkRenderWindowInteractor.
VR rendering window.
abstract specification for renderers
Definition: vtkRenderer.h:72
vtkOpenXRManager::Action_t Action_t
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:39
void Initialize() override
Initialize the event handler.
std::map< std::string, ActionData * > MapAction
static vtkRenderWindowInteractor3D * New()
Construct object so that light follows camera motion.