VTK  9.4.20241112
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
134#ifndef vtkOpenVRRenderWindow_h
135#define vtkOpenVRRenderWindow_h
136
137#include "vtkEventData.h" // for enums
138#include "vtkOpenVROverlay.h" // used for ivars
139#include "vtkRenderingOpenVRModule.h" // For export macro
140#include "vtkSmartPointer.h" // used for ivars
141#include "vtkVRRenderWindow.h"
142
143#include <openvr.h> // for ivars
144
145VTK_ABI_NAMESPACE_BEGIN
146class vtkMatrix4x4;
147class vtkOpenVRModel;
148
149class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkVRRenderWindow
150{
151public:
154
158 static bool IsHMDPresent();
159
163 void Initialize() override;
164
170 void Finalize() override;
171
175 vr::IVRSystem* GetHMD() { return this->HMD; }
176
181
186 void Render() override;
187
192 void StereoMidpoint() override;
193
198 void StereoRenderComplete() override;
199
204
205 /*
206 * Get the overlay to use on the VR dashboard.
207 */
209
215 void UpdateHMDMatrixPose() override;
216
220 void SetMatrixFromOpenVRPose(vtkMatrix4x4* result, const vr::TrackedDevicePose_t& vrPose);
221
225 vr::IVRRenderModels* GetOpenVRRenderModels() { return this->OpenVRRenderModels; }
226
230 void RenderModels() override;
231
232 uint32_t GetDeviceHandleForOpenVRHandle(vr::TrackedDeviceIndex_t index);
233 vtkEventDataDevice GetDeviceForOpenVRHandle(vr::TrackedDeviceIndex_t ohandle);
234
236
241 void GetOpenVRPose(vtkEventDataDevice dev, vr::TrackedDevicePose_t** pose)
242 {
243 return this->GetOpenVRPose(dev, 0, pose);
244 }
245 void GetOpenVRPose(vtkEventDataDevice dev, uint32_t index, vr::TrackedDevicePose_t** pose);
247
248protected:
251
252 std::string GetWindowTitleFromAPI() override;
253 bool GetSizeFromAPI() override;
254
255 bool CreateFramebuffers(uint32_t viewCount = 2) override;
256 void RenderFramebuffer(FramebufferDesc& framebufferDesc) override;
257 bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc& framebufferDesc);
258
262 std::string GetTrackedDeviceString(vr::IVRSystem* pHmd, vr::TrackedDeviceIndex_t unDevice,
263 vr::TrackedDeviceProperty prop, vr::TrackedPropertyError* peError = nullptr);
264
268 vtkOpenVRModel* FindOrLoadRenderModel(const char* modelName);
269
271 vr::IVRSystem* HMD = nullptr;
272 vr::IVRRenderModels* OpenVRRenderModels = nullptr;
273 vr::TrackedDevicePose_t OpenVRTrackedDevicePoses[vr::k_unMaxTrackedDeviceCount];
274
275private:
277 void operator=(const vtkOpenVRRenderWindow&) = delete;
278};
279
280VTK_ABI_NAMESPACE_END
281#endif
represent and manipulate 4x4 transformation matrices
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::IVRSystem * GetHMD()
Get the system pointer.
static vtkOpenVRRenderWindow * New()
void RenderFramebuffer(FramebufferDesc &framebufferDesc) override
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override
Create an interactor specific to OpenVR to control renderers in this window.
void RenderModels() override
Render the controller and base station models.
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
uint32_t GetDeviceHandleForOpenVRHandle(vr::TrackedDeviceIndex_t index)
std::string GetWindowTitleFromAPI() override
vtkOpenVRModel * FindOrLoadRenderModel(const char *modelName)
Find a render model that has already been loaded or load a new one.
void GetOpenVRPose(vtkEventDataDevice dev, uint32_t index, vr::TrackedDevicePose_t **pose)
Get the most recent OpenVR pose for a given device.
bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc &framebufferDesc)
~vtkOpenVRRenderWindow() override
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.
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.
void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
void GetOpenVRPose(vtkEventDataDevice dev, vr::TrackedDevicePose_t **pose)
Get the most recent OpenVR pose for a given device.
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.
Hold a reference to a vtkObjectBase instance.
VR rendering window.
vtkEventDataDevice
platform-independent event data structures