VTK  9.3.0
vtkVRRenderWindow.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
39 #ifndef vtkVRRenderWindow_h
40 #define vtkVRRenderWindow_h
41 
42 #include "vtkEventData.h" // for enums
43 #include "vtkNew.h" // for vtkNew
44 #include "vtkOpenGLRenderWindow.h"
45 #include "vtkRenderingVRModule.h" // For export macro
46 #include "vtkSmartPointer.h" // for vtkSmartPointer
47 #include "vtk_glew.h" // used for methods
48 
49 #include <vector> // ivars
50 
51 VTK_ABI_NAMESPACE_BEGIN
52 class vtkCamera;
53 class vtkMatrix4x4;
54 class vtkVRModel;
55 
56 class VTKRENDERINGVR_EXPORT vtkVRRenderWindow : public vtkOpenGLRenderWindow
57 {
58 public:
59  enum
60  {
61  PhysicalToWorldMatrixModified = vtkCommand::UserEvent + 200
62  };
63 
64  enum
65  {
66  LeftEye = 0,
67  RightEye
68  };
69 
71  void PrintSelf(ostream& os, vtkIndent indent) override;
72 
78 
80 
83  GLuint GetLeftResolveBufferId() { return this->FramebufferDescs[LeftEye].ResolveFramebufferId; }
84  GLuint GetRightResolveBufferId() { return this->FramebufferDescs[RightEye].ResolveFramebufferId; }
85  void GetRenderBufferSize(int& width, int& height)
86  {
87  width = this->Size[0];
88  height = this->Size[1];
89  }
91 
93 
99 
101 
104  void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
106 
108 
116 
118  /*
119  * This method gets a device handle for a given device. index is used to
120  * disambiguate when there are multiple device handles that map to a
121  * device.
122  */
123  uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index = 0);
125 
127  /*
128  * This method returns how many device handles map to a device.
129  */
132 
134  /*
135  * This method adds a device handle if not already present. The second
136  * signature also sets the device associated with the device handle.
137  */
138  void AddDeviceHandle(uint32_t handle);
139  void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device);
141 
143  /*
144  * This method gets a device for a given device handle.
145  */
148 
156  vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
158  uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
159 
168 
170 
178  virtual void SetPhysicalViewDirection(double, double, double);
179  virtual void SetPhysicalViewDirection(double[3]);
180  vtkGetVector3Macro(PhysicalViewDirection, double);
182 
184 
192  virtual void SetPhysicalViewUp(double, double, double);
193  virtual void SetPhysicalViewUp(double[3]);
194  vtkGetVector3Macro(PhysicalViewUp, double);
196 
198 
206  virtual void SetPhysicalTranslation(double, double, double);
207  virtual void SetPhysicalTranslation(double[3]);
208  vtkGetVector3Macro(PhysicalTranslation, double);
210 
212 
221  virtual void SetPhysicalScale(double);
222  vtkGetMacro(PhysicalScale, double);
224 
231 
236  void GetPhysicalToWorldMatrix(vtkMatrix4x4* matrix) override;
237 
241  void AddRenderer(vtkRenderer*) override;
242 
246  void MakeCurrent() override;
247 
251  void ReleaseCurrent() override;
252 
256  bool IsCurrent() override;
257 
261  const char* ReportCapabilities() override { return "VR System"; }
262 
266  vtkTypeBool IsDirect() override { return 1; }
267 
273  vtkTypeBool GetEventPending() override { return 0; }
274 
278  int* GetScreenSize() override;
279 
281 
288  void SetSize(int width, int height) override;
289  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
291 
293 
296  void* GetGenericDisplayId() override { return this->HelperWindow->GetGenericDisplayId(); }
297  void* GetGenericWindowId() override { return this->HelperWindow->GetGenericWindowId(); }
298  void* GetGenericParentId() override { return nullptr; }
299  void* GetGenericContext() override { return this->HelperWindow->GetGenericContext(); }
300  void* GetGenericDrawable() override { return this->HelperWindow->GetGenericDrawable(); }
302 
306  int SupportsOpenGL() override { return 1; }
307 
312  void Render() override;
313 
315 
318  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
321 
326 
332 
336  virtual void RenderModels() = 0;
337 
339 
343  vtkSetMacro(TrackHMD, bool);
344  vtkGetMacro(TrackHMD, bool);
346 
348 
351  vtkGetMacro(BaseStationVisibility, bool);
352  vtkSetMacro(BaseStationVisibility, bool);
353  vtkBooleanMacro(BaseStationVisibility, bool);
355 
359  virtual void UpdateHMDMatrixPose(){};
360 
365  vtkGetMacro(VRInitialized, bool);
366 
367 protected:
369  ~vtkVRRenderWindow() override;
370 
372  {
373  GLuint ResolveFramebufferId = 0;
374  GLuint ResolveColorTextureId = 0;
375  GLuint ResolveDepthTextureId = 0;
376  };
377 
378  void CreateAWindow() override {}
379  void DestroyWindow() override {}
380 
386  virtual bool GetSizeFromAPI() = 0;
387 
388  virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
389 
390  virtual bool CreateFramebuffers(uint32_t viewCount = 2) = 0;
391  virtual void RenderFramebuffer(FramebufferDesc& framebufferDesc) = 0;
392 
393  bool VRInitialized = false;
394  bool TrackHMD = true;
395 
396  // One per view (typically one per eye)
397  std::vector<FramebufferDesc> FramebufferDescs;
398 
400  {
401  public:
405  uint32_t Index = 0;
406  };
407 
408  std::map<uint32_t, DeviceData> DeviceHandleToDeviceDataMap;
409  uint32_t InvalidDeviceIndex = UINT32_MAX;
410 
411  // -Z axis of the Physical to World matrix
412  double PhysicalViewDirection[3] = { 0.0, 0.0, -1.0 };
413  // Y axis of the Physical to World matrix
414  double PhysicalViewUp[3] = { 0.0, 1.0, 0.0 };
415  // Inverse of the translation component of the Physical to World matrix, in mm
416  double PhysicalTranslation[3] = { 0.0, 0.0, 0.0 };
417  // Scale of the Physical to World matrix
418  double PhysicalScale = 1.0;
419 
420  bool BaseStationVisibility = false;
421 
423 
424 private:
425  vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
426  void operator=(const vtkVRRenderWindow&) = delete;
427 };
428 
429 VTK_ABI_NAMESPACE_END
430 #endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:50
a simple class to control print indentation
Definition: vtkIndent.h:38
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
OpenGL rendering window.
OpenGL state storage.
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
Definition: vtkRenderer.h:71
VR device model.
Definition: vtkVRModel.h:29
vtkNew< vtkMatrix4x4 > DeviceToPhysicalMatrix
vtkSmartPointer< vtkVRModel > Model
VR 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.
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.
virtual void RenderFramebuffer(FramebufferDesc &framebufferDesc)=0
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()
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:37
@ height
Definition: vtkX3D.h:254
@ index
Definition: vtkX3D.h:246
@ string
Definition: vtkX3D.h:490
int vtkTypeBool
Definition: vtkABI.h:64
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:15