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 
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
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.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
vr::TrackedDevicePose_t & GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
virtual void * GetGenericParentId()
Dummy stubs for vtkWindow API.
void Render() override
Handle opengl specific code and calls superclass.
void StereoUpdate() override
Update the system, if needed, due to stereo rendering.
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)
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
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 ShowCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
double PhysicalScale
Scale of the Physical to World matrix.
int vtkTypeBool
Definition: vtkABI.h:69
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.
OpenGL state storage.
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.
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...
void SetParentInfo(const char *)
Dummy stubs for vtkWindow API.
void SetNextWindowInfo(const char *)
Dummy stubs for vtkWindow API.
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
OpenVR rendering window.
void SetWindowInfo(const char *)
Dummy stubs for vtkWindow API.
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 SetFullScreen(vtkTypeBool)
Turn on/off rendering full screen window size.
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.
virtual vtkOpenGLState * GetState()
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.
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye...
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...