VTK  9.1.0
vtkOpenVRRenderWindow.h
Go to the documentation of this file.
1/*=========================================================================
2
3Program: Visualization Toolkit
4
5Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6All rights reserved.
7See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9This software is distributed WITHOUT ANY WARRANTY; without even
10the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
150#ifndef vtkOpenVRRenderWindow_h
151#define vtkOpenVRRenderWindow_h
152
153#include "vtkRenderingOpenVRModule.h" // For export macro
154#include "vtkVRRenderWindow.h"
155
156#include "vtkEventData.h" // for enums
157#include "vtkOpenGLHelper.h" // used for ivars
158#include "vtk_glew.h" // used for methods
159#include <openvr.h> // for ivars
160#include <vector> // ivars
161
162class vtkCamera;
163class vtkMatrix4x4;
164class vtkOpenVRModel;
165class vtkOpenVROverlay;
167class vtkTransform;
168
169class VTKRENDERINGOPENVR_EXPORT vtkOpenVRRenderWindow : public vtkVRRenderWindow
170{
171public:
174
175 void Initialize(void) override;
176
177 void ReleaseGraphicsResources(vtkWindow* renWin) override;
178
182 vr::IVRSystem* GetHMD() { return this->HMD; }
183
184 static bool IsHMDPresent();
185
191
192 void Render() override;
193
198 void StereoMidpoint() override;
199
204 void StereoRenderComplete() override;
205
210
212 /*
213 * Set/Get the overlay to use on the VR dashboard
214 */
215 vtkGetObjectMacro(DashboardOverlay, vtkOpenVROverlay);
218
220
223 vtkGetMacro(BaseStationVisibility, bool);
224 vtkSetMacro(BaseStationVisibility, bool);
225 vtkBooleanMacro(BaseStationVisibility, bool);
227
233 void UpdateHMDMatrixPose() override;
234
236
241
245 vr::IVRRenderModels* GetOpenVRRenderModels() { return this->OpenVRRenderModels; }
246
250 vtkEventDataDevice GetDeviceFromDeviceIndex(vr::TrackedDeviceIndex_t index);
251
256 {
257 return this->GetTrackedDeviceIndexForDevice(dev, 0);
258 }
259 vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index);
261
265 vr::TrackedDevicePose_t* GetTrackedDevicePose(vtkEventDataDevice idx)
266 {
267 return this->GetTrackedDevicePose(idx, 0);
268 }
269 vr::TrackedDevicePose_t* GetTrackedDevicePose(vtkEventDataDevice idx, uint32_t index);
270 vr::TrackedDevicePose_t& GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
271 {
272 return this->TrackedDevicePose[idx];
273 }
274
278 void RenderModels() override;
279
281 vtkEventDataDevice device, vtkMatrix4x4* poseMatrixWorld) override;
282
283 void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t& tdPose,
284 vtkMatrix4x4* poseMatrixWorld, vtkMatrix4x4* poseMatrixPhysical = nullptr);
285
286protected:
289
290 std::string GetWindowTitleFromAPI() override;
291
292 bool GetSizeFromAPI() override;
293
295
296 vr::IVRSystem* HMD;
297 vr::IVRRenderModels* OpenVRRenderModels;
298
299 bool CreateFramebuffers() override;
300
301 bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc& framebufferDesc);
302
303 // convert a device index to a human string
304 std::string GetTrackedDeviceString(vr::IVRSystem* pHmd, vr::TrackedDeviceIndex_t unDevice,
305 vr::TrackedDeviceProperty prop, vr::TrackedPropertyError* peError = nullptr);
306
307 // devices may have polygonal models
308 // load them
309 vtkOpenVRModel* FindOrLoadRenderModel(const char* modelName);
310
311 vr::TrackedDevicePose_t TrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
312
314
315private:
317 void operator=(const vtkOpenVRRenderWindow&) = delete;
318};
319
320#endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:155
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
OpenVR device model.
OpenVR overlay.
OpenVR rendering window.
bool GetPoseMatrixWorldFromDevice(vtkEventDataDevice device, vtkMatrix4x4 *poseMatrixWorld) override
Store in poseMatrixWorld the pose matrix in world coordinate from an event data device.
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.
void ConvertOpenVRPoseToMatrices(const vr::TrackedDevicePose_t &tdPose, vtkMatrix4x4 *poseMatrixWorld, vtkMatrix4x4 *poseMatrixPhysical=nullptr)
static vtkOpenVRRenderWindow * New()
vr::TrackedDevicePose_t * GetTrackedDevicePose(vtkEventDataDevice idx, uint32_t index)
void SetDashboardOverlay(vtkOpenVROverlay *)
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev)
Get the index corresponding to the tracked device.
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override
Create an interactor to control renderers in this window.
void RenderModels() override
Render the controller and base station models.
vr::IVRRenderModels * GetOpenVRRenderModels()
Get the openVR Render Models.
bool CreateFramebuffers() override
vr::TrackedDevicePose_t * GetTrackedDevicePose(vtkEventDataDevice idx)
Get the most recent pose corresponding to the tracked device.
vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForDevice(vtkEventDataDevice dev, uint32_t index)
vr::TrackedDevicePose_t & GetTrackedDevicePose(vr::TrackedDeviceIndex_t idx)
std::string GetWindowTitleFromAPI() override
vtkOpenVRModel * FindOrLoadRenderModel(const char *modelName)
bool CreateOneFramebuffer(int nWidth, int nHeight, FramebufferDesc &framebufferDesc)
~vtkOpenVRRenderWindow() override
vtkEventDataDevice GetDeviceFromDeviceIndex(vr::TrackedDeviceIndex_t index)
Get the EventDataDevice corresponding to the OpenVR index.
uint32_t GetNumberOfTrackedDevicesForDevice(vtkEventDataDevice dev)
void StereoRenderComplete() override
Handles work required once both views have been rendered when using stereo rendering.
void ReleaseGraphicsResources(vtkWindow *renWin) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
void RenderOverlay()
Draw the overlay.
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx, uint32_t index) override
Get the VRModel corresponding to the tracked device.
std::string GetTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError=nullptr)
void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
void Initialize(void) override
Initialize the rendering window.
vtkOpenVROverlay * DashboardOverlay
vr::IVRRenderModels * OpenVRRenderModels
static bool IsHMDPresent()
platform-independent render window interaction including picking and frame rate control.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
VR device model.
Definition: vtkVRModel.h:41
VR rendering window.
vtkVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx)
Get the VRModel corresponding to the tracked device.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26