VTK  9.3.1
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 
96  vtkVRModel* GetModelForDevice(vtkEventDataDevice idx);
97  vtkVRModel* GetModelForDeviceHandle(uint32_t handle);
99 
101 
104  void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
106 
108 
113  vtkMatrix4x4* GetDeviceToPhysicalMatrixForDevice(vtkEventDataDevice idx);
114  vtkMatrix4x4* GetDeviceToPhysicalMatrixForDeviceHandle(uint32_t handle);
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  */
130  uint32_t GetNumberOfDeviceHandlesForDevice(vtkEventDataDevice dev);
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  */
146  vtkEventDataDevice GetDeviceForDeviceHandle(uint32_t handle);
148 
156  vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
157  virtual bool GetDeviceToWorldMatrixForDeviceHandle(
158  uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
159 
167  virtual void InitializeViewFromCamera(vtkCamera* cam);
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 
230  void SetPhysicalToWorldMatrix(vtkMatrix4x4* matrix);
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);
319  void SetHelperWindow(vtkOpenGLRenderWindow* val);
321 
325  vtkOpenGLState* GetState() override;
326 
331  void ReleaseGraphicsResources(vtkWindow*) override;
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
OpenGL rendering window.
void * GetGenericParentId() override
Implement required virtual functions.
void GetRenderBufferSize(int &width, int &height)
Get the frame buffers used for rendering.
virtual bool GetDeviceToWorldMatrixForDevice(vtkEventDataDevice device, vtkMatrix4x4 *deviceToWorldMatrix)
Store in deviceToWorldMatrix the matrix that goes from device coordinates to world coordinates...
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
void Render() override
Handle opengl specific code and calls superclass.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
VR rendering window.
void DestroyWindow() override
Destroy a not-off-screen window.
abstract specification for renderers
Definition: vtkRenderer.h:61
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
virtual vtkRenderWindowInteractor * MakeRenderWindowInteractor()
Create an interactor to control renderers in this window.
virtual bool IsCurrent()
Tells if this window is the current graphics context for the calling thread.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
GLuint GetRightResolveBufferId()
Get the frame buffers used for rendering.
void * GetGenericDisplayId() override
Implement required virtual functions.
int vtkTypeBool
Definition: vtkABI.h:64
VR device model.
Definition: vtkVRModel.h:28
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
void * GetGenericContext() override
Implement required virtual functions.
platform-independent render window interaction including picking and frame rate control.
vtkNew< vtkMatrix4x4 > DeviceToPhysicalMatrix
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
OpenGL state storage.
virtual std::string GetWindowTitleFromAPI()
void * GetGenericWindowId() override
Implement required virtual functions.
a simple class to control print indentation
Definition: vtkIndent.h:28
a virtual camera for 3D rendering
Definition: vtkCamera.h:40
virtual int * GetScreenSize()
Get the current size of the screen in pixels.
Definition: vtkWindow.h:94
void * GetGenericDrawable() override
Implement required virtual functions.
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:14
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:235
std::vector< FramebufferDesc > FramebufferDescs
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
virtual void ReleaseCurrent()
Release the current context.
Definition: vtkWindow.h:241
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeBool IsDirect() override
Is this render window using hardware acceleration? 0-false, 1-true.
void CreateAWindow() override
Create a not-off-screen window.
vtkOpenGLFramebufferObject * RenderFramebuffer
vtkSmartPointer< vtkVRModel > Model
std::map< uint32_t, DeviceData > DeviceHandleToDeviceDataMap
virtual vtkOpenGLState * GetState()
virtual void GetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Get physical to world transform matrix.
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
virtual void UpdateHMDMatrixPose()
Update the HMD pose.
int CreateFramebuffers(int width, int height)
Create the offScreen framebuffer Return if the creation was successful or not.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
vtkTypeBool GetEventPending() override
Check to see if a mouse button has been pressed or mouse wheel activated.
vtkOpenGLRenderWindow * HelperWindow