VTK
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 =========================================================================*/
54 #ifndef vtkOpenVRRenderWindow_h
55 #define vtkOpenVRRenderWindow_h
56 
57 #include "vtkRenderingOpenVRModule.h" // For export macro
58 #include "vtkOpenGLRenderWindow.h"
59 
60 #include <openvr.h> // for ivars
61 #include <vector> // ivars
62 #include "vtkOpenGLHelper.h" // used for ivars
63 #include "vtk_glew.h" // used for methods
64 #include "vtkEventData.h" // for enums
65 
66 class vtkCamera;
67 class vtkMatrix4x4;
68 class vtkOpenVRModel;
69 class vtkOpenVROverlay;
71 class vtkTransform;
72 
73 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWindow
74 {
75 public:
76  enum
77  {
78  PhysicalToWorldMatrixModified = vtkCommand::UserEvent + 200
79  };
80 
83  void PrintSelf(ostream& os, vtkIndent indent);
84 
88  vr::IVRSystem *GetHMD() { return this->HMD; };
89 
93  void RenderOverlay();
94 
96 
99  vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
102 
109 
111 
115  { return this->LeftEyeDesc.m_nRenderFramebufferId; };
117  { return this->LeftEyeDesc.m_nResolveFramebufferId; };
119  { return this->RightEyeDesc.m_nRenderFramebufferId; };
121  { return this->RightEyeDesc.m_nResolveFramebufferId; };
122  void GetRenderBufferSize(int &width, int &height)
123  {
124  width = this->Size[0];
125  height = this->Size[1];
126  };
128 
133  vtkOpenVRModel *GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx) {
134  return this->TrackedDeviceToRenderModel[idx]; };
135 
139  vr::IVRRenderModels * GetOpenVRRenderModels() {
140  return this->OpenVRRenderModels; };
141 
145  vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev);
146 
150  void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose);
151  vr::TrackedDevicePose_t &GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx) {
152  return this->TrackedDevicePose[idx]; };
153 
163 
165 
173  virtual void SetPhysicalViewDirection(double,double,double);
174  virtual void SetPhysicalViewDirection(double[3]);
175  vtkGetVector3Macro(PhysicalViewDirection, double);
177 
179 
187  virtual void SetPhysicalViewUp(double,double,double);
188  virtual void SetPhysicalViewUp(double[3]);
189  vtkGetVector3Macro(PhysicalViewUp, double);
191 
193 
201  virtual void SetPhysicalTranslation(double,double,double);
202  virtual void SetPhysicalTranslation(double[3]);
203  vtkGetVector3Macro(PhysicalTranslation, double);
205 
207 
216  virtual void SetPhysicalScale(double);
217  vtkGetMacro(PhysicalScale, double);
219 
231 
233 
237  vtkSetMacro(TrackHMD, bool);
238  vtkGetMacro(TrackHMD, bool);
240 
244  virtual void AddRenderer(vtkRenderer *) override;
245 
249  virtual void Start(void);
250 
255  virtual void StereoUpdate();
256 
261  virtual void StereoMidpoint();
262 
267  virtual void StereoRenderComplete();
268 
272  void Frame(void);
273 
280  virtual void Initialize(void);
281 
287  virtual void Finalize(void);
288 
292  void MakeCurrent();
293 
297  virtual bool IsCurrent();
298 
302  const char *ReportCapabilities() { return "OpenVR System";};
303 
307  int IsDirect() { return 1; };
308 
314  virtual int GetEventPending() { return 0;};
315 
319  virtual int *GetScreenSize();
320 
322 
325  virtual void SetSize(int,int);
326  virtual void SetSize(int a[2]) {vtkOpenGLRenderWindow::SetSize(a);};
328 
330 
333  virtual void SetPosition(int,int);
334  virtual void SetPosition(int a[2]) {vtkOpenGLRenderWindow::SetPosition(a);};
336 
337  // implement required virtual functions
338  void SetWindowInfo(const char *) {};
339  void SetNextWindowInfo(const char *) {};
340  void SetParentInfo(const char *) {};
341  virtual void *GetGenericDisplayId() {return (void *)this->HelperWindow->GetGenericDisplayId();};
342  virtual void *GetGenericWindowId() {return (void *)this->HelperWindow->GetGenericWindowId();};
343  virtual void *GetGenericParentId() {return (void *)nullptr;};
344  virtual void *GetGenericContext() { return (void *)this->HelperWindow->GetGenericContext(); };
345  virtual void *GetGenericDrawable() {return (void *)this->HelperWindow->GetGenericDrawable();};
346  virtual void SetDisplayId(void *) {};
347  void SetWindowId(void *) {};
348  void SetParentId(void *) {};
349  void HideCursor() {};
350  void ShowCursor() {};
351  virtual void SetFullScreen(vtkTypeBool) {};
352  virtual void WindowRemap(void) {};
353  virtual void SetNextWindowId(void *) {};
354 
358  virtual int SupportsOpenGL() { return 1; };
359 
364  void Render();
365 
369  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
371 
372  // Get the state object used to keep track of
373  // OpenGL state
375 
376 protected:
379 
385 
386  virtual void CreateAWindow() {};
387  virtual void DestroyWindow() {};
388 
391  vr::IVRSystem *HMD;
392  vr::IVRRenderModels *OpenVRRenderModels;
393 
395  {
401  };
404  bool CreateFrameBuffer( int nWidth, int nHeight,
405  FramebufferDesc &framebufferDesc );
406 
407  // convert a device index to a human string
409  vr::IVRSystem *pHmd,
410  vr::TrackedDeviceIndex_t unDevice,
411  vr::TrackedDeviceProperty prop,
412  vr::TrackedPropertyError *peError = nullptr );
413 
414  // devices may have polygonal models
415  // load them
416  vtkOpenVRModel *FindOrLoadRenderModel(const char *modelName );
417  void RenderModels();
418  std::vector<vtkOpenVRModel * > VTKRenderModels;
419  vtkOpenVRModel *TrackedDeviceToRenderModel[ vr::k_unMaxTrackedDeviceCount ];
420  vr::TrackedDevicePose_t TrackedDevicePose[ vr::k_unMaxTrackedDeviceCount ];
421 
422  // used in computing the pose
425  double PhysicalViewDirection[3];
427  double PhysicalViewUp[3];
429  double PhysicalTranslation[3];
432 
433  // for the overlay
435 
436  bool TrackHMD;
437 
439 
440 
441 private:
443  void operator=(const vtkOpenVRRenderWindow&) = delete;
444 };
445 
446 
447 #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:351
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:347
vtkOpenVRRenderWindow::GetRenderBufferSize
void GetRenderBufferSize(int &width, int &height)
Definition: vtkOpenVRRenderWindow.h:122
vtkOpenVRRenderWindow::StereoRenderComplete
virtual void StereoRenderComplete()
Handles work required once both views have been rendered when using stereo rendering.
vtkOpenGLRenderWindow::SetSize
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
vtkCommand::UserEvent
@ UserEvent
Definition: vtkCommand.h:448
vtkOpenVRRenderWindow::DestroyWindow
virtual void DestroyWindow()
Destroy a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:387
vtkOpenVRRenderWindow::StereoUpdate
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
vtkOpenVRRenderWindow::GetLeftResolveBufferId
GLuint GetLeftResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:116
vtkOpenVRRenderWindow::HelperWindow
vtkOpenGLRenderWindow * HelperWindow
Definition: vtkOpenVRRenderWindow.h:438
vtkOpenVRRenderWindow::SetParentInfo
void SetParentInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:340
vtkOpenVRRenderWindow::GetOpenVRRenderModels
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
Definition: vtkOpenVRRenderWindow.h:139
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:339
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.
vtkOpenVRRenderWindow::GetGenericParentId
virtual void * GetGenericParentId()
Definition: vtkOpenVRRenderWindow.h:343
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderFramebufferId
GLuint m_nRenderFramebufferId
Definition: vtkOpenVRRenderWindow.h:398
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:302
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:423
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.
vtkOpenVRRenderWindow::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources(vtkRenderWindow *)
Free up any graphics resources associated with this window a value of nullptr means the context may a...
vtkOpenVRRenderWindow::vtkOpenVRRenderWindow
vtkOpenVRRenderWindow()
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:61
vtkOpenVRRenderWindow::SetPhysicalToWorldMatrix
void SetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Set physical to world transform matrix.
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderTextureId
GLuint m_nRenderTextureId
Definition: vtkOpenVRRenderWindow.h:397
vtkOpenVRRenderWindow::Frame
void Frame(void)
End the rendering process and display the image.
vtkOpenVRRenderWindow::VTKRenderModels
std::vector< vtkOpenVRModel * > VTKRenderModels
Definition: vtkOpenVRRenderWindow.h:418
vtkOpenVRRenderWindow::SetPosition
virtual void SetPosition(int, int)
Set the position of the window.
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:338
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:151
vtkOpenVRRenderWindow::SetSize
virtual void SetSize(int a[2])
Set the size of the window in screen coordinates in pixels.
Definition: vtkOpenVRRenderWindow.h:326
vtkOpenVRRenderWindow::LeftEyeDesc
FramebufferDesc LeftEyeDesc
Definition: vtkOpenVRRenderWindow.h:402
vtkX3D::height
@ height
Definition: vtkX3D.h:254
vtkOpenVRRenderWindow::GetGenericDrawable
virtual void * GetGenericDrawable()
Definition: vtkOpenVRRenderWindow.h:345
vtkOpenVRRenderWindow::GetRightRenderBufferId
GLuint GetRightRenderBufferId()
Definition: vtkOpenVRRenderWindow.h:118
vtkOpenVRRenderWindow::GetLeftRenderBufferId
GLuint GetLeftRenderBufferId()
Get the frame buffers used for rendering.
Definition: vtkOpenVRRenderWindow.h:114
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:346
vtkOpenVRRenderWindow::GetGenericContext
virtual void * GetGenericContext()
Definition: vtkOpenVRRenderWindow.h:344
vtkOpenVRRenderWindow::SetPhysicalTranslation
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow::IsDirect
int IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:307
vtkOpenVRRenderWindow::GetRightResolveBufferId
GLuint GetRightResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:120
vtkOpenVROverlay
OpenVR overlay.
Definition: vtkOpenVROverlay.h:40
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:74
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:42
vtkOpenVRRenderWindow::FramebufferDesc::m_nDepthBufferId
GLuint m_nDepthBufferId
Definition: vtkOpenVRRenderWindow.h:396
vtkOpenVRRenderWindow::GetGenericDisplayId
virtual void * GetGenericDisplayId()
Definition: vtkOpenVRRenderWindow.h:341
vtkCamera
a virtual camera for 3D rendering
Definition: vtkCamera.h:51
vtkOpenVRRenderWindow::SetPosition
virtual void SetPosition(int a[2])
Definition: vtkOpenVRRenderWindow.h:334
vtkOpenVRRenderWindow::SetHelperWindow
void SetHelperWindow(vtkOpenGLRenderWindow *val)
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:40
vtkEventData.h
vtkOpenVRRenderWindow::HMD
vr::IVRSystem * HMD
Definition: vtkOpenVRRenderWindow.h:391
vtkOpenVRRenderWindow::GetGenericWindowId
virtual void * GetGenericWindowId()
Definition: vtkOpenVRRenderWindow.h:342
vtkOpenVRRenderWindow::PhysicalScale
double PhysicalScale
Scale of the Physical to World matrix.
Definition: vtkOpenVRRenderWindow.h:431
vtkOpenVRRenderWindow::ShowCursor
void ShowCursor()
Definition: vtkOpenVRRenderWindow.h:350
vtkOpenVRRenderWindow::GetHMD
vr::IVRSystem * GetHMD()
Get the system pointer.
Definition: vtkOpenVRRenderWindow.h:88
vtkOpenVRRenderWindow::TrackHMD
bool TrackHMD
Definition: vtkOpenVRRenderWindow.h:436
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkOpenVRRenderWindow::m_strDriver
std::string m_strDriver
Definition: vtkOpenVRRenderWindow.h:387
vtkOpenVRRenderWindow::FindOrLoadRenderModel
vtkOpenVRModel * FindOrLoadRenderModel(const char *modelName)
vtkOpenVRRenderWindow::SetNextWindowId
virtual void SetNextWindowId(void *)
Definition: vtkOpenVRRenderWindow.h:353
vtkOpenVRRenderWindow::OpenVRRenderModels
vr::IVRRenderModels * OpenVRRenderModels
Definition: vtkOpenVRRenderWindow.h:392
vtkEventDataDevice
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:25
vtkOpenVRRenderWindow::DashboardOverlay
vtkOpenVROverlay * DashboardOverlay
Definition: vtkOpenVRRenderWindow.h:434
vtkOpenVRRenderWindow::~vtkOpenVRRenderWindow
~vtkOpenVRRenderWindow()
vtkOpenVRRenderWindow::CreateAWindow
virtual void CreateAWindow()
Create a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:386
vtkOpenVRRenderWindow::StereoMidpoint
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye.
vtkOpenVRRenderWindow::GetEventPending
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
Definition: vtkOpenVRRenderWindow.h:314
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:395
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkOpenVRRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:358
vtkOpenVRRenderWindow::WindowRemap
virtual void WindowRemap(void)
Remap the rendering window.
Definition: vtkOpenVRRenderWindow.h:352
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::m_strDisplay
std::string m_strDisplay
Definition: vtkOpenVRRenderWindow.h:390
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:54
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:88
vtkOpenVRRenderWindow::GetScreenSize
virtual int * GetScreenSize()
Get the current size of the screen in pixels.
vtkOpenVRRenderWindow::GetState
vtkOpenGLState * GetState() override
vtkWindow::SetPosition
virtual void SetPosition(int, int)
vtkOpenVRRenderWindow::SetSize
virtual void SetSize(int, int)
Set the size of the window in pixels.
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:349
vtkOpenVRRenderWindow::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx)
Get the VRModel corresponding to the tracked device.
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:68
vtkOpenVRRenderWindow::SetParentId
void SetParentId(void *)
Definition: vtkOpenVRRenderWindow.h:348
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveTextureId
GLuint m_nResolveTextureId
Definition: vtkOpenVRRenderWindow.h:399
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkOpenVRRenderWindow::RightEyeDesc
FramebufferDesc RightEyeDesc
Definition: vtkOpenVRRenderWindow.h:403
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:400