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=========================================================================*/
38#ifndef vtkOpenVRRenderWindowInteractor_h
39#define vtkOpenVRRenderWindowInteractor_h
40
41#include "vtkEventData.h" // for ivar
42#include "vtkNew.h" // ivars
44#include "vtkRenderingOpenVRModule.h" // For export macro
45#include <functional> // for ivar
46#include <map> // for ivar
47#include <openvr.h> // for ivar
48#include <string> // for ivar
49#include <tuple> // for ivar
50
51class vtkTransform;
52class vtkMatrix4x4;
54
55class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindowInteractor : public vtkRenderWindowInteractor3D
56{
57public:
62
64 void PrintSelf(ostream& os, vtkIndent indent);
65
69 virtual void Initialize();
70
72
78 static void SetClassExitMethod(void (*f)(void*), void* arg);
79 static void SetClassExitMethodArgDelete(void (*f)(void*));
81
86 virtual void ExitCallback();
87
89
93 virtual void SetPhysicalTranslation(vtkCamera*, double, double, double);
95 virtual void SetPhysicalScale(double);
96 virtual double GetPhysicalScale();
98
104 void ProcessEvents() override;
105
106 virtual void DoOneEvent(vtkOpenVRRenderWindow* renWin, vtkRenderer* ren);
107
108 /*
109 * Return the pointer index as a device
110 */
112
113 /*
114 * Convert a device pose to pose matrices
115 * \param poseMatrixPhysical Optional output pose matrix in physical frame
116 * \param poseMatrixWorld Optional output pose matrix in world frame
117 */
118 void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
119 vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
120
121 /*
122 * Convert a device pose to a world coordinate position and orientation
123 * \param pos Output world position
124 * \param wxyz Output world orientation quaternion
125 * \param ppos Output physical position
126 * \param wdir Output world view direction (-Z)
127 */
128 void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t& tdPose, double pos[3],
129 double wxyz[4], double ppos[3], double wdir[3]);
131 const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3]);
132
134
137 // void GetTouchPadPosition(vtkEventDataDevice, vtkEventDataDeviceInput, float[3]) override;
139
140 /*
141 * Return starting physical to world matrix
142 */
143 void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4* startingPhysicalToWorldMatrix);
144
146
149 void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog);
150 void AddAction(std::string path, bool isAnalog, std::function<void(vtkEventData*)>);
152 // add an event action
153
155
159 vtkGetMacro(ActionManifestFileName, std::string);
160 vtkSetMacro(ActionManifestFileName, std::string);
162
164
167 vtkGetMacro(ActionSetName, std::string);
168 vtkSetMacro(ActionSetName, std::string);
170
171protected:
174
176
181 static void (*ClassExitMethod)(void*);
182 static void (*ClassExitMethodArgDelete)(void*);
183 static void* ClassExitMethodArg;
185
187
191 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
192 virtual int InternalDestroyTimer(int platformTimerId);
194
200 virtual void StartEventLoop();
201
206 int DeviceInputDownCount[vtkEventDataNumberOfDevices];
208
213
215 {
216 public:
217 vr::VRActionHandle_t ActionHandle;
219 std::function<void(vtkEventData*)> Function;
220 bool UseFunction = false;
221 bool IsAnalog = false;
222 };
223
224 std::map<std::string, ActionData> ActionMap;
225
227 std::string ActionSetName;
228
229 vr::VRActionSetHandle_t ActionsetVTK = vr::k_ulInvalidActionSetHandle;
230
232 {
233 LeftHand = 0,
236 NumberOfTrackers
237 };
238
240 {
241 vr::VRInputValueHandle_t Source = vr::k_ulInvalidInputValueHandle;
242 // vr::VRActionHandle_t ActionPose = vr::k_ulInvalidActionHandle;
243 // vr::InputPoseActionData_t LastPoseData;
244 vr::TrackedDevicePose_t LastPose;
245 };
246 TrackerActions Trackers[NumberOfTrackers];
247
249
250private:
252 void operator=(const vtkOpenVRRenderWindowInteractor&) = delete;
253};
254
255#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
Allocate and hold a VTK object.
Definition: vtkNew.h:65
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:82
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:64
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36