VTK  9.3.0
vtkOpenVRRenderWindow.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
44 #ifndef vtkOpenVRRenderWindow_h
45 #define vtkOpenVRRenderWindow_h
46 
47 #include "vtkEventData.h" // for enums
48 #include "vtkOpenVROverlay.h" // used for ivars
49 #include "vtkRenderingOpenVRModule.h" // For export macro
50 #include "vtkSmartPointer.h" // used for ivars
51 #include "vtkVRRenderWindow.h"
52 
53 #include <openvr.h> // for ivars
54 
55 VTK_ABI_NAMESPACE_BEGIN
56 class vtkMatrix4x4;
57 class vtkOpenVRModel;
58 
59 class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkVRRenderWindow
60 {
61 public:
64 
68  static bool IsHMDPresent();
69 
73  void Initialize() override;
74 
80  void Finalize() override;
81 
85  vr::IVRSystem* GetHMD() { return this->HMD; }
86 
91 
96  void Render() override;
97 
102  void StereoMidpoint() override;
103 
108  void StereoRenderComplete() override;
109 
114 
115  /*
116  * Get the overlay to use on the VR dashboard.
117  */
119 
125  void UpdateHMDMatrixPose() override;
126 
130  void SetMatrixFromOpenVRPose(vtkMatrix4x4* result, const vr::TrackedDevicePose_t& vrPose);
131 
135  vr::IVRRenderModels* GetOpenVRRenderModels() { return this->OpenVRRenderModels; }
136 
140  void RenderModels() override;
141 
142  uint32_t GetDeviceHandleForOpenVRHandle(vr::TrackedDeviceIndex_t index);
143  vtkEventDataDevice GetDeviceForOpenVRHandle(vr::TrackedDeviceIndex_t ohandle);
144 
145 protected:
148 
150  bool GetSizeFromAPI() override;
151 
152  bool CreateFramebuffers(uint32_t viewCount = 2) override;
153  void RenderFramebuffer(FramebufferDesc& framebufferDesc) override;
154  bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc& framebufferDesc);
155 
159  std::string GetTrackedDeviceString(vr::IVRSystem* pHmd, vr::TrackedDeviceIndex_t unDevice,
160  vr::TrackedDeviceProperty prop, vr::TrackedPropertyError* peError = nullptr);
161 
165  vtkOpenVRModel* FindOrLoadRenderModel(const char* modelName);
166 
168  vr::IVRSystem* HMD = nullptr;
169  vr::IVRRenderModels* OpenVRRenderModels = nullptr;
170 
171 private:
173  void operator=(const vtkOpenVRRenderWindow&) = delete;
174 };
175 
176 VTK_ABI_NAMESPACE_END
177 #endif
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
OpenVR device model.
OpenVR overlay.
OpenVR rendering window.
vtkEventDataDevice GetDeviceForOpenVRHandle(vr::TrackedDeviceIndex_t ohandle)
bool GetSizeFromAPI() override
Attempt to get the size of the display from the API and store it in this->Size.
void UpdateHMDMatrixPose() override
Update the HMD pose based on hardware pose and physical to world transform.
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
void RenderFramebuffer(FramebufferDesc &framebufferDesc) override
void RenderModels() override
Render the controller and base station models.
uint32_t GetDeviceHandleForOpenVRHandle(vr::TrackedDeviceIndex_t index)
std::string GetWindowTitleFromAPI() override
bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc &framebufferDesc)
~vtkOpenVRRenderWindow() override
static vtkOpenVRRenderWindow * New()
bool CreateFramebuffers(uint32_t viewCount=2) override
void StereoRenderComplete() override
Handles work required once both views have been rendered when using stereo rendering.
void SetMatrixFromOpenVRPose(vtkMatrix4x4 *result, const vr::TrackedDevicePose_t &vrPose)
Convert an OpenVR pose struct to a vtkMatrix4x4 object.
void RenderOverlay()
Draw the overlay.
void Finalize() override
Finalize the rendering window.
vtkSmartPointer< vtkOpenVROverlay > DashboardOverlay
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkGetSmartPointerMacro(DashboardOverlay, vtkOpenVROverlay)
void Initialize() override
Initialize the rendering window.
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override
Create an interactor specific to OpenVR to control renderers in this window.
std::string GetTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError=nullptr)
Convert a device index to a human-readable string.
vr::IVRSystem * GetHMD()
Get the system pointer.
vtkOpenVRModel * FindOrLoadRenderModel(const char *modelName)
Find a render model that has already been loaded or load a new one.
void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
static bool IsHMDPresent()
Returns true if the system believes that an HMD is present on the system.
platform-independent render window interaction including picking and frame rate control.
VR rendering window.
@ index
Definition: vtkX3D.h:246
@ string
Definition: vtkX3D.h:490
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:15