VTK  9.2.6
vtkVRRenderWindow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkVRRenderWindow.h
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
51 #ifndef vtkVRRenderWindow_h
52 #define vtkVRRenderWindow_h
53 
54 #include "vtkEventData.h" // for enums
55 #include "vtkNew.h" // for vtkNew
56 #include "vtkOpenGLRenderWindow.h"
57 #include "vtkRenderingVRModule.h" // For export macro
58 #include "vtkSmartPointer.h" // for vtkSmartPointer
59 #include "vtk_glew.h" // used for methods
60 
61 #include <vector> // ivars
62 
63 class vtkCamera;
64 class vtkMatrix4x4;
65 class vtkVRModel;
66 
67 class VTKRENDERINGVR_EXPORT vtkVRRenderWindow : public vtkOpenGLRenderWindow
68 {
69 public:
70  enum
71  {
72  PhysicalToWorldMatrixModified = vtkCommand::UserEvent + 200
73  };
74 
75  enum
76  {
77  LeftEye = 0,
78  RightEye
79  };
80 
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
89 
91 
94  GLuint GetLeftResolveBufferId() { return this->FramebufferDescs[LeftEye].ResolveFramebufferId; }
95  GLuint GetRightResolveBufferId() { return this->FramebufferDescs[RightEye].ResolveFramebufferId; }
96  void GetRenderBufferSize(int& width, int& height)
97  {
98  width = this->Size[0];
99  height = this->Size[1];
100  }
102 
104 
110 
112 
115  void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
117 
119 
127 
129  /*
130  * This method gets a device handle for a given device. index is used to
131  * disambiguate when there are multiple device handles that map to a
132  * device.
133  */
134  uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index = 0);
136 
138  /*
139  * This method returns how many device handles map to a device.
140  */
143 
145  /*
146  * This method adds a device handle if not already present. The second
147  * signature also sets the device associated with the device handle.
148  */
149  void AddDeviceHandle(uint32_t handle);
150  void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device);
152 
154  /*
155  * This method gets a device for a given device handle.
156  */
159 
167  vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
169  uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
170 
179 
181 
189  virtual void SetPhysicalViewDirection(double, double, double);
190  virtual void SetPhysicalViewDirection(double[3]);
191  vtkGetVector3Macro(PhysicalViewDirection, double);
193 
195 
203  virtual void SetPhysicalViewUp(double, double, double);
204  virtual void SetPhysicalViewUp(double[3]);
205  vtkGetVector3Macro(PhysicalViewUp, double);
207 
209 
217  virtual void SetPhysicalTranslation(double, double, double);
218  virtual void SetPhysicalTranslation(double[3]);
219  vtkGetVector3Macro(PhysicalTranslation, double);
221 
223 
232  virtual void SetPhysicalScale(double);
233  vtkGetMacro(PhysicalScale, double);
235 
242 
247  void GetPhysicalToWorldMatrix(vtkMatrix4x4* matrix) override;
248 
252  void AddRenderer(vtkRenderer*) override;
253 
257  void Start() override;
258 
262  void Initialize() override;
263 
269  void Finalize() override;
270 
274  void MakeCurrent() override;
275 
279  void ReleaseCurrent() override;
280 
284  bool IsCurrent() override;
285 
289  const char* ReportCapabilities() override { return "VR System"; }
290 
294  vtkTypeBool IsDirect() override { return 1; }
295 
301  vtkTypeBool GetEventPending() override { return 0; }
302 
306  int* GetScreenSize() override;
307 
309 
316  void SetSize(int width, int height) override;
317  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
319 
321 
324  void* GetGenericDisplayId() override { return (void*)this->HelperWindow->GetGenericDisplayId(); }
325  void* GetGenericWindowId() override { return (void*)this->HelperWindow->GetGenericWindowId(); }
326  void* GetGenericParentId() override { return (void*)nullptr; }
327  void* GetGenericContext() override { return (void*)this->HelperWindow->GetGenericContext(); }
328  void* GetGenericDrawable() override { return (void*)this->HelperWindow->GetGenericDrawable(); }
330 
334  int SupportsOpenGL() override { return 1; }
335 
340  void Render() override;
341 
343 
346  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
349 
354 
360 
364  virtual void RenderModels() = 0;
365 
367 
371  vtkSetMacro(TrackHMD, bool);
372  vtkGetMacro(TrackHMD, bool);
374 
376 
379  vtkGetMacro(BaseStationVisibility, bool);
380  vtkSetMacro(BaseStationVisibility, bool);
381  vtkBooleanMacro(BaseStationVisibility, bool);
383 
387  virtual void UpdateHMDMatrixPose(){};
388 
392  vtkGetMacro(Initialized, bool);
393 
394 protected:
396  ~vtkVRRenderWindow() override;
397 
399  {
400  GLuint ResolveFramebufferId = 0;
401  GLuint ResolveColorTextureId = 0;
402  GLuint ResolveDepthTextureId = 0;
403  };
404 
405  void CreateAWindow() override {}
406  void DestroyWindow() override {}
407 
413  virtual bool GetSizeFromAPI() = 0;
414 
415  virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
416 
417  virtual bool CreateFramebuffers(uint32_t viewCount = 2) = 0;
418  void RenderFramebuffer(FramebufferDesc& framebufferDesc);
419 
420  bool TrackHMD = true;
421 
422  // One per view (typically one per eye)
423  std::vector<FramebufferDesc> FramebufferDescs;
424 
426  {
427  public:
431  uint32_t Index = 0;
432  };
433 
434  std::map<uint32_t, DeviceData> DeviceHandleToDeviceDataMap;
435  uint32_t InvalidDeviceIndex = UINT32_MAX;
436 
437  // -Z axis of the Physical to World matrix
438  double PhysicalViewDirection[3] = { 0.0, 0.0, -1.0 };
439  // Y axis of the Physical to World matrix
440  double PhysicalViewUp[3] = { 0.0, 1.0, 0.0 };
441  // Inverse of the translation component of the Physical to World matrix, in mm
442  double PhysicalTranslation[3] = { 0.0, 0.0, 0.0 };
443  // Scale of the Physical to World matrix
444  double PhysicalScale = 1.0;
445 
446  bool BaseStationVisibility = false;
447 
449 
450 private:
451  vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
452  void operator=(const vtkVRRenderWindow&) = delete;
453 };
454 
455 #endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:161
a simple class to control print indentation
Definition: vtkIndent.h:119
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
OpenGL rendering window.
OpenGL state storage.
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
Definition: vtkRenderer.h:182
VR device model.
Definition: vtkVRModel.h:40
vtkNew< vtkMatrix4x4 > DeviceToPhysicalMatrix
vtkSmartPointer< vtkVRModel > Model
VR rendering window.
void Finalize() override
Finalize the rendering window.
void Initialize() override
Initialize the rendering window.
void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
void AddDeviceHandle(uint32_t handle)
void CreateAWindow() override
Create a not-off-screen window.
void MakeCurrent() override
Make this windows OpenGL context the current context.
vtkMatrix4x4 * GetDeviceToPhysicalMatrixForDeviceHandle(uint32_t handle)
Get the DeviceToPhysical matrix corresponding to the device or device handle.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of nullptr means the context may a...
virtual void SetPhysicalViewUp(double[3])
Set/get physical coordinate system in world coordinate system.
std::map< uint32_t, DeviceData > DeviceHandleToDeviceDataMap
vtkVRModel * GetModelForDevice(vtkEventDataDevice idx)
Get the VRModel corresponding to the device or device handle.
virtual void RenderModels()=0
Render the controller and base station models.
void GetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix) override
Get physical to world transform matrix.
vtkOpenGLRenderWindow * HelperWindow
vtkMatrix4x4 * GetDeviceToPhysicalMatrixForDevice(vtkEventDataDevice idx)
Get the DeviceToPhysical matrix corresponding to the device or device handle.
void RenderFramebuffer(FramebufferDesc &framebufferDesc)
virtual bool GetDeviceToWorldMatrixForDeviceHandle(uint32_t handle, vtkMatrix4x4 *deviceToWorldMatrix)
virtual void SetPhysicalScale(double)
Set/get physical coordinate system in world coordinate system.
virtual void SetPhysicalViewDirection(double[3])
Set/get physical coordinate system in world coordinate system.
uint32_t GetNumberOfDeviceHandlesForDevice(vtkEventDataDevice dev)
~vtkVRRenderWindow() override
virtual void UpdateHMDMatrixPose()
Update the HMD pose.
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override=0
Create an interactor to control renderers in this window.
virtual bool GetSizeFromAPI()=0
Attempt to get the size of the display from the API and store it in this->Size.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
void AddRenderer(vtkRenderer *) override
Add a renderer to the list of renderers.
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index=0)
void * GetGenericParentId() override
Implement required virtual functions.
void SetSize(int width, int height) override
Set the size of the window in screen coordinates in pixels.
vtkVRModel * GetModelForDeviceHandle(uint32_t handle)
Get the VRModel corresponding to the device or device handle.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
vtkEventDataDevice GetDeviceForDeviceHandle(uint32_t handle)
virtual void SetPhysicalViewDirection(double, double, double)
Set/get physical coordinate system in world coordinate system.
virtual void SetPhysicalTranslation(double[3])
Set/get physical coordinate system in world coordinate system.
void DestroyWindow() override
Destroy a not-off-screen window.
void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device)
void * GetGenericContext() override
Implement required virtual functions.
void * GetGenericDrawable() override
Implement required virtual functions.
void GetRenderBufferSize(int &width, int &height)
Get the frame buffers used for rendering.
bool IsCurrent() override
Tells if this window is the current OpenGL context for the calling thread.
GLuint GetRightResolveBufferId()
Get the frame buffers used for rendering.
bool GetDeviceToWorldMatrixForDevice(vtkEventDataDevice device, vtkMatrix4x4 *deviceToWorldMatrix) override
Store in deviceToWorldMatrix the matrix that goes from device coordinates to world coordinates.
void * GetGenericWindowId() override
Implement required virtual functions.
vtkTypeBool GetEventPending() override
Check to see if a mouse button has been pressed or mouse wheel activated.
void SetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Set physical to world transform matrix.
vtkTypeBool IsDirect() override
Is this render window using hardware acceleration? 0-false, 1-true.
virtual void InitializeViewFromCamera(vtkCamera *cam)
Initialize the HMD to World setting and camera settings so that the VR world view most closely matche...
virtual bool CreateFramebuffers(uint32_t viewCount=2)=0
std::vector< FramebufferDesc > FramebufferDescs
void SetHelperWindow(vtkOpenGLRenderWindow *val)
Set/Get the window to use for the openGL context.
void SetModelForDeviceHandle(uint32_t handle, vtkVRModel *model)
Set the VRModel corresponding to the device handle.
vtkOpenGLState * GetState() override
Get the state object used to keep track of OpenGL state.
virtual std::string GetWindowTitleFromAPI()
void Start() override
Begin the rendering process.
int * GetScreenSize() override
Get the current size of the screen in pixels.
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
void ReleaseCurrent() override
Release the current context.
virtual void SetPhysicalViewUp(double, double, double)
Set/get physical coordinate system in world coordinate system.
void * GetGenericDisplayId() override
Implement required virtual functions.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ height
Definition: vtkX3D.h:260
@ index
Definition: vtkX3D.h:252
@ string
Definition: vtkX3D.h:496
int vtkTypeBool
Definition: vtkABI.h:69
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26