VTK  9.0.1
vtkOpenVRRenderWindow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
51 #ifndef vtkOpenVRRenderWindow_h
52 #define vtkOpenVRRenderWindow_h
53 
54 #include "vtkOpenGLRenderWindow.h"
55 #include "vtkRenderingOpenVRModule.h" // For export macro
56 
57 #include "vtkEventData.h" // for enums
58 #include "vtkOpenGLHelper.h" // used for ivars
59 #include "vtk_glew.h" // used for methods
60 #include <openvr.h> // for ivars
61 #include <vector> // ivars
62 
63 class vtkCamera;
64 class vtkMatrix4x4;
65 class vtkOpenVRModel;
66 class vtkOpenVROverlay;
68 class vtkTransform;
69 
70 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWindow
71 {
72 public:
73  enum
74  {
75  PhysicalToWorldMatrixModified = vtkCommand::UserEvent + 200
76  };
77 
80  void PrintSelf(ostream& os, vtkIndent indent);
81 
85  vr::IVRSystem* GetHMD() { return this->HMD; }
86 
92 
96  void RenderOverlay();
97 
99 
102  vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
105 
112 
114 
117  GLuint GetLeftResolveBufferId() { return this->LeftEyeDesc.m_nResolveFramebufferId; }
118  GLuint GetRightResolveBufferId() { return this->RightEyeDesc.m_nResolveFramebufferId; }
119  void GetRenderBufferSize(int& width, int& height)
120  {
121  width = this->Size[0];
122  height = this->Size[1];
123  }
125 
130  {
131  return this->GetTrackedDeviceModel(idx, 0);
132  }
133  vtkOpenVRModel* GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx)
134  {
135  return this->TrackedDeviceToRenderModel[idx];
136  }
138 
142  vr::IVRRenderModels* GetOpenVRRenderModels() { return this->OpenVRRenderModels; }
143 
148  {
149  return this->GetTrackedDeviceIndexForDevice(dev, 0);
150  }
151  vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index);
153 
157  void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t** pose)
158  {
159  return this->GetTrackedDevicePose(idx, 0, pose);
160  }
161  void GetTrackedDevicePose(vtkEventDataDevice idx, uint32_t index, vr::TrackedDevicePose_t** pose);
162  vr::TrackedDevicePose_t& GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
163  {
164  return this->TrackedDevicePose[idx];
165  }
166 
176 
178 
186  virtual void SetPhysicalViewDirection(double, double, double);
187  virtual void SetPhysicalViewDirection(double[3]);
188  vtkGetVector3Macro(PhysicalViewDirection, double);
190 
192 
200  virtual void SetPhysicalViewUp(double, double, double);
201  virtual void SetPhysicalViewUp(double[3]);
202  vtkGetVector3Macro(PhysicalViewUp, double);
204 
206 
214  virtual void SetPhysicalTranslation(double, double, double);
215  virtual void SetPhysicalTranslation(double[3]);
216  vtkGetVector3Macro(PhysicalTranslation, double);
218 
220 
229  virtual void SetPhysicalScale(double);
230  vtkGetMacro(PhysicalScale, double);
232 
244 
246 
250  vtkSetMacro(TrackHMD, bool);
251  vtkGetMacro(TrackHMD, bool);
253 
257  virtual void AddRenderer(vtkRenderer*) override;
258 
262  virtual void Start(void);
263 
268  virtual void StereoUpdate();
269 
274  virtual void StereoMidpoint();
275 
280  virtual void StereoRenderComplete();
281 
288  virtual void Initialize(void);
289 
295  virtual void Finalize(void);
296 
300  void MakeCurrent();
301 
305  virtual bool IsCurrent();
306 
310  const char* ReportCapabilities() { return "OpenVR System"; }
311 
315  vtkTypeBool IsDirect() { return 1; }
316 
322  virtual vtkTypeBool GetEventPending() { return 0; }
323 
327  virtual int* GetScreenSize();
328 
330 
337  void SetSize(int width, int height) override;
338  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
340 
342 
347  void SetPosition(int x, int y) override;
348  void SetPosition(int a[2]) override { this->SetPosition(a[0], a[1]); }
350 
351  // implement required virtual functions
352  void SetWindowInfo(const char*) {}
353  void SetNextWindowInfo(const char*) {}
354  void SetParentInfo(const char*) {}
355  virtual void* GetGenericDisplayId() { return (void*)this->HelperWindow->GetGenericDisplayId(); }
356  virtual void* GetGenericWindowId() { return (void*)this->HelperWindow->GetGenericWindowId(); }
357  virtual void* GetGenericParentId() { return (void*)nullptr; }
358  virtual void* GetGenericContext() { return (void*)this->HelperWindow->GetGenericContext(); }
359  virtual void* GetGenericDrawable() { return (void*)this->HelperWindow->GetGenericDrawable(); }
360  virtual void SetDisplayId(void*) {}
361  void SetWindowId(void*) {}
362  void SetParentId(void*) {}
363  void HideCursor() {}
364  void ShowCursor() {}
365  virtual void SetFullScreen(vtkTypeBool) {}
366  virtual void WindowRemap(void) {}
367  virtual void SetNextWindowId(void*) {}
368 
372  virtual int SupportsOpenGL() { return 1; }
373 
378  void Render();
379 
383  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
385 
386  // Get the state object used to keep track of
387  // OpenGL state
389 
395 
396 protected:
399 
400  virtual void CreateAWindow() {}
401  virtual void DestroyWindow() {}
402 
405  vr::IVRSystem* HMD;
406  vr::IVRRenderModels* OpenVRRenderModels;
407 
409  {
412  };
415  bool CreateFrameBuffer(int nWidth, int nHeight, FramebufferDesc& framebufferDesc);
416 
417  // convert a device index to a human string
418  std::string GetTrackedDeviceString(vr::IVRSystem* pHmd, vr::TrackedDeviceIndex_t unDevice,
419  vr::TrackedDeviceProperty prop, vr::TrackedPropertyError* peError = nullptr);
420 
421  // devices may have polygonal models
422  // load them
423  vtkOpenVRModel* FindOrLoadRenderModel(const char* modelName);
424  void RenderModels();
425  std::vector<vtkOpenVRModel*> VTKRenderModels;
426  vtkOpenVRModel* TrackedDeviceToRenderModel[vr::k_unMaxTrackedDeviceCount];
427  vr::TrackedDevicePose_t TrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
428 
429  // used in computing the pose
432  double PhysicalViewDirection[3];
434  double PhysicalViewUp[3];
436  double PhysicalTranslation[3];
439 
440  // for the overlay
442 
443  bool TrackHMD;
444 
446 
447 private:
449  void operator=(const vtkOpenVRRenderWindow&) = delete;
450 };
451 
452 #endif
vtkOpenVRRenderWindow::Finalize
virtual void Finalize(void)
Finalize the rendering window.
vtkOpenVRRenderWindow::SetFullScreen
virtual void SetFullScreen(vtkTypeBool)
Turn on/off rendering full screen window size.
Definition: vtkOpenVRRenderWindow.h:365
vtkOpenVRRenderWindow::SetPhysicalViewUp
virtual void SetPhysicalViewUp(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow::SetWindowId
void SetWindowId(void *)
Definition: vtkOpenVRRenderWindow.h:361
vtkOpenVRRenderWindow::GetRenderBufferSize
void GetRenderBufferSize(int &width, int &height)
Definition: vtkOpenVRRenderWindow.h:119
vtkOpenVRRenderWindow::StereoRenderComplete
virtual void StereoRenderComplete()
Handles work required once both views have been rendered when using stereo rendering.
vtkCommand::UserEvent
@ UserEvent
Definition: vtkCommand.h:445
vtkOpenVRRenderWindow::DestroyWindow
virtual void DestroyWindow()
Destroy a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:401
vtkOpenVRRenderWindow::VTKRenderModels
std::vector< vtkOpenVRModel * > VTKRenderModels
Definition: vtkOpenVRRenderWindow.h:425
vtkOpenVRRenderWindow::StereoUpdate
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
vtkOpenVRRenderWindow::GetLeftResolveBufferId
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
Definition: vtkOpenVRRenderWindow.h:117
vtkOpenVRRenderWindow::HelperWindow
vtkOpenGLRenderWindow * HelperWindow
Definition: vtkOpenVRRenderWindow.h:445
vtkOpenVRRenderWindow::SetParentInfo
void SetParentInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:354
vtkOpenVRRenderWindow::GetOpenVRRenderModels
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
Definition: vtkOpenVRRenderWindow.h:142
vtkOpenVRRenderWindow::Initialize
virtual void Initialize(void)
Initialize the rendering window.
vtkOpenVRRenderWindow::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx)
Definition: vtkOpenVRRenderWindow.h:133
vtkOpenVRRenderWindow::SetNextWindowInfo
void SetNextWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:353
vtkOpenVRRenderWindow::MakeCurrent
void MakeCurrent()
Make this windows OpenGL context the current context.
vtkOpenVRRenderWindow::GetTrackedDevicePose
void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose)
Get the most recent pose corresponding to the tracked device.
Definition: vtkOpenVRRenderWindow.h:157
vtkOpenVRRenderWindow::~vtkOpenVRRenderWindow
~vtkOpenVRRenderWindow() override
vtkOpenVRRenderWindow::GetGenericParentId
virtual void * GetGenericParentId()
Definition: vtkOpenVRRenderWindow.h:357
vtkOpenVRRenderWindow::SetPhysicalViewUp
virtual void SetPhysicalViewUp(double[3])
vtkOpenGLHelper.h
vtkOpenVRRenderWindow::GetPhysicalToWorldMatrix
void GetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Get physical to world transform matrix.
vtkOpenVRRenderWindow::ReportCapabilities
const char * ReportCapabilities()
Get report of capabilities for the render window.
Definition: vtkOpenVRRenderWindow.h:310
vtkOpenVRRenderWindow::IsCurrent
virtual bool IsCurrent()
Tells if this window is the current OpenGL context for the calling thread.
vtkOpenVRRenderWindow::HMDTransform
vtkTransform * HMDTransform
Definition: vtkOpenVRRenderWindow.h:430
vtkOpenVRRenderWindow::SetPhysicalScale
virtual void SetPhysicalScale(double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow::GetTrackedDeviceIndexForDevice
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev)
Get the index corresponding to the tracked device.
Definition: vtkOpenVRRenderWindow.h:147
vtkOpenVRRenderWindow::vtkOpenVRRenderWindow
vtkOpenVRRenderWindow()
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:55
vtkOpenVRRenderWindow::SetPhysicalToWorldMatrix
void SetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Set physical to world transform matrix.
vtkOpenVRRenderWindow::SetPosition
void SetPosition(int x, int y) override
Set the position (x and y) of the rendering window in screen coordinates (in pixels).
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
vtkOpenVRRenderWindow::SetPhysicalTranslation
virtual void SetPhysicalTranslation(double[3])
vtkOpenVRModel
OpenVR device model.
Definition: vtkOpenVRModel.h:40
vtkOpenVRRenderWindow::Start
virtual void Start(void)
Begin the rendering process.
vtkOpenVRRenderWindow::SetDashboardOverlay
void SetDashboardOverlay(vtkOpenVROverlay *)
vtkOpenVRRenderWindow::CreateFrameBuffer
bool CreateFrameBuffer(int nWidth, int nHeight, FramebufferDesc &framebufferDesc)
vtkOpenVRRenderWindow::RenderOverlay
void RenderOverlay()
Draw the overlay.
vtkOpenVRRenderWindow::SetWindowInfo
void SetWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:352
vtkOpenVRRenderWindow::GetTrackedDeviceString
std::string GetTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError=nullptr)
vtkOpenVRRenderWindow::GetTrackedDevicePose
vr::TrackedDevicePose_t & GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
Definition: vtkOpenVRRenderWindow.h:162
vtkOpenVRRenderWindow::LeftEyeDesc
FramebufferDesc LeftEyeDesc
Definition: vtkOpenVRRenderWindow.h:413
vtkOpenVRRenderWindow::GetTrackedDevicePose
void GetTrackedDevicePose(vtkEventDataDevice idx, uint32_t index, vr::TrackedDevicePose_t **pose)
vtkX3D::height
@ height
Definition: vtkX3D.h:260
vtkOpenVRRenderWindow::GetGenericDrawable
virtual void * GetGenericDrawable()
Definition: vtkOpenVRRenderWindow.h:359
vtkOpenVRRenderWindow::Render
void Render()
Overridden to not release resources that would interfere with an external application's rendering.
vtkOpenVRRenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkOpenVRRenderWindow::SetDisplayId
virtual void SetDisplayId(void *)
Dummy stubs for vtkWindow API.
Definition: vtkOpenVRRenderWindow.h:360
vtkOpenVRRenderWindow::GetGenericContext
virtual void * GetGenericContext()
Definition: vtkOpenVRRenderWindow.h:358
vtkOpenVRRenderWindow::SetPhysicalTranslation
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow::GetRightResolveBufferId
GLuint GetRightResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:118
vtkOpenVROverlay
OpenVR overlay.
Definition: vtkOpenVROverlay.h:41
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:71
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
vtkOpenVRRenderWindow::SetPosition
void SetPosition(int a[2]) override
Definition: vtkOpenVRRenderWindow.h:348
vtkOpenVRRenderWindow::GetGenericDisplayId
virtual void * GetGenericDisplayId()
Definition: vtkOpenVRRenderWindow.h:355
vtkCamera
a virtual camera for 3D rendering
Definition: vtkCamera.h:46
vtkOpenVRRenderWindow::SetHelperWindow
void SetHelperWindow(vtkOpenGLRenderWindow *val)
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:37
vtkEventData.h
vtkOpenVRRenderWindow::GetNumberOfTrackedDevicesForDevice
uint32_t GetNumberOfTrackedDevicesForDevice(vtkEventDataDevice dev)
vtkOpenVRRenderWindow::SetSize
void SetSize(int width, int height) override
Set the size of the window in screen coordinates in pixels.
vtkOpenVRRenderWindow::HMD
vr::IVRSystem * HMD
Definition: vtkOpenVRRenderWindow.h:405
vtkOpenVRRenderWindow::IsDirect
vtkTypeBool IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:315
vtkRenderWindowInteractor
platform-independent render window interaction including picking and frame rate control.
Definition: vtkRenderWindowInteractor.h:74
vtkOpenVRRenderWindow::GetGenericWindowId
virtual void * GetGenericWindowId()
Definition: vtkOpenVRRenderWindow.h:356
vtkOpenVRRenderWindow::MakeRenderWindowInteractor
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override
Create an interactor to control renderers in this window.
vtkOpenVRRenderWindow::PhysicalScale
double PhysicalScale
Scale of the Physical to World matrix.
Definition: vtkOpenVRRenderWindow.h:438
vtkOpenVRRenderWindow::ShowCursor
void ShowCursor()
Definition: vtkOpenVRRenderWindow.h:364
vtkOpenVRRenderWindow::GetHMD
vr::IVRSystem * GetHMD()
Get the system pointer.
Definition: vtkOpenVRRenderWindow.h:85
vtkOpenVRRenderWindow::TrackHMD
bool TrackHMD
Definition: vtkOpenVRRenderWindow.h:443
vtkOpenVRRenderWindow::GetEventPending
virtual vtkTypeBool GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
Definition: vtkOpenVRRenderWindow.h:322
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkOpenVRRenderWindow::m_strDriver
std::string m_strDriver
Definition: vtkOpenVRRenderWindow.h:403
vtkOpenVRRenderWindow::GetTrackedDeviceIndexForDevice
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index)
vtkOpenVRRenderWindow::FindOrLoadRenderModel
vtkOpenVRModel * FindOrLoadRenderModel(const char *modelName)
vtkOpenVRRenderWindow::SetNextWindowId
virtual void SetNextWindowId(void *)
Definition: vtkOpenVRRenderWindow.h:367
vtkOpenVRRenderWindow::OpenVRRenderModels
vr::IVRRenderModels * OpenVRRenderModels
Definition: vtkOpenVRRenderWindow.h:406
vtkEventDataDevice
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26
vtkOpenVRRenderWindow::DashboardOverlay
vtkOpenVROverlay * DashboardOverlay
Definition: vtkOpenVRRenderWindow.h:441
vtkOpenVRRenderWindow::CreateAWindow
virtual void CreateAWindow()
Create a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:400
vtkOpenVRRenderWindow::StereoMidpoint
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye.
vtkOpenVRRenderWindow::AddRenderer
virtual void AddRenderer(vtkRenderer *) override
Add a renderer to the list of renderers.
vtkOpenVRRenderWindow::New
static vtkOpenVRRenderWindow * New()
vtkOpenVRRenderWindow::FramebufferDesc
Definition: vtkOpenVRRenderWindow.h:409
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:59
vtkOpenVRRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:372
vtkOpenVRRenderWindow::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx, uint32_t index)
vtkOpenVRRenderWindow::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of nullptr means the context may a...
vtkOpenVRRenderWindow::WindowRemap
virtual void WindowRemap(void)
Remap the rendering window.
Definition: vtkOpenVRRenderWindow.h:366
vtkOpenVRRenderWindow::InitializeViewFromCamera
void InitializeViewFromCamera(vtkCamera *cam)
Initialize the HMD to World setting and camera settings so that the VR world view most closely matche...
vtkOpenVRRenderWindow::RenderModels
void RenderModels()
vtkOpenVRRenderWindow::SetSize
void SetSize(int a[2]) override
Definition: vtkOpenVRRenderWindow.h:338
vtkOpenVRRenderWindow::m_strDisplay
std::string m_strDisplay
Definition: vtkOpenVRRenderWindow.h:404
vtkOpenVRRenderWindow::SetPhysicalViewDirection
virtual void SetPhysicalViewDirection(double[3])
vtkOpenVRRenderWindow::UpdateHMDMatrixPose
void UpdateHMDMatrixPose()
Update the HMD pose based on hardware pose and physical to world transform.
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:52
vtkOpenVRRenderWindow::GetScreenSize
virtual int * GetScreenSize()
Get the current size of the screen in pixels.
vtkOpenVRRenderWindow::GetState
vtkOpenGLState * GetState() override
vtkOpenVRRenderWindow::HideCursor
void HideCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
Definition: vtkOpenVRRenderWindow.h:363
vtkOpenVRRenderWindow::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx)
Get the VRModel corresponding to the tracked device.
Definition: vtkOpenVRRenderWindow.h:129
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:80
vtkOpenVRRenderWindow::SetParentId
void SetParentId(void *)
Definition: vtkOpenVRRenderWindow.h:362
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveTextureId
GLuint m_nResolveTextureId
Definition: vtkOpenVRRenderWindow.h:410
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkOpenVRRenderWindow::RightEyeDesc
FramebufferDesc RightEyeDesc
Definition: vtkOpenVRRenderWindow.h:414
vtkOpenGLRenderWindow.h
vtkOpenVRRenderWindow::SetPhysicalViewDirection
virtual void SetPhysicalViewDirection(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveFramebufferId
GLuint m_nResolveFramebufferId
Definition: vtkOpenVRRenderWindow.h:411