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=========================================================================*/
21
22#ifndef vtkOpenXRRenderWindowInteractor_h
23#define vtkOpenXRRenderWindowInteractor_h
24
25#include "vtkRenderingOpenXRModule.h" // For export macro
27
28#include "vtkEventData.h" // for ivar
29#include "vtkOpenXRManager.h" //for types
30
31#include <functional> // for std::function
32#include <map> // for std::map
33
35
36class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
37{
38public:
41
45 void Initialize() override;
46
47 void DoOneEvent(vtkVRRenderWindow* renWin, vtkRenderer* ren) override;
48
54 XrPosef* GetHandPose(const uint32_t hand);
55
57
61 void AddAction(const std::string& path, const vtkCommand::EventIds&);
62 void AddAction(const std::string& path, const std::function<void(vtkEventData*)>&);
64 // add an event action
65
66 void ConvertOpenXRPoseToWorldCoordinates(const XrPosef& xrPose,
67 double pos[3], // Output world position
68 double wxyz[4], // Output world orientation quaternion
69 double ppos[3], // Output physical position
70 double wdir[3]); // Output world view direction (-Z)
71
77 bool ApplyVibration(const std::string& actionName, const int hand, const float amplitude = 0.5f,
78 const float duration = 25000000.0f, const float frequency = XR_FREQUENCY_UNSPECIFIED);
79
80protected:
83 void PrintSelf(ostream& os, vtkIndent indent) override;
84
89
95
96 struct ActionData;
97
98 XrActionType GetActionTypeFromString(const std::string& type);
99 bool LoadActions(const std::string& actionFilename);
100 bool LoadDefaultBinding(const std::string& bindingFilename);
101 ActionData* GetActionDataFromName(const std::string& actionName);
102
103 void HandleAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
104 void HandleBooleanAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
105 void HandlePoseAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
106 void HandleVector2fAction(const ActionData& actionData, const int hand, vtkEventDataDevice3D* ed);
107 void ApplyAction(const ActionData& actionData, vtkEventDataDevice3D* ed);
108
110 {
111 std::string Name;
112
114
115 // This structure is defined in vtkOpenXRManager
116 // And hold OpenXR related data
117 Action_t ActionStruct{ XR_NULL_HANDLE };
118
120 std::function<void(vtkEventData*)> Function;
121 bool UseFunction = false;
122 };
123
124 using MapAction = std::map<std::string, ActionData*>;
126
128
129private:
131 void operator=(const vtkOpenXRRenderWindowInteractor&) = delete;
132};
133
134#endif
135// VTK-HeaderTest-Exclude: vtkOpenXRRenderWindowInteractor.h
a simple class to control print indentation
Definition vtkIndent.h:34
Allocate and hold a VTK object.
Definition vtkNew.h:56
XrPosef * GetHandPose(const uint32_t hand)
Return the XrPosef for the action named "handpose" and the hand hand or return nullptr if "handpose" ...
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...
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 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)
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 HandleVector2fAction(const ActionData &actionData, const int hand, vtkEventDataDevice3D *ed)
static vtkOpenXRRenderWindowInteractor * New()
void Initialize() override
Initialize the event handler.
bool LoadActions(const std::string &actionFilename)
abstract specification for renderers
Definition vtkRenderer.h:67
VR rendering window.
vtkEventDataDeviceInput
vtkOpenXRManager::Action_t Action_t