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 
81  static vtkOpenVRRenderWindow *New();
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);
100  void SetDashboardOverlay(vtkOpenVROverlay *);
102 
108  void UpdateHMDMatrixPose();
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 
132  vtkOpenVRModel *GetTrackedDeviceModel(vtkEventDataDevice idx);
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 
162  void InitializeViewFromCamera(vtkCamera *cam);
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 
225  void SetPhysicalToWorldMatrix(vtkMatrix4x4* matrix);
230  void GetPhysicalToWorldMatrix(vtkMatrix4x4* matrix);
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);
370  void SetHelperWindow(vtkOpenGLRenderWindow *val);
371 
372  // Get the state object used to keep track of
373  // OpenGL state
374  vtkOpenGLState *GetState() override;
375 
376 protected:
379 
385 
386  virtual void CreateAWindow() {};
387  virtual void DestroyWindow() {};
388 
389  std::string m_strDriver;
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
408  std::string GetTrackedDeviceString(
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
vtkOpenGLRenderWindow::StereoMidpoint
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkOpenVRRenderWindow::SetFullScreen
virtual void SetFullScreen(vtkTypeBool)
Turn on/off rendering full screen window size.
Definition: vtkOpenVRRenderWindow.h:351
vtkOpenGLRenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkOpenVRRenderWindow::SetWindowId
void SetWindowId(void *)
Definition: vtkOpenVRRenderWindow.h:347
vtkOpenVRRenderWindow::GetRenderBufferSize
void GetRenderBufferSize(int &width, int &height)
Definition: vtkOpenVRRenderWindow.h:122
vtkOpenGLRenderWindow::SetSize
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
vtkCommand::UserEvent
Definition: vtkCommand.h:448
vtkRenderWindow::Start
virtual void Start()=0
Initialize the rendering process.
vtkOpenVRRenderWindow::GetLeftResolveBufferId
GLuint GetLeftResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:116
vtkOpenVRRenderWindow::HelperWindow
vtkOpenGLRenderWindow * HelperWindow
Definition: vtkOpenVRRenderWindow.h:438
vtkRenderWindow::StereoRenderComplete
virtual void StereoRenderComplete()
Handles work required once both views have been rendered when using stereo rendering.
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::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx)
Definition: vtkOpenVRRenderWindow.h:133
vtkOpenVRRenderWindow::SetNextWindowInfo
void SetNextWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:339
vtkOpenVRRenderWindow::GetGenericParentId
virtual void * GetGenericParentId()
Definition: vtkOpenVRRenderWindow.h:343
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderFramebufferId
GLuint m_nRenderFramebufferId
Definition: vtkOpenVRRenderWindow.h:398
vtkOpenGLHelper.h
vtkOpenVRRenderWindow::ReportCapabilities
const char * ReportCapabilities()
Get report of capabilities for the render window.
Definition: vtkOpenVRRenderWindow.h:302
vtkOpenVRRenderWindow::HMDTransform
vtkTransform * HMDTransform
Definition: vtkOpenVRRenderWindow.h:423
vtkRenderWindow::Finalize
virtual void Finalize()=0
Finalize the rendering process.
vtkWindow::GetScreenSize
virtual int * GetScreenSize()=0
Get the current size of the screen in pixels.
vtkRenderWindow::IsCurrent
virtual bool IsCurrent()=0
Tells if this window is the current graphics context for the calling thread.
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderTextureId
GLuint m_nRenderTextureId
Definition: vtkOpenVRRenderWindow.h:397
vtkOpenVRRenderWindow::VTKRenderModels
std::vector< vtkOpenVRModel * > VTKRenderModels
Definition: vtkOpenVRRenderWindow.h:418
vtkOpenVRModel
OpenVR device model.
Definition: vtkOpenVRModel.h:39
vtkOpenVRRenderWindow::SetWindowInfo
void SetWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:338
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
vtkOpenGLRenderWindow::Render
void Render() override
Handle opengl specific code and calls superclass.
vtkX3D::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::SetDisplayId
virtual void SetDisplayId(void *)
Dummy stubs for vtkWindow API.
Definition: vtkOpenVRRenderWindow.h:346
vtkOpenVRRenderWindow::GetGenericContext
virtual void * GetGenericContext()
Definition: vtkOpenVRRenderWindow.h:344
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:39
vtkRenderWindow::AddRenderer
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:73
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
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:50
vtkOpenVRRenderWindow::SetPosition
virtual void SetPosition(int a[2])
Definition: vtkOpenVRRenderWindow.h:334
vtkOpenGLRenderWindow::GetState
virtual vtkOpenGLState * GetState()
Definition: vtkOpenGLRenderWindow.h:428
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:38
vtkEventData.h
vtkRenderWindow::MakeCurrent
void MakeCurrent() override=0
Attempt to make this window the current graphics context for the calling thread.
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
Definition: vtkX3D.h:490
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::CreateAWindow
virtual void CreateAWindow()
Create a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:386
vtkOpenVRRenderWindow::GetEventPending
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
Definition: vtkOpenVRRenderWindow.h:314
vtkOpenVRRenderWindow::FramebufferDesc
Definition: vtkOpenVRRenderWindow.h:394
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:63
vtkOpenVRRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:358
vtkOpenGLRenderWindow::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources(vtkRenderWindow *)
Free up any graphics resources associated with this window a value of NULL means the context may alre...
vtkOpenGLRenderWindow::DestroyWindow
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
vtkOpenVRRenderWindow::WindowRemap
virtual void WindowRemap(void)
Remap the rendering window.
Definition: vtkOpenVRRenderWindow.h:352
vtkOpenVRRenderWindow::m_strDisplay
std::string m_strDisplay
Definition: vtkOpenVRRenderWindow.h:390
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:53
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:87
vtkWindow::SetPosition
virtual void SetPosition(int, int)
vtkOpenGLRenderWindow::StereoUpdate
void StereoUpdate() override
Update the system, if needed, due to stereo rendering.
vtkRenderWindow::Frame
virtual void Frame()=0
A termination method performed at the end of the rendering process to do things like swapping buffers...
vtkRenderWindow::New
static vtkRenderWindow * New()
Construct an instance of vtkRenderWindow with its screen size set to 300x300, borders turned on,...
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
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:67
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
vtkOpenGLRenderWindow::Initialize
virtual void Initialize(void)
Initialize the rendering window.
Definition: vtkOpenGLRenderWindow.h:366
vtkOpenVRRenderWindow::RightEyeDesc
FramebufferDesc RightEyeDesc
Definition: vtkOpenVRRenderWindow.h:403
vtkOpenGLRenderWindow.h
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveFramebufferId
GLuint m_nResolveFramebufferId
Definition: vtkOpenVRRenderWindow.h:400