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 =========================================================================*/
42 #ifndef vtkOpenVRRenderWindow_h
43 #define vtkOpenVRRenderWindow_h
44 
45 #include "vtkRenderingOpenVRModule.h" // For export macro
46 #include "vtkOpenGLRenderWindow.h"
47 
48 #include <openvr.h> // for ivars
49 #include <vector> // ivars
50 #include "vtkOpenGLHelper.h" // used for ivars
51 #include "vtk_glew.h" // used for methods
52 #include "vtkEventData.h" // for enums
53 
54 class vtkCamera;
55 class vtkOpenVRModel;
56 class vtkOpenVROverlay;
58 class vtkTransform;
59 
60 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWindow
61 {
62 public:
63  static vtkOpenVRRenderWindow *New();
65  void PrintSelf(ostream& os, vtkIndent indent);
66 
70  vr::IVRSystem *GetHMD() { return this->HMD; };
71 
75  void RenderOverlay();
76 
78 
81  vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
82  void SetDashboardOverlay(vtkOpenVROverlay *);
84 
88  void UpdateHMDMatrixPose();
89 
91 
95  { return this->LeftEyeDesc.m_nRenderFramebufferId; };
97  { return this->LeftEyeDesc.m_nResolveFramebufferId; };
99  { return this->RightEyeDesc.m_nRenderFramebufferId; };
101  { return this->RightEyeDesc.m_nResolveFramebufferId; };
102  void GetRenderBufferSize(int &width, int &height)
103  {
104  width = this->Size[0];
105  height = this->Size[1];
106  };
108 
112  vtkOpenVRModel *GetTrackedDeviceModel(vtkEventDataDevice idx);
113  vtkOpenVRModel *GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx) {
114  return this->TrackedDeviceToRenderModel[idx]; };
115 
119  vr::IVRRenderModels * GetOpenVRRenderModels() {
120  return this->OpenVRRenderModels; };
121 
125  vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev);
126 
130  void GetTrackedDevicePose(vtkEventDataDevice idx, vr::TrackedDevicePose_t **pose);
131  vr::TrackedDevicePose_t &GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx) {
132  return this->TrackedDevicePose[idx]; };
133 
142  void InitializeViewFromCamera(vtkCamera *cam);
143 
145 
150  vtkSetVector3Macro(PhysicalViewDirection, double);
151  vtkSetVector3Macro(PhysicalViewUp, double);
152  vtkGetVector3Macro(PhysicalViewDirection, double);
153  vtkGetVector3Macro(PhysicalViewUp, double);
154  vtkSetVector3Macro(PhysicalTranslation, double);
155  vtkGetVector3Macro(PhysicalTranslation, double);
156  vtkSetMacro(PhysicalScale, double);
157  vtkGetMacro(PhysicalScale, double);
159 
161 
165  vtkSetMacro(TrackHMD, bool);
166  vtkGetMacro(TrackHMD, bool);
168 
172  virtual void Start(void);
173 
178  virtual void StereoUpdate();
179 
184  virtual void StereoMidpoint();
185 
190  virtual void StereoRenderComplete();
191 
195  void Frame(void);
196 
203  virtual void Initialize(void);
204 
210  virtual void Finalize(void);
211 
215  void MakeCurrent();
216 
220  virtual bool IsCurrent();
221 
225  const char *ReportCapabilities() { return "OpenVR System";};
226 
230  int IsDirect() { return 1; };
231 
237  virtual int GetEventPending() { return 0;};
238 
242  virtual int *GetScreenSize();
243 
245 
248  virtual void SetSize(int,int);
249  virtual void SetSize(int a[2]) {vtkOpenGLRenderWindow::SetSize(a);};
251 
253 
256  virtual void SetPosition(int,int);
257  virtual void SetPosition(int a[2]) {vtkOpenGLRenderWindow::SetPosition(a);};
259 
260  // implement required virtual functions
261  void SetWindowInfo(char *) {};
262  void SetNextWindowInfo(char *) {};
263  void SetParentInfo(char *) {};
264  virtual void *GetGenericDisplayId() {return (void *)this->HelperWindow->GetGenericDisplayId();};
265  virtual void *GetGenericWindowId() {return (void *)this->HelperWindow->GetGenericWindowId();};
266  virtual void *GetGenericParentId() {return (void *)nullptr;};
267  virtual void *GetGenericContext() { return (void *)this->HelperWindow->GetGenericContext(); };
268  virtual void *GetGenericDrawable() {return (void *)this->HelperWindow->GetGenericDrawable();};
269  virtual void SetDisplayId(void *) {};
270  void SetWindowId(void *) {};
271  void SetParentId(void *) {};
272  void HideCursor() {};
273  void ShowCursor() {};
274  virtual void SetFullScreen(int) {};
275  virtual void WindowRemap(void) {};
276  virtual void SetNextWindowId(void *) {};
277 
281  virtual int SupportsOpenGL() { return 1; };
282 
287  void Render();
288 
292  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
293  void SetHelperWindow(vtkOpenGLRenderWindow *val);
294 
295 protected:
298 
304 
305  virtual void CreateAWindow() {};
306  virtual void DestroyWindow() {};
307 
308  std::string m_strDriver;
310  vr::IVRSystem *HMD;
311  vr::IVRRenderModels *OpenVRRenderModels;
312 
314  {
320  };
323  bool CreateFrameBuffer( int nWidth, int nHeight,
324  FramebufferDesc &framebufferDesc );
325 
326  // convert a device index to a human string
327  std::string GetTrackedDeviceString(
328  vr::IVRSystem *pHmd,
329  vr::TrackedDeviceIndex_t unDevice,
330  vr::TrackedDeviceProperty prop,
331  vr::TrackedPropertyError *peError = nullptr );
332 
333  // devices may have polygonal models
334  // load them
335  vtkOpenVRModel *FindOrLoadRenderModel(const char *modelName );
336  void RenderModels();
337  std::vector<vtkOpenVRModel * > VTKRenderModels;
338  vtkOpenVRModel *TrackedDeviceToRenderModel[ vr::k_unMaxTrackedDeviceCount ];
339  vr::TrackedDevicePose_t TrackedDevicePose[ vr::k_unMaxTrackedDeviceCount ];
340 
341  // used in computing the pose
343  double PhysicalViewDirection[3];
344  double PhysicalViewUp[3];
345  double PhysicalTranslation[3];
347 
348  // for the overlay
350 
351  bool TrackHMD;
352 
354 
355 
356 private:
358  void operator=(const vtkOpenVRRenderWindow&) = delete;
359 };
360 
361 
362 #endif
OpenGL rendering window.
virtual void Finalize()=0
Finalize the rendering process.
int IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.
virtual void SetPosition(int a[2])
Set the position of the window.
vr::TrackedDevicePose_t & GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
virtual void * GetGenericParentId()
Dummy stubs for vtkWindow API.
static vtkRenderWindow * New()
Construct an instance of vtkRenderWindow with its screen size set to 300x300, borders turned on...
virtual int * GetScreenSize()=0
Get the current size of the screen in pixels.
virtual void SetNextWindowId(void *)
Dummy stubs for vtkWindow API.
vr::IVRRenderModels * OpenVRRenderModels
virtual void SetDisplayId(void *)
Dummy stubs for vtkWindow API.
vtkOpenVROverlay * DashboardOverlay
vtkOpenVRModel * GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx)
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process...
void GetRenderBufferSize(int &width, int &height)
Get the frame buffers used for rendering.
virtual void WindowRemap(void)
Remap the rendering window.
void SetWindowId(void *)
Dummy stubs for vtkWindow API.
void SetParentInfo(char *)
Dummy stubs for vtkWindow API.
void ShowCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
void SetParentId(void *)
Dummy stubs for vtkWindow API.
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models
virtual bool IsCurrent()=0
Tells if this window is the current graphics context for the calling thread.
virtual void CreateAWindow()
Create a not-off-screen window.
GLuint GetRightResolveBufferId()
Get the frame buffers used for rendering.
void SetWindowInfo(char *)
Dummy stubs for vtkWindow API.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
a virtual camera for 3D rendering
Definition: vtkCamera.h:50
OpenVR overlay.
const char * ReportCapabilities()
Get report of capabilities for the render window.
void SetNextWindowInfo(char *)
Dummy stubs for vtkWindow API.
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:25
vtkOpenGLRenderWindow * HelperWindow
virtual void Frame()=0
A termination method performed at the end of the rendering process to do things like swapping buffers...
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
OpenVR rendering window.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void StereoRenderComplete()
Handles work required once both views have been rendered when using stereo rendering.
create a window for renderers to draw into
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
GLuint GetLeftRenderBufferId()
Get the frame buffers used for rendering.
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye...
virtual void Start()=0
Initialize the rendering process.
virtual void * GetGenericContext()
Dummy stubs for vtkWindow API.
virtual void * GetGenericDrawable()
Dummy stubs for vtkWindow API.
GLuint GetRightRenderBufferId()
Get the frame buffers used for rendering.
virtual void SetPosition(int, int)
Set/Get the position in screen coordinates of the rendering window.
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
std::vector< vtkOpenVRModel *> VTKRenderModels
virtual void * GetGenericDisplayId()
Dummy stubs for vtkWindow API.
virtual void ReleaseGraphicsResources(vtkRenderWindow *)
Free up any graphics resources associated with this window a value of NULL means the context may alre...
virtual void Initialize(void)
Initialize the rendering window.
virtual void * GetGenericWindowId()
Dummy stubs for vtkWindow API.
virtual void SetSize(int a[2])
Set the size of the window in pixels.
void MakeCurrent() override=0
Attempt to make this window the current graphics context for the calling thread.
OpenVR device model.
virtual void SetFullScreen(int)
Turn on/off rendering full screen window size.
vr::IVRSystem * GetHMD()
Get the system pointer.
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...