VTK  9.5.2
vtkOpenXRRenderWindowInteractor.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
31
32#ifndef vtkOpenXRRenderWindowInteractor_h
33#define vtkOpenXRRenderWindowInteractor_h
34
35#include "vtkRenderingOpenXRModule.h" // For export macro
37
38#include "vtkEventData.h" // for ivar
39#include "vtkOpenXRManager.h" //for types
40
41#include <functional> // for std::function
42#include <map> // for std::map
43
45
46VTK_ABI_NAMESPACE_BEGIN
47class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
48{
49public:
52
56 void Initialize() override;
57
58 void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
59
65 XrPosef* GetHandPose(uint32_t hand);
66
68
72 void AddAction(const std::string& path, const vtkCommand::EventIds&);
73 void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
75
77
85 void AddAction(const std::string& path, const vtkCommand::EventIds&, bool isAnalog) override;
87 const std::string& path, bool isAnalog, const std::function<void(vtkEventData*)>&) override;
89
90 void ConvertOpenXRPoseToWorldCoordinates(const XrPosef& xrPose,
91 double pos[3], // Output world position
92 double wxyz[4], // Output world orientation quaternion
93 double ppos[3], // Output physical position
94 double wdir[3]); // Output world view direction (-Z)
95
101 bool ApplyVibration(const std::string& actionName, int hand, float amplitude = 0.5,
102 float duration = 25000000.0, float frequency = XR_FREQUENCY_UNSPECIFIED);
103
104protected:
111
113 void PrintSelf(ostream& os, vtkIndent indent) override;
114
119
125
126 struct ActionData;
127
128 XrActionType GetActionTypeFromString(const std::string& type);
129 bool LoadActions(const std::string& actionFilename);
130 bool LoadDefaultBinding(const std::string& bindingFilename);
131 ActionData* GetActionDataFromName(const std::string& actionName);
132
133 void HandleAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
134 void HandleBooleanAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
135 void HandlePoseAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
136 void HandleVector2fAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
137 void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
138
140 {
141 std::string Name;
142
144
145 // This structure is defined in vtkOpenXRManager
146 // And hold OpenXR related data
147 Action_t ActionStruct{ XR_NULL_HANDLE };
148
150 std::function<void(vtkEventData*)> Function;
151 bool UseFunction = false;
152 };
153
154 using MapAction = std::map<std::string, ActionData*>;
156
158
159private:
161 void operator=(const vtkOpenXRRenderWindowInteractor&) = delete;
162};
163
164VTK_ABI_NAMESPACE_END
165#endif
166// VTK-HeaderTest-Exclude: vtkOpenXRRenderWindowInteractor.h
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
void AddAction(const std::string &path, bool isAnalog, const std::function< void(vtkEventData *)> &) override
Assign an event or std::function to an event path.
void HandlePoseAction(const ActionData &actionData, int hand, vtkEventDataDevice3D *ed)
void ProcessXrEvents()
Process OpenXR specific events.
void DoOneEvent(vtkVRRenderWindow *renWin, vtkRenderer *ren) override
Implements the event loop.
void AddAction(const std::string &path, const std::function< void(vtkEventData *)> &)
Assign an event or std::function to an event path.
void AddAction(const std::string &path, const vtkCommand::EventIds &)
Assign an event or std::function to an event path.
ActionData * GetActionDataFromName(const std::string &actionName)
bool LoadDefaultBinding(const std::string &bindingFilename)
XrActionType GetActionTypeFromString(const std::string &type)
void ApplyAction(const ActionData &actionData, vtkEventDataDevice3D *ed)
void PollXrActions()
Update the action states using the OpenXRManager and handle all actions.
std::map< std::string, ActionData * > MapAction
void HandleBooleanAction(const ActionData &actionData, int hand, vtkEventDataDevice3D *ed)
bool ApplyVibration(const std::string &actionName, int hand, float amplitude=0.5, float duration=25000000.0, float frequency=XR_FREQUENCY_UNSPECIFIED)
Apply haptic vibration using the provided action action to emit vibration on hand to emit on amplitud...
void AddAction(const std::string &path, const vtkCommand::EventIds &, bool isAnalog) override
Assign an event or std::function to an event path.
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])
void HandleAction(const ActionData &actionData, int hand, vtkEventDataDevice3D *ed)
XrPosef * GetHandPose(uint32_t hand)
Return the XrPosef for the action named "handpose" and the hand hand or return nullptr if "handpose" ...
static vtkOpenXRRenderWindowInteractor * New()
void Initialize() override
Initialize the event handler.
bool LoadActions(const std::string &actionFilename)
vtkOpenXRRenderWindowInteractor()
Create and set the openxr style on this Set ActionManifestFileName to vtk_openxr_actions....
void HandleVector2fAction(const ActionData &actionData, int hand, vtkEventDataDevice3D *ed)
abstract specification for renderers
VR rendering window.
vtkEventDataDeviceInput
vtkOpenXRManager::Action_t Action_t