VTK  9.3.0
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
16#ifndef vtkOpenXRRenderWindowInteractor_h
17#define vtkOpenXRRenderWindowInteractor_h
18
19#include "vtkRenderingOpenXRModule.h" // For export macro
21
22#include "vtkEventData.h" // for ivar
23#include "vtkOpenXRManager.h" //for types
24
25#include <functional> // for std::function
26#include <map> // for std::map
27
29
30VTK_ABI_NAMESPACE_BEGIN
31class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
32{
33public:
36
40 void Initialize() override;
41
42 void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
43
49 XrPosef* GetHandPose(uint32_t hand);
50
52
56 void AddAction(const std::string& path, const vtkCommand::EventIds&);
57 void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
59 // add an event action
60
61 void ConvertOpenXRPoseToWorldCoordinates(const XrPosef& xrPose,
62 double pos[3], // Output world position
63 double wxyz[4], // Output world orientation quaternion
64 double ppos[3], // Output physical position
65 double wdir[3]); // Output world view direction (-Z)
66
72 bool ApplyVibration(const std::string& actionName, int hand, float amplitude = 0.5f,
73 float duration = 25000000.0f, float frequency = XR_FREQUENCY_UNSPECIFIED);
74
75protected:
82
84 void PrintSelf(ostream& os, vtkIndent indent) override;
85
90
96
97 struct ActionData;
98
99 XrActionType GetActionTypeFromString(const std::string& type);
100 bool LoadActions(const std::string& actionFilename);
101 bool LoadDefaultBinding(const std::string& bindingFilename);
102 ActionData* GetActionDataFromName(const std::string& actionName);
103
104 void HandleAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
105 void HandleBooleanAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
106 void HandlePoseAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
107 void HandleVector2fAction(const ActionData& actionData, int hand, vtkEventDataDevice3D* ed);
108 void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
109
111 {
112 std::string Name;
113
115
116 // This structure is defined in vtkOpenXRManager
117 // And hold OpenXR related data
118 Action_t ActionStruct{ XR_NULL_HANDLE };
119
121 std::function<void(vtkEventData*)> Function;
122 bool UseFunction = false;
123 };
124
125 using MapAction = std::map<std::string, ActionData*>;
127
129
130private:
132 void operator=(const vtkOpenXRRenderWindowInteractor&) = delete;
133};
134
135VTK_ABI_NAMESPACE_END
136#endif
137// VTK-HeaderTest-Exclude: vtkOpenXRRenderWindowInteractor.h
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:51
implements OpenXR specific functions required by vtkRenderWindowInteractor.
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.
bool ApplyVibration(const std::string &actionName, int hand, float amplitude=0.5f, float duration=25000000.0f, 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 &)
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)
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
Definition vtkRenderer.h:62
Implements VR specific functions required by vtkRenderWindowInteractor.
VR rendering window.
vtkEventDataDeviceInput
vtkOpenXRManager::Action_t Action_t