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
48class VTKRENDERINGOPENXR_EXPORT vtkOpenXRRenderWindowInteractor : public vtkVRRenderWindowInteractor
49{
50public:
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
92protected:
95 void PrintSelf(ostream& os, vtkIndent indent) override;
96
101
107
108 struct ActionData;
109
110 XrActionType GetActionTypeFromString(const std::string& type);
111 bool LoadActions(const std::string& actionFilename);
112 bool LoadDefaultBinding(const std::string& bindingFilename);
113 ActionData* GetActionDataFromName(const std::string& actionName);
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
122 {
123 std::string Name;
124
126
127 // This structure is defined in vtkOpenXRManager
128 // And hold OpenXR related data
129 Action_t ActionStruct{ XR_NULL_HANDLE };
130
132 std::function<void(vtkEventData*)> Function;
133 bool UseFunction = false;
134 };
135
136 using MapAction = std::map<std::string, ActionData*>;
138
140
141private:
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
Allocate and hold a VTK object.
Definition vtkNew.h:71
implements OpenXR specific functions required by vtkRenderWindowInteractor.
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:82
Implements VR specific functions required by vtkRenderWindowInteractor.
VR rendering window.
vtkEventDataDeviceInput
vtkOpenXRManager::Action_t Action_t