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=========================================================================*/
128#ifndef vtkOpenVRRenderWindowInteractor_h
129#define vtkOpenVRRenderWindowInteractor_h
130
131#include "vtkEventData.h" // for ivar
132#include "vtkNew.h" // ivars
134#include "vtkRenderingOpenVRModule.h" // For export macro
135#include <functional> // for ivar
136#include <map> // for ivar
137#include <openvr.h> // for ivar
138#include <string> // for ivar
139#include <tuple> // for ivar
140
141class vtkTransform;
142class vtkMatrix4x4;
144
145class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindowInteractor : public vtkRenderWindowInteractor3D
146{
147public:
152
154 void PrintSelf(ostream& os, vtkIndent indent);
155
159 virtual void Initialize();
160
162
168 static void SetClassExitMethod(void (*f)(void*), void* arg);
169 static void SetClassExitMethodArgDelete(void (*f)(void*));
171
176 virtual void ExitCallback();
177
179
183 virtual void SetPhysicalTranslation(vtkCamera*, double, double, double);
185 virtual void SetPhysicalScale(double);
186 virtual double GetPhysicalScale();
188
194 void ProcessEvents() override;
195
196 virtual void DoOneEvent(vtkOpenVRRenderWindow* renWin, vtkRenderer* ren);
197
198 /*
199 * Return the pointer index as a device
200 */
202
203 /*
204 * Convert a device pose to pose matrices
205 * \param poseMatrixPhysical Optional output pose matrix in physical frame
206 * \param poseMatrixWorld Optional output pose matrix in world frame
207 */
208 void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
209 vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
210
211 /*
212 * Convert a device pose to a world coordinate position and orientation
213 * \param pos Output world position
214 * \param wxyz Output world orientation quaternion
215 * \param ppos Output physical position
216 * \param wdir Output world view direction (-Z)
217 */
218 void ConvertPoseToWorldCoordinates(const vr::TrackedDevicePose_t& tdPose, double pos[3],
219 double wxyz[4], double ppos[3], double wdir[3]);
221 const float poseMatrix[3][4], double pos[3], double wxyz[4], double ppos[3], double wdir[3]);
222
224
227 // void GetTouchPadPosition(vtkEventDataDevice, vtkEventDataDeviceInput, float[3]) override;
229
230 /*
231 * Return starting physical to world matrix
232 */
233 void GetStartingPhysicalToWorldMatrix(vtkMatrix4x4* startingPhysicalToWorldMatrix);
234
236
239 void AddAction(std::string path, vtkCommand::EventIds, bool isAnalog);
240 void AddAction(std::string path, bool isAnalog, std::function<void(vtkEventData*)>);
242 // add an event action
243
245
249 vtkGetMacro(ActionManifestFileName, std::string);
250 vtkSetMacro(ActionManifestFileName, std::string);
252
254
257 vtkGetMacro(ActionSetName, std::string);
258 vtkSetMacro(ActionSetName, std::string);
260
261protected:
264
266
271 static void (*ClassExitMethod)(void*);
272 static void (*ClassExitMethodArgDelete)(void*);
273 static void* ClassExitMethodArg;
275
277
281 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
282 virtual int InternalDestroyTimer(int platformTimerId);
284
290 virtual void StartEventLoop();
291
296 int DeviceInputDownCount[vtkEventDataNumberOfDevices];
298
303
305 {
306 public:
307 vr::VRActionHandle_t ActionHandle;
309 std::function<void(vtkEventData*)> Function;
310 bool UseFunction = false;
311 bool IsAnalog = false;
312 };
313
314 std::map<std::string, ActionData> ActionMap;
315
317 std::string ActionSetName;
318
319 vr::VRActionSetHandle_t ActionsetVTK = vr::k_ulInvalidActionSetHandle;
320
322 {
323 LeftHand = 0,
326 NumberOfTrackers
327 };
328
330 {
331 vr::VRInputValueHandle_t Source = vr::k_ulInvalidInputValueHandle;
332 // vr::VRActionHandle_t ActionPose = vr::k_ulInvalidActionHandle;
333 // vr::InputPoseActionData_t LastPoseData;
334 vr::TrackedDevicePose_t LastPose;
335 };
336 TrackerActions Trackers[NumberOfTrackers];
337
339
340private:
342 void operator=(const vtkOpenVRRenderWindowInteractor&) = delete;
343};
344
345#endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:155
a simple class to control print indentation
Definition: vtkIndent.h:113
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
Allocate and hold a VTK object.
Definition: vtkNew.h:165
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:182
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36