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 =========================================================================*/
118 #ifndef vtkOpenVRRenderWindowInteractor_h
119 #define vtkOpenVRRenderWindowInteractor_h
120 
121 #include "vtkEventData.h" // for ivar
122 #include "vtkNew.h" // ivars
124 #include "vtkRenderingOpenVRModule.h" // For export macro
125 #include <functional> // for ivar
126 #include <map> // for ivar
127 #include <openvr.h> // for ivar
128 #include <string> // for ivar
129 #include <tuple> // for ivar
130 
131 class vtkTransform;
132 class vtkMatrix4x4;
134 
135 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindowInteractor : public vtkRenderWindowInteractor3D
136 {
137 public:
142 
144  void PrintSelf(ostream& os, vtkIndent indent);
145 
149  virtual void Initialize();
150 
152 
158  static void SetClassExitMethod(void (*f)(void*), void* arg);
159  static void SetClassExitMethodArgDelete(void (*f)(void*));
161 
166  virtual void ExitCallback();
167 
169 
173  virtual void SetPhysicalTranslation(vtkCamera*, double, double, double);
175  virtual void SetPhysicalScale(double);
176  virtual double GetPhysicalScale();
178 
184  void ProcessEvents() override;
185 
186  virtual void DoOneEvent(vtkOpenVRRenderWindow* renWin, vtkRenderer* ren);
187 
188  /*
189  * Return the pointer index as a device
190  */
192 
193  /*
194  * Convert a device pose to pose matrices
195  * \param poseMatrixPhysical Optional output pose matrix in physical frame
196  * \param poseMatrixWorld Optional output pose matrix in world frame
197  */
198  void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
199  vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
200 
201  /*
202  * Convert a device pose to a world coordinate position and orientation
203  * \param pos Output world position
204  * \param wxyz Output world orientation quaternion
205  * \param ppos Output physical position
206  * \param wdir Output world view direction (-Z)
207  */
208  void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t& tdPose, double pos[3],
209  double wxyz[4], double ppos[3], double wdir[3]);
211  const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3]);
212 
214 
217  // void GetTouchPadPosition(vtkEventDataDevice, vtkEventDataDeviceInput, float[3]) override;
219 
220  /*
221  * Return starting physical to world matrix
222  */
223  void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4* startingPhysicalToWorldMatrix);
224 
226 
229  void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog);
230  void AddAction(std::string path, bool isAnalog, std::function<void(vtkEventData*)>);
232  // add an event action
233 
235 
239  vtkGetMacro(ActionManifestFileName, std::string);
240  vtkSetMacro(ActionManifestFileName, std::string);
242 
244 
247  vtkGetMacro(ActionSetName, std::string);
248  vtkSetMacro(ActionSetName, std::string);
250 
251 protected:
254 
256 
261  static void (*ClassExitMethod)(void*);
262  static void (*ClassExitMethodArgDelete)(void*);
263  static void* ClassExitMethodArg;
265 
267 
271  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
272  virtual int InternalDestroyTimer(int platformTimerId);
274 
280  virtual void StartEventLoop();
281 
286  int DeviceInputDownCount[vtkEventDataNumberOfDevices];
288 
293 
295  {
296  public:
297  vr::VRActionHandle_t ActionHandle;
300  bool UseFunction = false;
301  bool IsAnalog = false;
302  };
303 
304  std::map<std::string, ActionData> ActionMap;
305 
308 
309  vr::VRActionSetHandle_t ActionsetVTK = vr::k_ulInvalidActionSetHandle;
310 
312  {
313  LeftHand = 0,
316  NumberOfTrackers
317  };
318 
320  {
321  vr::VRInputValueHandle_t Source = vr::k_ulInvalidInputValueHandle;
322  // vr::VRActionHandle_t ActionPose = vr::k_ulInvalidActionHandle;
323  // vr::InputPoseActionData_t LastPoseData;
324  vr::TrackedDevicePose_t LastPose;
325  };
326  TrackerActions Trackers[NumberOfTrackers];
327 
329 
330 private:
332  void operator=(const vtkOpenVRRenderWindowInteractor&) = delete;
333 };
334 
335 #endif
vtkOpenVRRenderWindowInteractor::RightHand
@ RightHand
Definition: vtkOpenVRRenderWindowInteractor.h:314
vtkOpenVRRenderWindowInteractor::StartEventLoop
virtual void StartEventLoop()
This will start up the event loop and never return.
vtkOpenVRRenderWindowInteractor::InternalDestroyTimer
virtual int InternalDestroyTimer(int platformTimerId)
Win32-specific internal timer methods.
vtkX3D::function
@ function
Definition: vtkX3D.h:255
vtkOpenVRRenderWindowInteractor::AddAction
void AddAction(std::string path, bool isAnalog, std::function< void(vtkEventData *)>)
Assign an event or std::function to an event path.
vtkOpenVRRenderWindowInteractor::New
static vtkOpenVRRenderWindowInteractor * New()
Construct object so that light follows camera motion.
vtkOpenVRRenderWindowInteractor::ActionSetName
std::string ActionSetName
Definition: vtkOpenVRRenderWindowInteractor.h:307
vtkEventData
Definition: vtkEventData.h:69
vtkEventDataDevice3D
Definition: vtkEventData.h:161
vtkOpenVRRenderWindowInteractor::ConvertOpenVRPoseToMatrices
void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t &tdPose, vtkMatrix4x4 *poseMatrixWorld, vtkMatrix4x4 *poseMatrixPhysical=nullptr)
vtkOpenVRRenderWindowInteractor::GetPhysicalScale
virtual double GetPhysicalScale()
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
vtkOpenVRRenderWindowInteractor::ActionManifestFileName
std::string ActionManifestFileName
Definition: vtkOpenVRRenderWindowInteractor.h:306
vtkOpenVRRenderWindowInteractor::ActionData::Function
std::function< void(vtkEventData *)> Function
Definition: vtkOpenVRRenderWindowInteractor.h:299
vtkRenderWindowInteractor3D
adds support for 3D events to vtkRenderWindowInteractor.
Definition: vtkRenderWindowInteractor3D.h:46
vtkOpenVRRenderWindowInteractor::ConvertPoseMatrixToWorldCoordinates
void ConvertPoseMatrixToWorldCoordinates(const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3])
vtkOpenVRRenderWindowInteractor::TrackerActions::LastPose
vr::TrackedDevicePose_t LastPose
Definition: vtkOpenVRRenderWindowInteractor.h:324
vtkOpenVRRenderWindowInteractor::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkOpenVRRenderWindowInteractor::DoOneEvent
virtual void DoOneEvent(vtkOpenVRRenderWindow *renWin, vtkRenderer *ren)
vtkOpenVRRenderWindowInteractor::~vtkOpenVRRenderWindowInteractor
~vtkOpenVRRenderWindowInteractor() override
vtkOpenVRRenderWindowInteractor::RecognizeComplexGesture
virtual void RecognizeComplexGesture(vtkEventDataDevice3D *edata)
vtkOpenVRRenderWindowInteractor::ActionMap
std::map< std::string, ActionData > ActionMap
Definition: vtkOpenVRRenderWindowInteractor.h:304
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
vtkOpenVRRenderWindowInteractor::TrackerEnum
TrackerEnum
Definition: vtkOpenVRRenderWindowInteractor.h:312
vtkOpenVRRenderWindowInteractor::SetPhysicalScale
virtual void SetPhysicalScale(double)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
vtkOpenVRRenderWindowInteractor::SetPhysicalTranslation
virtual void SetPhysicalTranslation(vtkCamera *, double, double, double)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
vtkOpenVRRenderWindowInteractor::ExitCallback
virtual void ExitCallback()
These methods correspond to the Exit, User and Pick callbacks.
vtkEventDataNumberOfDevices
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36
vtkOpenVRRenderWindowInteractor::ProcessEvents
void ProcessEvents() override
Run the event loop and return.
vtkOpenVRRenderWindowInteractor::ActionData::EventId
vtkCommand::EventIds EventId
Definition: vtkOpenVRRenderWindowInteractor.h:298
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:160
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
vtkCamera
a virtual camera for 3D rendering
Definition: vtkCamera.h:155
vtkEventData.h
vtkNew< vtkMatrix4x4 >
vtkRenderWindowInteractor3D.h
vtkOpenVRRenderWindowInteractor::GetPhysicalTranslation
virtual double * GetPhysicalTranslation(vtkCamera *)
Set/Get the optional translation to map world coordinates into the 3D physical space (meters,...
vtkOpenVRRenderWindowInteractor::Initialize
virtual void Initialize()
Initialize the event handler.
vtkOpenVRRenderWindowInteractor::ConvertPoseToWorldCoordinates
void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t &tdPose, double pos[3], double wxyz[4], double ppos[3], double wdir[3])
vtkOpenVRRenderWindowInteractor::ActionData
Definition: vtkOpenVRRenderWindowInteractor.h:295
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkOpenVRRenderWindowInteractor::SetClassExitMethod
static void SetClassExitMethod(void(*f)(void *), void *arg)
Methods to set the default exit method for the class.
vtkOpenVRRenderWindowInteractor::InternalCreateTimer
virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration)
Win32-specific internal timer methods.
vtkEventDataDevice
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
vtkNew.h
vtkOpenVRRenderWindowInteractor::Head
@ Head
Definition: vtkOpenVRRenderWindowInteractor.h:315
vtkCommand::EventIds
EventIds
Definition: vtkCommand.h:461
vtkOpenVRRenderWindowInteractor::AddAction
void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog)
Assign an event or std::function to an event path.
vtkOpenVRRenderWindowInteractor::TrackerActions
Definition: vtkOpenVRRenderWindowInteractor.h:320
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:182
vtkOpenVRRenderWindowInteractor::GetPointerDevice
vtkEventDataDevice GetPointerDevice()
vtkOpenVRRenderWindowInteractor::vtkOpenVRRenderWindowInteractor
vtkOpenVRRenderWindowInteractor()
vtkOpenVRRenderWindowInteractor
implements OpenVR specific functions required by vtkRenderWindowInteractor.
Definition: vtkOpenVRRenderWindowInteractor.h:136
vtkOpenVRRenderWindowInteractor::HandleGripEvents
void HandleGripEvents(vtkEventData *ed)
vtkOpenVRRenderWindowInteractor::GetStartingPhysicalToWorldMatrix
void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4 *startingPhysicalToWorldMatrix)
Get the latest touchpad or joystick position for a device.
vtkOpenVRRenderWindowInteractor::ActionData::ActionHandle
vr::VRActionHandle_t ActionHandle
Definition: vtkOpenVRRenderWindowInteractor.h:297
vtkOpenVRRenderWindowInteractor::SetClassExitMethodArgDelete
static void SetClassExitMethodArgDelete(void(*f)(void *))
Methods to set the default exit method for the class.
vtkOpenVRRenderWindowInteractor::StartingPhysicalToWorldMatrix
vtkNew< vtkMatrix4x4 > StartingPhysicalToWorldMatrix
Store physical to world matrix at the start of a multi-touch gesture.
Definition: vtkOpenVRRenderWindowInteractor.h:292
vtkOpenVRRenderWindowInteractor::ClassExitMethodArg
static void * ClassExitMethodArg
Class variables so an exit method can be defined for this class (used to set different exit methods f...
Definition: vtkOpenVRRenderWindowInteractor.h:263