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 #define SDL_MAIN_HANDLED
46 #include <SDL.h> // for ivars
47 #include <openvr.h> // for ivars
48 #include <vector> // ivars
49 #include "vtkOpenGLHelper.h" // used for ivars
50 #include "vtk_glew.h" // used for methods
51 
52 class vtkCamera;
53 class vtkOpenVRModel;
54 class vtkOpenVROverlay;
56 class vtkTransform;
57 
58 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkOpenGLRenderWindow
59 {
60 public:
61  static vtkOpenVRRenderWindow *New();
63  void PrintSelf(ostream& os, vtkIndent indent);
64 
68  virtual void Start(void);
69 
74  virtual void StereoUpdate();
75 
80  virtual void StereoMidpoint();
81 
86  virtual void StereoRenderComplete();
87 
91  void Frame(void);
92 
99  virtual void Initialize(void);
100 
106  virtual void Finalize(void);
107 
111  void MakeCurrent();
112 
116  virtual bool IsCurrent();
117 
121  const char *ReportCapabilities() { return "OpenVR System";};
122 
126  int IsDirect() { return 1; };
127 
133  virtual int GetEventPending() { return 0;};
134 
138  void Clean();
139 
143  virtual int *GetScreenSize();
144 
146 
149  virtual void SetSize(int,int);
150  virtual void SetSize(int a[2]) {vtkOpenGLRenderWindow::SetSize(a);};
152 
154 
157  virtual void SetPosition(int,int);
158  virtual void SetPosition(int a[2]) {vtkOpenGLRenderWindow::SetPosition(a);};
160 
161  // implement required virtual functions
162  void SetWindowInfo(char *) {};
163  void SetNextWindowInfo(char *) {};
164  void SetParentInfo(char *) {};
165  virtual void *GetGenericDisplayId() {return (void *)this->ContextId;};
166  virtual void *GetGenericWindowId() {return (void *)this->WindowId;};
167  virtual void *GetGenericParentId() {return (void *)NULL;};
168  virtual void *GetGenericContext() {return (void *)this->ContextId;};
169  virtual void *GetGenericDrawable() {return (void *)this->WindowId;};
170  virtual void SetDisplayId(void *) {};
171  void SetWindowId(void *) {};
172  void SetParentId(void *) {};
173  void HideCursor() {};
174  void ShowCursor() {};
175  virtual void SetFullScreen(int) {};
176  virtual void WindowRemap(void) {};
177  virtual void SetNextWindowId(void *) {};
178 
182  vr::IVRSystem *GetHMD() { return this->HMD; };
183 
187  void RenderOverlay();
188 
190 
193  vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
194  void SetDashboardOverlay(vtkOpenVROverlay *);
196 
200  void UpdateHMDMatrixPose();
201 
205  virtual int SupportsOpenGL() { return 1; };
206 
208 
212  { return this->LeftEyeDesc.m_nRenderFramebufferId; };
214  { return this->LeftEyeDesc.m_nResolveFramebufferId; };
216  { return this->RightEyeDesc.m_nRenderFramebufferId; };
218  { return this->RightEyeDesc.m_nResolveFramebufferId; };
219  void GetRenderBufferSize(int &width, int &height)
220  {
221  width = this->Size[0];
222  height = this->Size[1];
223  };
225 
230  void Render();
231 
235  vr::TrackedDevicePose_t &GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx) {
236  return this->TrackedDevicePose[idx]; };
237 
241  vtkOpenVRModel *GetTrackedDeviceModel(vr::TrackedDeviceIndex_t idx) {
242  return this->TrackedDeviceToRenderModel[idx]; };
243 
252  void InitializeViewFromCamera(vtkCamera *cam);
253 
255 
260  vtkSetVector3Macro(InitialViewDirection, double);
261  vtkSetVector3Macro(InitialViewUp, double);
262  vtkGetVector3Macro(InitialViewDirection, double);
263  vtkGetVector3Macro(InitialViewUp, double);
265 
266 protected:
269 
275 
276  virtual void CreateAWindow() {};
277  virtual void DestroyWindow() {};
278 
279  SDL_Window *WindowId;
280  SDL_GLContext ContextId;
283  vr::IVRSystem *HMD;
284  vr::IVRRenderModels *OpenVRRenderModels;
285 
287  {
293  };
296  bool CreateFrameBuffer( int nWidth, int nHeight,
297  FramebufferDesc &framebufferDesc );
298 
299  // convert a device index to a human string
300  std::string GetTrackedDeviceString(
301  vr::IVRSystem *pHmd,
302  vr::TrackedDeviceIndex_t unDevice,
303  vr::TrackedDeviceProperty prop,
304  vr::TrackedPropertyError *peError = NULL );
305 
306  // devices may have polygonal models
307  // load them
308  vtkOpenVRModel *FindOrLoadRenderModel(const char *modelName );
309  void RenderModels();
310  std::vector<vtkOpenVRModel * > VTKRenderModels;
311  vtkOpenVRModel *TrackedDeviceToRenderModel[ vr::k_unMaxTrackedDeviceCount ];
312  vr::TrackedDevicePose_t TrackedDevicePose[ vr::k_unMaxTrackedDeviceCount ];
313 
314  // used in computing the pose
316  double InitialViewDirection[3];
317  double InitialViewUp[3];
318 
319  // for the overlay
321 
322 private:
323  vtkOpenVRRenderWindow(const vtkOpenVRRenderWindow&) VTK_DELETE_FUNCTION;
324  void operator=(const vtkOpenVRRenderWindow&) VTK_DELETE_FUNCTION;
325 };
326 
327 
328 #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)
Get the most recent pose of any tracked devices.
virtual void * GetGenericParentId()
Dummy stubs for vtkWindow API.
void StereoUpdate() override
Update 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)
Get the VRModel corresponding to the tracked device index.
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:54
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.
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:33
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
a virtual camera for 3D rendering
Definition: vtkCamera.h:44
OpenVR overlay.
const char * ReportCapabilities()
Get report of capabilities for the render window.
void SetNextWindowInfo(char *)
Dummy stubs for vtkWindow API.
virtual void Frame()=0
A termination method performed at the end of the rendering process to do things like swapping buffers...
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...