VTK  9.1.0
vtkOpenVRRenderWindowInteractor.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOpenVRRenderWindowInteractor.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=========================================================================*/
32#ifndef vtkOpenVRRenderWindowInteractor_h
33#define vtkOpenVRRenderWindowInteractor_h
34
35#include "vtkEventData.h" // for ivar
36#include "vtkNew.h" // ivars
38#include "vtkRenderingOpenVRModule.h" // For export macro
39#include <functional> // for ivar
40#include <map> // for ivar
41#include <openvr.h> // for ivar
42#include <string> // for ivar
43#include <tuple> // for ivar
44
45class vtkTransform;
46class vtkMatrix4x4;
48
49class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindowInteractor : public vtkRenderWindowInteractor3D
50{
51public:
56
58 void PrintSelf(ostream& os, vtkIndent indent);
59
63 virtual void Initialize();
64
66
72 static void SetClassExitMethod(void (*f)(void*), void* arg);
73 static void SetClassExitMethodArgDelete(void (*f)(void*));
75
80 virtual void ExitCallback();
81
83
87 virtual void SetPhysicalTranslation(vtkCamera*, double, double, double);
89 virtual void SetPhysicalScale(double);
90 virtual double GetPhysicalScale();
92
98 void ProcessEvents() override;
99
100 virtual void DoOneEvent(vtkOpenVRRenderWindow* renWin, vtkRenderer* ren);
101
102 /*
103 * Return the pointer index as a device
104 */
106
107 /*
108 * Convert a device pose to pose matrices
109 * \param poseMatrixPhysical Optional output pose matrix in physical frame
110 * \param poseMatrixWorld Optional output pose matrix in world frame
111 */
112 void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
113 vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
114
115 /*
116 * Convert a device pose to a world coordinate position and orientation
117 * \param pos Output world position
118 * \param wxyz Output world orientation quaternion
119 * \param ppos Output physical position
120 * \param wdir Output world view direction (-Z)
121 */
122 void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t& tdPose, double pos[3],
123 double wxyz[4], double ppos[3], double wdir[3]);
125 const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3]);
126
128
131 // void GetTouchPadPosition(vtkEventDataDevice, vtkEventDataDeviceInput, float[3]) override;
133
134 /*
135 * Return starting physical to world matrix
136 */
137 void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4* startingPhysicalToWorldMatrix);
138
140
143 void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog);
144 void AddAction(std::string path, bool isAnalog, std::function<void(vtkEventData*)>);
146 // add an event action
147
149
153 vtkGetMacro(ActionManifestFileName, std::string);
154 vtkSetMacro(ActionManifestFileName, std::string);
156
158
161 vtkGetMacro(ActionSetName, std::string);
162 vtkSetMacro(ActionSetName, std::string);
164
165protected:
168
170
175 static void (*ClassExitMethod)(void*);
176 static void (*ClassExitMethodArgDelete)(void*);
177 static void* ClassExitMethodArg;
179
181
185 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
186 virtual int InternalDestroyTimer(int platformTimerId);
188
194 virtual void StartEventLoop();
195
200 int DeviceInputDownCount[vtkEventDataNumberOfDevices];
202
207
209 {
210 public:
211 vr::VRActionHandle_t ActionHandle;
214 bool UseFunction = false;
215 bool IsAnalog = false;
216 };
217
218 std::map<std::string, ActionData> ActionMap;
219
222
223 vr::VRActionSetHandle_t ActionsetVTK = vr::k_ulInvalidActionSetHandle;
224
226 {
227 LeftHand = 0,
230 NumberOfTrackers
231 };
232
234 {
235 vr::VRInputValueHandle_t Source = vr::k_ulInvalidInputValueHandle;
236 // vr::VRActionHandle_t ActionPose = vr::k_ulInvalidActionHandle;
237 // vr::InputPoseActionData_t LastPoseData;
238 vr::TrackedDevicePose_t LastPose;
239 };
240 TrackerActions Trackers[NumberOfTrackers];
241
243
244private:
246 void operator=(const vtkOpenVRRenderWindowInteractor&) = delete;
247};
248
249#endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:55
a simple class to control print indentation
Definition: vtkIndent.h:43
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:45
implements OpenVR specific functions required by vtkRenderWindowInteractor.
void AddAction(std::string path, bool isAnalog, std::function< void(vtkEventData *)>)
Assign an event or std::function to an event path.
static void SetClassExitMethodArgDelete(void(*f)(void *))
Methods to set the default exit method for the class.
virtual double * GetPhysicalTranslation(vtkCamera *)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual int InternalDestroyTimer(int platformTimerId)
Win32-specific internal timer methods.
void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t &tdPose, vtkMatrix4x4 *poseMatrixWorld, vtkMatrix4x4 *poseMatrixPhysical=nullptr)
void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t &tdPose, double pos[3], double wxyz[4], double ppos[3], double wdir[3])
virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration)
Win32-specific internal timer methods.
static vtkOpenVRRenderWindowInteractor * New()
Construct object so that light follows camera motion.
vtkEventDataDevice GetPointerDevice()
virtual void RecognizeComplexGesture(vtkEventDataDevice3D *edata)
std::map< std::string, ActionData > ActionMap
virtual void StartEventLoop()
This will start up the event loop and never return.
static void SetClassExitMethod(void(*f)(void *), void *arg)
Methods to set the default exit method for the class.
virtual void SetPhysicalScale(double)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
virtual void Initialize()
Initialize the event handler.
void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog)
Assign an event or std::function to an event path.
virtual void ExitCallback()
These methods correspond to the Exit, User and Pick callbacks.
void ConvertPoseMatrixToWorldCoordinates(const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3])
static void * ClassExitMethodArg
Class variables so an exit method can be defined for this class (used to set different exit methods f...
void ProcessEvents() override
Run the event loop and return.
void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4 *startingPhysicalToWorldMatrix)
Get the latest touchpad or joystick position for a device.
virtual double GetPhysicalScale()
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
vtkNew< vtkMatrix4x4 > StartingPhysicalToWorldMatrix
Store physical to world matrix at the start of a multi-touch gesture.
void HandleGripEvents(vtkEventData *ed)
virtual void SetPhysicalTranslation(vtkCamera *, double, double, double)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
virtual void DoOneEvent(vtkOpenVRRenderWindow *renWin, vtkRenderer *ren)
OpenVR rendering window.
adds support for 3D events to vtkRenderWindowInteractor.
abstract specification for renderers
Definition: vtkRenderer.h:73
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:64
@ function
Definition: vtkX3D.h:255
@ string
Definition: vtkX3D.h:496
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36