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 =========================================================================*/
29 #ifndef vtkOpenVRRenderWindowInteractor_h
30 #define vtkOpenVRRenderWindowInteractor_h
31 
32 #include "vtkEventData.h" // for ivar
33 #include "vtkNew.h" // ivars
35 #include "vtkRenderingOpenVRModule.h" // For export macro
36 #include <functional> // for ivar
37 #include <map> // for ivar
38 #include <openvr.h> // for ivar
39 #include <string> // for ivar
40 #include <tuple> // for ivar
41 
42 class vtkTransform;
43 class vtkMatrix4x4;
45 
46 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindowInteractor : public vtkRenderWindowInteractor3D
47 {
48 public:
53 
55  void PrintSelf(ostream& os, vtkIndent indent);
56 
60  virtual void Initialize();
61 
63 
69  static void SetClassExitMethod(void (*f)(void*), void* arg);
70  static void SetClassExitMethodArgDelete(void (*f)(void*));
72 
77  virtual void ExitCallback();
78 
80 
84  virtual void SetPhysicalTranslation(vtkCamera*, double, double, double);
85  virtual double* GetPhysicalTranslation(vtkCamera*);
86  virtual void SetPhysicalScale(double);
87  virtual double GetPhysicalScale();
89 
95  void ProcessEvents() override;
96 
97  virtual void DoOneEvent(vtkOpenVRRenderWindow* renWin, vtkRenderer* ren);
98 
99  /*
100  * Return the pointer index as a device
101  */
103 
104  /*
105  * Convert a device pose to pose matrices
106  * \param poseMatrixPhysical Optional output pose matrix in physical frame
107  * \param poseMatrixWorld Optional output pose matrix in world frame
108  */
109  void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
110  vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
111 
112  /*
113  * Convert a device pose to a world coordinate position and orientation
114  * \param pos Output world position
115  * \param wxyz Output world orientation quaternion
116  * \param ppos Output physical position
117  * \param wdir Output world view direction (-Z)
118  */
119  void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t& tdPose, double pos[3],
120  double wxyz[4], double ppos[3], double wdir[3]);
122  const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3]);
123 
125 
128  // void GetTouchPadPosition(vtkEventDataDevice, vtkEventDataDeviceInput, float[3]) override;
130 
131  /*
132  * Return starting physical to world matrix
133  */
134  void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4* startingPhysicalToWorldMatrix);
135 
137 
140  void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog);
141  void AddAction(std::string path, bool isAnalog, std::function<void(vtkEventData*)>);
143  // add an event action
144 
146 
150  vtkGetMacro(ActionManifestFileName, std::string);
151  vtkSetMacro(ActionManifestFileName, std::string);
153 
155 
158  vtkGetMacro(ActionSetName, std::string);
159  vtkSetMacro(ActionSetName, std::string);
161 
162 protected:
165 
167 
172  static void (*ClassExitMethod)(void*);
173  static void (*ClassExitMethodArgDelete)(void*);
174  static void* ClassExitMethodArg;
176 
178 
182  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
183  virtual int InternalDestroyTimer(int platformTimerId);
185 
191  virtual void StartEventLoop();
192 
197  int DeviceInputDownCount[vtkEventDataNumberOfDevices];
199 
204 
206  {
207  public:
208  vr::VRActionHandle_t ActionHandle;
211  bool UseFunction = false;
212  bool IsAnalog = false;
213  };
214 
215  std::map<std::string, ActionData> ActionMap;
216 
219 
220  vr::VRActionSetHandle_t ActionsetVTK = vr::k_ulInvalidActionSetHandle;
221 
223  {
224  LeftHand = 0,
227  NumberOfTrackers
228  };
229 
231  {
232  vr::VRInputValueHandle_t Source = vr::k_ulInvalidInputValueHandle;
233  // vr::VRActionHandle_t ActionPose = vr::k_ulInvalidActionHandle;
234  // vr::InputPoseActionData_t LastPoseData;
235  vr::TrackedDevicePose_t LastPose;
236  };
237  TrackerActions Trackers[NumberOfTrackers];
238 
240 
241 private:
243  void operator=(const vtkOpenVRRenderWindowInteractor&) = delete;
244 };
245 
246 #endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:46
a simple class to control print indentation
Definition: vtkIndent.h:34
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
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.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual double * GetPhysicalTranslation(vtkCamera *)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
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.
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.
static vtkOpenVRRenderWindowInteractor * New()
Construct object so that light follows camera motion.
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:55
@ 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