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 =========================================================================*/
39 #ifndef vtkOpenVRRenderWindow_h
40 #define vtkOpenVRRenderWindow_h
41 
42 #include "vtkRenderingOpenVRModule.h" // For export macro
43 #include "vtkOpenGLRenderWindow.h"
44 
45 #include <openvr.h> // for ivars
46 #include <vector> // ivars
47 #include "vtkOpenGLHelper.h" // used for ivars
48 #include "vtk_glew.h" // used for methods
49 #include "vtkEventData.h" // for enums
50 
51 class vtkCamera;
52 class vtkOpenVRModel;
53 class vtkOpenVROverlay;
55 class vtkTransform;
56 
57 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWindow
58 {
59 public:
60  static vtkOpenVRRenderWindow *New();
62  void PrintSelf(ostream& os, vtkIndent indent);
63 
67  vr::IVRSystem *GetHMD() { return this->HMD; };
68 
72  void RenderOverlay();
73 
75 
78  vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
79  void SetDashboardOverlay(vtkOpenVROverlay *);
81 
85  void UpdateHMDMatrixPose();
86 
88 
92  { return this->LeftEyeDesc.m_nRenderFramebufferId; };
94  { return this->LeftEyeDesc.m_nResolveFramebufferId; };
96  { return this->RightEyeDesc.m_nRenderFramebufferId; };
98  { return this->RightEyeDesc.m_nResolveFramebufferId; };
99  void GetRenderBufferSize(int &width, int &height)
100  {
101  width = this->Size[0];
102  height = this->Size[1];
103  };
105 
109  vtkOpenVRModel *GetTrackedDeviceModel(vtkEventDataDevice idx);
110  vtkOpenVRModel *GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx) {
111  return this->TrackedDeviceToRenderModel[idx]; };
112 
116  vr::IVRRenderModels * GetOpenVRRenderModels() {
117  return this->OpenVRRenderModels; };
118 
122  vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev);
123 
127  void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose);
128  vr::TrackedDevicePose_t &GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx) {
129  return this->TrackedDevicePose[idx]; };
130 
139  void InitializeViewFromCamera(vtkCamera *cam);
140 
142 
147  vtkSetVector3Macro(PhysicalViewDirection, double);
148  vtkSetVector3Macro(PhysicalViewUp, double);
149  vtkGetVector3Macro(PhysicalViewDirection, double);
150  vtkGetVector3Macro(PhysicalViewUp, double);
151  vtkSetVector3Macro(PhysicalTranslation, double);
152  vtkGetVector3Macro(PhysicalTranslation, double);
153  vtkSetMacro(PhysicalScale, double);
154  vtkGetMacro(PhysicalScale, double);
156 
158 
162  vtkSetMacro(TrackHMD, bool);
163  vtkGetMacro(TrackHMD, bool);
165 
169  virtual void AddRenderer(vtkRenderer *) override;
170 
174  virtual void Start(void);
175 
180  virtual void StereoUpdate();
181 
186  virtual void StereoMidpoint();
187 
192  virtual void StereoRenderComplete();
193 
197  void Frame(void);
198 
205  virtual void Initialize(void);
206 
212  virtual void Finalize(void);
213 
217  void MakeCurrent();
218 
222  virtual bool IsCurrent();
223 
227  const char *ReportCapabilities() { return "OpenVR System";};
228 
232  int IsDirect() { return 1; };
233 
239  virtual int GetEventPending() { return 0;};
240 
244  virtual int *GetScreenSize();
245 
247 
250  virtual void SetSize(int,int);
251  virtual void SetSize(int a[2]) {vtkOpenGLRenderWindow::SetSize(a);};
253 
255 
258  virtual void SetPosition(int,int);
259  virtual void SetPosition(int a[2]) {vtkOpenGLRenderWindow::SetPosition(a);};
261 
262  // implement required virtual functions
263  void SetWindowInfo(const char *) {};
264  void SetNextWindowInfo(const char *) {};
265  void SetParentInfo(const char *) {};
266  virtual void *GetGenericDisplayId() {return (void *)this->HelperWindow->GetGenericDisplayId();};
267  virtual void *GetGenericWindowId() {return (void *)this->HelperWindow->GetGenericWindowId();};
268  virtual void *GetGenericParentId() {return (void *)nullptr;};
269  virtual void *GetGenericContext() { return (void *)this->HelperWindow->GetGenericContext(); };
270  virtual void *GetGenericDrawable() {return (void *)this->HelperWindow->GetGenericDrawable();};
271  virtual void SetDisplayId(void *) {};
272  void SetWindowId(void *) {};
273  void SetParentId(void *) {};
274  void HideCursor() {};
275  void ShowCursor() {};
276  virtual void SetFullScreen(int) {};
277  virtual void WindowRemap(void) {};
278  virtual void SetNextWindowId(void *) {};
279 
283  virtual int SupportsOpenGL() { return 1; };
284 
289  void Render();
290 
294  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
295  void SetHelperWindow(vtkOpenGLRenderWindow *val);
296 
297  // Get the state object used to keep track of
298  // OpenGL state
299  vtkOpenGLState *GetState() override;
300 
301 protected:
304 
310 
311  virtual void CreateAWindow() {};
312  virtual void DestroyWindow() {};
313 
314  std::string m_strDriver;
316  vr::IVRSystem *HMD;
317  vr::IVRRenderModels *OpenVRRenderModels;
318 
320  {
326  };
329  bool CreateFrameBuffer( int nWidth, int nHeight,
330  FramebufferDesc &framebufferDesc );
331 
332  // convert a device index to a human string
333  std::string GetTrackedDeviceString(
334  vr::IVRSystem *pHmd,
335  vr::TrackedDeviceIndex_t unDevice,
336  vr::TrackedDeviceProperty prop,
337  vr::TrackedPropertyError *peError = nullptr );
338 
339  // devices may have polygonal models
340  // load them
341  vtkOpenVRModel *FindOrLoadRenderModel(const char *modelName );
342  void RenderModels();
343  std::vector<vtkOpenVRModel * > VTKRenderModels;
344  vtkOpenVRModel *TrackedDeviceToRenderModel[ vr::k_unMaxTrackedDeviceCount ];
345  vr::TrackedDevicePose_t TrackedDevicePose[ vr::k_unMaxTrackedDeviceCount ];
346 
347  // used in computing the pose
349  double PhysicalViewDirection[3];
350  double PhysicalViewUp[3];
351  double PhysicalTranslation[3];
353 
354  // for the overlay
356 
357  bool TrackHMD;
358 
360 
361 
362 private:
364  void operator=(const vtkOpenVRRenderWindow&) = delete;
365 };
366 
367 
368 #endif
vtkOpenGLRenderWindow::StereoMidpoint
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
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:272
vtkOpenVRRenderWindow::GetRenderBufferSize
void GetRenderBufferSize(int &width, int &height)
Definition: vtkOpenVRRenderWindow.h:99
vtkOpenGLRenderWindow::SetSize
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
vtkRenderWindow::Start
virtual void Start()=0
Initialize the rendering process.
vtkOpenVRRenderWindow::GetLeftResolveBufferId
GLuint GetLeftResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:93
vtkOpenVRRenderWindow::HelperWindow
vtkOpenGLRenderWindow * HelperWindow
Definition: vtkOpenVRRenderWindow.h:359
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:265
vtkOpenVRRenderWindow::GetOpenVRRenderModels
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
Definition: vtkOpenVRRenderWindow.h:116
vtkOpenVRRenderWindow::GetTrackedDeviceModel
vtkOpenVRModel * GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx)
Definition: vtkOpenVRRenderWindow.h:110
vtkOpenVRRenderWindow::SetNextWindowInfo
void SetNextWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:264
vtkOpenVRRenderWindow::GetGenericParentId
virtual void * GetGenericParentId()
Definition: vtkOpenVRRenderWindow.h:268
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderFramebufferId
GLuint m_nRenderFramebufferId
Definition: vtkOpenVRRenderWindow.h:323
vtkOpenGLHelper.h
vtkOpenVRRenderWindow::ReportCapabilities
const char * ReportCapabilities()
Get report of capabilities for the render window.
Definition: vtkOpenVRRenderWindow.h:227
vtkOpenVRRenderWindow::HMDTransform
vtkTransform * HMDTransform
Definition: vtkOpenVRRenderWindow.h:348
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:54
vtkOpenVRRenderWindow::FramebufferDesc::m_nRenderTextureId
GLuint m_nRenderTextureId
Definition: vtkOpenVRRenderWindow.h:322
vtkOpenVRRenderWindow::VTKRenderModels
std::vector< vtkOpenVRModel * > VTKRenderModels
Definition: vtkOpenVRRenderWindow.h:343
vtkOpenVRModel
OpenVR device model.
Definition: vtkOpenVRModel.h:39
vtkOpenVRRenderWindow::SetWindowInfo
void SetWindowInfo(const char *)
Definition: vtkOpenVRRenderWindow.h:263
vtkOpenVRRenderWindow::GetTrackedDevicePose
vr::TrackedDevicePose_t & GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
Definition: vtkOpenVRRenderWindow.h:128
vtkOpenVRRenderWindow::SetSize
virtual void SetSize(int a[2])
Set the size of the window in screen coordinates in pixels.
Definition: vtkOpenVRRenderWindow.h:251
vtkOpenVRRenderWindow::LeftEyeDesc
FramebufferDesc LeftEyeDesc
Definition: vtkOpenVRRenderWindow.h:327
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:270
vtkOpenVRRenderWindow::GetRightRenderBufferId
GLuint GetRightRenderBufferId()
Definition: vtkOpenVRRenderWindow.h:95
vtkOpenVRRenderWindow::GetLeftRenderBufferId
GLuint GetLeftRenderBufferId()
Get the frame buffers used for rendering.
Definition: vtkOpenVRRenderWindow.h:91
vtkOpenVRRenderWindow::SetDisplayId
virtual void SetDisplayId(void *)
Dummy stubs for vtkWindow API.
Definition: vtkOpenVRRenderWindow.h:271
vtkOpenVRRenderWindow::GetGenericContext
virtual void * GetGenericContext()
Definition: vtkOpenVRRenderWindow.h:269
vtkOpenVRRenderWindow::IsDirect
int IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:232
vtkOpenVRRenderWindow::GetRightResolveBufferId
GLuint GetRightResolveBufferId()
Definition: vtkOpenVRRenderWindow.h:97
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:33
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:57
vtkOpenVRRenderWindow::FramebufferDesc::m_nDepthBufferId
GLuint m_nDepthBufferId
Definition: vtkOpenVRRenderWindow.h:321
vtkOpenVRRenderWindow::GetGenericDisplayId
virtual void * GetGenericDisplayId()
Definition: vtkOpenVRRenderWindow.h:266
vtkCamera
a virtual camera for 3D rendering
Definition: vtkCamera.h:44
vtkOpenVRRenderWindow::SetPosition
virtual void SetPosition(int a[2])
Definition: vtkOpenVRRenderWindow.h:259
vtkOpenGLRenderWindow::GetState
virtual vtkOpenGLState * GetState()
Definition: vtkOpenGLRenderWindow.h:425
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:316
vtkOpenVRRenderWindow::SetFullScreen
virtual void SetFullScreen(int)
Turn on/off rendering full screen window size.
Definition: vtkOpenVRRenderWindow.h:276
vtkOpenVRRenderWindow::GetGenericWindowId
virtual void * GetGenericWindowId()
Definition: vtkOpenVRRenderWindow.h:267
vtkOpenVRRenderWindow::PhysicalScale
double PhysicalScale
Definition: vtkOpenVRRenderWindow.h:352
vtkOpenVRRenderWindow::ShowCursor
void ShowCursor()
Definition: vtkOpenVRRenderWindow.h:275
vtkOpenVRRenderWindow::GetHMD
vr::IVRSystem * GetHMD()
Get the system pointer.
Definition: vtkOpenVRRenderWindow.h:67
vtkOpenVRRenderWindow::TrackHMD
bool TrackHMD
Definition: vtkOpenVRRenderWindow.h:357
vtkX3D::string
Definition: vtkX3D.h:490
vtkOpenVRRenderWindow::SetNextWindowId
virtual void SetNextWindowId(void *)
Definition: vtkOpenVRRenderWindow.h:278
vtkOpenVRRenderWindow::OpenVRRenderModels
vr::IVRRenderModels * OpenVRRenderModels
Definition: vtkOpenVRRenderWindow.h:317
vtkEventDataDevice
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:25
vtkOpenVRRenderWindow::DashboardOverlay
vtkOpenVROverlay * DashboardOverlay
Definition: vtkOpenVRRenderWindow.h:355
vtkOpenVRRenderWindow::CreateAWindow
virtual void CreateAWindow()
Create a not-off-screen window.
Definition: vtkOpenVRRenderWindow.h:311
vtkOpenVRRenderWindow::GetEventPending
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
Definition: vtkOpenVRRenderWindow.h:239
vtkOpenVRRenderWindow::FramebufferDesc
Definition: vtkOpenVRRenderWindow.h:319
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:57
vtkOpenVRRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkOpenVRRenderWindow.h:283
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:277
vtkOpenVRRenderWindow::m_strDisplay
std::string m_strDisplay
Definition: vtkOpenVRRenderWindow.h:315
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:50
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:81
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:274
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:67
vtkOpenVRRenderWindow::SetParentId
void SetParentId(void *)
Definition: vtkOpenVRRenderWindow.h:273
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveTextureId
GLuint m_nResolveTextureId
Definition: vtkOpenVRRenderWindow.h:324
vtkOpenGLRenderWindow::Initialize
virtual void Initialize(void)
Initialize the rendering window.
Definition: vtkOpenGLRenderWindow.h:363
vtkOpenVRRenderWindow::RightEyeDesc
FramebufferDesc RightEyeDesc
Definition: vtkOpenVRRenderWindow.h:328
vtkOpenGLRenderWindow.h
vtkOpenVRRenderWindow::FramebufferDesc::m_nResolveFramebufferId
GLuint m_nResolveFramebufferId
Definition: vtkOpenVRRenderWindow.h:325